Convert all path-related (body, switch) logic to use integer milliseconds
[neverball] / share / gui.c
index 8b10b1a..a942126 100644 (file)
@@ -46,6 +46,8 @@
 #define GUI_CLOCK  18
 #define GUI_SPACE  20
 
+#define GUI_LINES 8
+
 struct widget
 {
     int     type;
@@ -616,25 +618,29 @@ void gui_set_multi(int id, const char *text)
 {
     const char *p;
 
-    char s[8][MAXSTR];
-    int  i, j, jd;
+    char s[GUI_LINES][MAXSTR];
+    int i, sc, lc, jd;
 
     size_t n = 0;
 
+    /* Count available labels. */
+
+    for (lc = 0, jd = widget[id].car; jd; lc++, jd = widget[jd].cdr);
+
     /* Copy each delimited string to a line buffer. */
 
-    for (p = text, j = 0; *p && j < 8; j++)
+    for (p = text, sc = 0; *p && sc < lc; sc++)
     {
-        strncpy(s[j], p, (n = strcspn(p, "\\")));
-        s[j][n] = 0;
+        strncpy(s[sc], p, (n = strcspn(p, "\\")));
+        s[sc][n] = 0;
 
         if (*(p += n) == '\\') p++;
     }
 
     /* Set the label value for each line. */
 
-    for (i = j - 1, jd = widget[id].car; i >= 0 && jd; i--, jd = widget[jd].cdr)
-        gui_set_label(jd, s[i]);
+    for (i = lc - 1, jd = widget[id].car; i >= 0; i--, jd = widget[jd].cdr)
+        gui_set_label(jd, i < sc ? s[i] : "");
 }
 
 void gui_set_trunc(int id, enum trunc trunc)
@@ -752,6 +758,7 @@ int gui_space(int pd)
 }
 
 /*---------------------------------------------------------------------------*/
+
 /*
  * Create  a multi-line  text box  using a  vertical array  of labels.
  * Parse the  text for '\'  characters and treat them  as line-breaks.
@@ -767,15 +774,15 @@ int gui_multi(int pd, const char *text, int size, int rect, const float *c0,
     {
         const char *p;
 
-        char s[8][MAXSTR];
-        int  r[8];
+        char s[GUI_LINES][MAXSTR];
+        int  r[GUI_LINES];
         int  i, j;
 
         size_t n = 0;
 
         /* Copy each delimited string to a line buffer. */
 
-        for (p = text, j = 0; *p && j < 8; j++)
+        for (p = text, j = 0; *p && j < GUI_LINES; j++)
         {
             strncpy(s[j], p, (n = strcspn(p, "\\")));
             s[j][n] = 0;
@@ -1816,42 +1823,24 @@ static int gui_wrap_D(int id, int dd)
 
 /*---------------------------------------------------------------------------*/
 
-/* Flag the axes to prevent uncontrolled scrolling. */
-
-static int xflag = 1;
-static int yflag = 1;
-
-void gui_stuck()
-{
-    /* Force the user to recenter the joystick before the next GUI action. */
-
-    xflag = 0;
-    yflag = 0;
-}
-
-int gui_stick(int id, int a, float v)
+int gui_stick(int id, int a, float v, int bump)
 {
     int jd = 0;
 
+    if (!bump)
+        return 0;
+
     /* Find a new active widget in the direction of joystick motion. */
 
     if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
     {
-        if (-0.5f <= v && v <= +0.5f)
-            xflag = 1;
-        else if (v < -0.5f && xflag && (jd = gui_wrap_L(id, active)))
-            xflag = 0;
-        else if (v > +0.5f && xflag && (jd = gui_wrap_R(id, active)))
-            xflag = 0;
+        if (v < 0) jd = gui_wrap_L(id, active);
+        if (v > 0) jd = gui_wrap_R(id, active);
     }
     else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
     {
-        if (-0.5f <= v && v <= +0.5f)
-            yflag = 1;
-        else if (v < -0.5f && yflag && (jd = gui_wrap_U(id, active)))
-            yflag = 0;
-        else if (v > +0.5f && yflag && (jd = gui_wrap_D(id, active)))
-            yflag = 0;
+        if (v < 0) jd = gui_wrap_U(id, active);
+        if (v > 0) jd = gui_wrap_D(id, active);
     }
 
     /* If the active widget has changed, return the new active id. */