X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=64f0e0a99d9a57bbedac20d6bc94be28698e82c2;hp=cba655f874a89a29d9c31d0001c5a75506ef9088;hb=f7b47bbe40b05bc4d815f94dd1bcdc21596d4ff5;hpb=a21695563e089926d8e859e1ee0f3b077c8a7ed0 diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index cba655f8..64f0e0a9 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" @@ -59,7 +60,7 @@ static struct GadgetInfo *getGadgetInfoFromGadgetID(int id) return gi; } -static int getNewGadgetID() +static int getNewGadgetID(void) { int id = next_free_gadget_id++; @@ -1431,37 +1432,37 @@ static void MultiMapGadgets(int mode) } } -void UnmapAllGadgets() +void UnmapAllGadgets(void) { MultiMapGadgets(MULTIMAP_ALL | MULTIMAP_UNMAP); } -void RemapAllGadgets() +void RemapAllGadgets(void) { MultiMapGadgets(MULTIMAP_ALL | MULTIMAP_REMAP); } -boolean anyTextInputGadgetActive() +boolean anyTextInputGadgetActive(void) { return (last_gi && (last_gi->type & GD_TYPE_TEXT_INPUT) && last_gi->mapped); } -boolean anyTextAreaGadgetActive() +boolean anyTextAreaGadgetActive(void) { return (last_gi && (last_gi->type & GD_TYPE_TEXT_AREA) && last_gi->mapped); } -boolean anySelectboxGadgetActive() +boolean anySelectboxGadgetActive(void) { return (last_gi && (last_gi->type & GD_TYPE_SELECTBOX) && last_gi->mapped); } -boolean anyScrollbarGadgetActive() +boolean anyScrollbarGadgetActive(void) { return (last_gi && (last_gi->type & GD_TYPE_SCROLLBAR) && last_gi->mapped); } -boolean anyTextGadgetActive() +boolean anyTextGadgetActive(void) { return (anyTextInputGadgetActive() || anyTextAreaGadgetActive() || @@ -1493,11 +1494,18 @@ void ClickOnGadget(struct GadgetInfo *gi, int button) if (button_status) HandleGadgets(-1, -1, 0); + int x = gi->x; + int y = gi->y; + + /* set cursor position to the end of the text for text input gadgets */ + if (gi->type & GD_TYPE_TEXT_INPUT) + x = gi->x + gi->width - 1; + /* simulate pressing mouse button over specified gadget */ - HandleGadgets(gi->x, gi->y, button); + HandleGadgets(x, y, button); /* simulate releasing mouse button over specified gadget */ - HandleGadgets(gi->x, gi->y, 0); + HandleGadgets(x, y, 0); } boolean HandleGadgets(int mx, int my, int button) @@ -2272,3 +2280,43 @@ boolean HandleGadgetsKeyInput(Key key) return TRUE; } + +void DumpGadgetIdentifiers(void) +{ + 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; +}