From 80a5c5c6bfbc73e930b61f171a6901ef1ee12bb8 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Thu, 15 Aug 2019 10:58:11 +0200 Subject: [PATCH] first pass on converting int into JoyAxis/JoyDir --- src/common/PJoystickHandler.cxx | 2 +- src/common/PJoystickHandler.hxx | 4 ++-- src/emucore/EventHandler.hxx | 2 +- src/gui/ContextMenu.cxx | 4 ++-- src/gui/ContextMenu.hxx | 2 +- src/gui/Dialog.cxx | 6 +++--- src/gui/Dialog.hxx | 4 ++-- src/gui/DialogContainer.cxx | 8 +++++--- src/gui/DialogContainer.hxx | 4 ++-- src/gui/EventMappingWidget.cxx | 10 +++++----- src/gui/EventMappingWidget.hxx | 5 +++-- src/gui/InputDialog.cxx | 2 +- src/gui/InputDialog.hxx | 2 +- src/gui/LauncherDialog.cxx | 2 +- src/gui/LauncherDialog.hxx | 2 +- src/gui/Widget.hxx | 2 +- 16 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index b6db891e3..c94e332f3 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -666,7 +666,7 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) if (value != j->axisLastValue[axis]) { #ifdef GUI_SUPPORT - myHandler.overlay().handleJoyAxisEvent(stick, axis, value, button); + myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), value, button); #endif j->axisLastValue[axis] = value; } diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index c12081412..ffefbe406 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -90,9 +90,9 @@ class PhysicalJoystickHandler void handleBtnEvent(int stick, int button, bool pressed); void handleHatEvent(int stick, int hat, int value); - Event::Type eventForAxis(EventMode mode, int stick, int axis, int value, int button) const { + Event::Type eventForAxis(EventMode mode, int stick, JoyAxis axis, int value, int button) const { const PhysicalJoystickPtr j = joy(stick); - return j->joyMap.get(mode, button, JoyAxis(axis), convertAxisValue(value)); + return j->joyMap.get(mode, button, axis, convertAxisValue(value)); } Event::Type eventForButton(EventMode mode, int stick, int button) const { const PhysicalJoystickPtr j = joy(stick); diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index fd3b0e083..1cbea2e86 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -162,7 +162,7 @@ class EventHandler Event::Type eventForKey(EventMode mode, StellaKey key, StellaMod mod) const { return myPKeyHandler->eventForKey(mode, key, mod); } - Event::Type eventForJoyAxis(EventMode mode, int stick, int axis, int value, int button) const { + Event::Type eventForJoyAxis(EventMode mode, int stick, JoyAxis axis, int value, int button) const { return myPJoyHandler->eventForAxis(mode, stick, axis, value, button); } Event::Type eventForJoyButton(EventMode mode, int stick, int button) const { diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index d15c78a05..39bf1bce2 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -292,9 +292,9 @@ void ContextMenu::handleJoyDown(int stick, int button, bool longPress) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ContextMenu::handleJoyAxis(int stick, int axis, int value, int button) +void ContextMenu::handleJoyAxis(int stick, JoyAxis axis, int value, int button) { - if(value != 0) // we don't care about 'axis up' events + if(value != int(JoyDir::NONE)) // we don't care about 'axis off' events handleEvent(instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, value, button)); } diff --git a/src/gui/ContextMenu.hxx b/src/gui/ContextMenu.hxx index 508200bcb..3b16c79ac 100644 --- a/src/gui/ContextMenu.hxx +++ b/src/gui/ContextMenu.hxx @@ -88,7 +88,7 @@ class ContextMenu : public Dialog, public CommandSender void handleMouseWheel(int x, int y, int direction) override; void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override; void handleJoyDown(int stick, int button, bool longPress) override; - void handleJoyAxis(int stick, int axis, int value, int button) override; + void handleJoyAxis(int stick, JoyAxis axis, int value, int button) override; bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; void handleEvent(Event::Type e); diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index a7cf9cc0e..46df692ca 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -613,13 +613,13 @@ void Dialog::handleJoyUp(int stick, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Event::Type Dialog::getJoyAxisEvent(int stick, int axis, int value, int button) +Event::Type Dialog::getJoyAxisEvent(int stick, JoyAxis axis, int value, int button) { return instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, value, button); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::handleJoyAxis(int stick, int axis, int value, int button) +void Dialog::handleJoyAxis(int stick, JoyAxis axis, int value, int button) { Event::Type e = getJoyAxisEvent(stick, axis, value, button); @@ -629,7 +629,7 @@ void Dialog::handleJoyAxis(int stick, int axis, int value, int button) { if(_focusedWidget->wantsRaw() || e == Event::NoType) _focusedWidget->handleJoyAxis(stick, axis, value, button); - else if(value != 0) + else if(value != int(JoyDir::NONE)) _focusedWidget->handleEvent(e); } } diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index 9c46fa763..39b2c8e1c 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -139,10 +139,10 @@ class Dialog : public GuiObject virtual bool handleMouseClicks(int x, int y, MouseButton b); virtual void handleJoyDown(int stick, int button, bool longPress = false); virtual void handleJoyUp(int stick, int button); - virtual void handleJoyAxis(int stick, int axis, int value, int button = JOY_CTRL_NONE); + virtual void handleJoyAxis(int stick, JoyAxis axis, int value, int button = JOY_CTRL_NONE); virtual bool handleJoyHat(int stick, int hat, JoyHat value, int button = JOY_CTRL_NONE); virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) override; - virtual Event::Type getJoyAxisEvent(int stick, int axis, int value, int button); + virtual Event::Type getJoyAxisEvent(int stick, JoyAxis axis, int value, int button); Widget* findWidget(int x, int y) const; // Find the widget at pos x,y if any diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index 0b5977bce..26c3a44a3 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -313,7 +313,7 @@ void DialogContainer::handleJoyBtnEvent(int stick, int button, bool pressed) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value, int button) +void DialogContainer::handleJoyAxisEvent(int stick, JoyAxis axis, int value, int button) { if(myDialogStack.empty()) return; @@ -327,7 +327,8 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value, int but // Only stop firing events if it's the current stick if(myCurrentAxisDown.stick == stick && value == 0) { - myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1; + myCurrentAxisDown.stick = -1; + myCurrentAxisDown.axis = JoyAxis::NONE; myAxisRepeatTime = 0; } else if(value != 0 && myAxisRepeatTime < myTime) // never repeat the 'off' event; prevent pending repeats after enabling repeat again @@ -379,7 +380,8 @@ void DialogContainer::reset() myLastClick.count = 0; myCurrentButtonDown.stick = myCurrentButtonDown.button = -1; - myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1; + myCurrentAxisDown.stick = -1; + myCurrentAxisDown.axis = JoyAxis::NONE; myCurrentHatDown.stick = myCurrentHatDown.hat = -1; } diff --git a/src/gui/DialogContainer.hxx b/src/gui/DialogContainer.hxx index 30f234ac4..d5c054264 100644 --- a/src/gui/DialogContainer.hxx +++ b/src/gui/DialogContainer.hxx @@ -108,7 +108,7 @@ class DialogContainer @param axis The joystick axis @param value Value associated with given axis */ - void handleJoyAxisEvent(int stick, int axis, int value, int button); + void handleJoyAxisEvent(int stick, JoyAxis axis, int value, int button); /** Handle a joystick hat event. @@ -208,7 +208,7 @@ class DialogContainer // For continuous 'joy axis down' events struct { int stick; - int axis; + JoyAxis axis; int value; } myCurrentAxisDown; uInt64 myAxisRepeatTime; diff --git a/src/gui/EventMappingWidget.cxx b/src/gui/EventMappingWidget.cxx index 6361948dd..f0aee483f 100644 --- a/src/gui/EventMappingWidget.cxx +++ b/src/gui/EventMappingWidget.cxx @@ -44,7 +44,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, myActionSelected(-1), myRemapStatus(false), myLastStick(0), - myLastAxis(0), + myLastAxis(JoyAxis::NONE), myLastHat(0), myLastValue(0), myLastButton(JOY_CTRL_NONE), @@ -165,7 +165,7 @@ void EventMappingWidget::startRemapping() // Reset all previous events for determining correct axis/hat values myLastStick = -1; myLastButton = JOY_CTRL_NONE; - myLastAxis = int(JoyAxis::NONE); + myLastAxis = JoyAxis::NONE; myLastHat = -1; myLastValue = int(JoyDir::NONE); @@ -223,7 +223,7 @@ void EventMappingWidget::stopRemapping() // Reset all previous events for determining correct axis/hat values myLastStick = -1; myLastButton = JOY_CTRL_NONE; - myLastAxis = int(JoyAxis::NONE); + myLastAxis = JoyAxis::NONE; myLastHat = -1; myLastValue = int(JoyDir::NONE); @@ -345,7 +345,7 @@ void EventMappingWidget::handleJoyUp(int stick, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int button) +void EventMappingWidget::handleJoyAxis(int stick, JoyAxis axis, int value, int button) { // Remap joystick axes in remap mode // There are two phases to detection: @@ -354,7 +354,7 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int butto if(myRemapStatus && myActionSelected >= 0) { // Detect the first axis event that represents 'on' - if((myLastStick == -1 || myLastStick == stick) && myLastAxis == -1 && value != 0) + if((myLastStick == -1 || myLastStick == stick) && myLastAxis == JoyAxis::NONE && value != 0) { myLastStick = stick; myLastAxis = axis; diff --git a/src/gui/EventMappingWidget.hxx b/src/gui/EventMappingWidget.hxx index 051ca8a78..abd6daf43 100644 --- a/src/gui/EventMappingWidget.hxx +++ b/src/gui/EventMappingWidget.hxx @@ -60,7 +60,7 @@ class EventMappingWidget : public Widget, public CommandSender bool handleKeyUp(StellaKey key, StellaMod mod) override; void handleJoyDown(int stick, int button, bool longPress = false) override; void handleJoyUp(int stick, int button) override; - void handleJoyAxis(int stick, int axis, int value, int button) override; + void handleJoyAxis(int stick, JoyAxis axis, int value, int button) override; bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; void loadConfig() override; @@ -105,7 +105,8 @@ class EventMappingWidget : public Widget, public CommandSender // Therefore, we map these events when they've been 'released', rather // than on their first occurrence (aka, when they're 'pressed') // As a result, we need to keep track of their old values - int myLastStick, myLastAxis, myLastHat, myLastValue; + int myLastStick, myLastHat, myLastValue; + JoyAxis myLastAxis; // Aggregates the modifier flags of the mapping int myMod; diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index d4db36abb..fd857bb67 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -499,7 +499,7 @@ void InputDialog::handleJoyUp(int stick, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void InputDialog::handleJoyAxis(int stick, int axis, int value, int button) +void InputDialog::handleJoyAxis(int stick, JoyAxis axis, int value, int button) { // Remap joystick axis in remap mode, otherwise pass to parent dialog if(myEmulEventMapper->remapMode()) diff --git a/src/gui/InputDialog.hxx b/src/gui/InputDialog.hxx index 5b14d9f80..280808ca3 100644 --- a/src/gui/InputDialog.hxx +++ b/src/gui/InputDialog.hxx @@ -51,7 +51,7 @@ class InputDialog : public Dialog void handleKeyUp(StellaKey key, StellaMod mod) override; void handleJoyDown(int stick, int button, bool longPress) override; void handleJoyUp(int stick, int button) override; - void handleJoyAxis(int stick, int axis, int value, int button) override; + void handleJoyAxis(int stick, JoyAxis axis, int value, int button) override; bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 95e3bb292..1889923d3 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -493,7 +493,7 @@ void LauncherDialog::handleJoyUp(int stick, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Event::Type LauncherDialog::getJoyAxisEvent(int stick, int axis, int value, int button) +Event::Type LauncherDialog::getJoyAxisEvent(int stick, JoyAxis axis, int value, int button) { Event::Type e = instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, value, button); diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index b9fa49e6f..07e48ca0a 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -93,7 +93,7 @@ class LauncherDialog : public Dialog void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleJoyDown(int stick, int button, bool longPress) override; void handleJoyUp(int stick, int button) override; - Event::Type getJoyAxisEvent(int stick, int axis, int value, int button) override; + Event::Type getJoyAxisEvent(int stick, JoyAxis axis, int value, int button) override; void loadConfig() override; void updateUI(); diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index 8f8ba8e2b..e9a3ebcba 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -79,7 +79,7 @@ class Widget : public GuiObject virtual bool handleMouseClicks(int x, int y, MouseButton b) { return false; } virtual void handleJoyDown(int stick, int button, bool longPress = false) { } virtual void handleJoyUp(int stick, int button) { } - virtual void handleJoyAxis(int stick, int axis, int value, int button = JOY_CTRL_NONE) { } + virtual void handleJoyAxis(int stick, JoyAxis axis, int value, int button = JOY_CTRL_NONE) { } virtual bool handleJoyHat(int stick, int hat, JoyHat value, int button = JOY_CTRL_NONE) { return false; } virtual bool handleEvent(Event::Type event) { return false; }