X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=6c394d7ab2a6993ad080bc7a2b51de61aebd95ba;hb=3bb225da5092d0741870829d9f8f8642070d29c5;hp=cbe1cabc2e23200c04961b7733fa49ce4db9fa99;hpb=1651b494b33800344452c3e88fa54412063393ab;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index cbe1cabc..6c394d7a 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -4,7 +4,7 @@ // (c) 1995-2014 by Artsoft Entertainment // Holger Schemel // info@artsoft.org -// http://www.artsoft.org/ +// https://www.artsoft.org/ // ---------------------------------------------------------------------------- // gadgets.c // ============================================================================ @@ -78,7 +78,7 @@ static int getNewGadgetID(void) } if (next_free_gadget_id <= 0) // cannot get new gadget id - Error(ERR_EXIT, "too much gadgets -- this should not happen"); + Fail("too much gadgets -- this should not happen"); return id; } @@ -1207,7 +1207,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) break; default: - Error(ERR_EXIT, "HandleGadgetTags(): unknown tag %d", tag); + Fail("HandleGadgetTags(): unknown tag %d", tag); } tag = va_arg(ap, int); // read next tag @@ -1268,7 +1268,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) gi->height = 2 * border_ysize + font_height; if (gi->selectbox.options == NULL) - Error(ERR_EXIT, "selectbox gadget incomplete (missing options array)"); + Fail("selectbox gadget incomplete (missing options array)"); gi->selectbox.num_values = 0; while (gi->selectbox.options[gi->selectbox.num_values].text != NULL) @@ -1330,7 +1330,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) if (gi->width == 0 || gi->height == 0 || gs->items_max == 0 || gs->items_visible == 0) - Error(ERR_EXIT, "scrollbar gadget incomplete (missing tags)"); + Fail("scrollbar gadget incomplete (missing tags)"); // calculate internal scrollbar values gs->size_min = (gi->type == GD_TYPE_SCROLLBAR_VERTICAL ? @@ -1711,7 +1711,7 @@ boolean HandleGadgets(int mx, int my, int button) struct GadgetInfo *gi = last_gi; boolean gadget_changed = ((gi->event_mask & GD_EVENT_TEXT_LEAVING) != 0); - // check if text gadget has changed its value + // check if text input gadget has changed its value if (gi->type & GD_TYPE_TEXT_INPUT) { CheckRangeOfNumericInputGadget(gi); @@ -1722,6 +1722,15 @@ boolean HandleGadgets(int mx, int my, int button) gadget_changed = FALSE; } + // check if text area gadget has changed its value + if (gi->type & GD_TYPE_TEXT_AREA) + { + if (!strEqual(gi->textarea.last_value, gi->textarea.value)) + strcpy(gi->textarea.last_value, gi->textarea.value); + else + gadget_changed = FALSE; + } + // selectbox does not change its value when closed by clicking outside if (gi->type & GD_TYPE_SELECTBOX) gadget_changed = FALSE; @@ -2228,12 +2237,34 @@ boolean HandleGadgetsKeyInput(Key key) { if (anyTextGadgetActive()) { + boolean gadget_changed = ((gi->event_mask & GD_EVENT_TEXT_LEAVING) != 0); + // restore previous text (before activating text gadget) if (gi->type & GD_TYPE_TEXT_INPUT) + { strcpy(gi->textinput.value, gi->textinput.last_value); + CheckRangeOfNumericInputGadget(gi); + } + + // store current text for text area gadgets when pressing "Escape" key + if (gi->type & GD_TYPE_TEXT_AREA) + { + if (!strEqual(gi->textarea.last_value, gi->textarea.value)) + strcpy(gi->textarea.last_value, gi->textarea.value); + else + gadget_changed = FALSE; + } + DrawGadget(gi, DG_UNPRESSED, gi->direct_draw); + if (gi->type & GD_TYPE_TEXT_AREA) + { + gi->event.type = GD_EVENT_TEXT_LEAVING; + + DoGadgetCallbackAction(gi, gadget_changed); + } + last_gi = NULL; StopTextInput();