diff --git a/src/common/JoyMap.cxx b/src/common/JoyMap.cxx index 5d89d5361..312b91d43 100644 --- a/src/common/JoyMap.cxx +++ b/src/common/JoyMap.cxx @@ -31,14 +31,14 @@ void JoyMap::add(const Event::Type event, const JoyMapping& mapping) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void JoyMap::add(const Event::Type event, const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir, - const int hat, const JoyHat hdir) + const int hat, const JoyHatDir hdir) { add(event, JoyMapping(mode, button, axis, adir, hat, hdir)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void JoyMap::add(const Event::Type event, const EventMode mode, const int button, - const int hat, const JoyHat hdir) + const int hat, const JoyHatDir hdir) { add(event, JoyMapping(mode, button, hat, hdir)); } @@ -58,7 +58,7 @@ void JoyMap::erase(const EventMode mode, const int button, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void JoyMap::erase(const EventMode mode, const int button, - const int hat, const JoyHat hdir) + const int hat, const JoyHatDir hdir) { erase(JoyMapping(mode, button, hat, hdir)); } @@ -91,7 +91,7 @@ Event::Type JoyMap::get(const EventMode mode, const int button, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Event::Type JoyMap::get(const EventMode mode, const int button, - const int hat, const JoyHat hdir) const + const int hat, const JoyHatDir hdir) const { return get(JoyMapping(mode, button, hat, hdir)); } @@ -107,7 +107,7 @@ bool JoyMap::check(const JoyMapping & mapping) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool JoyMap::check(const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir, - const int hat, const JoyHat hdir) const + const int hat, const JoyHatDir hdir) const { return check(JoyMapping(mode, button, axis, adir, hat, hdir)); } @@ -147,10 +147,10 @@ string JoyMap::getDesc(const Event::Type event, const JoyMapping& mapping) const buf << "/H" << mapping.hat; switch (mapping.hdir) { - case JoyHat::UP: buf << "/up"; break; - case JoyHat::DOWN: buf << "/down"; break; - case JoyHat::LEFT: buf << "/left"; break; - case JoyHat::RIGHT: buf << "/right"; break; + case JoyHatDir::UP: buf << "/up"; break; + case JoyHatDir::DOWN: buf << "/down"; break; + case JoyHatDir::LEFT: buf << "/left"; break; + case JoyHatDir::RIGHT: buf << "/right"; break; default: break; } } @@ -220,7 +220,7 @@ int JoyMap::loadMapping(string& list, const EventMode mode) while (buf >> event && buf >> button && buf >> axis && buf >> adir && buf >> hat && buf >> hdir && ++i) - add(Event::Type(event), EventMode(mode), button, JoyAxis(axis), JoyDir(adir), hat, JoyHat(hdir)); + add(Event::Type(event), EventMode(mode), button, JoyAxis(axis), JoyDir(adir), hat, JoyHatDir(hdir)); return i; } diff --git a/src/common/JoyMap.hxx b/src/common/JoyMap.hxx index 6706bb49b..e83cb7530 100644 --- a/src/common/JoyMap.hxx +++ b/src/common/JoyMap.hxx @@ -38,19 +38,19 @@ class JoyMap JoyAxis axis; // horizontal/vertical JoyDir adir; // axis direction (neg/pos) int hat; // hat number - JoyHat hdir; // hat direction (left/right/up/down) + JoyHatDir hdir; // hat direction (left/right/up/down) JoyMapping() : mode(EventMode(0)), button(0), axis(JoyAxis(0)), adir(JoyDir(0)), - hat(0), hdir(JoyHat(0)) { } + hat(0), hdir(JoyHatDir(0)) { } JoyMapping(const JoyMapping& m) : mode(m.mode), button(m.button), axis(m.axis), adir(m.adir), hat(m.hat), hdir(m.hdir) { } explicit JoyMapping(EventMode c_mode, int c_button, JoyAxis c_axis, JoyDir c_adir, - int c_hat, JoyHat c_hdir) + int c_hat, JoyHatDir c_hdir) : mode(c_mode), button(c_button), axis(c_axis), adir(c_adir), hat(c_hat), hdir(c_hdir) { } @@ -58,9 +58,9 @@ class JoyMap JoyAxis c_axis, JoyDir c_adir) : mode(c_mode), button(c_button), axis(c_axis), adir(c_adir), - hat(JOY_CTRL_NONE), hdir(JoyHat::CENTER) { } + hat(JOY_CTRL_NONE), hdir(JoyHatDir::CENTER) { } explicit JoyMapping(EventMode c_mode, int c_button, - int c_hat, JoyHat c_hdir) + int c_hat, JoyHatDir c_hdir) : mode(c_mode), button(c_button), axis(JoyAxis::NONE), adir(JoyDir::NONE), hat(c_hat), hdir(c_hdir) { } @@ -85,30 +85,29 @@ class JoyMap void add(const Event::Type event, const JoyMapping& mapping); void add(const Event::Type event, const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir, - const int hat = JOY_CTRL_NONE, const JoyHat hdir = JoyHat::CENTER); - void add(const Event::Type event, const EventMode mode, const int button, - const int hat, const JoyHat hdir); + const int hat = JOY_CTRL_NONE, const JoyHatDir hdir = JoyHatDir::CENTER); + void add(const Event::Type event, const EventMode mode, const int button, + const int hat, const JoyHatDir hdir); /** Erase mapping */ void erase(const JoyMapping& mapping); void erase(const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir); - void erase(const EventMode mode, const int button, - const int hat, const JoyHat hdir); - + void erase(const EventMode mode, const int button, + const int hat, const JoyHatDir hdir); /** Get event for mapping */ Event::Type get(const JoyMapping& mapping) const; Event::Type get(const EventMode mode, const int button, const JoyAxis axis = JoyAxis::NONE, const JoyDir adir = JoyDir::NONE) const; - Event::Type get(const EventMode mode, const int button, - const int hat, const JoyHat hdir) const; + Event::Type get(const EventMode mode, const int button, + const int hat, const JoyHatDir hdir) const; /** Check if a mapping exists */ bool check(const JoyMapping& mapping) const; bool check(const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir, - const int hat = JOY_CTRL_NONE, const JoyHat hdir = JoyHat::CENTER) const; + const int hat = JOY_CTRL_NONE, const JoyHatDir hdir = JoyHatDir::CENTER) const; /** Get mapping description */ string getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const; diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index c94e332f3..d0a707737 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -551,7 +551,7 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, int stick, - int button, JoyAxis axis, int value) + int button, JoyAxis axis, JoyDir adir) { const PhysicalJoystickPtr j = joy(stick); @@ -574,11 +574,11 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i // Otherwise, turn off the analog event(s) for this axis if (Event::isAnalog(j->joyMap.get(evMode, button, axis, JoyDir::ANALOG))) j->joyMap.erase(evMode, button, axis, JoyDir::ANALOG); - j->joyMap.add(event, evMode, button, axis, convertAxisValue(value)); + j->joyMap.add(event, evMode, button, axis, adir); // update running emulation mapping too if(Event::isAnalog(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG))) j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG); - j->joyMap.add(event, EventMode::kEmulationMode, button, axis, convertAxisValue(value)); + j->joyMap.add(event, EventMode::kEmulationMode, button, axis, adir); } return true; } @@ -587,17 +587,17 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode, int stick, - int button, int hat, JoyHat dir) + int button, int hat, JoyHatDir hdir) { const PhysicalJoystickPtr j = joy(stick); if (j && event < Event::LastType && button >= JOY_CTRL_NONE && button < j->numButtons && - hat >= 0 && hat < j->numHats && dir != JoyHat::CENTER) + hat >= 0 && hat < j->numHats && hdir != JoyHatDir::CENTER) { - j->joyMap.add(event, getEventMode(event, mode), button, hat, dir); + j->joyMap.add(event, getEventMode(event, mode), button, hat, hdir); // update running emulation mapping too - j->joyMap.add(event, EventMode::kEmulationMode, button, hat, dir); + j->joyMap.add(event, EventMode::kEmulationMode, button, hat, hdir); return true; } return false; @@ -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, JoyAxis(axis), value, button); + myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), convertAxisValue(value), button); #endif j->axisLastValue[axis] = value; } @@ -700,7 +700,7 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PhysicalJoystickHandler::handleHatEvent(int stick, int hat, int value) { - // Preprocess all hat events, converting to Stella JoyHat type + // Preprocess all hat events, converting to Stella JoyHatDir type // Generate multiple equivalent hat events representing combined direction // when we get a diagonal hat event @@ -712,30 +712,30 @@ void PhysicalJoystickHandler::handleHatEvent(int stick, int hat, int value) if (myHandler.state() == EventHandlerState::EMULATION) { - myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHat::UP), + myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHatDir::UP), value & EVENT_HATUP_M); - myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHat::RIGHT), + myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHatDir::RIGHT), value & EVENT_HATRIGHT_M); - myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHat::DOWN), + myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHatDir::DOWN), value & EVENT_HATDOWN_M); - myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHat::LEFT), + myHandler.handleEvent(j->joyMap.get(EventMode::kEmulationMode, button, hat, JoyHatDir::LEFT), value & EVENT_HATLEFT_M); } #ifdef GUI_SUPPORT else if (myHandler.hasOverlay()) { if (value == EVENT_HATCENTER_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::CENTER, button); + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHatDir::CENTER, button); else { if (value & EVENT_HATUP_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::UP, button); + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHatDir::UP, button); if (value & EVENT_HATRIGHT_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::RIGHT, button); + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHatDir::RIGHT, button); if (value & EVENT_HATDOWN_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::DOWN, button); + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHatDir::DOWN, button); if (value & EVENT_HATLEFT_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::LEFT, button); + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHatDir::LEFT, button); } } #endif @@ -783,11 +783,11 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftJ {Event::JoystickZeroUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG}, {Event::JoystickZeroDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, // Left joystick left/right directions (assume hat 0) - {Event::JoystickZeroLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::LEFT}, - {Event::JoystickZeroRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::RIGHT}, + {Event::JoystickZeroLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT}, + {Event::JoystickZeroRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT}, // Left joystick up/down directions (assume hat 0) - {Event::JoystickZeroUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::UP}, - {Event::JoystickZeroDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::DOWN}, + {Event::JoystickZeroUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::UP}, + {Event::JoystickZeroDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::DOWN}, }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -803,11 +803,11 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRight {Event::JoystickOneUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG}, {Event::JoystickOneDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, // Right joystick left/right directions (assume hat 0) - {Event::JoystickOneLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::LEFT}, - {Event::JoystickOneRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::RIGHT}, + {Event::JoystickOneLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT}, + {Event::JoystickOneRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT}, // Right joystick up/down directions (assume hat 0) - {Event::JoystickOneUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::UP}, - {Event::JoystickOneDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::DOWN}, + {Event::JoystickOneUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::UP}, + {Event::JoystickOneDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::DOWN}, }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -895,8 +895,8 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultMenuM {Event::UIUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG}, {Event::UIDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, - {Event::UINavPrev, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::LEFT}, - {Event::UINavNext, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::RIGHT}, - {Event::UIUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::UP}, - {Event::UIDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::DOWN}, + {Event::UINavPrev, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT}, + {Event::UINavNext, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT}, + {Event::UIUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::UP}, + {Event::UIDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::DOWN}, }; diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index ffefbe406..ab782a0d2 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -81,24 +81,24 @@ class PhysicalJoystickHandler /** Bind a physical joystick event to a virtual event/action. */ bool addJoyMapping(Event::Type event, EventMode mode, int stick, - int button, JoyAxis axis, int value); + int button, JoyAxis axis, JoyDir adir); bool addJoyHatMapping(Event::Type event, EventMode mode, int stick, - int button, int hat, JoyHat hdir); + int button, int hat, JoyHatDir hdir); /** Handle a physical joystick event. */ void handleAxisEvent(int stick, int axis, int value); void handleBtnEvent(int stick, int button, bool pressed); void handleHatEvent(int stick, int hat, int value); - Event::Type eventForAxis(EventMode mode, int stick, JoyAxis axis, int value, int button) const { + Event::Type eventForAxis(EventMode mode, int stick, JoyAxis axis, JoyDir adir, int button) const { const PhysicalJoystickPtr j = joy(stick); - return j->joyMap.get(mode, button, axis, convertAxisValue(value)); + return j->joyMap.get(mode, button, axis, adir); } Event::Type eventForButton(EventMode mode, int stick, int button) const { const PhysicalJoystickPtr j = joy(stick); return j->joyMap.get(mode, button); } - Event::Type eventForHat(EventMode mode, int stick, int hat, JoyHat hatDir, int button) const { + Event::Type eventForHat(EventMode mode, int stick, int hat, JoyHatDir hatDir, int button) const { const PhysicalJoystickPtr j = joy(stick); return j->joyMap.get(mode, button, hat, hatDir); } @@ -144,7 +144,7 @@ class PhysicalJoystickHandler JoyAxis axis = JoyAxis::NONE; JoyDir adir = JoyDir::NONE; int hat = JOY_CTRL_NONE; - JoyHat hdir = JoyHat::CENTER; + JoyHatDir hdir = JoyHatDir::CENTER; }; using EventMappingArray = std::vector; diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 342b9fede..6608c6806 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -1132,11 +1132,11 @@ bool EventHandler::addKeyMapping(Event::Type event, EventMode mode, StellaKey ke // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool EventHandler::addJoyMapping(Event::Type event, EventMode mode, - int stick, int button, JoyAxis axis, int value, + int stick, int button, JoyAxis axis, JoyDir adir, bool updateMenus) { #ifdef JOYSTICK_SUPPORT - bool mapped = myPJoyHandler->addJoyMapping(event, mode, stick, button, axis, value); + bool mapped = myPJoyHandler->addJoyMapping(event, mode, stick, button, axis, adir); if (mapped && updateMenus) setActionMappings(mode); @@ -1148,7 +1148,7 @@ bool EventHandler::addJoyMapping(Event::Type event, EventMode mode, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode, - int stick, int button, int hat, JoyHat dir, + int stick, int button, int hat, JoyHatDir dir, bool updateMenus) { #ifdef JOYSTICK_SUPPORT diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 1cbea2e86..984398e28 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -162,13 +162,13 @@ 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, JoyAxis axis, int value, int button) const { - return myPJoyHandler->eventForAxis(mode, stick, axis, value, button); + Event::Type eventForJoyAxis(EventMode mode, int stick, JoyAxis axis, JoyDir adir, int button) const { + return myPJoyHandler->eventForAxis(mode, stick, axis, adir, button); } Event::Type eventForJoyButton(EventMode mode, int stick, int button) const { return myPJoyHandler->eventForButton(mode, stick, button); } - Event::Type eventForJoyHat(EventMode mode, int stick, int hat, JoyHat value, int button) const { + Event::Type eventForJoyHat(EventMode mode, int stick, int hat, JoyHatDir value, int button) const { return myPJoyHandler->eventForHat(mode, stick, hat, value, button); } @@ -215,13 +215,13 @@ class EventHandler @param stick The joystick number @param button The joystick button @param axis The joystick axis - @param value The value on the given axis + @param adir The given axis @param updateMenus Whether to update the action mappings (normally we want to do this, unless there are a batch of 'adds', in which case it's delayed until the end */ bool addJoyMapping(Event::Type event, EventMode mode, int stick, - int button, JoyAxis axis = JoyAxis::NONE, int value = 0, + int button, JoyAxis axis = JoyAxis::NONE, JoyDir adir = JoyDir::NONE, bool updateMenus = true); /** @@ -239,7 +239,7 @@ class EventHandler 'adds', in which case it's delayed until the end */ bool addJoyHatMapping(Event::Type event, EventMode mode, int stick, - int button, int hat, JoyHat dir, + int button, int hat, JoyHatDir dir, bool updateMenus = true); /** diff --git a/src/emucore/EventHandlerConstants.hxx b/src/emucore/EventHandlerConstants.hxx index 7b06e94f1..fc45f1d76 100644 --- a/src/emucore/EventHandlerConstants.hxx +++ b/src/emucore/EventHandlerConstants.hxx @@ -41,8 +41,8 @@ enum class MouseButton { static constexpr int JOY_CTRL_NONE = -1; enum class JoyAxis { - X = 0, - Y = 1, + X = 0, // make sure these are set correctly, + Y = 1, // since they'll be used as array indices Z = 2, NONE = JOY_CTRL_NONE }; @@ -54,7 +54,7 @@ enum class JoyDir { ANALOG = 2 }; -enum class JoyHat { +enum class JoyHatDir { UP = 0, // make sure these are set correctly, DOWN = 1, // since they'll be used as array indices LEFT = 2, diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index 39bf1bce2..b7bc5da65 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -292,14 +292,14 @@ void ContextMenu::handleJoyDown(int stick, int button, bool longPress) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ContextMenu::handleJoyAxis(int stick, JoyAxis axis, int value, int button) +void ContextMenu::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) { - if(value != int(JoyDir::NONE)) // we don't care about 'axis off' events - handleEvent(instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, value, button)); + if(adir != JoyDir::NONE) // we don't care about 'axis off' events + handleEvent(instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, adir, button)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool ContextMenu::handleJoyHat(int stick, int hat, JoyHat value, int button) +bool ContextMenu::handleJoyHat(int stick, int hat, JoyHatDir value, int button) { handleEvent(instance().eventHandler().eventForJoyHat(EventMode::kMenuMode, stick, hat, value, button)); return true; diff --git a/src/gui/ContextMenu.hxx b/src/gui/ContextMenu.hxx index 3b16c79ac..746382c49 100644 --- a/src/gui/ContextMenu.hxx +++ b/src/gui/ContextMenu.hxx @@ -88,8 +88,8 @@ 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, JoyAxis axis, int value, int button) override; - bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; + void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override; + bool handleJoyHat(int stick, int hat, JoyHatDir value, int button) override; void handleEvent(Event::Type e); void drawDialog() override; diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 46df692ca..02a138c6d 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -613,29 +613,29 @@ void Dialog::handleJoyUp(int stick, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Event::Type Dialog::getJoyAxisEvent(int stick, JoyAxis axis, int value, int button) +Event::Type Dialog::getJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir, int button) { - return instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, value, button); + return instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, adir, button); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::handleJoyAxis(int stick, JoyAxis axis, int value, int button) +void Dialog::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) { - Event::Type e = getJoyAxisEvent(stick, axis, value, button); + Event::Type e = getJoyAxisEvent(stick, axis, adir, button); // Unless a widget has claimed all responsibility for data, we assume // that if an event exists for the given data, it should have priority. if(!handleNavEvent(e) && _focusedWidget) { if(_focusedWidget->wantsRaw() || e == Event::NoType) - _focusedWidget->handleJoyAxis(stick, axis, value, button); - else if(value != int(JoyDir::NONE)) + _focusedWidget->handleJoyAxis(stick, axis, adir, button); + else if(adir != JoyDir::NONE) _focusedWidget->handleEvent(e); } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Dialog::handleJoyHat(int stick, int hat, JoyHat value, int button) +bool Dialog::handleJoyHat(int stick, int hat, JoyHatDir value, int button) { Event::Type e = instance().eventHandler().eventForJoyHat(EventMode::kMenuMode, stick, hat, value, button); diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index 39b2c8e1c..60a17ac36 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, 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 handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button = JOY_CTRL_NONE); + virtual bool handleJoyHat(int stick, int hat, JoyHatDir value, int button = JOY_CTRL_NONE); virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) override; - virtual Event::Type getJoyAxisEvent(int stick, JoyAxis axis, int value, int button); + virtual Event::Type getJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir, 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 26c3a44a3..7cc7287a3 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -80,7 +80,7 @@ void DialogContainer::updateTime(uInt64 time) if(myCurrentAxisDown.stick != -1 && myAxisRepeatTime < myTime) { activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis, - myCurrentAxisDown.value); + myCurrentAxisDown.adir); myAxisRepeatTime = myTime + _REPEAT_SUSTAIN_DELAY; } @@ -313,7 +313,7 @@ void DialogContainer::handleJoyBtnEvent(int stick, int button, bool pressed) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DialogContainer::handleJoyAxisEvent(int stick, JoyAxis axis, int value, int button) +void DialogContainer::handleJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir, int button) { if(myDialogStack.empty()) return; @@ -325,25 +325,25 @@ void DialogContainer::handleJoyAxisEvent(int stick, JoyAxis axis, int value, int myButtonLongPressTime = myTime + _REPEAT_NONE; // Only stop firing events if it's the current stick - if(myCurrentAxisDown.stick == stick && value == 0) + if(myCurrentAxisDown.stick == stick && adir == JoyDir::NONE) { 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 + else if(adir != JoyDir::NONE && myAxisRepeatTime < myTime) // never repeat the 'off' event; prevent pending repeats after enabling repeat again { // Now account for repeated axis events (press and hold) myCurrentAxisDown.stick = stick; myCurrentAxisDown.axis = axis; - myCurrentAxisDown.value = value; + myCurrentAxisDown.adir = adir; myAxisRepeatTime = myTime + (activeDialog->repeatEnabled() ? _REPEAT_INITIAL_DELAY : _REPEAT_NONE); } - activeDialog->handleJoyAxis(stick, axis, value, button); + activeDialog->handleJoyAxis(stick, axis, adir, button); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DialogContainer::handleJoyHatEvent(int stick, int hat, JoyHat value, int button) +void DialogContainer::handleJoyHatEvent(int stick, int hat, JoyHatDir value, int button) { if(myDialogStack.empty()) return; @@ -355,12 +355,12 @@ void DialogContainer::handleJoyHatEvent(int stick, int hat, JoyHat value, int bu myButtonLongPressTime = myTime + _REPEAT_NONE; // Only stop firing events if it's the current stick - if(myCurrentHatDown.stick == stick && value == JoyHat::CENTER) + if(myCurrentHatDown.stick == stick && value == JoyHatDir::CENTER) { myCurrentHatDown.stick = myCurrentHatDown.hat = -1; myHatRepeatTime = 0; } - else if(value != JoyHat::CENTER && myHatRepeatTime < myTime) // never repeat the 'center' direction; prevent pending repeats after enabling repeat again + else if(value != JoyHatDir::CENTER && myHatRepeatTime < myTime) // never repeat the 'center' direction; prevent pending repeats after enabling repeat again { // Now account for repeated hat events (press and hold) myCurrentHatDown.stick = stick; diff --git a/src/gui/DialogContainer.hxx b/src/gui/DialogContainer.hxx index d5c054264..e75762063 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, JoyAxis axis, int value, int button); + void handleJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir, int button); /** Handle a joystick hat event. @@ -117,7 +117,7 @@ class DialogContainer @param hat The joystick hat @param value Value associated with given hat */ - void handleJoyHatEvent(int stick, int hat, JoyHat value, int button); + void handleJoyHatEvent(int stick, int hat, JoyHatDir value, int button); /** Draw the stack of menus (full indicates to redraw all items). @@ -209,7 +209,7 @@ class DialogContainer struct { int stick; JoyAxis axis; - int value; + JoyDir adir; } myCurrentAxisDown; uInt64 myAxisRepeatTime; @@ -217,7 +217,7 @@ class DialogContainer struct { int stick; int hat; - JoyHat value; + JoyHatDir value; } myCurrentHatDown; uInt64 myHatRepeatTime; diff --git a/src/gui/EventMappingWidget.cxx b/src/gui/EventMappingWidget.cxx index f0aee483f..49d3241a2 100644 --- a/src/gui/EventMappingWidget.cxx +++ b/src/gui/EventMappingWidget.cxx @@ -45,8 +45,9 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, myRemapStatus(false), myLastStick(0), myLastAxis(JoyAxis::NONE), + myLastDir(JoyDir::NONE), myLastHat(0), - myLastValue(0), + myLastHatDir(JoyHatDir::CENTER), myLastButton(JOY_CTRL_NONE), myFirstTime(true) { @@ -166,8 +167,9 @@ void EventMappingWidget::startRemapping() myLastStick = -1; myLastButton = JOY_CTRL_NONE; myLastAxis = JoyAxis::NONE; + myLastDir = JoyDir::NONE; myLastHat = -1; - myLastValue = int(JoyDir::NONE); + myLastHatDir = JoyHatDir::CENTER; // Reset the previously aggregated key mappings myMod = myLastKey = 0; @@ -224,8 +226,9 @@ void EventMappingWidget::stopRemapping() myLastStick = -1; myLastButton = JOY_CTRL_NONE; myLastAxis = JoyAxis::NONE; + myLastDir = JoyDir::NONE; myLastHat = -1; - myLastValue = int(JoyDir::NONE); + myLastHatDir = JoyHatDir::CENTER; // And re-enable all the widgets enableButtons(true); @@ -334,18 +337,18 @@ void EventMappingWidget::handleJoyUp(int stick, int button) // map either button/hat, solo button or button/axis combinations if(myLastHat != -1) { - if(eh.addJoyHatMapping(event, myEventMode, stick, button, myLastHat, JoyHat(myLastValue))) + if(eh.addJoyHatMapping(event, myEventMode, stick, button, myLastHat, myLastHatDir)) stopRemapping(); } else - if (eh.addJoyMapping(event, myEventMode, stick, button, JoyAxis(myLastAxis), myLastValue)) + if (eh.addJoyMapping(event, myEventMode, stick, button, myLastAxis, myLastDir)) stopRemapping(); } } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventMappingWidget::handleJoyAxis(int stick, JoyAxis axis, int value, int button) +void EventMappingWidget::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) { // Remap joystick axes in remap mode // There are two phases to detection: @@ -354,27 +357,27 @@ void EventMappingWidget::handleJoyAxis(int stick, JoyAxis axis, int value, int b if(myRemapStatus && myActionSelected >= 0) { // Detect the first axis event that represents 'on' - if((myLastStick == -1 || myLastStick == stick) && myLastAxis == JoyAxis::NONE && value != 0) + if((myLastStick == -1 || myLastStick == stick) && myLastAxis == JoyAxis::NONE && adir != JoyDir::NONE) { myLastStick = stick; myLastAxis = axis; - myLastValue = value; + myLastDir = adir; } // Detect the first axis event that matches a previously set // stick and axis, but turns the axis 'off' - else if(myLastStick == stick && axis == myLastAxis && value == 0) + else if(myLastStick == stick && axis == myLastAxis && adir == JoyDir::NONE) { EventHandler& eh = instance().eventHandler(); Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); - if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue)) + if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, axis, myLastDir)) stopRemapping(); } } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHat value, int button) +bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHatDir hdir, int button) { // Remap joystick hats in remap mode // There are two phases to detection: @@ -383,22 +386,22 @@ bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHat value, int butt if(myRemapStatus && myActionSelected >= 0) { // Detect the first hat event that represents a valid direction - if((myLastStick == -1 || myLastStick == stick) && myLastHat == -1 && value != JoyHat::CENTER) + if((myLastStick == -1 || myLastStick == stick) && myLastHat == -1 && hdir != JoyHatDir::CENTER) { myLastStick = stick; myLastHat = hat; - myLastValue = int(value); + myLastHatDir = hdir; return true; } // Detect the first hat event that matches a previously set // stick and hat, but centers the hat - else if(myLastStick == stick && hat == myLastHat && value == JoyHat::CENTER) + else if(myLastStick == stick && hat == myLastHat && hdir == JoyHatDir::CENTER) { EventHandler& eh = instance().eventHandler(); Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); - if (eh.addJoyHatMapping(event, myEventMode, stick, myLastButton, hat, JoyHat(myLastValue))) + if (eh.addJoyHatMapping(event, myEventMode, stick, myLastButton, hat, myLastHatDir)) { stopRemapping(); return true; diff --git a/src/gui/EventMappingWidget.hxx b/src/gui/EventMappingWidget.hxx index abd6daf43..55f1c7620 100644 --- a/src/gui/EventMappingWidget.hxx +++ b/src/gui/EventMappingWidget.hxx @@ -60,8 +60,8 @@ 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, JoyAxis axis, int value, int button) override; - bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; + void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override; + bool handleJoyHat(int stick, int hat, JoyHatDir hdir, int button) override; void loadConfig() override; void saveConfig(); @@ -105,8 +105,10 @@ 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, myLastHat, myLastValue; + int myLastStick, myLastHat; JoyAxis myLastAxis; + JoyDir myLastDir; + JoyHatDir myLastHatDir; // Aggregates the modifier flags of the mapping int myMod; diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index fd857bb67..f6d1301cc 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -499,19 +499,19 @@ void InputDialog::handleJoyUp(int stick, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void InputDialog::handleJoyAxis(int stick, JoyAxis axis, int value, int button) +void InputDialog::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) { // Remap joystick axis in remap mode, otherwise pass to parent dialog if(myEmulEventMapper->remapMode()) - myEmulEventMapper->handleJoyAxis(stick, axis, value, button); + myEmulEventMapper->handleJoyAxis(stick, axis, adir, button); else if(myMenuEventMapper->remapMode()) - myMenuEventMapper->handleJoyAxis(stick, axis, value, button); + myMenuEventMapper->handleJoyAxis(stick, axis, adir, button); else - Dialog::handleJoyAxis(stick, axis, value, button); + Dialog::handleJoyAxis(stick, axis, adir, button); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool InputDialog::handleJoyHat(int stick, int hat, JoyHat value, int button) +bool InputDialog::handleJoyHat(int stick, int hat, JoyHatDir value, int button) { // Remap joystick hat in remap mode, otherwise pass to parent dialog if(myEmulEventMapper->remapMode()) diff --git a/src/gui/InputDialog.hxx b/src/gui/InputDialog.hxx index 280808ca3..05448ee4a 100644 --- a/src/gui/InputDialog.hxx +++ b/src/gui/InputDialog.hxx @@ -51,8 +51,8 @@ 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, JoyAxis axis, int value, int button) override; - bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; + void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override; + bool handleJoyHat(int stick, int hat, JoyHatDir value, int button) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void loadConfig() override; diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 1889923d3..d051f49ac 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -493,9 +493,9 @@ void LauncherDialog::handleJoyUp(int stick, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Event::Type LauncherDialog::getJoyAxisEvent(int stick, JoyAxis axis, int value, int button) +Event::Type LauncherDialog::getJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir, int button) { - Event::Type e = instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, value, button); + Event::Type e = instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, adir, button); if(myUseMinimalUI) { diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index 07e48ca0a..47e26cbcf 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, JoyAxis axis, int value, int button) override; + Event::Type getJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir, int button) override; void loadConfig() override; void updateUI(); diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index e9a3ebcba..a0831ae55 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -79,8 +79,8 @@ 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, 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 void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button = JOY_CTRL_NONE) { } + virtual bool handleJoyHat(int stick, int hat, JoyHatDir value, int button = JOY_CTRL_NONE) { return false; } virtual bool handleEvent(Event::Type event) { return false; } void setDirty() override;