mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-26 05:24:21 +01:00
Refactor string/key listeners and make the main menu one such
This commit is contained in:
parent
f8bbe977c0
commit
6b4ac470f9
@ -1,7 +1,7 @@
|
||||
#include "menu.hh"
|
||||
|
||||
class MainView;
|
||||
class MainMenu : public Menu
|
||||
class MainMenu : public Menu, KeyListener
|
||||
{
|
||||
friend class MainView;
|
||||
|
||||
@ -71,9 +71,10 @@ public:
|
||||
Gui::gui->pushView(Gui::gui->dv);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 4:
|
||||
Gui::gui->pushView(Gui::gui->kv);
|
||||
Gui::gui->kv->activate();
|
||||
Gui::gui->kv->registerKeyListener(this);
|
||||
break;
|
||||
|
||||
case 11:
|
||||
@ -85,6 +86,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void keyCallback(bool shift, const char *str)
|
||||
{
|
||||
printf("Vobb: %d: %s\n", shift, str);
|
||||
}
|
||||
|
||||
virtual void hoverCallback(int which)
|
||||
{
|
||||
this->help->updateHelpMessage(which);
|
||||
|
@ -225,7 +225,7 @@ const char VirtualKeyboard::keycodeToChar(int kc)
|
||||
return s[0];
|
||||
}
|
||||
|
||||
void VirtualKeyboard::registerListener(KeyListener *kl)
|
||||
void VirtualKeyboard::registerKeyListener(KeyListener *kl)
|
||||
{
|
||||
int n_listeners = sizeof(this->keyListeners) / sizeof(*this->keyListeners);
|
||||
int i;
|
||||
@ -239,7 +239,7 @@ void VirtualKeyboard::registerListener(KeyListener *kl)
|
||||
}
|
||||
|
||||
/* Templates FTW! */
|
||||
void VirtualKeyboard::registerListener(StringListener *sl)
|
||||
void VirtualKeyboard::registerStringListener(StringListener *sl)
|
||||
{
|
||||
int n_listeners = sizeof(this->stringListeners) / sizeof(*this->stringListeners);
|
||||
int i;
|
||||
@ -252,7 +252,7 @@ void VirtualKeyboard::registerListener(StringListener *sl)
|
||||
this->stringListeners[i] = sl;
|
||||
}
|
||||
|
||||
void VirtualKeyboard::unregisterListener(KeyListener *kl)
|
||||
void VirtualKeyboard::unregisterKeyListener(KeyListener *kl)
|
||||
{
|
||||
int n_listeners = sizeof(this->keyListeners) / sizeof(*this->keyListeners);
|
||||
|
||||
@ -263,7 +263,7 @@ void VirtualKeyboard::unregisterListener(KeyListener *kl)
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualKeyboard::unregisterListener(StringListener *sl)
|
||||
void VirtualKeyboard::unregisterStringListener(StringListener *sl)
|
||||
{
|
||||
int n_listeners = sizeof(this->stringListeners) / sizeof(*this->stringListeners);
|
||||
|
||||
@ -355,6 +355,12 @@ void VirtualKeyboard::runLogic()
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualKeyboard::flushKeyListeners()
|
||||
{
|
||||
memset(this->keyListeners, 0, sizeof(this->keyListeners));
|
||||
memset(this->stringListeners, 0, sizeof(this->stringListeners));
|
||||
}
|
||||
|
||||
void VirtualKeyboard::draw(SDL_Surface *where)
|
||||
{
|
||||
this->draw(where, 20, 240, 600, 240);
|
||||
|
@ -38,10 +38,10 @@ class VirtualKeyboard : public GuiView
|
||||
public:
|
||||
VirtualKeyboard(Font *font);
|
||||
|
||||
void registerListener(KeyListener *kl);
|
||||
void registerListener(StringListener *sl);
|
||||
void unregisterListener(KeyListener *kl);
|
||||
void unregisterListener(StringListener *sl);
|
||||
void registerKeyListener(KeyListener *kl);
|
||||
void registerStringListener(StringListener *sl);
|
||||
void unregisterKeyListener(KeyListener *kl);
|
||||
void unregisterStringListener(StringListener *sl);
|
||||
|
||||
/* Conversions */
|
||||
const char *keycodeToString(int kc);
|
||||
@ -59,6 +59,7 @@ public:
|
||||
void deactivate()
|
||||
{
|
||||
this->is_active = false;
|
||||
this->flushKeyListeners();
|
||||
}
|
||||
|
||||
bool isActive()
|
||||
@ -83,6 +84,8 @@ private:
|
||||
void selectNext(int dx, int dy);
|
||||
void toggleShift();
|
||||
|
||||
void flushKeyListeners();
|
||||
|
||||
Font *font;
|
||||
int sel_x;
|
||||
int sel_y;
|
||||
|
Loading…
Reference in New Issue
Block a user