mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-29 23:14:23 +01:00
Event handling
This commit is contained in:
parent
adb9f867da
commit
68c8a20e35
77
menu.cpp
77
menu.cpp
@ -480,6 +480,78 @@ const char *menu_select_file(const char *dir_path)
|
||||
32, 32, FULL_DISPLAY_X/2, FULL_DISPLAY_Y - 32);
|
||||
}
|
||||
|
||||
event_t Menu::popEvent()
|
||||
{
|
||||
event_t out;
|
||||
|
||||
if (this->ev_head == this->ev_tail)
|
||||
return EVENT_NONE;
|
||||
out = this->event_stack[this->ev_tail];
|
||||
this->ev_tail = (this->ev_tail + 1) % 8;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void Menu::pushEvent(event_t ev)
|
||||
{
|
||||
/* Push... */
|
||||
this->event_stack[this->ev_head] = ev;
|
||||
|
||||
/* ... and update */
|
||||
this->ev_head = (this->ev_head + 1) % 8;
|
||||
if (this->ev_head == this->ev_tail)
|
||||
this->ev_tail = (this->ev_tail + 1) % 8;
|
||||
}
|
||||
|
||||
void Menu::pushEvent(SDL_Event *ev)
|
||||
{
|
||||
int keys = 0;
|
||||
|
||||
switch(ev->type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
switch (ev->key.keysym.sym)
|
||||
{
|
||||
case SDLK_UP:
|
||||
keys |= KEY_UP;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
keys |= KEY_DOWN;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
keys |= KEY_LEFT;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
keys |= KEY_RIGHT;
|
||||
break;
|
||||
case SDLK_PAGEDOWN:
|
||||
keys |= KEY_PAGEDOWN;
|
||||
break;
|
||||
case SDLK_PAGEUP:
|
||||
keys |= KEY_PAGEUP;
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_SPACE:
|
||||
keys |= KEY_SELECT;
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
case SDLK_ESCAPE:
|
||||
keys |= KEY_ESCAPE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
void Menu::setText(const char *messages)
|
||||
{
|
||||
int submenu;
|
||||
@ -542,10 +614,11 @@ Menu::Menu(TTF_Font *font, SDL_Color clr, int w, int h)
|
||||
this->n_submenus = 0;
|
||||
|
||||
this->cur_sel = 0;
|
||||
this->hover_callback = NULL;
|
||||
this->selection_callback = NULL;
|
||||
this->mouse_x = -1;
|
||||
this->mouse_y = -1;
|
||||
|
||||
memset(this->event_stack, 0, sizeof(this->event_stack));
|
||||
this->ev_head = this->ev_tail = 0;
|
||||
}
|
||||
|
||||
Menu::~Menu()
|
||||
|
31
menu.hh
31
menu.hh
@ -17,15 +17,16 @@
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
KEY_UP,
|
||||
KEY_DOWN,
|
||||
KEY_LEFT,
|
||||
KEY_RIGHT,
|
||||
KEY_SELECT,
|
||||
KEY_ESCAPE,
|
||||
KEY_PAGEDOWN,
|
||||
KEY_PAGEUP,
|
||||
KEY_HELP,
|
||||
EVENT_NONE = 0,
|
||||
KEY_UP = 1,
|
||||
KEY_DOWN = 2,
|
||||
KEY_LEFT = 4,
|
||||
KEY_RIGHT = 8,
|
||||
KEY_SELECT = 16,
|
||||
KEY_ESCAPE = 32,
|
||||
KEY_PAGEDOWN = 64,
|
||||
KEY_PAGEUP = 128,
|
||||
KEY_HELP = 256,
|
||||
};
|
||||
|
||||
|
||||
@ -36,6 +37,8 @@ typedef struct
|
||||
int sel;
|
||||
} submenu_t;
|
||||
|
||||
typedef int event_t;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public:
|
||||
@ -53,14 +56,15 @@ public:
|
||||
~Menu();
|
||||
|
||||
private:
|
||||
void pushEvent(event_t ev);
|
||||
|
||||
event_t popEvent();
|
||||
|
||||
const char *title;
|
||||
const char **pp_msgs;
|
||||
TTF_Font *font;
|
||||
SDL_Color text_color;
|
||||
|
||||
int (*hover_callback)(Menu *me, int index);
|
||||
int (*selection_callback)(Menu *me, int index);
|
||||
|
||||
/* Width and height */
|
||||
int w, h;
|
||||
|
||||
@ -73,6 +77,9 @@ private:
|
||||
int cur_sel; /* Main selection */
|
||||
int start_entry_visible;
|
||||
int n_entries;
|
||||
|
||||
int ev_head, ev_tail;
|
||||
event_t event_stack[8];
|
||||
};
|
||||
|
||||
#endif /* !__MENU_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user