{
struct GadgetInfo *gi = gadget_list_first_entry;
- while (gi)
+ while (gi != NULL)
{
printf("-XXX-1-> '%s': %s\n",
gi->info_text, (gi->mapped ? "mapped" : "not mapped"));
static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my)
{
- struct GadgetInfo *gi = gadget_list_first_entry;
+ struct GadgetInfo *gi;
- while (gi)
+ /* open selectboxes may overlap other active gadgets, so check them first */
+ for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
{
if (gi->mapped && gi->active &&
- ((mx >= gi->x && mx < gi->x + gi->width &&
- my >= gi->y && my < gi->y + gi->height) ||
- (gi->type & GD_TYPE_SELECTBOX && gi->selectbox.open &&
- mx >= gi->selectbox.x && mx < gi->selectbox.x+gi->selectbox.width &&
- my >= gi->selectbox.y && my < gi->selectbox.y+gi->selectbox.height)))
- break;
+ gi->type & GD_TYPE_SELECTBOX && gi->selectbox.open &&
+ mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width &&
+ my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height)
+ return gi;
+ }
- gi = gi->next;
+ /* check all other gadgets */
+ for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
+ {
+ if (gi->mapped && gi->active &&
+ mx >= gi->x && mx < gi->x + gi->width &&
+ my >= gi->y && my < gi->y + gi->height)
+ return gi;
}
- return gi;
+ return NULL;
}
static void default_callback_info(void *ptr)
static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
{
- int state = (pressed ? 1 : 0);
- struct GadgetDesign *gd = (!gi->active ? &gi->alt_design[0] :
+ int state = (pressed ? GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED);
+ struct GadgetDesign *gd = (!gi->active ? &gi->alt_design[state] :
gi->checked ? &gi->alt_design[state] :
&gi->design[state]);
boolean redraw_selectbox = FALSE;
int border_xsize = gi->border.xsize;
int border_ysize = gi->border.ysize;
int button_size = gi->border.xsize_selectbutton;
+ int bottom_screen_border = gfx.sy + gfx.sysize - font_height;
Bitmap *src_bitmap;
int src_x, src_y;
gi->selectbox.x = gi->x;
gi->selectbox.y = gi->y + gi->height;
- if (gi->selectbox.y + gi->selectbox.height > gfx.real_sy + gfx.full_sysize)
+ if (gi->selectbox.y + gi->selectbox.height > bottom_screen_border)
gi->selectbox.y = gi->y - gi->selectbox.height;
if (gi->selectbox.y < 0)
- gi->selectbox.y = gfx.real_sy + gfx.full_sysize - gi->selectbox.height;
+ gi->selectbox.y = bottom_screen_border - gi->selectbox.height;
getFontCharSource(font_nr, FONT_ASCII_CURSOR, &src_bitmap, &src_x, &src_y);
src_x += font_width / 2;
static boolean map_state[MAX_NUM_GADGETS];
int map_count = 0;
- while (gi)
+ while (gi != NULL)
{
if ((mode & MULTIMAP_PLAYFIELD &&
gi->x < gfx.sx + gfx.sxsize) ||
if (gadget_list_first_entry == NULL)
return;
+ /* simulated release of mouse button over last gadget */
+ if (mx == -1 && my == -1 && button == 0)
+ {
+ mx = last_mx;
+ my = last_my;
+ }
+
/* check which gadget is under the mouse pointer */
new_gi = getGadgetInfoFromMousePosition(mx, my);
/* if mouse button pressed inside activated selectbox, select value */
if (my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height)
gi->selectbox.current_index =
- (my - gi->selectbox.y - gi->border.xsize) / getFontWidth(gi->font);
+ (my - gi->selectbox.y - gi->border.ysize) / getFontHeight(gi->font);
if (gi->selectbox.current_index < 0)
gi->selectbox.current_index = 0;
(mx >= gi->x && mx < gi->x + gi->width &&
my >= gi->y && my < gi->y + gi->height);
gadget_released_inside_select_area =
- (mx >= gi->selectbox.x && mx < gi->selectbox.x+gi->selectbox.width &&
- my >= gi->selectbox.y && my < gi->selectbox.y+gi->selectbox.height);
+ (mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width &&
+ my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height);
}
else
{
if (button == 0 && !release_event)
gi = new_gi;
- if (gi)
+ if (gi != NULL)
{
int last_x = gi->event.x;
int last_y = gi->event.y;
/* if mouse moving inside activated selectbox, select value */
if (my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height)
gi->selectbox.current_index =
- (my - gi->selectbox.y - gi->border.xsize) / getFontWidth(gi->font);
+ (my - gi->selectbox.y - gi->border.ysize) / getFontHeight(gi->font);
if (gi->selectbox.current_index < 0)
gi->selectbox.current_index = 0;
gi->event_mask & GD_EVENT_OFF_BORDERS)
gi->callback_action(gi);
}
+
+ /* handle gadgets unmapped/mapped between pressing and releasing */
+ if (release_event && !gadget_released && new_gi)
+ new_gi->state = GD_BUTTON_UNPRESSED;
}
void HandleGadgetsKeyInput(Key key)