X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=9c07371bc31a7321e6422ea839f45133af95143f;hp=00a41a8b94d18fc73c970398e745b3d507aa67f4;hb=abe44529b439ad39b4d8dbf19cbd67c9b9844279;hpb=4d765f70b0accf29a631e833e7ddfd57ef8bbfee diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 00a41a8b..9c07371b 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -1,15 +1,13 @@ -/*********************************************************** -* Artsoft Retro-Game Library * -*----------------------------------------------------------* -* (c) 1994-2002 Artsoft Entertainment * -* Holger Schemel * -* Detmolder Strasse 189 * -* 33604 Bielefeld * -* Germany * -* e-mail: info@artsoft.org * -*----------------------------------------------------------* -* gadgets.c * -***********************************************************/ +// ============================================================================ +// Artsoft Retro-Game Library +// ---------------------------------------------------------------------------- +// (c) 1995-2014 by Artsoft Entertainment +// Holger Schemel +// info@artsoft.org +// http://www.artsoft.org/ +// ---------------------------------------------------------------------------- +// gadgets.c +// ============================================================================ #include #include @@ -26,12 +24,26 @@ #define DG_BUFFERED 0 #define DG_DIRECT 1 +#define GADGET_DEACTIVATED(g) ((g)->x < 0 || (g)->y < 0) + + static struct GadgetInfo *gadget_list_first_entry = NULL; static struct GadgetInfo *gadget_list_last_entry = NULL; static struct GadgetInfo *last_info_gi = NULL; static int next_free_gadget_id = 1; static boolean gadget_id_wrapped = FALSE; +static void (*PlayGadgetSoundActivating)(void) = NULL; +static void (*PlayGadgetSoundSelecting)(void) = NULL; + + +void InitGadgetsSoundCallback(void (*activating_function)(void), + void (*selecting_function)(void)) +{ + PlayGadgetSoundActivating = activating_function; + PlayGadgetSoundSelecting = selecting_function; +} + static struct GadgetInfo *getGadgetInfoFromGadgetID(int id) { struct GadgetInfo *gi = gadget_list_first_entry; @@ -65,10 +77,33 @@ static int getNewGadgetID() return id; } -static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my) +static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my, + int button) { struct GadgetInfo *gi; + /* first check for scrollbars in case of mouse scroll wheel button events */ + if (IS_WHEEL_BUTTON(button)) + { + /* real horizontal wheel or vertical wheel with modifier key pressed */ + boolean check_horizontal = (IS_WHEEL_BUTTON_HORIZONTAL(button) || + GetKeyModState() & KMOD_Shift); + + /* check for the first active scrollbar with matching mouse wheel area */ + for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) + { + if (gi->mapped && gi->active && + ((gi->type & GD_TYPE_SCROLLBAR_HORIZONTAL && check_horizontal) || + (gi->type & GD_TYPE_SCROLLBAR_VERTICAL && !check_horizontal)) && + mx >= gi->wheelarea.x && mx < gi->wheelarea.x + gi->wheelarea.width && + my >= gi->wheelarea.y && my < gi->wheelarea.y + gi->wheelarea.height) + return gi; + } + + /* no active scrollbar found -- ignore this scroll wheel button event */ + return NULL; + } + /* open selectboxes may overlap other active gadgets, so check them first */ for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) { @@ -347,10 +382,16 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->height - 2 * border_y); /* gadget text value */ +#if 1 + 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); +#else DrawTextToTextArea(gi->x + border_x, gi->y + border_y, gi->textarea.value, font_nr, gi->textarea.xsize, gi->textarea.xsize, gi->textarea.ysize, BLIT_ON_BACKGROUND); +#endif cursor_letter = gi->textarea.value[gi->textarea.cursor_position]; cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' '); @@ -666,9 +707,21 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->selectbox.x, gi->selectbox.y); } else + { +#if 1 + int x = gi->x; + int y = gi->y; + + redraw_mask |= (IN_GFX_FIELD_FULL(x, y) ? REDRAW_FIELD : + IN_GFX_DOOR_1(x, y) ? REDRAW_DOOR_1 : + IN_GFX_DOOR_2(x, y) ? REDRAW_DOOR_2 : + IN_GFX_DOOR_3(x, y) ? REDRAW_DOOR_3 : REDRAW_ALL); +#else redraw_mask |= (gi->x < gfx.sx + gfx.sxsize ? REDRAW_FIELD : gi->y < gfx.dy + gfx.dysize ? REDRAW_DOOR_1 : gi->y > gfx.vy ? REDRAW_DOOR_2 : REDRAW_DOOR_3); +#endif + } } static int get_minimal_size_for_numeric_input(int minmax_value) @@ -708,7 +761,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) case GDI_INFO_TEXT: { - int max_textsize = MAX_INFO_TEXTSIZE - 1; + int max_textsize = MAX_INFO_TEXTSIZE; char *text = va_arg(ap, char *); if (text != NULL) @@ -745,20 +798,14 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) break; case GDI_ACTIVE: - /* take care here: "boolean" is typedef'ed as "unsigned char", - which gets promoted to "int" */ gi->active = (boolean)va_arg(ap, int); break; case GDI_DIRECT_DRAW: - /* take care here: "boolean" is typedef'ed as "unsigned char", - which gets promoted to "int" */ gi->direct_draw = (boolean)va_arg(ap, int); break; case GDI_CHECKED: - /* take care here: "boolean" is typedef'ed as "unsigned char", - which gets promoted to "int" */ gi->checked = (boolean)va_arg(ap, int); break; @@ -798,7 +845,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) int max_textsize = MAX_GADGET_TEXTSIZE; if (gi->textinput.size) - max_textsize = MIN(gi->textinput.size, MAX_GADGET_TEXTSIZE - 1); + max_textsize = MIN(gi->textinput.size, MAX_GADGET_TEXTSIZE); strncpy(gi->textinput.value, va_arg(ap, char *), max_textsize); strcpy(gi->textinput.last_value, gi->textinput.value); @@ -816,7 +863,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) case GDI_TEXT_SIZE: { int tag_value = va_arg(ap, int); - int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE - 1); + int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE); gi->textinput.size = max_textsize; gi->textinput.value[max_textsize] = '\0'; @@ -976,6 +1023,22 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) gi->scrollbar.item_position = va_arg(ap, int); break; + case GDI_WHEEL_AREA_X: + gi->wheelarea.x = va_arg(ap, int); + break; + + case GDI_WHEEL_AREA_Y: + gi->wheelarea.y = va_arg(ap, int); + break; + + case GDI_WHEEL_AREA_WIDTH: + gi->wheelarea.width = va_arg(ap, int); + break; + + case GDI_WHEEL_AREA_HEIGHT: + gi->wheelarea.height = va_arg(ap, int); + break; + case GDI_CALLBACK_INFO: gi->callback_info = va_arg(ap, gadget_function); break; @@ -1198,6 +1261,9 @@ void FreeGadget(struct GadgetInfo *gi) { struct GadgetInfo *gi_previous = gadget_list_first_entry; + if (gi == NULL) + return; + /* prevent "last_info_gi" from pointing to memory that will be freed */ if (last_info_gi == gi) last_info_gi = NULL; @@ -1242,7 +1308,7 @@ static struct GadgetInfo *last_gi = NULL; static void MapGadgetExt(struct GadgetInfo *gi, boolean redraw) { - if (gi == NULL || gi->mapped) + if (gi == NULL || gi->mapped || GADGET_DEACTIVATED(gi)) return; gi->mapped = TRUE; @@ -1274,9 +1340,11 @@ void UnmapGadget(struct GadgetInfo *gi) #define MULTIMAP_PLAYFIELD (1 << 3) #define MULTIMAP_DOOR_1 (1 << 4) #define MULTIMAP_DOOR_2 (1 << 5) +#define MULTIMAP_DOOR_3 (1 << 6) #define MULTIMAP_ALL (MULTIMAP_PLAYFIELD | \ - MULTIMAP_DOOR_1 | \ - MULTIMAP_DOOR_2) + MULTIMAP_DOOR_1 | \ + MULTIMAP_DOOR_2 | \ + MULTIMAP_DOOR_3) static void MultiMapGadgets(int mode) { @@ -1286,6 +1354,16 @@ static void MultiMapGadgets(int mode) while (gi != NULL) { +#if 1 + int x = gi->x; + int y = gi->y; + + if ((mode & MULTIMAP_PLAYFIELD && IN_GFX_FIELD_FULL(x, y)) || + (mode & MULTIMAP_DOOR_1 && IN_GFX_DOOR_1(x, y)) || + (mode & MULTIMAP_DOOR_2 && IN_GFX_DOOR_2(x, y)) || + (mode & MULTIMAP_DOOR_3 && IN_GFX_DOOR_3(x, y)) || + (mode & MULTIMAP_ALL) == MULTIMAP_ALL) +#else if ((mode & MULTIMAP_PLAYFIELD && gi->x < gfx.sx + gfx.sxsize) || (mode & MULTIMAP_DOOR_1 && @@ -1293,6 +1371,7 @@ static void MultiMapGadgets(int mode) (mode & MULTIMAP_DOOR_2 && gi->x >= gfx.dx && gi->y > gfx.dy + gfx.dysize) || (mode & MULTIMAP_ALL) == MULTIMAP_ALL) +#endif { if (mode & MULTIMAP_UNMAP) { @@ -1349,18 +1428,18 @@ boolean anyTextGadgetActive() static boolean insideSelectboxLine(struct GadgetInfo *gi, int mx, int my) { - return(gi != NULL && - gi->type & GD_TYPE_SELECTBOX && - mx >= gi->x && mx < gi->x + gi->width && - my >= gi->y && my < gi->y + gi->height); + return (gi != NULL && + gi->type & GD_TYPE_SELECTBOX && + mx >= gi->x && mx < gi->x + gi->width && + my >= gi->y && my < gi->y + gi->height); } static boolean insideSelectboxArea(struct GadgetInfo *gi, int mx, int my) { - return(gi != NULL && - gi->type & GD_TYPE_SELECTBOX && - mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width && - my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height); + return (gi != NULL && + gi->type & GD_TYPE_SELECTBOX && + mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width && + my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height); } void ClickOnGadget(struct GadgetInfo *gi, int button) @@ -1381,11 +1460,13 @@ void ClickOnGadget(struct GadgetInfo *gi, int button) boolean HandleGadgets(int mx, int my, int button) { - static unsigned long pressed_delay = 0; + static unsigned int pressed_delay = 0; + static unsigned int pressed_delay_value = GADGET_FRAME_DELAY; static int last_button = 0; static int last_mx = 0, last_my = 0; static int pressed_mx = 0, pressed_my = 0; static boolean keep_selectbox_open = FALSE; + static boolean gadget_stopped = FALSE; int scrollbar_mouse_pos = 0; struct GadgetInfo *new_gi, *gi; boolean press_event; @@ -1398,12 +1479,17 @@ boolean HandleGadgets(int mx, int my, int button) boolean gadget_pressed_repeated; boolean gadget_pressed_off_borders; boolean gadget_pressed_inside_select_line; + boolean gadget_pressed_delay_reached; boolean gadget_moving; boolean gadget_moving_inside; boolean gadget_moving_off_borders; + boolean gadget_draggable; + boolean gadget_dragging; boolean gadget_released; boolean gadget_released_inside; +#if 0 boolean gadget_released_inside_select_line; +#endif boolean gadget_released_inside_select_area; boolean gadget_released_off_borders; boolean changed_position = FALSE; @@ -1420,10 +1506,10 @@ boolean HandleGadgets(int mx, int my, int button) } /* check which gadget is under the mouse pointer */ - new_gi = getGadgetInfoFromMousePosition(mx, my); + new_gi = getGadgetInfoFromMousePosition(mx, my, button); /* check if button state has changed since last invocation */ - press_event = (button != 0 && last_button == 0); + press_event = (button != 0 && last_button == 0); release_event = (button == 0 && last_button != 0); last_button = button; @@ -1457,14 +1543,14 @@ boolean HandleGadgets(int mx, int my, int button) (gadget_pressed_inside_select_line && !mouse_inside_select_area))) { struct GadgetInfo *gi = last_gi; - boolean gadget_changed = (gi->event_mask & GD_EVENT_TEXT_LEAVING); + boolean gadget_changed = ((gi->event_mask & GD_EVENT_TEXT_LEAVING) != 0); /* check if text gadget has changed its value */ if (gi->type & GD_TYPE_TEXT_INPUT) { CheckRangeOfNumericInputGadget(gi); - if (strcmp(gi->textinput.value, gi->textinput.last_value) != 0) + if (!strEqual(gi->textinput.last_value, gi->textinput.value)) strcpy(gi->textinput.last_value, gi->textinput.value); else gadget_changed = FALSE; @@ -1492,6 +1578,9 @@ boolean HandleGadgets(int mx, int my, int button) gadget_pressed_repeated = (button != 0 && last_gi != NULL && new_gi == last_gi); + gadget_pressed_delay_reached = + DelayReached(&pressed_delay, pressed_delay_value); + gadget_released = (release_event && last_gi != NULL); gadget_released_inside = (gadget_released && new_gi == last_gi); gadget_released_off_borders = (gadget_released && new_gi != last_gi); @@ -1503,12 +1592,16 @@ boolean HandleGadgets(int mx, int my, int button) /* when handling selectbox, set additional state values */ if (gadget_released_inside && (last_gi->type & GD_TYPE_SELECTBOX)) { +#if 0 gadget_released_inside_select_line = insideSelectboxLine(last_gi, mx, my); +#endif gadget_released_inside_select_area = insideSelectboxArea(last_gi, mx, my); } else { +#if 0 gadget_released_inside_select_line = FALSE; +#endif gadget_released_inside_select_area = FALSE; } @@ -1549,6 +1642,14 @@ boolean HandleGadgets(int mx, int my, int button) if (button == 0 && !release_event) gi = new_gi; + /* if new gadget or if no gadget was pressed, release stopped processing */ + if (gadget_pressed || new_gi == NULL) + gadget_stopped = FALSE; + + /* if gadget was stopped while being handled, stop gadget processing here */ + if (gadget_stopped) + return TRUE; + if (gi != NULL) { int last_x = gi->event.x; @@ -1633,65 +1734,68 @@ boolean HandleGadgets(int mx, int my, int button) last_info_gi = new_gi; } - if (gadget_pressed) - { - if (gi->type == GD_TYPE_CHECK_BUTTON) - { - gi->checked = !gi->checked; - } - else if (gi->type == GD_TYPE_RADIO_BUTTON) - { - struct GadgetInfo *rgi = gadget_list_first_entry; + gadget_draggable = (gi && gi->type & GD_TYPE_SCROLLBAR); - while (rgi) - { - if (rgi->mapped && - rgi->type == GD_TYPE_RADIO_BUTTON && - rgi->radio_nr == gi->radio_nr && - rgi != gi) - { - rgi->checked = FALSE; - DrawGadget(rgi, DG_UNPRESSED, rgi->direct_draw); - } + /* reset drag position for newly pressed scrollbar to "not dragging" */ + if (gadget_pressed && gadget_draggable) + gi->scrollbar.drag_position = -1; - rgi = rgi->next; - } + gadget_dragging = (gadget_draggable && gi->scrollbar.drag_position != -1); - gi->checked = TRUE; + /* clicking next to a scrollbar to move it is not considered "moving" */ + if (gadget_draggable && !gadget_dragging) + gadget_moving = FALSE; + + /* when leaving scrollbar area when jump-scrolling, stop gadget processing */ + if (gadget_draggable && !gadget_dragging && gadget_moving_off_borders) + gadget_stopped = TRUE; + + if ((gadget_pressed) || + (gadget_pressed_repeated && gadget_pressed_delay_reached)) + { + if (gadget_pressed) /* gadget pressed the first time */ + { + /* initialize delay counter */ + DelayReached(&pressed_delay, 0); + + /* start gadget delay with longer delay after first click on gadget */ + pressed_delay_value = GADGET_FRAME_DELAY_FIRST; } - else if (gi->type & GD_TYPE_SCROLLBAR) + else /* gadget hold pressed for some time */ { - int mpos, gpos; + /* after first repeated gadget click, continue with shorter delay value */ + pressed_delay_value = GADGET_FRAME_DELAY; + } - if (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL) - { - mpos = mx; - gpos = gi->x; - } - else - { - mpos = my; - gpos = gi->y; - } + if (gi->type & GD_TYPE_SCROLLBAR && !gadget_dragging) + { + int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my); + int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y); + int slider_start = gpos + gi->scrollbar.position; + int slider_end = gpos + gi->scrollbar.position + gi->scrollbar.size - 1; + boolean inside_slider = (mpos >= slider_start && mpos <= slider_end); - if (mpos >= gpos + gi->scrollbar.position && - mpos < gpos + gi->scrollbar.position + gi->scrollbar.size) - { - /* drag scrollbar */ - gi->scrollbar.drag_position = - scrollbar_mouse_pos - gi->scrollbar.position; - } - else + if (IS_WHEEL_BUTTON(button) || !inside_slider) { /* click scrollbar one scrollbar length up/left or down/right */ struct GadgetScrollbar *gs = &gi->scrollbar; int old_item_position = gs->item_position; + int item_steps = gs->items_visible - 1; + int item_direction = (mpos < gpos + gi->scrollbar.position ? -1 : +1); + + if (IS_WHEEL_BUTTON(button)) + { + boolean scroll_single_step = ((GetKeyModState() & KMOD_Alt) != 0); + + item_steps = (scroll_single_step ? 1 : DEFAULT_WHEEL_STEPS); + item_direction = (button == MB_WHEEL_UP || + button == MB_WHEEL_LEFT ? -1 : +1); + } changed_position = FALSE; - gs->item_position += - gs->items_visible * (mpos < gpos + gi->scrollbar.position ? -1 : +1); + gs->item_position += item_steps * item_direction; if (gs->item_position < 0) gs->item_position = 0; @@ -1714,11 +1818,63 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->event_mask & GD_EVENT_MOVING && changed_position) gi->callback_action(gi); - /* don't handle this scrollbar anymore while mouse button pressed */ - last_gi = NULL; - return TRUE; } + else + { + /* don't handle this scrollbar anymore when mouse position reached */ + if (gadget_pressed_repeated) + { + gadget_stopped = TRUE; + + return TRUE; + } + } + } + } + + if (gadget_pressed) + { + PlayGadgetSoundActivating(); + + if (gi->type == GD_TYPE_CHECK_BUTTON) + { + gi->checked = !gi->checked; + } + else if (gi->type == GD_TYPE_RADIO_BUTTON) + { + struct GadgetInfo *rgi = gadget_list_first_entry; + + while (rgi) + { + if (rgi->mapped && + rgi->type == GD_TYPE_RADIO_BUTTON && + rgi->radio_nr == gi->radio_nr && + rgi != gi) + { + rgi->checked = FALSE; + DrawGadget(rgi, DG_UNPRESSED, rgi->direct_draw); + } + + rgi = rgi->next; + } + + gi->checked = TRUE; + } + else if (gi->type & GD_TYPE_SCROLLBAR) + { + int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my); + int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y); + int slider_start = gpos + gi->scrollbar.position; + int slider_end = gpos + gi->scrollbar.position + gi->scrollbar.size - 1; + boolean inside_slider = (mpos >= slider_start && mpos <= slider_end); + + if (!IS_WHEEL_BUTTON(button) && inside_slider) + { + /* start dragging scrollbar */ + gi->scrollbar.drag_position = + scrollbar_mouse_pos - gi->scrollbar.position; + } } else if (gi->type & GD_TYPE_SELECTBOX) { @@ -1734,9 +1890,6 @@ boolean HandleGadgets(int mx, int my, int button) gi->event.button = button; gi->event.off_borders = FALSE; - /* initialize delay counter */ - DelayReached(&pressed_delay, 0); - if (gi->event_mask & GD_EVENT_PRESSED) gi->callback_action(gi); } @@ -1745,8 +1898,7 @@ boolean HandleGadgets(int mx, int my, int button) { gi->event.type = GD_EVENT_PRESSED; - if (gi->event_mask & GD_EVENT_REPEATED && - DelayReached(&pressed_delay, GADGET_FRAME_DELAY)) + if (gi->event_mask & GD_EVENT_REPEATED && gadget_pressed_delay_reached) gi->callback_action(gi); } @@ -1814,7 +1966,7 @@ boolean HandleGadgets(int mx, int my, int button) DrawGadget(gi, DG_PRESSED, gi->direct_draw); } - gi->state = (gadget_moving_inside || gi->type & GD_TYPE_SCROLLBAR ? + gi->state = (gadget_moving_inside || gadget_draggable ? GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED); gi->event.type = GD_EVENT_MOVING; gi->event.off_borders = gadget_moving_off_borders; @@ -1863,6 +2015,7 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->type & GD_TYPE_SCROLLBAR) DrawGadget(gi, DG_UNPRESSED, gi->direct_draw); + gi->state = GD_BUTTON_UNPRESSED; gi->event.type = GD_EVENT_RELEASED; if (gi->event_mask & GD_EVENT_RELEASED && @@ -1880,10 +2033,10 @@ boolean HandleGadgets(int mx, int my, int button) static void insertCharIntoTextArea(struct GadgetInfo *gi, char c) { - char text[MAX_GADGET_TEXTSIZE]; + char text[MAX_GADGET_TEXTSIZE + 1]; int cursor_position = gi->textarea.cursor_position; - if (strlen(gi->textarea.value) == MAX_GADGET_TEXTSIZE) /* no space left */ + if (strlen(gi->textarea.value) >= MAX_GADGET_TEXTSIZE) /* no space left */ return; strcpy(text, gi->textarea.value); @@ -1905,13 +2058,13 @@ boolean HandleGadgetsKeyInput(Key key) if (key == KSYM_Return) /* valid for both text input and selectbox */ { - boolean gadget_changed = (gi->event_mask & GD_EVENT_TEXT_RETURN); + boolean gadget_changed = ((gi->event_mask & GD_EVENT_TEXT_RETURN) != 0); if (gi->type & GD_TYPE_TEXT_INPUT) { CheckRangeOfNumericInputGadget(gi); - if (strcmp(gi->textinput.value, gi->textinput.last_value) != 0) + if (!strEqual(gi->textinput.last_value, gi->textinput.value)) strcpy(gi->textinput.last_value, gi->textinput.value); else gadget_changed = FALSE; @@ -1944,7 +2097,7 @@ boolean HandleGadgetsKeyInput(Key key) } else if (gi->type & GD_TYPE_TEXT_INPUT) /* only valid for text input */ { - char text[MAX_GADGET_TEXTSIZE]; + char text[MAX_GADGET_TEXTSIZE + 1]; int text_length = strlen(gi->textinput.value); int cursor_pos = gi->textinput.cursor_position; char letter = getCharFromKey(key); @@ -1991,7 +2144,7 @@ boolean HandleGadgetsKeyInput(Key key) } else if (gi->type & GD_TYPE_TEXT_AREA) /* only valid for text area */ { - char text[MAX_GADGET_TEXTSIZE]; + char text[MAX_GADGET_TEXTSIZE + 1]; int text_length = strlen(gi->textarea.value); int area_ysize = gi->textarea.ysize; int cursor_x_pref = gi->textarea.cursor_x_preferred;