added handling of unselectable selectbox options
authorHolger Schemel <info@artsoft.org>
Wed, 8 Oct 2014 23:58:07 +0000 (01:58 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 8 Oct 2014 23:58:07 +0000 (01:58 +0200)
ChangeLog
src/conftime.h
src/editor.c
src/libgame/gadgets.c
src/libgame/gadgets.h

index 34e424d03a9cdff1568e4883ef22059f4dfaf6cd..95f6b4533ade63c6c77c5e1268514eceb5d20b23 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2014-10-08
+       * added handling of unselectable selectbox options and option headlines
+
 2014-10-07
        * fixed bug when changing between graphic sets with different tile size
        * cleanup of handling the various graphic sizes for different purposes
index 4ee3b39cdb96ffea6e6450280b62d21b8ddeb1c7..d765e4479605193824ea84adf8eb89b21878aba1 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2014-10-08 00:24"
+#define COMPILE_DATE_STRING "2014-10-09 01:55"
index e8bc4e2082506f97c110c19c1ef37fa74081eea5..206d1c1df6d0b00d5525ffdd938da0c0007a4098 100644 (file)
@@ -5786,9 +5786,11 @@ static void CreateSelectboxGadgets()
                      GDI_Y, y,
                      GDI_TYPE, GD_TYPE_SELECTBOX,
                      GDI_SELECTBOX_OPTIONS, selectbox_info[i].options,
+                     GDI_SELECTBOX_CHAR_UNSELECTABLE, '[',
                      GDI_TEXT_SIZE, selectbox_info[i].size,
                      GDI_TEXT_FONT, FONT_INPUT_1,
                      GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
+                     GDI_TEXT_FONT_UNSELECTABLE, FONT_TEXT_1,
                      GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
                      GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
                      GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
index 9c974b872ed91f485820fe4378e17478f19b9fd0..1c52ec5d422e5ce591426280d792a62af9871c49 100644 (file)
 
 #define GADGET_DEACTIVATED(g)  ((g)->x < 0 || (g)->y < 0)
 
+#define OPTION_TEXT_SELECTABLE(g, t)                                   \
+  (t[0] != g->selectbox.char_unselectable &&                           \
+   t[0] != '\0' &&                                                     \
+   !strEqual(t, " "))
+#define CURRENT_OPTION_SELECTABLE(g)                                   \
+  OPTION_TEXT_SELECTABLE(g, g->selectbox.options[g->selectbox.current_index].text)
+
 
 static struct GadgetInfo *gadget_list_first_entry = NULL;
 static struct GadgetInfo *gadget_list_last_entry = NULL;
@@ -404,7 +411,8 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
       {
        int i;
        char text[MAX_GADGET_TEXTSIZE + 1];
-       int font_nr = (pressed ? gi->font_active : gi->font);
+       int font_nr_default = (pressed ? gi->font_active : gi->font);
+       int font_nr = font_nr_default;
        int font_width = getFontWidth(font_nr);
        int font_height = getFontHeight(font_nr);
        int border_x = gi->border.xsize;
@@ -441,6 +449,10 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
                gi->selectbox.size);
        text[gi->selectbox.size] = '\0';
 
+       /* set font value */
+       font_nr = (OPTION_TEXT_SELECTABLE(gi, text) ? font_nr_default :
+                  gi->font_unselectable);
+
        /* gadget text value */
        DrawTextExt(drawto, gi->x + border_x, gi->y + border_y, text,
                    font_nr, BLIT_MASKED);
@@ -549,7 +561,11 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
            strncpy(text, gi->selectbox.options[i].text, gi->selectbox.size);
            text[gi->selectbox.size] = '\0';
 
-           if (i == gi->selectbox.current_index)
+           font_nr = (OPTION_TEXT_SELECTABLE(gi, text) ? font_nr_default :
+                      gi->font_unselectable);
+
+           if (i == gi->selectbox.current_index &&
+               OPTION_TEXT_SELECTABLE(gi, text))
            {
              FillRectangle(drawto,
                            gi->selectbox.x + border_x,
@@ -873,12 +889,18 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
        gi->font = va_arg(ap, int);
        if (gi->font_active == 0)
          gi->font_active = gi->font;
+       if (gi->font_unselectable == 0)
+         gi->font_unselectable = gi->font;
        break;
 
       case GDI_TEXT_FONT_ACTIVE:
        gi->font_active = va_arg(ap, int);
        break;
 
+      case GDI_TEXT_FONT_UNSELECTABLE:
+       gi->font_unselectable = va_arg(ap, int);
+       break;
+
       case GDI_SELECTBOX_OPTIONS:
        gi->selectbox.options = va_arg(ap, struct ValueTextInfo *);
        break;
@@ -887,6 +909,10 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
        gi->selectbox.index = va_arg(ap, int);
        break;
 
+      case GDI_SELECTBOX_CHAR_UNSELECTABLE:
+       gi->selectbox.char_unselectable = (char)va_arg(ap, int);
+       break;
+
       case GDI_DESIGN_UNPRESSED:
        gi->design[GD_BUTTON_UNPRESSED].bitmap = va_arg(ap, Bitmap *);
        gi->design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int);
@@ -1591,7 +1617,8 @@ boolean HandleGadgets(int mx, int my, int button)
     if (gi->type & GD_TYPE_SELECTBOX &&
        (keep_selectbox_open ||
         mouse_released_where_pressed ||
-        !gadget_released_inside_select_area))       /* selectbox stays open */
+        !gadget_released_inside_select_area ||
+        !CURRENT_OPTION_SELECTABLE(gi)))           /* selectbox stays open */
     {
       gi->selectbox.stay_open = TRUE;
       pressed_mx = 0;
@@ -1949,7 +1976,8 @@ boolean HandleGadgets(int mx, int my, int button)
     {
       if (keep_selectbox_open ||
          mouse_released_where_pressed ||
-         !gadget_released_inside_select_area)       /* selectbox stays open */
+         !gadget_released_inside_select_area ||
+         !CURRENT_OPTION_SELECTABLE(gi))           /* selectbox stays open */
       {
        deactivate_gadget = FALSE;
        gadget_changed = FALSE;
index 47de5776bf05761aea91167e1e5acfcac5b70000..5b41ba478afdcc7f86e51870b688c732b12ba396 100644 (file)
 #define GDI_TEXT_SIZE                  15
 #define GDI_TEXT_FONT                  16
 #define GDI_TEXT_FONT_ACTIVE           17
-#define GDI_SELECTBOX_OPTIONS          18
-#define GDI_SELECTBOX_INDEX            19
-#define GDI_DESIGN_UNPRESSED           20
-#define GDI_DESIGN_PRESSED             21
-#define GDI_ALT_DESIGN_UNPRESSED       22
-#define GDI_ALT_DESIGN_PRESSED         23
-#define GDI_BORDER_SIZE                        24
-#define GDI_BORDER_SIZE_SELECTBUTTON   25
-#define GDI_DESIGN_WIDTH               26
-#define GDI_DECORATION_DESIGN          27
-#define GDI_DECORATION_POSITION                28
-#define GDI_DECORATION_SIZE            29
-#define GDI_DECORATION_SHIFTING                30
-#define GDI_EVENT_MASK                 31
-#define GDI_EVENT                      32
-#define GDI_CALLBACK_INFO              33
-#define GDI_CALLBACK_ACTION            34
-#define GDI_AREA_SIZE                  35
-#define GDI_ITEM_SIZE                  36
-#define GDI_SCROLLBAR_ITEMS_MAX                37
-#define GDI_SCROLLBAR_ITEMS_VISIBLE    38
-#define GDI_SCROLLBAR_ITEM_POSITION    39
-#define GDI_WHEEL_AREA_X               40
-#define GDI_WHEEL_AREA_Y               41
-#define GDI_WHEEL_AREA_WIDTH           42
-#define GDI_WHEEL_AREA_HEIGHT          43
-#define GDI_INFO_TEXT                  44
-#define GDI_ACTIVE                     45
-#define GDI_DIRECT_DRAW                        46
+#define GDI_TEXT_FONT_UNSELECTABLE     18
+#define GDI_SELECTBOX_OPTIONS          19
+#define GDI_SELECTBOX_INDEX            20
+#define GDI_SELECTBOX_CHAR_UNSELECTABLE        21
+#define GDI_DESIGN_UNPRESSED           22
+#define GDI_DESIGN_PRESSED             23
+#define GDI_ALT_DESIGN_UNPRESSED       24
+#define GDI_ALT_DESIGN_PRESSED         25
+#define GDI_BORDER_SIZE                        26
+#define GDI_BORDER_SIZE_SELECTBUTTON   27
+#define GDI_DESIGN_WIDTH               28
+#define GDI_DECORATION_DESIGN          29
+#define GDI_DECORATION_POSITION                30
+#define GDI_DECORATION_SIZE            31
+#define GDI_DECORATION_SHIFTING                32
+#define GDI_EVENT_MASK                 33
+#define GDI_EVENT                      34
+#define GDI_CALLBACK_INFO              35
+#define GDI_CALLBACK_ACTION            36
+#define GDI_AREA_SIZE                  37
+#define GDI_ITEM_SIZE                  38
+#define GDI_SCROLLBAR_ITEMS_MAX                39
+#define GDI_SCROLLBAR_ITEMS_VISIBLE    40
+#define GDI_SCROLLBAR_ITEM_POSITION    41
+#define GDI_WHEEL_AREA_X               42
+#define GDI_WHEEL_AREA_Y               43
+#define GDI_WHEEL_AREA_WIDTH           44
+#define GDI_WHEEL_AREA_HEIGHT          45
+#define GDI_INFO_TEXT                  46
+#define GDI_ACTIVE                     47
+#define GDI_DIRECT_DRAW                        48
 
 /* gadget deactivation hack */
 #define GDI_ACTIVE_POS(a)              ((a) < 0 ? POS_OFFSCREEN : (a))
@@ -184,6 +186,7 @@ struct GadgetSelectbox
   struct ValueTextInfo *options;       /* pointer to text/value array */
   int index;                           /* index of actual text string */
   int size;                            /* maximal size of text strings */
+  char char_unselectable;              /* first char of unselectable options */
 
   /* automatically determined values */
   int x, y;                            /* open selectbox position */
@@ -235,6 +238,7 @@ struct GadgetInfo
   boolean direct_draw;                 /* directly draw to frontbuffer */
   int font;                            /* font to use when inactive */
   int font_active;                     /* font to use when active */
+  int font_unselectable;               /* font to use when unselectable */
   struct GadgetBorder border;          /* gadget border design */
   struct GadgetDesign design[2];       /* 0: normal; 1: pressed */
   struct GadgetDesign alt_design[2];   /* alternative design */