Fix awkward requirement for non-zero joystick axis value in gui_stick
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Tue, 9 Nov 2010 15:50:12 +0000 (15:50 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Tue, 9 Nov 2010 15:50:12 +0000 (15:50 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3350 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/main.c
ball/st_shared.c
ball/st_start.c
putt/main.c
putt/st_all.c
putt/st_conf.c
share/gui.c
share/st_resol.c

index 0c9c557..f384bcd 100644 (file)
@@ -153,16 +153,16 @@ static int loop(void)
             c = e.key.keysym.sym;
 
             if      (config_tst_d(CONFIG_KEY_FORWARD, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0);
 
             else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0);
 
             else if (config_tst_d(CONFIG_KEY_LEFT, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0);
 
             else if (config_tst_d(CONFIG_KEY_RIGHT, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0);
 
             else switch (c)
             {
@@ -231,11 +231,11 @@ static int loop(void)
 
                 if      (pad[0] && !pad[1]) st_stick(X, -JOY_MAX);
                 else if (pad[1] && !pad[0]) st_stick(X, +JOY_MAX);
-                else                        st_stick(X,        1);
+                else                        st_stick(X,        0);
 
                 if      (pad[2] && !pad[3]) st_stick(Y, -JOY_MAX);
                 else if (pad[3] && !pad[2]) st_stick(Y, +JOY_MAX);
-                else                        st_stick(Y,        1);
+                else                        st_stick(Y,        0);
             }
             else d = st_buttn(b, s);
         }
index 7e3994b..8a720aa 100644 (file)
@@ -41,11 +41,9 @@ void shared_timer(int id, float dt)
 
 int shared_point_basic(int id, int x, int y)
 {
-    /* Pulse, activate and return the active id (if changed) */
+    int jd;
 
-    int jd = gui_point(id, x, y);
-
-    if (jd)
+    if ((jd = gui_point(id, x, y)))
         gui_pulse(jd, 1.2f);
 
     return jd;
@@ -58,15 +56,9 @@ void shared_point(int id, int x, int y, int dx, int dy)
 
 int shared_stick_basic(int id, int a, int v)
 {
-    /* Pulse, activate and return the active id (if changed) */
-
-    int jd = 0;
+    int jd;
 
-    if      (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
-        jd = gui_stick(id, v, 0);
-    else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
-        jd = gui_stick(id, 0, v);
-    if (jd)
+    if ((jd = gui_stick(id, a, v)))
         gui_pulse(jd, 1.2f);
 
     return jd;
index 5caa4cd..adc318e 100644 (file)
@@ -270,10 +270,7 @@ static void start_point(int id, int x, int y, int dx, int dy)
 
 static void start_stick(int id, int a, int v)
 {
-    int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
-    int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
-
-    start_over(gui_stick(id, x, y), 1);
+    start_over(gui_stick(id, a, v), 1);
 }
 
 static int start_keybd(int c, int d)
index ac08e1c..18d2a05 100644 (file)
@@ -140,19 +140,17 @@ static int loop(void)
 
             c = e.key.keysym.sym;
 
-            /* gui_stick needs a non-null value, so we use 1 instead of 0. */
-
             if (config_tst_d(CONFIG_KEY_FORWARD, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0);
 
             else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0);
 
             else if (config_tst_d(CONFIG_KEY_LEFT, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0);
 
             else if (config_tst_d(CONFIG_KEY_RIGHT, c))
-                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
+                st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0);
 
             else switch (c)
             {
index e5213c0..11c8f2c 100644 (file)
@@ -157,14 +157,9 @@ static int score_card(const char  *title,
 
 static int shared_stick_basic(int id, int a, int v)
 {
-    int jd = 0;
-
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
-        jd = gui_stick(id, v, 0);
-    else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
-        jd = gui_stick(id, 0, v);
+    int jd;
 
-    if (jd)
+    if ((jd = gui_stick(id, a, v)))
         gui_pulse(jd, 1.2f);
 
     return jd;
@@ -916,9 +911,6 @@ static void stroke_point(int id, int x, int y, int dx, int dy)
 
 static void stroke_stick(int id, int a, int v)
 {
-    if (v == 1) /* See 'loop' in main.c */
-        v = 0;
-
     if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
         stroke_rotate = (6 * v) / JOY_MAX;
     else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
index 0fbffeb..7a1ee34 100644 (file)
@@ -273,10 +273,7 @@ static void conf_point(int id, int x, int y, int dx, int dy)
 
 static void conf_stick(int id, int a, int v)
 {
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
-        gui_pulse(gui_stick(id, v, 0), 1.2f);
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
-        gui_pulse(gui_stick(id, 0, v), 1.2f);
+    gui_pulse(gui_stick(id, a, v), 1.2f);
 }
 
 static int conf_click(int b, int d)
index c758574..4d390c1 100644 (file)
@@ -1829,25 +1829,30 @@ void gui_stuck()
     yflag = 0;
 }
 
-int gui_stick(int id, int x, int y)
+int gui_stick(int id, int a, int v)
 {
     int jd = 0;
 
     /* Find a new active widget in the direction of joystick motion. */
 
-    if (x && -JOY_MID <= x && x <= +JOY_MID)
-        xflag = 1;
-    else if (x < -JOY_MID && xflag && (jd = gui_wrap_L(id, active)))
-        xflag = 0;
-    else if (x > +JOY_MID && xflag && (jd = gui_wrap_R(id, active)))
-        xflag = 0;
-
-    if (y && -JOY_MID <= y && y <= +JOY_MID)
-        yflag = 1;
-    else if (y < -JOY_MID && yflag && (jd = gui_wrap_U(id, active)))
-        yflag = 0;
-    else if (y > +JOY_MID && yflag && (jd = gui_wrap_D(id, active)))
-        yflag = 0;
+    if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
+    {
+        if (-JOY_MID <= v && v <= +JOY_MID)
+            xflag = 1;
+        else if (v < -JOY_MID && xflag && (jd = gui_wrap_L(id, active)))
+            xflag = 0;
+        else if (v > +JOY_MID && xflag && (jd = gui_wrap_R(id, active)))
+            xflag = 0;
+    }
+    else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
+    {
+        if (-JOY_MID <= v && v <= +JOY_MID)
+            yflag = 1;
+        else if (v < -JOY_MID && yflag && (jd = gui_wrap_U(id, active)))
+            yflag = 0;
+        else if (v > +JOY_MID && yflag && (jd = gui_wrap_D(id, active)))
+            yflag = 0;
+    }
 
     /* If the active widget has changed, return the new active id. */
 
index 9a1ff7f..701e86b 100644 (file)
@@ -156,10 +156,7 @@ static void resol_point(int id, int x, int y, int dx, int dy)
 
 static void resol_stick(int id, int a, int v)
 {
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
-        gui_pulse(gui_stick(id, v, 0), 1.2f);
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
-        gui_pulse(gui_stick(id, 0, v), 1.2f);
+    gui_pulse(gui_stick(id, a, v), 1.2f);
 }
 
 static int resol_click(int b, int d)