Key repeat in menus
This commit is contained in:
parent
89a019f1fb
commit
cbbecc4bec
3 changed files with 100 additions and 63 deletions
|
@ -36,14 +36,7 @@ void create_menu(MenuData *menu) {
|
|||
menu->selected = -1;
|
||||
}
|
||||
|
||||
void menu_input(MenuData *menu) {
|
||||
SDL_Event event;
|
||||
|
||||
while(SDL_PollEvent(&event)) {
|
||||
int sym = event.key.keysym.sym;
|
||||
|
||||
global_processevent(&event);
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
static void key_action(MenuData *menu, int sym) {
|
||||
if(sym == tconfig.intval[KEY_DOWN] || sym == SDLK_DOWN) {
|
||||
do {
|
||||
if(++menu->cursor >= menu->ecount)
|
||||
|
@ -60,10 +53,34 @@ void menu_input(MenuData *menu) {
|
|||
} else if(sym == SDLK_ESCAPE && menu->type == MT_Transient) {
|
||||
menu->quit = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void menu_input(MenuData *menu) {
|
||||
SDL_Event event;
|
||||
|
||||
while(SDL_PollEvent(&event)) {
|
||||
int sym = event.key.keysym.sym;
|
||||
|
||||
global_processevent(&event);
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
key_action(menu,sym);
|
||||
|
||||
menu->lastkey = sym;
|
||||
} else if(event.type == SDL_QUIT) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Uint8 *keys = SDL_GetKeyState(NULL);
|
||||
if(keys[menu->lastkey])
|
||||
menu->keypressed++;
|
||||
else
|
||||
menu->keypressed = 0;
|
||||
|
||||
if(menu->keypressed > KEYREPEAT_TIME) {
|
||||
key_action(menu, menu->lastkey);
|
||||
menu->keypressed = KEYREPEAT_TIME-10;
|
||||
}
|
||||
}
|
||||
|
||||
void menu_logic(MenuData *menu) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#define IMENU_BLUR 0.05
|
||||
#define FADE_TIME 15
|
||||
#define KEYREPEAT_TIME 40
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
|
@ -29,6 +30,9 @@ typedef struct MenuData{
|
|||
int cursor;
|
||||
int selected;
|
||||
|
||||
int lastkey;
|
||||
int keypressed;
|
||||
|
||||
MenuEntry *entries;
|
||||
int ecount;
|
||||
|
||||
|
|
|
@ -483,21 +483,7 @@ void binding_input(MenuData *menu, OptionBinding *b)
|
|||
}
|
||||
}
|
||||
|
||||
void options_menu_input(MenuData *menu) {
|
||||
SDL_Event event;
|
||||
OptionBinding *b;
|
||||
|
||||
if((b = get_input_blocking_binding(menu)) != NULL)
|
||||
{
|
||||
binding_input(menu, b);
|
||||
return;
|
||||
}
|
||||
|
||||
while(SDL_PollEvent(&event)) {
|
||||
int sym = event.key.keysym.sym;
|
||||
|
||||
global_processevent(&event);
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
static void options_key_action(MenuData *menu, int sym) {
|
||||
if(sym == tconfig.intval[KEY_DOWN] || sym == SDLK_DOWN) {
|
||||
menu->drawdata[3] = 10;
|
||||
do {
|
||||
|
@ -544,10 +530,40 @@ void options_menu_input(MenuData *menu) {
|
|||
}
|
||||
|
||||
menu->cursor = (menu->cursor % menu->ecount) + menu->ecount*(menu->cursor < 0);
|
||||
}
|
||||
|
||||
void options_menu_input(MenuData *menu) {
|
||||
SDL_Event event;
|
||||
OptionBinding *b;
|
||||
|
||||
if((b = get_input_blocking_binding(menu)) != NULL)
|
||||
{
|
||||
binding_input(menu, b);
|
||||
return;
|
||||
}
|
||||
|
||||
while(SDL_PollEvent(&event)) {
|
||||
int sym = event.key.keysym.sym;
|
||||
|
||||
global_processevent(&event);
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
options_key_action(menu, sym);
|
||||
menu->lastkey = sym;
|
||||
} else if(event.type == SDL_QUIT) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Uint8 *keys = SDL_GetKeyState(NULL);
|
||||
if(keys[menu->lastkey])
|
||||
menu->keypressed++;
|
||||
else
|
||||
menu->keypressed = 0;
|
||||
|
||||
if(menu->keypressed > KEYREPEAT_TIME) {
|
||||
options_key_action(menu, menu->lastkey);
|
||||
menu->keypressed = KEYREPEAT_TIME-10;
|
||||
}
|
||||
}
|
||||
|
||||
int options_menu_loop(MenuData *menu) {
|
||||
|
|
Loading…
Reference in a new issue