From: Holger Schemel Date: Sat, 29 Sep 2018 08:28:11 +0000 (+0200) Subject: added gadget tag to always execute the callback action when leaving gadget X-Git-Tag: 4.1.1.0~23 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7ae99e1573d948cb3e8ae98e6e7adb746956bdc3;p=rocksndiamonds.git added gadget tag to always execute the callback action when leaving gadget --- diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 64f0e0a9..937f7a3a 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -213,6 +213,12 @@ static void default_callback_action(void *ptr) return; } +static void DoGadgetCallbackAction(struct GadgetInfo *gi, boolean changed) +{ + if (changed || gi->callback_action_always) + gi->callback_action(gi); +} + static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) { struct GadgetDesign *gd; @@ -841,6 +847,10 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) gi->direct_draw = (boolean)va_arg(ap, int); break; + case GDI_CALLBACK_ACTION_ALWAYS: + gi->callback_action_always = (boolean)va_arg(ap, int); + break; + case GDI_CHECKED: gi->checked = (boolean)va_arg(ap, int); break; @@ -1611,8 +1621,8 @@ boolean HandleGadgets(int mx, int my, int button) gi->event.type = GD_EVENT_TEXT_LEAVING; - if (gadget_changed && !(gi->type & GD_TYPE_SELECTBOX)) - gi->callback_action(gi); + if (!(gi->type & GD_TYPE_SELECTBOX)) + DoGadgetCallbackAction(gi, gadget_changed); last_gi = NULL; @@ -1865,8 +1875,8 @@ boolean HandleGadgets(int mx, int my, int button) gi->event.type = GD_EVENT_MOVING; gi->event.off_borders = FALSE; - if (gi->event_mask & GD_EVENT_MOVING && changed_position) - gi->callback_action(gi); + if (gi->event_mask & GD_EVENT_MOVING) + DoGadgetCallbackAction(gi, changed_position); return TRUE; } @@ -2021,9 +2031,9 @@ boolean HandleGadgets(int mx, int my, int button) gi->event.type = GD_EVENT_MOVING; gi->event.off_borders = gadget_moving_off_borders; - if (gi->event_mask & GD_EVENT_MOVING && changed_position && + if (gi->event_mask & GD_EVENT_MOVING && (gadget_moving_inside || gi->event_mask & GD_EVENT_OFF_BORDERS)) - gi->callback_action(gi); + DoGadgetCallbackAction(gi, changed_position); } if (gadget_released_inside) @@ -2055,10 +2065,8 @@ boolean HandleGadgets(int mx, int my, int button) gi->state = GD_BUTTON_UNPRESSED; gi->event.type = GD_EVENT_RELEASED; - if ((gi->event_mask & GD_EVENT_RELEASED) && gadget_changed) - { - gi->callback_action(gi); - } + if ((gi->event_mask & GD_EVENT_RELEASED)) + DoGadgetCallbackAction(gi, gadget_changed); } if (gadget_released_off_borders) @@ -2149,8 +2157,7 @@ boolean HandleGadgetsKeyInput(Key key) last_gi = NULL; } - if (gadget_changed) - gi->callback_action(gi); + DoGadgetCallbackAction(gi, gadget_changed); } else if (gi->type & GD_TYPE_TEXT_INPUT) /* only valid for text input */ { diff --git a/src/libgame/gadgets.h b/src/libgame/gadgets.h index 3cfd3dbb..5f873747 100644 --- a/src/libgame/gadgets.h +++ b/src/libgame/gadgets.h @@ -112,6 +112,7 @@ #define GDI_INFO_TEXT 48 #define GDI_ACTIVE 49 #define GDI_DIRECT_DRAW 50 +#define GDI_CALLBACK_ACTION_ALWAYS 51 /* gadget deactivation hack */ #define GDI_ACTIVE_POS(a) ((a) < 0 ? POS_OFFSCREEN : (a)) @@ -244,6 +245,7 @@ struct GadgetInfo boolean mapped; /* gadget is mapped on the screen */ boolean active; /* gadget is active */ boolean direct_draw; /* directly draw to frontbuffer */ + boolean callback_action_always; /* also callback if gadget unchanged */ int font; /* font to use when inactive */ int font_active; /* font to use when active */ int font_unselectable; /* font to use when unselectable */