X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=ede8cfc7f54cad4888b0209ef96a99db72a93f24;hb=03f1156cc40e36c17e19a1c9ee02f0cbd70b8989;hp=1b368c569f703cb37f0245f1e09cf6d72b53bd12;hpb=37a06df577bbfd00f4b361f92cacb0d97036ba93;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 1b368c56..ede8cfc7 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -28,6 +28,7 @@ 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; @@ -1197,6 +1198,10 @@ void FreeGadget(struct GadgetInfo *gi) { struct GadgetInfo *gi_previous = gadget_list_first_entry; + /* prevent "last_info_gi" from pointing to memory that will be freed */ + if (last_info_gi == gi) + last_info_gi = NULL; + while (gi_previous != NULL && gi_previous->next != gi) gi_previous = gi_previous->next; @@ -1376,11 +1381,11 @@ void ClickOnGadget(struct GadgetInfo *gi, int button) boolean HandleGadgets(int mx, int my, int button) { - static struct GadgetInfo *last_info_gi = NULL; static unsigned long pressed_delay = 0; 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; int scrollbar_mouse_pos = 0; struct GadgetInfo *new_gi, *gi; boolean press_event; @@ -1459,7 +1464,7 @@ boolean HandleGadgets(int mx, int my, int button) { 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; @@ -1507,6 +1512,10 @@ boolean HandleGadgets(int mx, int my, int button) gadget_released_inside_select_area = FALSE; } + /* setting state for handling over-large selectbox */ + if (keep_selectbox_open && (press_event || !mouse_inside_select_line)) + keep_selectbox_open = FALSE; + /* if new gadget pressed, store this gadget */ if (gadget_pressed) last_gi = new_gi; @@ -1523,8 +1532,9 @@ boolean HandleGadgets(int mx, int my, int button) if (gadget_released) { if (gi->type & GD_TYPE_SELECTBOX && - (mouse_released_where_pressed || - !gadget_released_inside_select_area)) /* selectbox stays open */ + (keep_selectbox_open || + mouse_released_where_pressed || + !gadget_released_inside_select_area)) /* selectbox stays open */ { gi->selectbox.stay_open = TRUE; pressed_mx = 0; @@ -1585,7 +1595,8 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->textarea.cursor_position != old_cursor_position) DrawGadget(gi, DG_PRESSED, gi->direct_draw); } - else if (gi->type & GD_TYPE_SELECTBOX && gi->selectbox.open) + else if (gi->type & GD_TYPE_SELECTBOX && gi->selectbox.open && + !keep_selectbox_open) { int old_index = gi->selectbox.current_index; @@ -1709,6 +1720,12 @@ boolean HandleGadgets(int mx, int my, int button) return TRUE; } } + else if (gi->type & GD_TYPE_SELECTBOX) + { + /* keep selectbox open in case of over-large selectbox */ + keep_selectbox_open = (mouse_inside_select_line && + mouse_inside_select_area); + } DrawGadget(gi, DG_PRESSED, gi->direct_draw); @@ -1742,7 +1759,7 @@ boolean HandleGadgets(int mx, int my, int button) else if (gadget_moving_off_borders && gi->state == GD_BUTTON_PRESSED) DrawGadget(gi, DG_UNPRESSED, gi->direct_draw); } - else if (gi->type & GD_TYPE_SELECTBOX) + else if (gi->type & GD_TYPE_SELECTBOX && !keep_selectbox_open) { int old_index = gi->selectbox.current_index; @@ -1814,7 +1831,8 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->type & GD_TYPE_SELECTBOX) { - if (mouse_released_where_pressed || + if (keep_selectbox_open || + mouse_released_where_pressed || !gadget_released_inside_select_area) /* selectbox stays open */ { deactivate_gadget = FALSE; @@ -1893,7 +1911,7 @@ boolean HandleGadgetsKeyInput(Key key) { 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;