return id;
}
-static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my)
+static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my,
+ int button)
{
struct GadgetInfo *gi;
+ /* first check for scrollbars in case of mouse scroll wheel button events */
+ if (button == 4 || button == 5)
+ {
+#if 0
+ printf("WHOA! SCROLL WHEEL DETECTED [%d]\n", button);
+#endif
+
+ for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
+ {
+ if (gi->mapped && gi->active &&
+ gi->type & GD_TYPE_SCROLLBAR)
+ return gi;
+ }
+
+ /* no active scrollbar found -- ignore this button event */
+ return NULL;
+ }
+
/* open selectboxes may overlap other active gadgets, so check them first */
for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
{
static int last_mx = 0, last_my = 0;
static int pressed_mx = 0, pressed_my = 0;
static boolean keep_selectbox_open = FALSE;
+ static boolean gadget_stopped = FALSE;
int scrollbar_mouse_pos = 0;
struct GadgetInfo *new_gi, *gi;
boolean press_event;
boolean gadget_pressed_repeated;
boolean gadget_pressed_off_borders;
boolean gadget_pressed_inside_select_line;
+ boolean gadget_pressed_delay_reached;
boolean gadget_moving;
boolean gadget_moving_inside;
boolean gadget_moving_off_borders;
+ boolean gadget_draggable;
+ boolean gadget_dragging;
boolean gadget_released;
boolean gadget_released_inside;
boolean gadget_released_inside_select_line;
}
/* check which gadget is under the mouse pointer */
- new_gi = getGadgetInfoFromMousePosition(mx, my);
+ new_gi = getGadgetInfoFromMousePosition(mx, my, button);
/* check if button state has changed since last invocation */
- press_event = (button != 0 && last_button == 0);
+ press_event = (button != 0 && last_button == 0);
release_event = (button == 0 && last_button != 0);
last_button = button;
gadget_pressed_repeated =
(button != 0 && last_gi != NULL && new_gi == last_gi);
+ gadget_pressed_delay_reached =
+ DelayReached(&pressed_delay, GADGET_FRAME_DELAY);
+
gadget_released = (release_event && last_gi != NULL);
gadget_released_inside = (gadget_released && new_gi == last_gi);
gadget_released_off_borders = (gadget_released && new_gi != last_gi);
if (button == 0 && !release_event)
gi = new_gi;
+ /* if new gadget or if no gadget was pressed, release stopped processing */
+ if (gadget_pressed || new_gi == NULL)
+ gadget_stopped = FALSE;
+
+ /* if gadget was stopped while being handled, stop gadget processing here */
+ if (gadget_stopped)
+ return TRUE;
+
if (gi != NULL)
{
int last_x = gi->event.x;
last_info_gi = new_gi;
}
- if (gadget_pressed)
- {
- if (gi->type == GD_TYPE_CHECK_BUTTON)
- {
- gi->checked = !gi->checked;
- }
- else if (gi->type == GD_TYPE_RADIO_BUTTON)
- {
- struct GadgetInfo *rgi = gadget_list_first_entry;
+#if 1
- while (rgi)
- {
- if (rgi->mapped &&
- rgi->type == GD_TYPE_RADIO_BUTTON &&
- rgi->radio_nr == gi->radio_nr &&
- rgi != gi)
- {
- rgi->checked = FALSE;
- DrawGadget(rgi, DG_UNPRESSED, rgi->direct_draw);
- }
+ gadget_draggable = (gi && gi->type & GD_TYPE_SCROLLBAR);
- rgi = rgi->next;
- }
+ /* reset drag position for newly pressed scrollbar to "not dragging" */
+ if (gadget_pressed && gadget_draggable)
+ gi->scrollbar.drag_position = -1;
- gi->checked = TRUE;
- }
- else if (gi->type & GD_TYPE_SCROLLBAR)
- {
- int mpos, gpos;
+ gadget_dragging = (gadget_draggable && gi->scrollbar.drag_position != -1);
- if (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL)
- {
- mpos = mx;
- gpos = gi->x;
- }
- else
- {
- mpos = my;
- gpos = gi->y;
- }
+ /* clicking next to a scrollbar to move it is not considered "moving" */
+ if (gadget_draggable && !gadget_dragging)
+ gadget_moving = FALSE;
- if (mpos >= gpos + gi->scrollbar.position &&
- mpos < gpos + gi->scrollbar.position + gi->scrollbar.size)
- {
- /* drag scrollbar */
- gi->scrollbar.drag_position =
- scrollbar_mouse_pos - gi->scrollbar.position;
- }
- else
+ /* when leaving scrollbar area when jump-scrolling, stop gadget processing */
+ if (gadget_draggable && !gadget_dragging && gadget_moving_off_borders)
+ gadget_stopped = TRUE;
+
+ if ((gadget_pressed) ||
+ (gadget_pressed_repeated && gadget_pressed_delay_reached))
+ {
+ if (gi->type & GD_TYPE_SCROLLBAR && !gadget_dragging)
+ {
+ int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my);
+ int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y);
+
+ if (button > 3 ||
+ mpos < gpos + gi->scrollbar.position ||
+ mpos >= gpos + gi->scrollbar.position + gi->scrollbar.size)
{
/* click scrollbar one scrollbar length up/left or down/right */
int item_steps = gs->items_visible - 1;
int item_direction = (mpos < gpos + gi->scrollbar.position ? -1 : +1);
+ if (button > 3)
+ {
+ item_steps = 3;
+ item_direction = (button == 4 ? -1 : +1);
+ }
+
changed_position = FALSE;
gs->item_position += item_steps * item_direction;
if (gi->event_mask & GD_EVENT_MOVING && changed_position)
gi->callback_action(gi);
- /* don't handle this scrollbar anymore while mouse button pressed */
- last_gi = NULL;
-
return TRUE;
}
+ else
+ {
+ /* don't handle this scrollbar anymore when mouse position reached */
+ if (gadget_pressed_repeated)
+ {
+ gadget_stopped = TRUE;
+
+ return TRUE;
+ }
+ }
+ }
+ }
+
+#endif
+
+ if (gadget_pressed)
+ {
+ if (gi->type == GD_TYPE_CHECK_BUTTON)
+ {
+ gi->checked = !gi->checked;
+ }
+ else if (gi->type == GD_TYPE_RADIO_BUTTON)
+ {
+ struct GadgetInfo *rgi = gadget_list_first_entry;
+
+ while (rgi)
+ {
+ if (rgi->mapped &&
+ rgi->type == GD_TYPE_RADIO_BUTTON &&
+ rgi->radio_nr == gi->radio_nr &&
+ rgi != gi)
+ {
+ rgi->checked = FALSE;
+ DrawGadget(rgi, DG_UNPRESSED, rgi->direct_draw);
+ }
+
+ rgi = rgi->next;
+ }
+
+ gi->checked = TRUE;
+ }
+ else if (gi->type & GD_TYPE_SCROLLBAR)
+ {
+ int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my);
+ int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y);
+
+ if (button >= 1 && button <= 3 &&
+ mpos >= gpos + gi->scrollbar.position &&
+ mpos < gpos + gi->scrollbar.position + gi->scrollbar.size)
+ {
+ /* start dragging scrollbar */
+ gi->scrollbar.drag_position =
+ scrollbar_mouse_pos - gi->scrollbar.position;
+ }
}
else if (gi->type & GD_TYPE_SELECTBOX)
{
{
gi->event.type = GD_EVENT_PRESSED;
+#if 1
+ if (gi->event_mask & GD_EVENT_REPEATED && gadget_pressed_delay_reached)
+ gi->callback_action(gi);
+#else
if (gi->event_mask & GD_EVENT_REPEATED &&
DelayReached(&pressed_delay, GADGET_FRAME_DELAY))
gi->callback_action(gi);
+#endif
}
if (gadget_moving)
DrawGadget(gi, DG_PRESSED, gi->direct_draw);
}
- gi->state = (gadget_moving_inside || gi->type & GD_TYPE_SCROLLBAR ?
+ gi->state = (gadget_moving_inside || gadget_draggable ?
GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED);
gi->event.type = GD_EVENT_MOVING;
gi->event.off_borders = gadget_moving_off_borders;
if (gi->type & GD_TYPE_SCROLLBAR)
DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
+#if 1
+ gi->state = GD_BUTTON_UNPRESSED;
+#endif
gi->event.type = GD_EVENT_RELEASED;
if (gi->event_mask & GD_EVENT_RELEASED &&