Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2003:
[Freeciv-Dev] (PR#3608) Convert to enums and make code typesafe
Home

[Freeciv-Dev] (PR#3608) Convert to enums and make code typesafe

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#3608) Convert to enums and make code typesafe
From: "Raimar Falke" <rf13@xxxxxxxxxxxxxxxxx>
Date: Tue, 4 Mar 2003 07:08:16 -0800
Reply-to: rt@xxxxxxxxxxxxxx


See $SUBJECT.

Rafal please apply.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Just because you put a flag on the moon doesn't make it yours, it just
  puts a hole in the moon."

diff -Nurd -X clean/diff_ignore sdl_base/client/gui-sdl/gui_stuff.c 
sdl_mod/client/gui-sdl/gui_stuff.c
--- sdl_base/client/gui-sdl/gui_stuff.c Sun Mar  2 18:31:04 2003
+++ sdl_mod/client/gui-sdl/gui_stuff.c  Tue Mar  4 14:47:20 2003
@@ -1009,7 +1009,8 @@
   ...
 **************************************************************************/
 void set_group_state(struct GUI *pBeginGroupWidgetList,
-                    struct GUI *pEndGroupWidgetList, enum WState state)
+                    struct GUI *pEndGroupWidgetList,
+                    enum widget_state state)
 {
   struct GUI *pTmpWidget = pEndGroupWidgetList;
   while (pTmpWidget) {
@@ -3965,3 +3966,38 @@
 
   return ret;
 }
+
+void set_wstate(struct GUI *pwidget, enum widget_state state)
+{
+  pwidget->state = state;
+}
+
+void set_wtype(struct GUI *pwidget, enum widget_type type)
+{
+  pwidget->type = type;
+}
+
+void set_wflag(struct GUI *pwidget, enum widget_flag flag)
+{
+  pwidget->flags = SET_BIT(pwidget->flags, flag);
+}
+
+void clear_wflag(struct GUI *pwidget, enum widget_flag flag)
+{
+  pwidget->flags = CLEAR_BIT(pwidget->flags, flag);
+}
+
+enum widget_state get_wstate(const struct GUI *pwidget)
+{
+  return pwidget->state;
+}
+
+enum widget_type get_wtype(const struct GUI *pwidget)
+{
+  return pwidget->type;
+}
+
+enum widget_flag get_wflags(const struct GUI *pwidget)
+{
+  return pwidget->flags;
+}
diff -Nurd -X clean/diff_ignore sdl_base/client/gui-sdl/gui_stuff.h 
sdl_mod/client/gui-sdl/gui_stuff.h
--- sdl_base/client/gui-sdl/gui_stuff.h Mon Feb 24 17:29:19 2003
+++ sdl_mod/client/gui-sdl/gui_stuff.h  Tue Mar  4 14:36:33 2003
@@ -28,59 +28,66 @@
 #define        FRAME_WH                3
 #define        DOUBLE_FRAME_WH         6
 
-#define STATE_MASK             0x03
-#define TYPE_MASK              0x03FC
-#define FLAG_MASK              0xFFFFFC00
-
 #define MAX_ID                 0xFFFF
 /* Text cetnter flags has been moved to 'string16->style' */
 
+enum widget_flag {
 /* Widget FLAGS -> allowed 20 flags */
 /* default: ICON_CENTER_Y, ICON_ON_LEFT */
-#define WF_HIDDEN                      0x400   /* 1024 */
-#define WF_FREE_GFX                    0x800   /* 2048 */
-#define WF_FREE_THEME                  0x1000  /* 4096 */
-#define WF_FREE_STRING                 0x2000  /* 8192 */
-#define WF_DRAW_THEME_TRANSPARENT      0x4000  /* 16384 */
-#define WF_ICON_ABOVE_TEXT             0x8000  /* 32768 */
-#define WF_ICON_UNDER_TEXT             0x10000 /* 65536 */
-#define WF_ICON_CENTER                 0x20000 /* 131072 */
-#define WF_ICON_CENTER_RIGHT           0x40000 /* 262144 */
-#define WF_WIDGET_HAS_INFO_LABEL       0x80000 /* 524288 */
-#define WF_DRAW_FRAME_AROUND_WIDGET    0x100000 /* 1048576 */
-#define WF_DRAW_TEXT_LABEL_WITH_SPACE  0x200000 /* 2097152 */
-#define WF_FREE_DATA                   0x400000 /* # */
-#define WF_SELLECT_WITHOUT_BAR         0x800000 /* # */
+  WF_HIDDEN,
+  WF_FREE_GFX,
+  WF_FREE_THEME,
+  WF_FREE_STRING,
+  WF_DRAW_THEME_TRANSPARENT,
+  WF_ICON_ABOVE_TEXT,
+  WF_ICON_UNDER_TEXT,
+  WF_ICON_CENTER,
+  WF_ICON_CENTER_RIGHT,
+  WF_WIDGET_HAS_INFO_LABEL,
+  WF_DRAW_FRAME_AROUND_WIDGET,
+  WF_DRAW_TEXT_LABEL_WITH_SPACE,
+  WF_FREE_DATA,
+  WF_SELLECT_WITHOUT_BAR
+};
 
 /* Widget states */
-enum WState {
-  WS_NORMAL = 0,
-  WS_SELLECTED = 1,
-  WS_PRESSED = 2,
-  WS_DISABLED = 3
+enum widget_state {
+  WS_NORMAL,
+  WS_SELLECTED,
+  WS_PRESSED,
+  WS_DISABLED
 };
 
 /* Widget Types */
-enum WTypes {                  /* allow 64 widgets type */
-  WT_BUTTON = 4,               /* Button with Text (not use !!!)
-                                  ( can be transparent ) */
-  WT_I_BUTTON = 8,             /* Button with TEXT and ICON
-                                  ( static; can't be transp. ) */
-  WT_TI_BUTTON = 12,           /* Button with TEXT and ICON
-                                  (themed; can't be transp. ) */
-  WT_EDIT = 16,                        /* edit field   */
-  WT_ICON = 20,                        /* flat Button from 4 - state icon */
-  WT_VSCROLLBAR = 24,          /* bugy */
-  WT_HSCROLLBAR = 28,          /* not use (Not DEFINED !!) */
-  WT_WINDOW = 32,
-  WT_T_LABEL = 36,             /* text label with theme backgroud */
-  WT_I_LABEL = 40,             /* text label with icon */
-  WT_TI_LABEL = 44,            /* text label with icon and theme backgroud.
-                                  NOTE: Not DEFINED- don't use
-                                  ( can't be transp. ) */
-  WT_CHECKBOX = 48,            /* checkbox. */
-  WT_TCHECKBOX = 52,           /* text label with checkbox. */
-  WT_ICON2 = 56                        /* flat Button from 1 - state icon */
+enum widget_type {
+  /* Button with Text (not use !!!)  ( can be transparent ) */
+  WT_BUTTON,
+  /* Button with TEXT and ICON ( static; can't be transp. ) */
+  WT_I_BUTTON,
+  /* Button with TEXT and ICON (themed; can't be transp. ) */
+  WT_TI_BUTTON,
+  /* edit field   */
+  WT_EDIT,
+  /* flat Button from 4 - state icon */
+  WT_ICON,
+  /* bugy, not use (Not DEFINED !!)  */
+  WT_VSCROLLBAR,
+  /* bugy, not use (Not DEFINED !!)  */
+  WT_HSCROLLBAR,
+  WT_WINDOW,
+  /* text label with theme backgroud */
+  WT_T_LABEL,
+  /* text label with icon */
+  WT_I_LABEL,
+  /* text label with icon and theme backgroud.  NOTE: Not DEFINED-
+     don't use ( can't be transp. ) */
+  WT_TI_LABEL,
+  /* checkbox. */
+  WT_CHECKBOX,
+  /* text label with checkbox. */
+  WT_TCHECKBOX,
+  /* flat Button from 1 - state icon */
+  WT_ICON2
 };
 
 struct ScrollBar {
@@ -104,8 +111,10 @@
   SDL_String16 *string16;
   
   void *data;
-  
-  Uint32 state_types_flags;    /* "packed" widget info */
+
+  enum widget_type type;
+  enum widget_state state;
+  enum widget_flag flags;
 
   SDL_Rect size;               /* size.w and size.h are the size of widget   
                                   size.x and size.y are the draw pozitions. */
@@ -176,7 +185,8 @@
                                     struct GUI *pEndGroupWidgetList);
 
 void set_group_state(struct GUI *pBeginGroupWidgetList,
-                    struct GUI *pEndGroupWidgetList, enum WState state);
+                    struct GUI *pEndGroupWidgetList,
+                    enum widget_state state);
 
 void show_group(struct GUI *pBeginGroupWidgetList,
                struct GUI *pEndGroupWidgetList);
@@ -302,34 +312,6 @@
 bool get_checkbox_state(struct GUI *pCBox);
 int redraw_textcheckbox(struct GUI *pCBox, SDL_Surface *pDest);
 
-#define set_wstate(pWidget, state)             \
-do {                                           \
-  pWidget->state_types_flags &= ~STATE_MASK;   \
-  pWidget->state_types_flags |= state;         \
-} while(0)
-
-#define set_wtype(pWidget, type)               \
-do {                                           \
-  pWidget->state_types_flags &= ~TYPE_MASK;    \
-  pWidget->state_types_flags |= type;          \
-} while(0)
-
-#define set_wflag(pWidget, flag)       \
-       (pWidget)->state_types_flags |= ((flag) & FLAG_MASK)
-
-#define clear_wflag(pWidget, flag)     \
-       (pWidget)->state_types_flags &= ~((flag) & FLAG_MASK)
-
-#define get_wstate(pWidget)                            \
-       fc__extension(pWidget->state_types_flags & STATE_MASK)
-
-#define get_wtype(pWidget)                             \
-       fc__extension(pWidget->state_types_flags & TYPE_MASK)
-
-#define get_wflags(pWidget)                            \
-       fc__extension(pWidget->state_types_flags & FLAG_MASK)
-
-
 #define FREEWIDGET(pGUI)                       \
 do {                                           \
   if (get_wflags(pGUI) & WF_FREE_STRING) {     \
@@ -476,4 +458,12 @@
 #define create_iconlabel_from_chars(pIcon, pCharString, iPtsize, flags) \
        create_iconlabel(pIcon, create_str16_from_char(pCharString, iPtsize), 
flags)
 
+void set_wstate(struct GUI *pwidget, enum widget_state state);
+void set_wtype(struct GUI *pwidget, enum widget_type type);
+void set_wflag(struct GUI *pwidget, enum widget_flag flag);
+void clear_wflag(struct GUI *pwidget, enum widget_flag flag);
+enum widget_state get_wstate(const struct GUI *pwidget);
+enum widget_type get_wtype(const struct GUI *pwidget);
+enum widget_flag get_wflags(const struct GUI *pwidget);
+
 #endif                         /* FC__GUI_STUFF_H */
diff -Nurd -X clean/diff_ignore sdl_base/common/shared.h sdl_mod/common/shared.h
--- sdl_base/common/shared.h    Fri Feb 28 09:58:52 2003
+++ sdl_mod/common/shared.h     Tue Mar  4 14:41:23 2003
@@ -102,6 +102,9 @@
  */
 #define TEST_BIT(val, bit_no)          (((val) & (1u << (bit_no))) == (1u << 
(bit_no)))
 
+#define SET_BIT(val, bit_no)           ((val) | (1u << (bit_no)))
+#define CLEAR_BIT(val, bit_no)         ((val) & (~(1u << (bit_no))))
+
 /*
  * If cond is TRUE it yields a value where only the bit bit_no is
  * set. If cond is FALSE it yields 0.

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#3608) Convert to enums and make code typesafe, Raimar Falke <=