Slideshow dialog scroll buttons auto-repeat

This commit is contained in:
Bill Kendrick 2022-04-18 22:03:54 -07:00
parent 10e121bd0f
commit 206ca7cee2
2 changed files with 113 additions and 57 deletions

View file

@ -132,7 +132,7 @@ http://www.tuxpaint.org/
------------------- -------------------
* The up & down scroll buttons now auto-repeat if you click/tap and * The up & down scroll buttons now auto-repeat if you click/tap and
hold them in the "Tools" section, [WIP] the "Open" dialog, hold them in the "Tools" section, [WIP] the "Open" dialog,
the "New" dialog, and the [WIP] "Slideshow" dialog. the "New" dialog, and the "Slideshow" dialog.
For https://sourceforge.net/p/tuxpaint/feature-requests/173/ For https://sourceforge.net/p/tuxpaint/feature-requests/173/
Bill Kendrick <bill@newbreedsoftware.com> Bill Kendrick <bill@newbreedsoftware.com>

View file

@ -17108,7 +17108,8 @@ static int do_slideshow(void)
playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR);
} }
} }
else if (event.type == SDL_MOUSEBUTTONDOWN && valid_click(event.button.button)) else if ((event.type == SDL_MOUSEBUTTONDOWN && valid_click(event.button.button)) ||
event.type == TP_SDL_MOUSEBUTTONSCROLL)
{ {
if (event.button.x >= r_ttools.w && event.button.x < WINDOW_WIDTH - r_ttoolopt.w && if (event.button.x >= r_ttools.w && event.button.x < WINDOW_WIDTH - r_ttoolopt.w &&
event.button.y >= img_scroll_up->h && event.button.y < (button_h * buttons_tall + r_ttools.h - button_h)) event.button.y >= img_scroll_up->h && event.button.y < (button_h * buttons_tall + r_ttools.h - button_h))
@ -17152,6 +17153,13 @@ static int do_slideshow(void)
else if (event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && else if (event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 &&
event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2) event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2)
{ {
if (event.button.y < img_scroll_up->h ||
(event.button.y >= (button_h * buttons_tall + r_ttools.h - button_h) &&
event.button.y < (button_h * buttons_tall + r_ttools.h - img_scroll_down->h))
)
{
/* Up or Down scroll button in Slideshow dialog: */
if (event.button.y < img_scroll_up->h) if (event.button.y < img_scroll_up->h)
{ {
/* Up scroll button: */ /* Up scroll button: */
@ -17188,6 +17196,38 @@ static int do_slideshow(void)
which = which + 4; which = which + 4;
} }
} }
if (scrolltimer_dialog != NULL)
{
SDL_RemoveTimer(scrolltimer_dialog);
scrolltimer_dialog = NULL;
}
if (!scrolling_dialog && event.type == SDL_MOUSEBUTTONDOWN)
{
DEBUG_PRINTF("Starting scrolling\n");
memcpy(&scrolltimer_dialog_event, &event, sizeof(SDL_Event));
scrolltimer_dialog_event.type = TP_SDL_MOUSEBUTTONSCROLL;
/*
* We enable the timer subsystem only when needed (e.g., to use SDL_AddTimer() needed
* for scrolling) then disable it immediately after (e.g., after the timer has fired or
* after SDL_RemoveTimer()) because enabling the timer subsystem in SDL1 has a high
* energy impact on the Mac.
*/
scrolling_dialog = 1;
SDL_InitSubSystem(SDL_INIT_TIMER);
scrolltimer_dialog =
SDL_AddTimer(REPEAT_SPEED, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);
}
else
{
DEBUG_PRINTF("Continuing scrolling\n");
scrolltimer_dialog =
SDL_AddTimer(REPEAT_SPEED / 3, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);
}
}
else if (event.button.x >= r_ttools.w && event.button.x < r_ttools.w + button_w && else if (event.button.x >= r_ttools.w && event.button.x < r_ttools.w + button_w &&
event.button.y >= (button_h * buttons_tall + r_ttools.h) - button_h && event.button.y >= (button_h * buttons_tall + r_ttools.h) - button_h &&
event.button.y < (button_h * buttons_tall + r_ttools.h)) event.button.y < (button_h * buttons_tall + r_ttools.h))
@ -17389,6 +17429,23 @@ static int do_slideshow(void)
oldpos_x = event.button.x; oldpos_x = event.button.x;
oldpos_y = event.button.y; oldpos_y = event.button.y;
} }
else if (event.type == SDL_MOUSEBUTTONUP)
{
if (scrolling_dialog)
{
if (scrolltimer_dialog != NULL)
{
SDL_RemoveTimer(scrolltimer_dialog);
scrolltimer_dialog = NULL;
}
scrolling_dialog = 0;
SDL_QuitSubSystem(SDL_INIT_TIMER);
DEBUG_PRINTF("Killing dialog scrolling\n");
}
}
else if (event.type == SDL_JOYAXISMOTION) else if (event.type == SDL_JOYAXISMOTION)
handle_joyaxismotion(event, &motioner, &val_x, &val_y); handle_joyaxismotion(event, &motioner, &val_x, &val_y);
@ -18552,7 +18609,6 @@ static Uint32 scrolltimer_tool_callback(Uint32 interval, void *param)
/* Scroll Timer for Dialogs (Open & New) */ /* Scroll Timer for Dialogs (Open & New) */
static Uint32 scrolltimer_dialog_callback(Uint32 interval, void *param) static Uint32 scrolltimer_dialog_callback(Uint32 interval, void *param)
{ {
printf("scrolltimer_dialog_callback(%d)\n", interval);
if (scrolling_dialog) if (scrolling_dialog)
{ {
DEBUG_PRINTF("(Still scrolling dialog)\n"); DEBUG_PRINTF("(Still scrolling dialog)\n");