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);
}
virtual void hoverCallback(int which)
{
printf("entry %d hover over: %s\n", which, this->pp_msgs[which]);
}
virtual void escapeCallback(int 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)
which = 0;
@ -222,9 +222,11 @@ void Menu::selectOne(int which)
if (this->pp_msgs[this->cur_sel][0] == ' ' ||
IS_SUBMENU(this->pp_msgs[this->cur_sel]))
this->selectNext(0, 1);
return this->cur_sel;
}
void Menu::selectNext(int dx, int dy)
int Menu::selectNext(int dx, int dy)
{
int next;
@ -234,8 +236,7 @@ void Menu::selectNext(int dx, int dy)
/* We want to skip this for some reason */
if (this->pp_msgs[this->cur_sel][0] == ' ' ||
IS_SUBMENU(this->pp_msgs[this->cur_sel]) ) {
this->selectNext(dx, dy);
return;
return this->selectNext(dx, dy);
}
/* 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 + dx) % p_submenu->n_entries;
}
return this->cur_sel;
}
void Menu::selectNext(event_t ev)
int Menu::selectNext(event_t ev)
{
switch (ev)
{
@ -264,6 +267,8 @@ void Menu::selectNext(event_t ev)
default:
panic("selectNext(ev) called with event %d\n", ev);
}
return this->cur_sel;
}
void Menu::runLogic()
@ -278,8 +283,14 @@ void Menu::runLogic()
case KEY_DOWN:
case KEY_LEFT:
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:
this->selectCallback(this->cur_sel); break;
case KEY_ESCAPE:

View File

@ -84,6 +84,8 @@ protected:
void printText(SDL_Surface *where, const char *msg, SDL_Color clr,
int x, int y, int w, int h);
virtual void hoverCallback(int which) = 0;
virtual void selectCallback(int which) = 0;
virtual void escapeCallback(int which) = 0;
@ -92,11 +94,11 @@ protected:
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);