From d2e0208510b25742a4da98f50b2238b2ae12c210 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sun, 21 Feb 2010 15:58:28 +0000 Subject: [PATCH] Push joystick events to the GUI. Not tested yet. --- Src/Display.cpp | 25 ++++++++++++++++++++----- Src/gui/gui.cpp | 19 +++++++++++++++++++ Src/gui/gui.hh | 2 ++ Src/gui/virtual_keyboard.cpp | 5 +++++ Src/gui/virtual_keyboard.hh | 2 ++ 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Src/Display.cpp b/Src/Display.cpp index d196465..efd7f1c 100644 --- a/Src/Display.cpp +++ b/Src/Display.cpp @@ -829,14 +829,22 @@ uint8 C64::poll_joystick_hats(int port) Uint8 v = SDL_JoystickGetHat (js, i); /* FIXME! This is the wrong way for the Wii */ - if (v & SDL_HAT_UP) + if (v & SDL_HAT_UP) { out &= 0xfe; - if (v & SDL_HAT_DOWN) + Gui::gui->pushEvent(KEY_UP); + } + if (v & SDL_HAT_DOWN) { out &= 0xfd; - if (v & SDL_HAT_LEFT) + Gui::gui->pushEvent(KEY_DOWN); + } + if (v & SDL_HAT_LEFT) { out &= 0xfb; - if (v & SDL_HAT_RIGHT) + Gui::gui->pushEvent(KEY_LEFT); + } + if (v & SDL_HAT_RIGHT) { out &= 0xf7; + Gui::gui->pushEvent(KEY_RIGHT); + } } return out; @@ -858,9 +866,16 @@ uint8 C64::poll_joystick_buttons(int port) if (kc == JOY_NONE) continue; - if (cur != old) + if (cur != old) { TheDisplay->UpdateKeyMatrix(kc, !cur, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &out); + if (kc == JOY_FIRE) + Gui::gui->pushEvent(KEY_SELECT); + else if (kc == JOY_ENTER_MENU) + Gui::gui->activate(); + else + Gui::gui->pushEvent(KEY_ESCAPE); + } } return out; diff --git a/Src/gui/gui.cpp b/Src/gui/gui.cpp index 48f0213..e8420de 100644 --- a/Src/gui/gui.cpp +++ b/Src/gui/gui.cpp @@ -326,6 +326,25 @@ void Gui::exitMenu() this->saveGameInfo(); } +void Gui::pushEvent(event_t ev) +{ + GuiView *cur_view = this->peekView(); + + if (!this->is_active || !cur_view) + { + if (this->kbd) + this->kbd->pushEvent(ev); + return; + } + + if (this->dlg) + this->dlg->pushEvent(ev); + else if (this->kbd) + this->kbd->pushEvent(ev); + else + cur_view->pushEvent(ev); +} + void Gui::pushEvent(SDL_Event *ev) { GuiView *cur_view = this->peekView(); diff --git a/Src/gui/gui.hh b/Src/gui/gui.hh index b7df4e9..1afacb0 100644 --- a/Src/gui/gui.hh +++ b/Src/gui/gui.hh @@ -43,6 +43,8 @@ public: void runLogic(void); + void pushEvent(event_t ev); + void pushEvent(SDL_Event *ev); void draw(SDL_Surface *where); diff --git a/Src/gui/virtual_keyboard.cpp b/Src/gui/virtual_keyboard.cpp index 4d0d779..5dbcef3 100644 --- a/Src/gui/virtual_keyboard.cpp +++ b/Src/gui/virtual_keyboard.cpp @@ -420,6 +420,11 @@ void VirtualKeyboard::updateTheme() this->setFont(Gui::gui->small_font); } +void VirtualKeyboard::pushEvent(event_t ev) +{ + Widget::pushEvent(ev); +} + void VirtualKeyboard::pushEvent(SDL_Event *ev) { switch(ev->type) diff --git a/Src/gui/virtual_keyboard.hh b/Src/gui/virtual_keyboard.hh index 32b1ae7..aed7631 100644 --- a/Src/gui/virtual_keyboard.hh +++ b/Src/gui/virtual_keyboard.hh @@ -71,6 +71,8 @@ public: void draw(SDL_Surface *where, int x, int y, int w, int h); + void pushEvent(event_t ev); + void pushEvent(SDL_Event *ev); const char *getString();