From: Holger Schemel Date: Wed, 26 Jul 2006 01:42:13 +0000 (+0200) Subject: rnd-20060726-1-src X-Git-Tag: 3.2.1^2~38 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=4dba06ad2079d7f9df56ec5512c6d27a0cf8c18e;p=rocksndiamonds.git rnd-20060726-1-src --- diff --git a/src/conftime.h b/src/conftime.h index 2b8cf3d4..06fac450 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2006-07-23 01:22]" +#define COMPILE_DATE_STRING "[2006-07-26 03:38]" diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index fc723cf9..678107c6 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -65,10 +65,29 @@ static int getNewGadgetID() 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) { @@ -1386,6 +1405,7 @@ boolean HandleGadgets(int mx, int my, int button) 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; @@ -1398,9 +1418,12 @@ boolean HandleGadgets(int mx, int my, int button) 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; @@ -1420,10 +1443,10 @@ boolean HandleGadgets(int mx, int my, int button) } /* 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; @@ -1492,6 +1515,9 @@ boolean HandleGadgets(int mx, int my, int 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); @@ -1549,6 +1575,14 @@ boolean HandleGadgets(int mx, int my, int button) 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; @@ -1633,55 +1667,35 @@ boolean HandleGadgets(int mx, int my, int button) 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 */ @@ -1690,6 +1704,12 @@ boolean HandleGadgets(int mx, int my, int button) 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; @@ -1715,11 +1735,62 @@ boolean HandleGadgets(int mx, int my, int button) 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) { @@ -1746,9 +1817,14 @@ boolean HandleGadgets(int mx, int my, int button) { 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) @@ -1815,7 +1891,7 @@ boolean HandleGadgets(int mx, int my, int button) 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; @@ -1864,6 +1940,9 @@ boolean HandleGadgets(int mx, int my, int button) 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 && diff --git a/src/libgame/misc.c b/src/libgame/misc.c index c98c9d07..a810b6d1 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -750,6 +750,45 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) /* when doing batch processing, always enable verbose mode (warnings) */ options.verbose = TRUE; } +#if 1 +#if DEBUG +#if defined(TARGET_SDL) + else if (strncmp(option, "-SDL_ListModes", option_len) == 0) + { + SDL_Rect **modes; + int i; + + SDL_Init(SDL_INIT_VIDEO); + + /* get available fullscreen/hardware modes */ + modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); + + /* check if there are any modes available */ + if (modes == (SDL_Rect **)0) + { + printf("No modes available!\n"); + + exit(-1); + } + + /* check if our resolution is restricted */ + if (modes == (SDL_Rect **)-1) + { + printf("All resolutions available.\n"); + } + else + { + /* print valid modes */ + printf("Available Modes:\n"); + for(i = 0; modes[i]; i++) + printf(" %d x %d\n", modes[i]->w, modes[i]->h); + } + + exit(0); + } +#endif +#endif +#endif else if (*option == '-') { Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);