X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=94fe74551cdd58ed60a001afd742c412cc2e1735;hb=77c205677b99af7f0dd31e8833887d75e89db7d1;hp=3ac1f9d55fdc5c100d29409e7fd244f367e66f94;hpb=b641818c787e48bbf03ce2a0cd5b542c4c21e523;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 3ac1f9d5..94fe7455 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/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; } @@ -423,9 +423,9 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->height - 2 * border_y); // gadget text value - DrawTextBuffer(gi->x + border_x, gi->y + border_y, gi->textarea.value, - font_nr, gi->textarea.xsize, -1, gi->textarea.ysize, 0, - BLIT_ON_BACKGROUND, FALSE, FALSE, FALSE); + DrawTextArea(gi->x + border_x, gi->y + border_y, gi->textarea.value, + font_nr, gi->textarea.xsize, -1, gi->textarea.ysize, 0, + BLIT_ON_BACKGROUND, FALSE, FALSE, FALSE); cursor_letter = gi->textarea.value[gi->textarea.cursor_position]; cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' '); @@ -879,7 +879,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) { int tag = first_tag; - if (gi == NULL || gi->deactivated) + if (gi == NULL) return; while (tag != GDI_END) @@ -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 ? @@ -1629,8 +1629,7 @@ void ClickOnGadget(struct GadgetInfo *gi, int button) boolean HandleGadgets(int mx, int my, int button) { - static unsigned int pressed_delay = 0; - static unsigned int pressed_delay_value = GADGET_FRAME_DELAY; + static DelayCounter pressed_delay = { GADGET_FRAME_DELAY }; static int last_button = 0; static int last_mx = 0, last_my = 0; static int pressed_mx = 0, pressed_my = 0; @@ -1711,7 +1710,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 +1721,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; @@ -1747,7 +1755,7 @@ boolean HandleGadgets(int mx, int my, int button) (button != 0 && last_gi != NULL && new_gi == last_gi); gadget_pressed_delay_reached = - DelayReached(&pressed_delay, pressed_delay_value); + DelayReached(&pressed_delay); gadget_released = (release_event && last_gi != NULL); gadget_released_inside = (gadget_released && new_gi == last_gi); @@ -1925,15 +1933,15 @@ boolean HandleGadgets(int mx, int my, int button) if (gadget_pressed) // gadget pressed the first time { // initialize delay counter - DelayReached(&pressed_delay, 0); + ResetDelayCounter(&pressed_delay); // start gadget delay with longer delay after first click on gadget - pressed_delay_value = GADGET_FRAME_DELAY_FIRST; + pressed_delay.value = GADGET_FRAME_DELAY_FIRST; } else // gadget hold pressed for some time { // after first repeated gadget click, continue with shorter delay value - pressed_delay_value = GADGET_FRAME_DELAY; + pressed_delay.value = GADGET_FRAME_DELAY; } if (gi->type & GD_TYPE_SCROLLBAR && !gadget_dragging) @@ -2228,12 +2236,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(); @@ -2323,6 +2353,18 @@ boolean HandleGadgetsKeyInput(Key key) strcpy(text, gi->textinput.value); strcpy(&gi->textinput.value[cursor_pos], &text[cursor_pos + 1]); + DrawGadget(gi, DG_PRESSED, gi->direct_draw); + } + else if (key == KSYM_Home && cursor_pos > 0) + { + gi->textinput.cursor_position = 0; + + DrawGadget(gi, DG_PRESSED, gi->direct_draw); + } + else if (key == KSYM_End && cursor_pos < text_length) + { + gi->textinput.cursor_position = text_length; + DrawGadget(gi, DG_PRESSED, gi->direct_draw); } } @@ -2332,6 +2374,7 @@ boolean HandleGadgetsKeyInput(Key key) int text_length = strlen(gi->textarea.value); int area_ysize = gi->textarea.ysize; int cursor_x_pref = gi->textarea.cursor_x_preferred; + int cursor_x = gi->textarea.cursor_x; int cursor_y = gi->textarea.cursor_y; int cursor_pos = gi->textarea.cursor_position; char letter = getCharFromKey(key); @@ -2383,6 +2426,25 @@ boolean HandleGadgetsKeyInput(Key key) strcpy(text, gi->textarea.value); strcpy(&gi->textarea.value[cursor_pos], &text[cursor_pos + 1]); + DrawGadget(gi, DG_PRESSED, gi->direct_draw); + } + else if (key == KSYM_Home && cursor_x > 0) + { + setTextAreaCursorPosition(gi, gi->textarea.cursor_position - cursor_x); + + DrawGadget(gi, DG_PRESSED, gi->direct_draw); + } + else if (key == KSYM_End && cursor_pos < text_length) + { + int last_cursor_pos = cursor_pos; + + while (gi->textarea.value[cursor_pos] != '\0' && + gi->textarea.value[cursor_pos] != '\n') + cursor_pos++; + + setTextAreaCursorPosition(gi, gi->textarea.cursor_position + cursor_pos - + last_cursor_pos); + DrawGadget(gi, DG_PRESSED, gi->direct_draw); } }