Implement keyboard input handling

This commit is contained in:
simon.kagstrom 2010-01-30 17:59:32 +00:00
parent c7023f1210
commit d3e4552174
5 changed files with 34 additions and 6 deletions

View File

@ -229,6 +229,7 @@ public:
void startFakeKeySequence(const char *str);
void run_fake_key_sequence();
void pushKeyCode(int kc, bool up);
#endif
#ifdef WIN32

View File

@ -84,6 +84,11 @@ void C64::c64_dtor(void)
}
void C64::pushKeyCode(int kc, bool up)
{
TheDisplay->UpdateKeyMatrix(kc, up, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL);
}
/* From dreamcast port but heavily modified */
void C64::run_fake_key_sequence()
{

View File

@ -690,7 +690,7 @@ void C64Display::PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joyst
Gui::gui->pushEvent(&event);
/* Ignore keyboard input while the menu is active */
if (Gui::gui->is_active)
if (Gui::gui->is_active || Gui::gui->kbd)
continue;
switch (event.type) {

View File

@ -240,13 +240,13 @@ void Gui::runLogic(void)
this->status_bar->runLogic();
this->timerController->tick();
if (this->kbd)
this->kbd->runLogic();
if (!this->is_active || !cur_view)
return;
if (this->dlg)
this->dlg->runLogic();
else if (this->kbd)
this->kbd->runLogic();
else
cur_view->runLogic();
}
@ -316,7 +316,11 @@ void Gui::pushEvent(SDL_Event *ev)
GuiView *cur_view = this->peekView();
if (!this->is_active || !cur_view)
{
if (this->kbd)
this->kbd->pushEvent(ev);
return;
}
if (ev->type == SDL_QUIT)
exit(0);
if (this->dlg)
@ -334,6 +338,8 @@ void Gui::draw(SDL_Surface *where)
if (!this->is_active || !cur_view)
{
this->status_bar->draw(where);
if (this->kbd)
this->kbd->draw(where);
return;
}

View File

@ -1,19 +1,34 @@
#include "menu.hh"
#include "dialogue_box.hh"
class KeyboardTypingListener : public KeyboardListener
class KeyboardTypingListener : public KeyboardListener, TimeoutHandler
{
public:
virtual void stringCallback(const char *str)
{
printf("string: %s\n", str);
/* Remove thyself! */
delete this;
}
virtual void keyCallback(bool shift, const char *str)
{
printf("Vobb: %d: %s\n", shift, str);
this->kc = VirtualKeyboard::kbd->stringToKeycode(str);
if (shift)
this->kc |= 0x80;
TheC64->pushKeyCode(this->kc, false);
/* Release it soon */
Gui::gui->timerController->arm(this, 1);
}
virtual void timeoutCallback()
{
TheC64->pushKeyCode(this->kc, true);
}
private:
int kc;
};
class ExitListener : public DialogueListener
@ -82,6 +97,7 @@ public:
case 0:
VirtualKeyboard::kbd->activate(false);
VirtualKeyboard::kbd->registerListener(new KeyboardTypingListener());
Gui::gui->exitMenu();
break;
case 1:
break;