X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=244db6ea8852b4a4df027f3ffbc95848b635210d;hp=736f1465fb2d381b5a07419f4f28759ff55de656;hb=93d70984a668ae9a0a6c76c42e660978f34c3993;hpb=6c674ccdd458314ced75459649c6acf1489b6056 diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 736f1465..244db6ea 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -13,6 +13,7 @@ #include #include "gadgets.h" +#include "image.h" #include "text.h" #include "misc.h" @@ -782,6 +783,10 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) { switch(tag) { + case GDI_IMAGE_ID: + gi->image_id = va_arg(ap, int); + break; + case GDI_CUSTOM_ID: gi->custom_id = va_arg(ap, int); break; @@ -1281,6 +1286,7 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) /* always start with reliable default values */ new_gadget->id = getNewGadgetID(); + new_gadget->image_id = -1; new_gadget->callback_info = default_callback_info; new_gadget->callback_action = default_callback_action; new_gadget->active = TRUE; @@ -1481,7 +1487,7 @@ static boolean insideSelectboxArea(struct GadgetInfo *gi, int mx, int my) void ClickOnGadget(struct GadgetInfo *gi, int button) { - if (!gi->mapped) + if (gi == NULL || gi->deactivated || !gi->mapped) return; /* simulate releasing mouse button over last gadget, if still pressed */ @@ -1681,16 +1687,20 @@ boolean HandleGadgets(int mx, int my, int button) { int last_x = gi->event.x; int last_y = gi->event.y; + int last_mx = gi->event.mx; + int last_my = gi->event.my; - gi->event.x = mx - gi->x; - gi->event.y = my - gi->y; + gi->event.x = gi->event.mx = mx - gi->x; + gi->event.y = gi->event.my = my - gi->y; if (gi->type == GD_TYPE_DRAWING_AREA) { gi->event.x /= gi->drawing.item_xsize; gi->event.y /= gi->drawing.item_ysize; - if (last_x != gi->event.x || last_y != gi->event.y) + if (last_x != gi->event.x || last_y != gi->event.y || + ((last_mx != gi->event.mx || last_my != gi->event.my) && + gi->event_mask & GD_EVENT_PIXEL_PRECISE)) changed_position = TRUE; } else if (gi->type & GD_TYPE_TEXT_INPUT && button != 0 && !motion_status) @@ -1709,7 +1719,8 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->textinput.cursor_position != old_cursor_position) DrawGadget(gi, DG_PRESSED, gi->direct_draw); - StartTextInput(gi->x, gi->y); + if (press_event) + StartTextInput(gi->x, gi->y, gi->width, gi->height); } else if (gi->type & GD_TYPE_TEXT_AREA && button != 0 && !motion_status) { @@ -1725,7 +1736,8 @@ boolean HandleGadgets(int mx, int my, int button) if (gi->textarea.cursor_position != old_cursor_position) DrawGadget(gi, DG_PRESSED, gi->direct_draw); - StartTextInput(gi->x, gi->y); + 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) @@ -1756,7 +1768,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); @@ -2261,3 +2273,43 @@ boolean HandleGadgetsKeyInput(Key key) return TRUE; } + +void DumpGadgetIdentifiers() +{ + struct GadgetInfo *gi; + + Print("Gadgets on current screen:\n"); + + for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) + { + if (gi->mapped && gi->image_id != -1) + { + char *token = getTokenFromImageID(gi->image_id); + char *prefix = "gfx."; + + if (strPrefix(token, prefix)) + token = &token[strlen(prefix)]; + + Print("- '%s'\n", token); + } + } + + Print("Done.\n"); +} + +boolean DoGadgetAction(int image_id) +{ + struct GadgetInfo *gi; + + for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) + { + if (gi->mapped && gi->image_id == image_id) + { + gi->callback_action(gi); + + return TRUE; + } + } + + return FALSE; +}