Add callback for hovering over an entry

This commit is contained in:
simon.kagstrom 2009-12-04 18:01:59 +00:00
parent 996382ebe9
commit c749c39936
3 changed files with 28 additions and 10 deletions

View File

@ -54,6 +54,11 @@ public:
exit(0); exit(0);
} }
virtual void hoverCallback(int which)
{
printf("entry %d hover over: %s\n", which, this->pp_msgs[which]);
}
virtual void escapeCallback(int which) virtual void escapeCallback(int which)
{ {
printf("entry %d escaped: %s\n", which, this->pp_msgs[which]); printf("entry %d escaped: %s\n", which, this->pp_msgs[which]);

View File

@ -213,7 +213,7 @@ submenu_t *Menu::findSubmenu(int index)
} }
void Menu::selectOne(int which) int Menu::selectOne(int which)
{ {
if (which >= this->n_entries) if (which >= this->n_entries)
which = 0; which = 0;
@ -222,9 +222,11 @@ void Menu::selectOne(int which)
if (this->pp_msgs[this->cur_sel][0] == ' ' || if (this->pp_msgs[this->cur_sel][0] == ' ' ||
IS_SUBMENU(this->pp_msgs[this->cur_sel])) IS_SUBMENU(this->pp_msgs[this->cur_sel]))
this->selectNext(0, 1); this->selectNext(0, 1);
return this->cur_sel;
} }
void Menu::selectNext(int dx, int dy) int Menu::selectNext(int dx, int dy)
{ {
int next; int next;
@ -234,8 +236,7 @@ void Menu::selectNext(int dx, int dy)
/* We want to skip this for some reason */ /* We want to skip this for some reason */
if (this->pp_msgs[this->cur_sel][0] == ' ' || if (this->pp_msgs[this->cur_sel][0] == ' ' ||
IS_SUBMENU(this->pp_msgs[this->cur_sel]) ) { IS_SUBMENU(this->pp_msgs[this->cur_sel]) ) {
this->selectNext(dx, dy); return this->selectNext(dx, dy);
return;
} }
/* If the next is a submenu */ /* If the next is a submenu */
@ -247,9 +248,11 @@ void Menu::selectNext(int dx, int dy)
p_submenu->sel = (p_submenu->sel + dx) < 0 ? p_submenu->n_entries - 1 : p_submenu->sel = (p_submenu->sel + dx) < 0 ? p_submenu->n_entries - 1 :
(p_submenu->sel + dx) % p_submenu->n_entries; (p_submenu->sel + dx) % p_submenu->n_entries;
} }
return this->cur_sel;
} }
void Menu::selectNext(event_t ev) int Menu::selectNext(event_t ev)
{ {
switch (ev) switch (ev)
{ {
@ -264,6 +267,8 @@ void Menu::selectNext(event_t ev)
default: default:
panic("selectNext(ev) called with event %d\n", ev); panic("selectNext(ev) called with event %d\n", ev);
} }
return this->cur_sel;
} }
void Menu::runLogic() void Menu::runLogic()
@ -278,8 +283,14 @@ void Menu::runLogic()
case KEY_DOWN: case KEY_DOWN:
case KEY_LEFT: case KEY_LEFT:
case KEY_RIGHT: case KEY_RIGHT:
this->selectNext(ev); {
break; int now = this->cur_sel;
int next;
next = this->selectNext(ev);
if (now != next)
this->hoverCallback(this->cur_sel);
} break;
case KEY_SELECT: case KEY_SELECT:
this->selectCallback(this->cur_sel); break; this->selectCallback(this->cur_sel); break;
case KEY_ESCAPE: case KEY_ESCAPE:

View File

@ -84,6 +84,8 @@ protected:
void printText(SDL_Surface *where, const char *msg, SDL_Color clr, void printText(SDL_Surface *where, const char *msg, SDL_Color clr,
int x, int y, int w, int h); int x, int y, int w, int h);
virtual void hoverCallback(int which) = 0;
virtual void selectCallback(int which) = 0; virtual void selectCallback(int which) = 0;
virtual void escapeCallback(int which) = 0; virtual void escapeCallback(int which) = 0;
@ -92,11 +94,11 @@ protected:
int getNextEntry(int dy); int getNextEntry(int dy);
void selectOne(int which); int selectOne(int which);
void selectNext(int dx, int dy); int selectNext(int dx, int dy);
void selectNext(event_t ev); int selectNext(event_t ev);
void pushEvent(event_t ev); void pushEvent(event_t ev);