Rework ball/util widget token policy
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 15 Aug 2008 23:50:10 +0000 (23:50 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 15 Aug 2008 23:50:10 +0000 (23:50 +0000)
Instead of using large negative values for the on-screen keyboard and
score board widget tokens, this patch introduces a "GUI bit" (the low
bit of the most significant byte of a 4-byte integer) which is ORed
with small integer values to obtain the final token values.  This is
done mainly to allow some of these tokens to be ORed with each other.

git-svn-id: https://s.snth.net/svn/neverball/trunk@2460 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/st_name.c
ball/st_save.c
ball/st_start.c
ball/util.h

index 758ed93..b454745 100644 (file)
@@ -48,8 +48,8 @@ int goto_name(struct state *ok, struct state *cancel, unsigned int back)
 
 /*---------------------------------------------------------------------------*/
 
-#define NAME_OK     1
-#define NAME_CANCEL 2
+#define NAME_OK     -1
+#define NAME_CANCEL -2
 
 static int name_id;
 
@@ -172,9 +172,10 @@ static int name_buttn(int b, int d)
         {
             int c = gui_token(gui_click());
 
-            /* Ugh.  This is such a hack. */
-
-            return name_action(isupper(c) ? gui_keyboard_char(c) : c);
+            if (c >= 0 && !GUI_ISMSK(c))
+                return name_action(gui_keyboard_char(c));
+            else
+                return name_action(c);
         }
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
             name_action(NAME_CANCEL);
index 01c7706..509eb94 100644 (file)
@@ -57,8 +57,8 @@ int goto_save(struct state *ok, struct state *cancel)
 
 static int file_id;
 
-#define SAVE_SAVE   1
-#define SAVE_CANCEL 2
+#define SAVE_SAVE   -1
+#define SAVE_CANCEL -2
 
 static int save_action(int i)
 {
@@ -162,9 +162,10 @@ static int save_buttn(int b, int d)
         {
             int c = gui_token(gui_click());
 
-            /* Ugh.  This is such a hack. */
-
-            return save_action(isupper(c) ? gui_keyboard_char(c) : c);
+            if (c >= 0 && !GUI_ISMSK(c))
+                return save_action(gui_keyboard_char(c));
+            else
+                return save_action(c);
         }
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
             return save_action(SAVE_CANCEL);
index 1686829..7d7b1fe 100644 (file)
@@ -102,7 +102,7 @@ static void start_over(int id, int pulse)
                         set_time_score(curr_set()), -1);
     }
 
-    if (i >= 0)
+    if (i >= 0 && !GUI_ISMSK(i))
         start_over_level(i);
 }
 
index 571c0ea..064aebc 100644 (file)
@@ -5,18 +5,23 @@
 
 /*---------------------------------------------------------------------------*/
 
-#define GUI_NULL -100
-#define GUI_BACK -101
-#define GUI_PREV -102
-#define GUI_NEXT -103
-#define GUI_BS   -104
-#define GUI_CL   -105
-
-#define GUI_MOST_COINS  -106
-#define GUI_BEST_TIMES  -107
-#define GUI_UNLOCK_GOAL -108
-
-#define GUI_NAME -109
+#define GUI_BIT      (1 << 24)
+
+#define GUI_MSK(i)   ((i) | GUI_BIT)
+#define GUI_UNMSK(i) ((i) & ~GUI_BIT)
+#define GUI_ISMSK(i) ((i) & GUI_BIT ? 1 : 0)
+
+#define GUI_NULL GUI_MSK(0)
+#define GUI_BACK GUI_MSK(1)
+#define GUI_PREV GUI_MSK(2)
+#define GUI_NEXT GUI_MSK(3)
+#define GUI_BS   GUI_MSK(4)
+#define GUI_CL   GUI_MSK(5)
+#define GUI_NAME GUI_MSK(6)
+
+#define GUI_MOST_COINS  GUI_MSK(8)
+#define GUI_BEST_TIMES  GUI_MSK(16)
+#define GUI_UNLOCK_GOAL GUI_MSK(32)
 
 void gui_score_set(int);
 int  gui_score_get(void);