X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=6b7d2592f435849b3bd8fb0f8798227278a18ca7;hp=daa045eb4892dd4ea28b98d9def164ad143bf12d;hb=0d214d4e314f6f42df24be140bb433e980319767;hpb=3b6f0ed7443f58031823df29c1a7bd89d7d63a8d diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index daa045eb..6b7d2592 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -24,8 +24,6 @@ #define DG_BUFFERED 0 #define DG_DIRECT 1 -#define GADGET_DEACTIVATED(g) ((g)->x < 0 || (g)->y < 0) - #define OPTION_TEXT_SELECTABLE(g, t) \ (t[0] != g->selectbox.char_unselectable && \ t[0] != '\0' && \ @@ -220,7 +218,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) int state = (pressed ? GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED); boolean redraw_selectbox = FALSE; - if (gi == NULL) + if (gi == NULL || gi->deactivated) return; gd = (!gi->active ? &gi->alt_design[state] : @@ -777,7 +775,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) { int tag = first_tag; - if (gi == NULL) + if (gi == NULL || gi->deactivated) return; while (tag != GDI_END) @@ -1097,11 +1095,17 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) tag = va_arg(ap, int); /* read next tag */ } - /* check if gadget is complete */ + gi->deactivated = FALSE; + + /* check if gadget has undefined bitmaps */ if (gi->type != GD_TYPE_DRAWING_AREA && - (!gi->design[GD_BUTTON_UNPRESSED].bitmap || - !gi->design[GD_BUTTON_PRESSED].bitmap)) - Error(ERR_EXIT, "gadget incomplete (missing Bitmap)"); + (gi->design[GD_BUTTON_UNPRESSED].bitmap == NULL || + gi->design[GD_BUTTON_PRESSED].bitmap == NULL)) + gi->deactivated = TRUE; + + /* check if gadget is placed off-screen */ + if (gi->x < 0 || gi->y < 0) + gi->deactivated = TRUE; /* adjust gadget values in relation to other gadget values */ @@ -1263,7 +1267,7 @@ void ModifyGadget(struct GadgetInfo *gi, int first_tag, ...) void RedrawGadget(struct GadgetInfo *gi) { - if (gi == NULL) + if (gi == NULL || gi->deactivated) return; if (gi->mapped) @@ -1351,7 +1355,7 @@ static struct GadgetInfo *last_gi = NULL; static void MapGadgetExt(struct GadgetInfo *gi, boolean redraw) { - if (gi == NULL || gi->mapped || GADGET_DEACTIVATED(gi)) + if (gi == NULL || gi->deactivated || gi->mapped) return; gi->mapped = TRUE; @@ -1367,7 +1371,7 @@ void MapGadget(struct GadgetInfo *gi) void UnmapGadget(struct GadgetInfo *gi) { - if (gi == NULL || !gi->mapped) + if (gi == NULL || gi->deactivated || !gi->mapped) return; gi->mapped = FALSE; @@ -1601,6 +1605,8 @@ boolean HandleGadgets(int mx, int my, int button) if (gadget_pressed_inside_select_line) new_gi = NULL; + + StopTextInput(); } gadget_pressed = @@ -1702,6 +1708,9 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->textinput.cursor_position != old_cursor_position) DrawGadget(gi, DG_PRESSED, gi->direct_draw); + + if (press_event) + StartTextInput(gi->x, gi->y, gi->width, gi->height); } else if (gi->type & GD_TYPE_TEXT_AREA && button != 0 && !motion_status) { @@ -1716,6 +1725,9 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->textarea.cursor_position != old_cursor_position) DrawGadget(gi, DG_PRESSED, gi->direct_draw); + + if (press_event) + StartTextInput(gi->x, gi->y, gi->width, gi->height); } else if (gi->type & GD_TYPE_SELECTBOX && gi->selectbox.open && !keep_selectbox_open) @@ -1746,7 +1758,7 @@ boolean HandleGadgets(int mx, int my, int button) new_gi->event.type = GD_EVENT_INFO_ENTERING; new_gi->callback_info(new_gi); } - else if (last_info_gi != NULL) + else if (last_info_gi != NULL && last_info_gi->mapped) { last_info_gi->event.type = GD_EVENT_INFO_LEAVING; last_info_gi->callback_info(last_info_gi); @@ -2072,13 +2084,17 @@ boolean HandleGadgetsKeyInput(Key key) { struct GadgetInfo *gi = last_gi; - if (gi == NULL || !gi->mapped || + if (gi == NULL || gi->deactivated || !gi->mapped || !(gi->type & GD_TYPE_TEXT_INPUT || gi->type & GD_TYPE_TEXT_AREA || gi->type & GD_TYPE_SELECTBOX)) return FALSE; - if (key == KSYM_Return) /* valid for both text input and selectbox */ + if (key == KSYM_Escape) + { + StopTextInput(); + } + else if (key == KSYM_Return) /* valid for both text input and selectbox */ { boolean gadget_changed = ((gi->event_mask & GD_EVENT_TEXT_RETURN) != 0); @@ -2090,6 +2106,8 @@ boolean HandleGadgetsKeyInput(Key key) strcpy(gi->textinput.last_value, gi->textinput.value); else gadget_changed = FALSE; + + StopTextInput(); } else if (gi->type & GD_TYPE_SELECTBOX) {