From 4e1c13ce6d4c8a879cd8cd5951345e90012de6d5 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sat, 13 Apr 2019 15:44:19 +0200 Subject: [PATCH] improved dialogs and launcher navigation with joysticks (left and right) --- src/common/PJoystickHandler.cxx | 23 ++++++++++------------- src/gui/Dialog.cxx | 9 +++++++-- src/gui/Dialog.hxx | 1 + src/gui/LauncherDialog.cxx | 27 +++++++++++++++++++++++++++ src/gui/LauncherDialog.hxx | 1 + 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index be80bfe36..4ebb98201 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -302,21 +302,18 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, break; case kMenuMode: // Default menu/UI events - if(stick == 0) - { - setDefaultAxis( 0, 0, 0, Event::UILeft ); - setDefaultAxis( 0, 0, 1, Event::UIRight ); - setDefaultAxis( 0, 1, 0, Event::UIUp ); - setDefaultAxis( 0, 1, 1, Event::UIDown ); + setDefaultAxis( stick, 0, 0, Event::UINavPrev ); + setDefaultAxis( stick, 0, 1, Event::UINavNext ); + setDefaultAxis( stick, 1, 0, Event::UIUp ); + setDefaultAxis( stick, 1, 1, Event::UIDown ); - // Left joystick (assume joystick zero, button zero) - setDefaultBtn( 0, 0, Event::UISelect ); + // Left joystick (assume joystick zero, button zero) + setDefaultBtn( stick, 0, Event::UISelect ); - setDefaultHat( 0, 0, JoyHat::LEFT, Event::UILeft ); - setDefaultHat( 0, 0, JoyHat::RIGHT, Event::UIRight ); - setDefaultHat( 0, 0, JoyHat::UP, Event::UIUp ); - setDefaultHat( 0, 0, JoyHat::DOWN, Event::UIDown ); - } + setDefaultHat( stick, 0, JoyHat::LEFT, Event::UINavPrev ); + setDefaultHat( stick, 0, JoyHat::RIGHT, Event::UINavNext ); + setDefaultHat( stick, 0, JoyHat::UP, Event::UIUp ); + setDefaultHat( stick, 0, JoyHat::DOWN, Event::UIDown ); break; default: diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index d402bd9e3..c94572e25 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -572,11 +572,16 @@ void Dialog::handleJoyUp(int stick, int button) _focusedWidget->handleJoyUp(stick, button); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Event::Type Dialog::getJoyAxisEvent(int stick, int axis, int value) +{ + return instance().eventHandler().eventForJoyAxis(stick, axis, value, kMenuMode); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::handleJoyAxis(int stick, int axis, int value) { - Event::Type e = - instance().eventHandler().eventForJoyAxis(stick, axis, value, kMenuMode); + Event::Type e = getJoyAxisEvent(stick, axis, value); // Unless a widget has claimed all responsibility for data, we assume // that if an event exists for the given data, it should have priority. diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index e99a5fb9a..0fec2c7b8 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -142,6 +142,7 @@ class Dialog : public GuiObject virtual void handleJoyAxis(int stick, int axis, int value); virtual bool handleJoyHat(int stick, int hat, JoyHat value); virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + virtual Event::Type getJoyAxisEvent(int stick, int axis, int value); Widget* findWidget(int x, int y) const; // Find the widget at pos x,y if any diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 8f599c1a1..02551bf84 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -491,6 +491,33 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod) Dialog::handleKeyDown(key, mod); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Event::Type LauncherDialog::getJoyAxisEvent(int stick, int axis, int value) +{ + Event::Type e = instance().eventHandler().eventForJoyAxis(stick, axis, value, kMenuMode); + + if(myUseMinimalUI) + { + // map axis events for launcher + switch(e) + { + case Event::UINavPrev: + // convert unused previous item event into page-up event + e = Event::UIPgUp; + break; + + case Event::UINavNext: + // convert unused next item event into page-down event + e = Event::UIPgDown; + break; + + default: + break; + } + } + return e; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::handleMouseDown(int x, int y, MouseButton b, int clickCount) { diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index 08b46dcce..791bc02c7 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -88,6 +88,7 @@ class LauncherDialog : public Dialog void handleKeyDown(StellaKey key, StellaMod mod) override; void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + Event::Type LauncherDialog::getJoyAxisEvent(int stick, int axis, int value) override; void loadConfig() override; void updateListing(const string& nameToSelect = "");