#include <string.h>
#include "gadgets.h"
+#include "image.h"
#include "text.h"
#include "misc.h"
return gi;
}
-static int getNewGadgetID()
+static int getNewGadgetID(void)
{
int id = next_free_gadget_id++;
{
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;
/* 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;
}
}
-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() ||
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 */
{
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)
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);
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;
+}