Skip to content

Commit

Permalink
allow faster menu navigation by holding down directions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Dec 28, 2018
1 parent 4169a9e commit dd0a1dc
Show file tree
Hide file tree
Showing 9 changed files with 486 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.MD
Expand Up @@ -3,6 +3,7 @@ Changes in this Version
1.82

- support up to eight controllers on Switch
- allow faster menu navigation by holding down directions

Description
=====
Expand Down Expand Up @@ -287,6 +288,7 @@ CHANGELOG
1.82

- support up to eight controllers on Switch
- allow faster menu navigation by holding down directions

1.81

Expand Down
3 changes: 3 additions & 0 deletions src/gp2x/menu/menu.h
Expand Up @@ -108,3 +108,6 @@ enum { MEMDISK_MENU_CASE_MAIN, MEMDISK_MENU_CASE_MISC };
#define DEFAULT_SWAPAB 1
#define DEFAULT_SINGLEJOYCONS 0
#endif

#define MENU_MIN_HOLDING_TIME 200
#define MENU_MOVE_DELAY 50
70 changes: 69 additions & 1 deletion src/gp2x/menu/menu_controls.cpp
Expand Up @@ -701,6 +701,31 @@ static int key_controlsMenu(int *c)
if (delay<5) return end;
delay=0;
#endif
static int holdingUp=0;
static int holdingDown=0;
static int holdingRight=0;
static int holdingLeft=0;
static Uint32 menu_last_press_time=0;
static Uint32 menu_last_move_time=0;
Uint32 now=SDL_GetTicks();
if (holdingLeft || holdingRight || holdingUp || holdingDown)
{
if (now-menu_last_press_time>MENU_MIN_HOLDING_TIME && now-menu_last_move_time>MENU_MOVE_DELAY)
{
menu_last_move_time=now;
SDL_Event ev;
ev.type = SDL_KEYDOWN;
if (holdingLeft)
ev.key.keysym.sym = SDLK_LEFT;
else if (holdingRight)
ev.key.keysym.sym = SDLK_RIGHT;
else if (holdingUp)
ev.key.keysym.sym = SDLK_UP;
else if (holdingDown)
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
}
}
while (SDL_PollEvent(&event) > 0)
{
left=right=up=down=hit0=hit1=hit2=hit3=del=0;
Expand All @@ -727,7 +752,50 @@ static int key_controlsMenu(int *c)
case SDLK_END: hit0=1; break;
#endif
}
}
}

if (event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
holdingRight=0;
break;
case SDLK_LEFT:
holdingLeft=0;
break;
case SDLK_UP:
holdingUp=0;
break;
case SDLK_DOWN:
holdingDown=0;
break;
default:
break;
}
}

if (left && !holdingLeft)
{
holdingLeft=1;
menu_last_press_time=now;
}
if (right && !holdingRight)
{
holdingRight=1;
menu_last_press_time=now;
}
if (up && !holdingUp)
{
holdingUp=1;
menu_last_press_time=now;
}
if (down && !holdingDown)
{
holdingDown=1;
menu_last_press_time=now;
}

if (hit2) //Does the user want to cancel the menu completely?
{
if (emulating)
Expand Down
69 changes: 69 additions & 0 deletions src/gp2x/menu/menu_display.cpp
Expand Up @@ -453,6 +453,32 @@ static int key_displayMenu(int *c)
int left=0, right=0, up=0, down=0, hit0=0, hit1=0, hit2=0;
SDL_Event event;

static int holdingUp=0;
static int holdingDown=0;
static int holdingRight=0;
static int holdingLeft=0;
static Uint32 menu_last_press_time=0;
static Uint32 menu_last_move_time=0;
Uint32 now=SDL_GetTicks();
if (holdingLeft || holdingRight || holdingUp || holdingDown)
{
if (now-menu_last_press_time>MENU_MIN_HOLDING_TIME && now-menu_last_move_time>MENU_MOVE_DELAY)
{
menu_last_move_time=now;
SDL_Event ev;
ev.type = SDL_KEYDOWN;
if (holdingLeft)
ev.key.keysym.sym = SDLK_LEFT;
else if (holdingRight)
ev.key.keysym.sym = SDLK_RIGHT;
else if (holdingUp)
ev.key.keysym.sym = SDLK_UP;
else if (holdingDown)
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
}
}

while (SDL_PollEvent(&event) > 0)
{
left=right=up=down=hit0=hit1=hit2=0;
Expand All @@ -478,6 +504,49 @@ static int key_displayMenu(int *c)
//note SDLK_CTRL corresponds to ButtonSelect on Vita
}
}

if (event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
holdingRight=0;
break;
case SDLK_LEFT:
holdingLeft=0;
break;
case SDLK_UP:
holdingUp=0;
break;
case SDLK_DOWN:
holdingDown=0;
break;
default:
break;
}
}

if (left && !holdingLeft)
{
holdingLeft=1;
menu_last_press_time=now;
}
if (right && !holdingRight)
{
holdingRight=1;
menu_last_press_time=now;
}
if (up && !holdingUp)
{
holdingUp=1;
menu_last_press_time=now;
}
if (down && !holdingDown)
{
holdingDown=1;
menu_last_press_time=now;
}

if (hit2) //Does the user want to cancel the menu completely?
{
if (emulating)
Expand Down
70 changes: 70 additions & 0 deletions src/gp2x/menu/menu_load.cpp
Expand Up @@ -375,6 +375,33 @@ static int menuLoadLoop(char *curr_path)
//unsigned long keys;
draw_dirlist(curr_path, namelist, n, sel);
delay ++;

static int holdingUp=0;
static int holdingDown=0;
static int holdingRight=0;
static int holdingLeft=0;
static Uint32 menu_last_press_time=0;
static Uint32 menu_last_move_time=0;
Uint32 now=SDL_GetTicks();
if (holdingLeft || holdingRight || holdingUp || holdingDown)
{
if (now-menu_last_press_time>MENU_MIN_HOLDING_TIME && now-menu_last_move_time>MENU_MOVE_DELAY)
{
menu_last_move_time=now;
SDL_Event ev;
ev.type = SDL_KEYDOWN;
if (holdingLeft)
ev.key.keysym.sym = SDLK_LEFT;
else if (holdingRight)
ev.key.keysym.sym = SDLK_RIGHT;
else if (holdingUp)
ev.key.keysym.sym = SDLK_UP;
else if (holdingDown)
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
}
}

while (SDL_PollEvent(&event) > 0 && hit0+hit1+hitL==0)
{
left=right=up=down=hit0=hit1=hit2=hit3=hit4=hitL=0;
Expand Down Expand Up @@ -408,6 +435,49 @@ static int menuLoadLoop(char *curr_path)
case SDLK_l: hitL=1;
}
}

if (event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
holdingRight=0;
break;
case SDLK_LEFT:
holdingLeft=0;
break;
case SDLK_UP:
holdingUp=0;
break;
case SDLK_DOWN:
holdingDown=0;
break;
default:
break;
}
}

if (left && !holdingLeft)
{
holdingLeft=1;
menu_last_press_time=now;
}
if (right && !holdingRight)
{
holdingRight=1;
menu_last_press_time=now;
}
if (up && !holdingUp)
{
holdingUp=1;
menu_last_press_time=now;
}
if (down && !holdingDown)
{
holdingDown=1;
menu_last_press_time=now;
}

if(up) { sel--; if (sel < 0) sel = n-2; /*usleep(10*1024);*/ }
if(down) { sel++; if (sel > n-2) sel = 0;/*usleep(10*1024);*/}
if(left) { sel-=10; if (sel < 0) sel = 0;/*usleep(10*1024);*/}
Expand Down
68 changes: 67 additions & 1 deletion src/gp2x/menu/menu_main.cpp
Expand Up @@ -491,6 +491,32 @@ SDL_ANDROID_SetScreenKeyboardShown(1);

force_quit=0;

static int holdingUp=0;
static int holdingDown=0;
static int holdingRight=0;
static int holdingLeft=0;
static Uint32 menu_last_press_time=0;
static Uint32 menu_last_move_time=0;
Uint32 now=SDL_GetTicks();
if (holdingLeft || holdingRight || holdingUp || holdingDown)
{
if (now-menu_last_press_time>MENU_MIN_HOLDING_TIME && now-menu_last_move_time>MENU_MOVE_DELAY)
{
menu_last_move_time=now;
SDL_Event ev;
ev.type = SDL_KEYDOWN;
if (holdingLeft)
ev.key.keysym.sym = SDLK_LEFT;
else if (holdingRight)
ev.key.keysym.sym = SDLK_RIGHT;
else if (holdingUp)
ev.key.keysym.sym = SDLK_UP;
else if (holdingDown)
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
}
}

while (SDL_PollEvent(&event) > 0)
{
left=right=up=down=hit0=hit1=hit2=hit3=hit4=hit5=hit6=hitH=hitS=hitQ=hitN1=hitN2=hitN3=hitN4=0;
Expand Down Expand Up @@ -529,8 +555,48 @@ SDL_ANDROID_SetScreenKeyboardShown(1);
case SDLK_3: hitN3=1; break;
case SDLK_4: hitN4=1;
}
} else if (event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
holdingRight=0;
break;
case SDLK_LEFT:
holdingLeft=0;
break;
case SDLK_UP:
holdingUp=0;
break;
case SDLK_DOWN:
holdingDown=0;
break;
default:
break;
}
}


if (left && !holdingLeft)
{
holdingLeft=1;
menu_last_press_time=now;
}
if (right && !holdingRight)
{
holdingRight=1;
menu_last_press_time=now;
}
if (up && !holdingUp)
{
holdingUp=1;
menu_last_press_time=now;
}
if (down && !holdingDown)
{
holdingDown=1;
menu_last_press_time=now;
}

if (info)
showInfo();
else if (hit1)
Expand Down

0 comments on commit dd0a1dc

Please sign in to comment.