Refactor handling of the virtual keyboard to have it on top of the

current view. Makes things a bit nicer but unfortunately makes the
keyboard a special case.
This commit is contained in:
simon.kagstrom 2010-01-02 12:28:18 +00:00
parent e903594921
commit c9c6b0f365
5 changed files with 21 additions and 13 deletions

17
gui.cpp
View File

@ -81,13 +81,13 @@ Gui::Gui()
this->game_base_path = GAME_ROOT_PATH;
this->dlg = NULL;
this->kbd = NULL;
/* Create the views */
this->mv = new MainView();
this->dv = new DiscView();
this->ov = new OptionsView();
this->nv = new NetworkView();
this->kv = VirtualKeyboard::kbd;
this->pushView(mv);
}
@ -149,10 +149,11 @@ bool Gui::setTheme(const char *path)
this->mv->updateTheme();
this->dv->updateTheme();
this->kv->updateTheme();
this->ov->updateTheme();
this->nv->updateTheme();
VirtualKeyboard::kbd->updateTheme();
return true;
}
@ -164,6 +165,8 @@ void Gui::runLogic(void)
return;
if (this->dlg)
this->dlg->runLogic();
else if (this->kbd)
this->kbd->runLogic();
else
cur_view->runLogic();
this->timerController->tick();
@ -234,11 +237,11 @@ void Gui::pushEvent(SDL_Event *ev)
if (!this->is_active || !cur_view)
return;
if (this->dlg)
{
this->dlg->pushEvent(ev);
return;
}
cur_view->pushEvent(ev);
else if (this->kbd)
this->kbd->pushEvent(ev);
else
cur_view->pushEvent(ev);
}
void Gui::draw(SDL_Surface *where)
@ -250,6 +253,8 @@ void Gui::draw(SDL_Surface *where)
SDL_BlitSurface(this->background, NULL, screen, NULL);
cur_view->draw(where);
if (this->kbd)
this->kbd->draw(where);
if (this->dlg)
this->dlg->draw(where);
}

5
gui.hh
View File

@ -39,6 +39,8 @@ public:
void pushView(GuiView *view);
void pushVirtualKeyboard(VirtualKeyboard *kbd);
void pushDialogueBox(DialogueBox *dlg);
DialogueBox *popDialogueBox();
@ -80,13 +82,14 @@ public:
Font *small_font;
TimerController *timerController;
/* Handled specially */
VirtualKeyboard *kbd;
DialogueBox *dlg;
MainView *mv;
DiscView *dv;
OptionsView *ov;
NetworkView *nv;
VirtualKeyboard *kv;
GuiView **views;
int n_views;

View File

@ -55,8 +55,8 @@ public:
case 2: /* Load/save states */
break;
case 4: /* Keyboard */
Gui::gui->kv->activate();
Gui::gui->kv->registerListener(new KeyboardTypingListener());
VirtualKeyboard::kbd->activate();
VirtualKeyboard::kbd->registerListener(new KeyboardTypingListener());
break;
case 7: /* Reset the C64 */
printf("Resetting the C64\n");

View File

@ -60,8 +60,8 @@ public:
case 0:
case 1:
case 2:
Gui::gui->kv->activate();
Gui::gui->kv->registerListener(this);
VirtualKeyboard::kbd->activate();
VirtualKeyboard::kbd->registerListener(this);
break;
case 4:
if ( strncmp(Gui::gui->np->NetworkName, "Unset", strlen("Unset")) == 0)

View File

@ -259,7 +259,7 @@ const char VirtualKeyboard::keycodeToChar(int kc)
void VirtualKeyboard::activate()
{
Gui::gui->pushView(Gui::gui->kv);
Gui::gui->kbd = this;
this->is_active = true;
memset(this->buf, 0, sizeof(struct virtkey) * this->buf_len);
this->buf_head = 0;
@ -340,7 +340,7 @@ void VirtualKeyboard::deactivate()
{
this->is_active = false;
this->flushListeners();
Gui::gui->popView();
Gui::gui->kbd = NULL;
}
void VirtualKeyboard::done()