mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-26 13:34:22 +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"
|
#include "menu.hh"
|
||||||
|
|
||||||
class MainView;
|
class MainView;
|
||||||
class MainMenu : public Menu
|
class MainMenu : public Menu, KeyListener
|
||||||
{
|
{
|
||||||
friend class MainView;
|
friend class MainView;
|
||||||
|
|
||||||
@ -71,9 +71,10 @@ public:
|
|||||||
Gui::gui->pushView(Gui::gui->dv);
|
Gui::gui->pushView(Gui::gui->dv);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 4:
|
||||||
Gui::gui->pushView(Gui::gui->kv);
|
Gui::gui->pushView(Gui::gui->kv);
|
||||||
Gui::gui->kv->activate();
|
Gui::gui->kv->activate();
|
||||||
|
Gui::gui->kv->registerKeyListener(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 11:
|
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)
|
virtual void hoverCallback(int which)
|
||||||
{
|
{
|
||||||
this->help->updateHelpMessage(which);
|
this->help->updateHelpMessage(which);
|
||||||
|
@ -225,7 +225,7 @@ const char VirtualKeyboard::keycodeToChar(int kc)
|
|||||||
return s[0];
|
return s[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualKeyboard::registerListener(KeyListener *kl)
|
void VirtualKeyboard::registerKeyListener(KeyListener *kl)
|
||||||
{
|
{
|
||||||
int n_listeners = sizeof(this->keyListeners) / sizeof(*this->keyListeners);
|
int n_listeners = sizeof(this->keyListeners) / sizeof(*this->keyListeners);
|
||||||
int i;
|
int i;
|
||||||
@ -239,7 +239,7 @@ void VirtualKeyboard::registerListener(KeyListener *kl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Templates FTW! */
|
/* Templates FTW! */
|
||||||
void VirtualKeyboard::registerListener(StringListener *sl)
|
void VirtualKeyboard::registerStringListener(StringListener *sl)
|
||||||
{
|
{
|
||||||
int n_listeners = sizeof(this->stringListeners) / sizeof(*this->stringListeners);
|
int n_listeners = sizeof(this->stringListeners) / sizeof(*this->stringListeners);
|
||||||
int i;
|
int i;
|
||||||
@ -252,7 +252,7 @@ void VirtualKeyboard::registerListener(StringListener *sl)
|
|||||||
this->stringListeners[i] = sl;
|
this->stringListeners[i] = sl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualKeyboard::unregisterListener(KeyListener *kl)
|
void VirtualKeyboard::unregisterKeyListener(KeyListener *kl)
|
||||||
{
|
{
|
||||||
int n_listeners = sizeof(this->keyListeners) / sizeof(*this->keyListeners);
|
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);
|
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)
|
void VirtualKeyboard::draw(SDL_Surface *where)
|
||||||
{
|
{
|
||||||
this->draw(where, 20, 240, 600, 240);
|
this->draw(where, 20, 240, 600, 240);
|
||||||
|
@ -38,10 +38,10 @@ class VirtualKeyboard : public GuiView
|
|||||||
public:
|
public:
|
||||||
VirtualKeyboard(Font *font);
|
VirtualKeyboard(Font *font);
|
||||||
|
|
||||||
void registerListener(KeyListener *kl);
|
void registerKeyListener(KeyListener *kl);
|
||||||
void registerListener(StringListener *sl);
|
void registerStringListener(StringListener *sl);
|
||||||
void unregisterListener(KeyListener *kl);
|
void unregisterKeyListener(KeyListener *kl);
|
||||||
void unregisterListener(StringListener *sl);
|
void unregisterStringListener(StringListener *sl);
|
||||||
|
|
||||||
/* Conversions */
|
/* Conversions */
|
||||||
const char *keycodeToString(int kc);
|
const char *keycodeToString(int kc);
|
||||||
@ -59,6 +59,7 @@ public:
|
|||||||
void deactivate()
|
void deactivate()
|
||||||
{
|
{
|
||||||
this->is_active = false;
|
this->is_active = false;
|
||||||
|
this->flushKeyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isActive()
|
bool isActive()
|
||||||
@ -83,6 +84,8 @@ private:
|
|||||||
void selectNext(int dx, int dy);
|
void selectNext(int dx, int dy);
|
||||||
void toggleShift();
|
void toggleShift();
|
||||||
|
|
||||||
|
void flushKeyListeners();
|
||||||
|
|
||||||
Font *font;
|
Font *font;
|
||||||
int sel_x;
|
int sel_x;
|
||||||
int sel_y;
|
int sel_y;
|
||||||
|
Loading…
Reference in New Issue
Block a user