New dialog scroll buttons auto-repeat
This commit is contained in:
parent
c022e0c1a1
commit
10e121bd0f
2 changed files with 105 additions and 45 deletions
|
|
@ -130,8 +130,9 @@ http://www.tuxpaint.org/
|
||||||
|
|
||||||
* Other Improvements:
|
* Other Improvements:
|
||||||
-------------------
|
-------------------
|
||||||
* The "Tools" section's, [WIP] "Open" dialog's, and [WIP] "New" dialogs'
|
* The up & down scroll buttons now auto-repeat if you click/tap and
|
||||||
up & down scroll buttons auto-repeat if you click/tap and hold them.
|
hold them in the "Tools" section, [WIP] the "Open" dialog,
|
||||||
|
the "New" dialog, and the [WIP] "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>
|
||||||
|
|
||||||
|
|
|
||||||
145
src/tuxpaint.c
145
src/tuxpaint.c
|
|
@ -22,7 +22,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
June 14, 2002 - April 8, 2022
|
June 14, 2002 - April 18, 2022
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
@ -2341,7 +2341,7 @@ SDL_Rect kbd_rect;
|
||||||
int brushflag, xnew, ynew, eraflag, lineflag, magicflag, keybd_flag, keybd_position, keyglobal, initial_y, gen_key_flag,
|
int brushflag, xnew, ynew, eraflag, lineflag, magicflag, keybd_flag, keybd_position, keyglobal, initial_y, gen_key_flag,
|
||||||
ide, activeflag, old_x, old_y;
|
ide, activeflag, old_x, old_y;
|
||||||
int cur_thing;
|
int cur_thing;
|
||||||
SDL_TimerID scrolltimer_dialog = NULL; /* Used by both Open and New dialogs */
|
SDL_TimerID scrolltimer_dialog = NULL; /* Used by Open, Open->Slideshow, and New dialogs */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* --- MAIN LOOP! ---
|
* --- MAIN LOOP! ---
|
||||||
|
|
@ -3598,7 +3598,7 @@ static void mainloop(void)
|
||||||
/* Tool up scroll button */
|
/* Tool up scroll button */
|
||||||
tool_scroll -= gd_tools.cols;
|
tool_scroll -= gd_tools.cols;
|
||||||
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
||||||
|
|
||||||
draw_toolbar();
|
draw_toolbar();
|
||||||
update_screen_rect(&r_tools);
|
update_screen_rect(&r_tools);
|
||||||
}
|
}
|
||||||
|
|
@ -3608,7 +3608,7 @@ static void mainloop(void)
|
||||||
tool_scroll += gd_tools.cols;
|
tool_scroll += gd_tools.cols;
|
||||||
draw_toolbar();
|
draw_toolbar();
|
||||||
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
||||||
|
|
||||||
update_screen_rect(&r_tools);
|
update_screen_rect(&r_tools);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16041,7 +16041,7 @@ static int do_open(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)
|
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)
|
||||||
|
|
@ -16085,17 +16085,17 @@ static int do_open(void)
|
||||||
if (event.button.y < img_scroll_up->h)
|
if (event.button.y < img_scroll_up->h)
|
||||||
{
|
{
|
||||||
/* Up scroll button in Open dialog: */
|
/* Up scroll button in Open dialog: */
|
||||||
|
|
||||||
if (cur > 0)
|
if (cur > 0)
|
||||||
{
|
{
|
||||||
cur = cur - 4;
|
cur = cur - 4;
|
||||||
update_list = 1;
|
update_list = 1;
|
||||||
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
||||||
|
|
||||||
if (cur == 0)
|
if (cur == 0)
|
||||||
do_setcursor(cursor_arrow);
|
do_setcursor(cursor_arrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which >= cur + 16)
|
if (which >= cur + 16)
|
||||||
which = which - 4;
|
which = which - 4;
|
||||||
}
|
}
|
||||||
|
|
@ -16103,23 +16103,24 @@ static int do_open(void)
|
||||||
event.button.y < (button_h * buttons_tall + r_ttools.h) - img_scroll_up->h)
|
event.button.y < (button_h * buttons_tall + r_ttools.h) - img_scroll_up->h)
|
||||||
{
|
{
|
||||||
/* Down scroll button in Open dialog: */
|
/* Down scroll button in Open dialog: */
|
||||||
|
|
||||||
if (cur < num_files - 16)
|
if (cur < num_files - 16)
|
||||||
{
|
{
|
||||||
cur = cur + 4;
|
cur = cur + 4;
|
||||||
update_list = 1;
|
update_list = 1;
|
||||||
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
||||||
|
|
||||||
if (cur >= num_files - 16)
|
if (cur >= num_files - 16)
|
||||||
do_setcursor(cursor_arrow);
|
do_setcursor(cursor_arrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which < cur)
|
if (which < cur)
|
||||||
which = which + 4;
|
which = which + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrolltimer_dialog != NULL)
|
if (scrolltimer_dialog != NULL)
|
||||||
{
|
{
|
||||||
|
printf("SDL_RemoveTimer(scrolltimer_dialog);\n");
|
||||||
SDL_RemoveTimer(scrolltimer_dialog);
|
SDL_RemoveTimer(scrolltimer_dialog);
|
||||||
scrolltimer_dialog = NULL;
|
scrolltimer_dialog = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -16138,15 +16139,18 @@ static int do_open(void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
scrolling_dialog = 1;
|
scrolling_dialog = 1;
|
||||||
SDL_InitSubSystem(SDL_INIT_TIMER);
|
//SDL_InitSubSystem(SDL_INIT_TIMER);
|
||||||
|
printf("SDL_InitSubSystem(SDL_INIT_TIMER) = %d\n", SDL_InitSubSystem(SDL_INIT_TIMER));
|
||||||
scrolltimer_dialog =
|
scrolltimer_dialog =
|
||||||
SDL_AddTimer(REPEAT_SPEED, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);
|
SDL_AddTimer(1/*REPEAT_SPEED*/, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);
|
||||||
|
printf("SDL_AddTimer(REPEAT_SPEED, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_PRINTF("Continuing scrolling\n");
|
DEBUG_PRINTF("Continuing scrolling\n");
|
||||||
scrolltimer_dialog =
|
scrolltimer_dialog =
|
||||||
SDL_AddTimer(REPEAT_SPEED / 3, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);
|
SDL_AddTimer(1/*REPEAT_SPEED / 3*/, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);
|
||||||
|
printf("SDL_AddTimer(REPEAT_SPEED / 3, scrolltimer_dialog_callback, (void *)&scrolltimer_dialog_event);\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16289,20 +16293,20 @@ static int do_open(void)
|
||||||
|
|
||||||
else if (event.type == SDL_MOUSEBUTTONUP)
|
else if (event.type == SDL_MOUSEBUTTONUP)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if (scrolling_dialog)
|
if (scrolling_dialog)
|
||||||
{
|
{
|
||||||
if (scrolltimer_dialog != NULL)
|
if (scrolltimer_dialog != NULL)
|
||||||
{
|
{
|
||||||
SDL_RemoveTimer(scrolltimer_dialog);
|
SDL_RemoveTimer(scrolltimer_dialog);
|
||||||
|
printf("SDL_RemoveTimer(scrolltimer_dialog);\n");
|
||||||
scrolltimer_dialog = NULL;
|
scrolltimer_dialog = NULL;
|
||||||
}
|
}
|
||||||
scrolling_dialog = 0;
|
scrolling_dialog = 0;
|
||||||
SDL_QuitSubSystem(SDL_INIT_TIMER);
|
SDL_QuitSubSystem(SDL_INIT_TIMER);
|
||||||
|
printf("SDL_QuitSubSystem(SDL_INIT_TIMER);\n");
|
||||||
|
|
||||||
DEBUG_PRINTF("Killing dialog scrolling\n");
|
DEBUG_PRINTF("Killing dialog scrolling\n");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (event.type == SDL_JOYAXISMOTION)
|
else if (event.type == SDL_JOYAXISMOTION)
|
||||||
|
|
@ -21096,7 +21100,8 @@ static int do_new_dialog(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))
|
||||||
|
|
@ -21127,40 +21132,79 @@ static int do_new_dialog(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)
|
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_up->h))
|
||||||
|
)
|
||||||
{
|
{
|
||||||
/* Up scroll button: */
|
/* Up or Down scroll button in New dialog: */
|
||||||
|
|
||||||
if (cur > 0)
|
if (event.button.y < img_scroll_up->h)
|
||||||
{
|
{
|
||||||
cur = cur - 4;
|
/* Up scroll button: */
|
||||||
update_list = 1;
|
|
||||||
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
|
||||||
|
|
||||||
if (cur == 0)
|
if (cur > 0)
|
||||||
do_setcursor(cursor_arrow);
|
{
|
||||||
|
cur = cur - 4;
|
||||||
|
update_list = 1;
|
||||||
|
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
||||||
|
|
||||||
|
if (cur == 0)
|
||||||
|
do_setcursor(cursor_arrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (which >= cur + 16)
|
||||||
|
which = which - 4;
|
||||||
|
}
|
||||||
|
else if (event.button.y >= (button_h * buttons_tall + r_ttools.h - button_h) &&
|
||||||
|
event.button.y < (button_h * buttons_tall + r_ttools.h - img_scroll_up->h))
|
||||||
|
{
|
||||||
|
/* Down scroll button: */
|
||||||
|
|
||||||
|
if (cur < num_files - 16)
|
||||||
|
{
|
||||||
|
cur = cur + 4;
|
||||||
|
update_list = 1;
|
||||||
|
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
||||||
|
|
||||||
|
if (cur >= num_files - 16)
|
||||||
|
do_setcursor(cursor_arrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (which < cur)
|
||||||
|
which = which + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which >= cur + 16)
|
if (scrolltimer_dialog != NULL)
|
||||||
which = which - 4;
|
{
|
||||||
}
|
SDL_RemoveTimer(scrolltimer_dialog);
|
||||||
else if (event.button.y >= (button_h * buttons_tall + r_ttools.h - button_h) &&
|
scrolltimer_dialog = NULL;
|
||||||
event.button.y < (button_h * buttons_tall + r_ttools.h - img_scroll_up->h))
|
}
|
||||||
{
|
|
||||||
/* Down scroll button: */
|
|
||||||
|
|
||||||
if (cur < num_files - 16)
|
if (!scrolling_dialog && event.type == SDL_MOUSEBUTTONDOWN)
|
||||||
{
|
{
|
||||||
cur = cur + 4;
|
DEBUG_PRINTF("Starting scrolling\n");
|
||||||
update_list = 1;
|
memcpy(&scrolltimer_dialog_event, &event, sizeof(SDL_Event));
|
||||||
playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR);
|
scrolltimer_dialog_event.type = TP_SDL_MOUSEBUTTONSCROLL;
|
||||||
|
|
||||||
if (cur >= num_files - 16)
|
/*
|
||||||
do_setcursor(cursor_arrow);
|
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which < cur)
|
|
||||||
which = which + 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 &&
|
||||||
|
|
@ -21266,6 +21310,21 @@ static int do_new_dialog(void)
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue