diff --git a/README.MD b/README.MD index 2ddc7ea..566ba22 100644 --- a/README.MD +++ b/README.MD @@ -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 ===== @@ -287,6 +288,7 @@ CHANGELOG 1.82 - support up to eight controllers on Switch +- allow faster menu navigation by holding down directions 1.81 diff --git a/src/gp2x/menu/menu.h b/src/gp2x/menu/menu.h index 453a353..d250b1c 100755 --- a/src/gp2x/menu/menu.h +++ b/src/gp2x/menu/menu.h @@ -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 diff --git a/src/gp2x/menu/menu_controls.cpp b/src/gp2x/menu/menu_controls.cpp index 537e808..214d45a 100755 --- a/src/gp2x/menu/menu_controls.cpp +++ b/src/gp2x/menu/menu_controls.cpp @@ -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; @@ -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) diff --git a/src/gp2x/menu/menu_display.cpp b/src/gp2x/menu/menu_display.cpp index 2d600b3..8e245ea 100755 --- a/src/gp2x/menu/menu_display.cpp +++ b/src/gp2x/menu/menu_display.cpp @@ -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; @@ -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) diff --git a/src/gp2x/menu/menu_load.cpp b/src/gp2x/menu/menu_load.cpp index 01ec2f8..32ced08 100755 --- a/src/gp2x/menu/menu_load.cpp +++ b/src/gp2x/menu/menu_load.cpp @@ -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; @@ -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);*/} diff --git a/src/gp2x/menu/menu_main.cpp b/src/gp2x/menu/menu_main.cpp index 7b399ae..7ceaaa5 100755 --- a/src/gp2x/menu/menu_main.cpp +++ b/src/gp2x/menu/menu_main.cpp @@ -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; @@ -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) diff --git a/src/gp2x/menu/menu_memory_disk.cpp b/src/gp2x/menu/menu_memory_disk.cpp index b7898b3..5cbd52d 100755 --- a/src/gp2x/menu/menu_memory_disk.cpp +++ b/src/gp2x/menu/menu_memory_disk.cpp @@ -342,7 +342,33 @@ static int key_memDiskMenu(int *c) int left=0, right=0, up=0, down=0, hit0=0, hit1=0, hit2=0, del=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=del=0; @@ -373,6 +399,48 @@ static int key_memDiskMenu(int *c) break; } } + + 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? { diff --git a/src/gp2x/menu/menu_misc.cpp b/src/gp2x/menu/menu_misc.cpp index 9d9be6e..1befca9 100755 --- a/src/gp2x/menu/menu_misc.cpp +++ b/src/gp2x/menu/menu_misc.cpp @@ -607,6 +607,32 @@ static int key_miscMenu(int *c) int directionHeld = 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=0; @@ -633,6 +659,48 @@ static int key_miscMenu(int *c) } } + 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; + } + #ifdef __SWITCH__ if (justSwitchedSingleJoycons) { if (left != 0 || right != 0 || up != 0 || down != 0) diff --git a/src/gp2x/menu/menu_savestates.cpp b/src/gp2x/menu/menu_savestates.cpp index 80b3b13..9386367 100755 --- a/src/gp2x/menu/menu_savestates.cpp +++ b/src/gp2x/menu/menu_savestates.cpp @@ -146,6 +146,32 @@ static inline int key_saveMenu(int *cp) //if (delay<3) return end; //delay=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=0; @@ -172,6 +198,49 @@ static inline int key_saveMenu(int *cp) #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 shut-down the whole menu? { if (emulating)