convert int into JoyAxis/JoyDir

This commit is contained in:
Thomas Jentzsch 2019-08-15 11:53:15 +02:00
parent 80a5c5c6bf
commit b47234f776
20 changed files with 135 additions and 131 deletions

View File

@ -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, void JoyMap::add(const Event::Type event, const EventMode mode, const int button,
const JoyAxis axis, const JoyDir adir, 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)); add(event, JoyMapping(mode, button, axis, adir, hat, hdir));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void JoyMap::add(const Event::Type event, const EventMode mode, const int button, 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)); 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, 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)); 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, 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)); 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, bool JoyMap::check(const EventMode mode, const int button,
const JoyAxis axis, const JoyDir adir, 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)); 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; buf << "/H" << mapping.hat;
switch (mapping.hdir) switch (mapping.hdir)
{ {
case JoyHat::UP: buf << "/up"; break; case JoyHatDir::UP: buf << "/up"; break;
case JoyHat::DOWN: buf << "/down"; break; case JoyHatDir::DOWN: buf << "/down"; break;
case JoyHat::LEFT: buf << "/left"; break; case JoyHatDir::LEFT: buf << "/left"; break;
case JoyHat::RIGHT: buf << "/right"; break; case JoyHatDir::RIGHT: buf << "/right"; break;
default: break; default: break;
} }
} }
@ -220,7 +220,7 @@ int JoyMap::loadMapping(string& list, const EventMode mode)
while (buf >> event && buf >> button while (buf >> event && buf >> button
&& buf >> axis && buf >> adir && buf >> axis && buf >> adir
&& buf >> hat && buf >> hdir && ++i) && 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; return i;
} }

View File

@ -38,19 +38,19 @@ class JoyMap
JoyAxis axis; // horizontal/vertical JoyAxis axis; // horizontal/vertical
JoyDir adir; // axis direction (neg/pos) JoyDir adir; // axis direction (neg/pos)
int hat; // hat number int hat; // hat number
JoyHat hdir; // hat direction (left/right/up/down) JoyHatDir hdir; // hat direction (left/right/up/down)
JoyMapping() JoyMapping()
: mode(EventMode(0)), button(0), : mode(EventMode(0)), button(0),
axis(JoyAxis(0)), adir(JoyDir(0)), axis(JoyAxis(0)), adir(JoyDir(0)),
hat(0), hdir(JoyHat(0)) { } hat(0), hdir(JoyHatDir(0)) { }
JoyMapping(const JoyMapping& m) JoyMapping(const JoyMapping& m)
: mode(m.mode), button(m.button), : mode(m.mode), button(m.button),
axis(m.axis), adir(m.adir), axis(m.axis), adir(m.adir),
hat(m.hat), hdir(m.hdir) { } hat(m.hat), hdir(m.hdir) { }
explicit JoyMapping(EventMode c_mode, int c_button, explicit JoyMapping(EventMode c_mode, int c_button,
JoyAxis c_axis, JoyDir c_adir, JoyAxis c_axis, JoyDir c_adir,
int c_hat, JoyHat c_hdir) int c_hat, JoyHatDir c_hdir)
: mode(c_mode), button(c_button), : mode(c_mode), button(c_button),
axis(c_axis), adir(c_adir), axis(c_axis), adir(c_adir),
hat(c_hat), hdir(c_hdir) { } hat(c_hat), hdir(c_hdir) { }
@ -58,9 +58,9 @@ class JoyMap
JoyAxis c_axis, JoyDir c_adir) JoyAxis c_axis, JoyDir c_adir)
: mode(c_mode), button(c_button), : mode(c_mode), button(c_button),
axis(c_axis), adir(c_adir), 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, 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), : mode(c_mode), button(c_button),
axis(JoyAxis::NONE), adir(JoyDir::NONE), axis(JoyAxis::NONE), adir(JoyDir::NONE),
hat(c_hat), hdir(c_hdir) { } 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 JoyMapping& mapping);
void add(const Event::Type event, const EventMode mode, const int button, void add(const Event::Type event, const EventMode mode, const int button,
const JoyAxis axis, const JoyDir adir, const JoyAxis axis, const JoyDir adir,
const int hat = JOY_CTRL_NONE, const JoyHat hdir = JoyHat::CENTER); const int hat = JOY_CTRL_NONE, const JoyHatDir hdir = JoyHatDir::CENTER);
void add(const Event::Type event, const EventMode mode, const int button, void add(const Event::Type event, const EventMode mode, const int button,
const int hat, const JoyHat hdir); const int hat, const JoyHatDir hdir);
/** Erase mapping */ /** Erase mapping */
void erase(const JoyMapping& mapping); void erase(const JoyMapping& mapping);
void erase(const EventMode mode, const int button, void erase(const EventMode mode, const int button,
const JoyAxis axis, const JoyDir adir); const JoyAxis axis, const JoyDir adir);
void erase(const EventMode mode, const int button, void erase(const EventMode mode, const int button,
const int hat, const JoyHat hdir); const int hat, const JoyHatDir hdir);
/** Get event for mapping */ /** Get event for mapping */
Event::Type get(const JoyMapping& mapping) const; Event::Type get(const JoyMapping& mapping) const;
Event::Type get(const EventMode mode, const int button, Event::Type get(const EventMode mode, const int button,
const JoyAxis axis = JoyAxis::NONE, const JoyDir adir = JoyDir::NONE) const; const JoyAxis axis = JoyAxis::NONE, const JoyDir adir = JoyDir::NONE) const;
Event::Type get(const EventMode mode, const int button, Event::Type get(const EventMode mode, const int button,
const int hat, const JoyHat hdir) const; const int hat, const JoyHatDir hdir) const;
/** Check if a mapping exists */ /** Check if a mapping exists */
bool check(const JoyMapping& mapping) const; bool check(const JoyMapping& mapping) const;
bool check(const EventMode mode, const int button, bool check(const EventMode mode, const int button,
const JoyAxis axis, const JoyDir adir, 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 */ /** Get mapping description */
string getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const; string getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const;

View File

@ -551,7 +551,7 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, int stick, 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); 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 // Otherwise, turn off the analog event(s) for this axis
if (Event::isAnalog(j->joyMap.get(evMode, button, axis, JoyDir::ANALOG))) if (Event::isAnalog(j->joyMap.get(evMode, button, axis, JoyDir::ANALOG)))
j->joyMap.erase(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 // update running emulation mapping too
if(Event::isAnalog(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG))) if(Event::isAnalog(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG)))
j->joyMap.erase(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; 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, 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); const PhysicalJoystickPtr j = joy(stick);
if (j && event < Event::LastType && if (j && event < Event::LastType &&
button >= JOY_CTRL_NONE && button < j->numButtons && 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 // 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 true;
} }
return false; return false;
@ -666,7 +666,7 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
if (value != j->axisLastValue[axis]) if (value != j->axisLastValue[axis])
{ {
#ifdef GUI_SUPPORT #ifdef GUI_SUPPORT
myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), value, button); myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), convertAxisValue(value), button);
#endif #endif
j->axisLastValue[axis] = value; 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) 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 // Generate multiple equivalent hat events representing combined direction
// when we get a diagonal hat event // 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) 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); 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); 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); 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); value & EVENT_HATLEFT_M);
} }
#ifdef GUI_SUPPORT #ifdef GUI_SUPPORT
else if (myHandler.hasOverlay()) else if (myHandler.hasOverlay())
{ {
if (value == EVENT_HATCENTER_M) if (value == EVENT_HATCENTER_M)
myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::CENTER, button); myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHatDir::CENTER, button);
else else
{ {
if (value & EVENT_HATUP_M) 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) 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) 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) if (value & EVENT_HATLEFT_M)
myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::LEFT, button); myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHatDir::LEFT, button);
} }
} }
#endif #endif
@ -783,11 +783,11 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftJ
{Event::JoystickZeroUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG}, {Event::JoystickZeroUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG},
{Event::JoystickZeroDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, {Event::JoystickZeroDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS},
// Left joystick left/right directions (assume hat 0) // Left joystick left/right directions (assume hat 0)
{Event::JoystickZeroLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::LEFT}, {Event::JoystickZeroLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT},
{Event::JoystickZeroRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::RIGHT}, {Event::JoystickZeroRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT},
// Left joystick up/down directions (assume hat 0) // Left joystick up/down directions (assume hat 0)
{Event::JoystickZeroUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::UP}, {Event::JoystickZeroUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::UP},
{Event::JoystickZeroDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::DOWN}, {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::JoystickOneUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG},
{Event::JoystickOneDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, {Event::JoystickOneDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS},
// Right joystick left/right directions (assume hat 0) // Right joystick left/right directions (assume hat 0)
{Event::JoystickOneLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::LEFT}, {Event::JoystickOneLeft, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT},
{Event::JoystickOneRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::RIGHT}, {Event::JoystickOneRight, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT},
// Right joystick up/down directions (assume hat 0) // Right joystick up/down directions (assume hat 0)
{Event::JoystickOneUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::UP}, {Event::JoystickOneUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::UP},
{Event::JoystickOneDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::DOWN}, {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::UIUp, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG},
{Event::UIDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, {Event::UIDown, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS},
{Event::UINavPrev, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::LEFT}, {Event::UINavPrev, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::LEFT},
{Event::UINavNext, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::RIGHT}, {Event::UINavNext, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::RIGHT},
{Event::UIUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::UP}, {Event::UIUp, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::UP},
{Event::UIDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::DOWN}, {Event::UIDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHatDir::DOWN},
}; };

View File

@ -81,24 +81,24 @@ class PhysicalJoystickHandler
/** Bind a physical joystick event to a virtual event/action. */ /** Bind a physical joystick event to a virtual event/action. */
bool addJoyMapping(Event::Type event, EventMode mode, int stick, 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, 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. */ /** Handle a physical joystick event. */
void handleAxisEvent(int stick, int axis, int value); void handleAxisEvent(int stick, int axis, int value);
void handleBtnEvent(int stick, int button, bool pressed); void handleBtnEvent(int stick, int button, bool pressed);
void handleHatEvent(int stick, int hat, int value); 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); 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 { Event::Type eventForButton(EventMode mode, int stick, int button) const {
const PhysicalJoystickPtr j = joy(stick); const PhysicalJoystickPtr j = joy(stick);
return j->joyMap.get(mode, button); 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); const PhysicalJoystickPtr j = joy(stick);
return j->joyMap.get(mode, button, hat, hatDir); return j->joyMap.get(mode, button, hat, hatDir);
} }
@ -144,7 +144,7 @@ class PhysicalJoystickHandler
JoyAxis axis = JoyAxis::NONE; JoyAxis axis = JoyAxis::NONE;
JoyDir adir = JoyDir::NONE; JoyDir adir = JoyDir::NONE;
int hat = JOY_CTRL_NONE; int hat = JOY_CTRL_NONE;
JoyHat hdir = JoyHat::CENTER; JoyHatDir hdir = JoyHatDir::CENTER;
}; };
using EventMappingArray = std::vector<EventMapping>; using EventMappingArray = std::vector<EventMapping>;

View File

@ -1132,11 +1132,11 @@ bool EventHandler::addKeyMapping(Event::Type event, EventMode mode, StellaKey ke
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventHandler::addJoyMapping(Event::Type event, EventMode mode, 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) bool updateMenus)
{ {
#ifdef JOYSTICK_SUPPORT #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) if (mapped && updateMenus)
setActionMappings(mode); setActionMappings(mode);
@ -1148,7 +1148,7 @@ bool EventHandler::addJoyMapping(Event::Type event, EventMode mode,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventHandler::addJoyHatMapping(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) bool updateMenus)
{ {
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT

View File

@ -162,13 +162,13 @@ class EventHandler
Event::Type eventForKey(EventMode mode, StellaKey key, StellaMod mod) const { Event::Type eventForKey(EventMode mode, StellaKey key, StellaMod mod) const {
return myPKeyHandler->eventForKey(mode, key, mod); return myPKeyHandler->eventForKey(mode, key, mod);
} }
Event::Type eventForJoyAxis(EventMode mode, int stick, JoyAxis axis, int value, int button) const { Event::Type eventForJoyAxis(EventMode mode, int stick, JoyAxis axis, JoyDir adir, int button) const {
return myPJoyHandler->eventForAxis(mode, stick, axis, value, button); return myPJoyHandler->eventForAxis(mode, stick, axis, adir, button);
} }
Event::Type eventForJoyButton(EventMode mode, int stick, int button) const { Event::Type eventForJoyButton(EventMode mode, int stick, int button) const {
return myPJoyHandler->eventForButton(mode, stick, button); 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); return myPJoyHandler->eventForHat(mode, stick, hat, value, button);
} }
@ -215,13 +215,13 @@ class EventHandler
@param stick The joystick number @param stick The joystick number
@param button The joystick button @param button The joystick button
@param axis The joystick axis @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 @param updateMenus Whether to update the action mappings (normally
we want to do this, unless there are a batch of we want to do this, unless there are a batch of
'adds', in which case it's delayed until the end 'adds', in which case it's delayed until the end
*/ */
bool addJoyMapping(Event::Type event, EventMode mode, int stick, 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); bool updateMenus = true);
/** /**
@ -239,7 +239,7 @@ class EventHandler
'adds', in which case it's delayed until the end 'adds', in which case it's delayed until the end
*/ */
bool addJoyHatMapping(Event::Type event, EventMode mode, int stick, bool addJoyHatMapping(Event::Type event, EventMode mode, int stick,
int button, int hat, JoyHat dir, int button, int hat, JoyHatDir dir,
bool updateMenus = true); bool updateMenus = true);
/** /**

View File

@ -41,8 +41,8 @@ enum class MouseButton {
static constexpr int JOY_CTRL_NONE = -1; static constexpr int JOY_CTRL_NONE = -1;
enum class JoyAxis { enum class JoyAxis {
X = 0, X = 0, // make sure these are set correctly,
Y = 1, Y = 1, // since they'll be used as array indices
Z = 2, Z = 2,
NONE = JOY_CTRL_NONE NONE = JOY_CTRL_NONE
}; };
@ -54,7 +54,7 @@ enum class JoyDir {
ANALOG = 2 ANALOG = 2
}; };
enum class JoyHat { enum class JoyHatDir {
UP = 0, // make sure these are set correctly, UP = 0, // make sure these are set correctly,
DOWN = 1, // since they'll be used as array indices DOWN = 1, // since they'll be used as array indices
LEFT = 2, LEFT = 2,

View File

@ -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 if(adir != JoyDir::NONE) // we don't care about 'axis off' events
handleEvent(instance().eventHandler().eventForJoyAxis(EventMode::kMenuMode, stick, axis, value, button)); 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)); handleEvent(instance().eventHandler().eventForJoyHat(EventMode::kMenuMode, stick, hat, value, button));
return true; return true;

View File

@ -88,8 +88,8 @@ class ContextMenu : public Dialog, public CommandSender
void handleMouseWheel(int x, int y, int direction) override; void handleMouseWheel(int x, int y, int direction) override;
void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override; void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override;
void handleJoyDown(int stick, int button, bool longPress) override; void handleJoyDown(int stick, int button, bool longPress) override;
void handleJoyAxis(int stick, JoyAxis axis, int value, int button) override; void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override;
bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; bool handleJoyHat(int stick, int hat, JoyHatDir value, int button) override;
void handleEvent(Event::Type e); void handleEvent(Event::Type e);
void drawDialog() override; void drawDialog() override;

View File

@ -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 // Unless a widget has claimed all responsibility for data, we assume
// that if an event exists for the given data, it should have priority. // that if an event exists for the given data, it should have priority.
if(!handleNavEvent(e) && _focusedWidget) if(!handleNavEvent(e) && _focusedWidget)
{ {
if(_focusedWidget->wantsRaw() || e == Event::NoType) if(_focusedWidget->wantsRaw() || e == Event::NoType)
_focusedWidget->handleJoyAxis(stick, axis, value, button); _focusedWidget->handleJoyAxis(stick, axis, adir, button);
else if(value != int(JoyDir::NONE)) else if(adir != JoyDir::NONE)
_focusedWidget->handleEvent(e); _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 = Event::Type e =
instance().eventHandler().eventForJoyHat(EventMode::kMenuMode, stick, hat, value, button); instance().eventHandler().eventForJoyHat(EventMode::kMenuMode, stick, hat, value, button);

View File

@ -139,10 +139,10 @@ class Dialog : public GuiObject
virtual bool handleMouseClicks(int x, int y, MouseButton b); virtual bool handleMouseClicks(int x, int y, MouseButton b);
virtual void handleJoyDown(int stick, int button, bool longPress = false); virtual void handleJoyDown(int stick, int button, bool longPress = false);
virtual void handleJoyUp(int stick, int button); virtual void handleJoyUp(int stick, int button);
virtual void handleJoyAxis(int stick, JoyAxis axis, int 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, JoyHat value, 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 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 Widget* findWidget(int x, int y) const; // Find the widget at pos x,y if any

View File

@ -80,7 +80,7 @@ void DialogContainer::updateTime(uInt64 time)
if(myCurrentAxisDown.stick != -1 && myAxisRepeatTime < myTime) if(myCurrentAxisDown.stick != -1 && myAxisRepeatTime < myTime)
{ {
activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis, activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis,
myCurrentAxisDown.value); myCurrentAxisDown.adir);
myAxisRepeatTime = myTime + _REPEAT_SUSTAIN_DELAY; 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()) if(myDialogStack.empty())
return; return;
@ -325,25 +325,25 @@ void DialogContainer::handleJoyAxisEvent(int stick, JoyAxis axis, int value, int
myButtonLongPressTime = myTime + _REPEAT_NONE; myButtonLongPressTime = myTime + _REPEAT_NONE;
// Only stop firing events if it's the current stick // 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.stick = -1;
myCurrentAxisDown.axis = JoyAxis::NONE; myCurrentAxisDown.axis = JoyAxis::NONE;
myAxisRepeatTime = 0; 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) // Now account for repeated axis events (press and hold)
myCurrentAxisDown.stick = stick; myCurrentAxisDown.stick = stick;
myCurrentAxisDown.axis = axis; myCurrentAxisDown.axis = axis;
myCurrentAxisDown.value = value; myCurrentAxisDown.adir = adir;
myAxisRepeatTime = myTime + (activeDialog->repeatEnabled() ? _REPEAT_INITIAL_DELAY : _REPEAT_NONE); 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()) if(myDialogStack.empty())
return; return;
@ -355,12 +355,12 @@ void DialogContainer::handleJoyHatEvent(int stick, int hat, JoyHat value, int bu
myButtonLongPressTime = myTime + _REPEAT_NONE; myButtonLongPressTime = myTime + _REPEAT_NONE;
// Only stop firing events if it's the current stick // 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; myCurrentHatDown.stick = myCurrentHatDown.hat = -1;
myHatRepeatTime = 0; 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) // Now account for repeated hat events (press and hold)
myCurrentHatDown.stick = stick; myCurrentHatDown.stick = stick;

View File

@ -108,7 +108,7 @@ class DialogContainer
@param axis The joystick axis @param axis The joystick axis
@param value Value associated with given 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. Handle a joystick hat event.
@ -117,7 +117,7 @@ class DialogContainer
@param hat The joystick hat @param hat The joystick hat
@param value Value associated with given 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). Draw the stack of menus (full indicates to redraw all items).
@ -209,7 +209,7 @@ class DialogContainer
struct { struct {
int stick; int stick;
JoyAxis axis; JoyAxis axis;
int value; JoyDir adir;
} myCurrentAxisDown; } myCurrentAxisDown;
uInt64 myAxisRepeatTime; uInt64 myAxisRepeatTime;
@ -217,7 +217,7 @@ class DialogContainer
struct { struct {
int stick; int stick;
int hat; int hat;
JoyHat value; JoyHatDir value;
} myCurrentHatDown; } myCurrentHatDown;
uInt64 myHatRepeatTime; uInt64 myHatRepeatTime;

View File

@ -45,8 +45,9 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font,
myRemapStatus(false), myRemapStatus(false),
myLastStick(0), myLastStick(0),
myLastAxis(JoyAxis::NONE), myLastAxis(JoyAxis::NONE),
myLastDir(JoyDir::NONE),
myLastHat(0), myLastHat(0),
myLastValue(0), myLastHatDir(JoyHatDir::CENTER),
myLastButton(JOY_CTRL_NONE), myLastButton(JOY_CTRL_NONE),
myFirstTime(true) myFirstTime(true)
{ {
@ -166,8 +167,9 @@ void EventMappingWidget::startRemapping()
myLastStick = -1; myLastStick = -1;
myLastButton = JOY_CTRL_NONE; myLastButton = JOY_CTRL_NONE;
myLastAxis = JoyAxis::NONE; myLastAxis = JoyAxis::NONE;
myLastDir = JoyDir::NONE;
myLastHat = -1; myLastHat = -1;
myLastValue = int(JoyDir::NONE); myLastHatDir = JoyHatDir::CENTER;
// Reset the previously aggregated key mappings // Reset the previously aggregated key mappings
myMod = myLastKey = 0; myMod = myLastKey = 0;
@ -224,8 +226,9 @@ void EventMappingWidget::stopRemapping()
myLastStick = -1; myLastStick = -1;
myLastButton = JOY_CTRL_NONE; myLastButton = JOY_CTRL_NONE;
myLastAxis = JoyAxis::NONE; myLastAxis = JoyAxis::NONE;
myLastDir = JoyDir::NONE;
myLastHat = -1; myLastHat = -1;
myLastValue = int(JoyDir::NONE); myLastHatDir = JoyHatDir::CENTER;
// And re-enable all the widgets // And re-enable all the widgets
enableButtons(true); enableButtons(true);
@ -334,18 +337,18 @@ void EventMappingWidget::handleJoyUp(int stick, int button)
// map either button/hat, solo button or button/axis combinations // map either button/hat, solo button or button/axis combinations
if(myLastHat != -1) if(myLastHat != -1)
{ {
if(eh.addJoyHatMapping(event, myEventMode, stick, button, myLastHat, JoyHat(myLastValue))) if(eh.addJoyHatMapping(event, myEventMode, stick, button, myLastHat, myLastHatDir))
stopRemapping(); stopRemapping();
} }
else else
if (eh.addJoyMapping(event, myEventMode, stick, button, JoyAxis(myLastAxis), myLastValue)) if (eh.addJoyMapping(event, myEventMode, stick, button, myLastAxis, myLastDir))
stopRemapping(); 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 // Remap joystick axes in remap mode
// There are two phases to detection: // 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) if(myRemapStatus && myActionSelected >= 0)
{ {
// Detect the first axis event that represents 'on' // 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; myLastStick = stick;
myLastAxis = axis; myLastAxis = axis;
myLastValue = value; myLastDir = adir;
} }
// Detect the first axis event that matches a previously set // Detect the first axis event that matches a previously set
// stick and axis, but turns the axis 'off' // 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(); EventHandler& eh = instance().eventHandler();
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); 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(); 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 // Remap joystick hats in remap mode
// There are two phases to detection: // 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) if(myRemapStatus && myActionSelected >= 0)
{ {
// Detect the first hat event that represents a valid direction // 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; myLastStick = stick;
myLastHat = hat; myLastHat = hat;
myLastValue = int(value); myLastHatDir = hdir;
return true; return true;
} }
// Detect the first hat event that matches a previously set // Detect the first hat event that matches a previously set
// stick and hat, but centers the hat // 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(); EventHandler& eh = instance().eventHandler();
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); 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(); stopRemapping();
return true; return true;

View File

@ -60,8 +60,8 @@ class EventMappingWidget : public Widget, public CommandSender
bool handleKeyUp(StellaKey key, StellaMod mod) override; bool handleKeyUp(StellaKey key, StellaMod mod) override;
void handleJoyDown(int stick, int button, bool longPress = false) override; void handleJoyDown(int stick, int button, bool longPress = false) override;
void handleJoyUp(int stick, int button) override; void handleJoyUp(int stick, int button) override;
void handleJoyAxis(int stick, JoyAxis axis, int value, int button) override; void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override;
bool handleJoyHat(int stick, int hat, JoyHat value, int button) override; bool handleJoyHat(int stick, int hat, JoyHatDir hdir, int button) override;
void loadConfig() override; void loadConfig() override;
void saveConfig(); void saveConfig();
@ -105,8 +105,10 @@ class EventMappingWidget : public Widget, public CommandSender
// Therefore, we map these events when they've been 'released', rather // Therefore, we map these events when they've been 'released', rather
// than on their first occurrence (aka, when they're 'pressed') // than on their first occurrence (aka, when they're 'pressed')
// As a result, we need to keep track of their old values // As a result, we need to keep track of their old values
int myLastStick, myLastHat, myLastValue; int myLastStick, myLastHat;
JoyAxis myLastAxis; JoyAxis myLastAxis;
JoyDir myLastDir;
JoyHatDir myLastHatDir;
// Aggregates the modifier flags of the mapping // Aggregates the modifier flags of the mapping
int myMod; int myMod;

View File

@ -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 // Remap joystick axis in remap mode, otherwise pass to parent dialog
if(myEmulEventMapper->remapMode()) if(myEmulEventMapper->remapMode())
myEmulEventMapper->handleJoyAxis(stick, axis, value, button); myEmulEventMapper->handleJoyAxis(stick, axis, adir, button);
else if(myMenuEventMapper->remapMode()) else if(myMenuEventMapper->remapMode())
myMenuEventMapper->handleJoyAxis(stick, axis, value, button); myMenuEventMapper->handleJoyAxis(stick, axis, adir, button);
else 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 // Remap joystick hat in remap mode, otherwise pass to parent dialog
if(myEmulEventMapper->remapMode()) if(myEmulEventMapper->remapMode())

View File

@ -51,8 +51,8 @@ class InputDialog : public Dialog
void handleKeyUp(StellaKey key, StellaMod mod) override; void handleKeyUp(StellaKey key, StellaMod mod) override;
void handleJoyDown(int stick, int button, bool longPress) override; void handleJoyDown(int stick, int button, bool longPress) override;
void handleJoyUp(int stick, int button) override; void handleJoyUp(int stick, int button) override;
void handleJoyAxis(int stick, JoyAxis axis, int value, int button) override; void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override;
bool handleJoyHat(int stick, int hat, JoyHat value, 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 handleCommand(CommandSender* sender, int cmd, int data, int id) override;
void loadConfig() override; void loadConfig() override;

View File

@ -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) if(myUseMinimalUI)
{ {

View File

@ -93,7 +93,7 @@ class LauncherDialog : public Dialog
void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
void handleJoyDown(int stick, int button, bool longPress) override; void handleJoyDown(int stick, int button, bool longPress) override;
void handleJoyUp(int stick, int button) 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 loadConfig() override;
void updateUI(); void updateUI();

View File

@ -79,8 +79,8 @@ class Widget : public GuiObject
virtual bool handleMouseClicks(int x, int y, MouseButton b) { return false; } virtual bool handleMouseClicks(int x, int y, MouseButton b) { return false; }
virtual void handleJoyDown(int stick, int button, bool longPress = false) { } virtual void handleJoyDown(int stick, int button, bool longPress = false) { }
virtual void handleJoyUp(int stick, int button) { } virtual void handleJoyUp(int stick, int button) { }
virtual void handleJoyAxis(int stick, JoyAxis axis, int 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, JoyHat value, int button = JOY_CTRL_NONE) { return false; } virtual bool handleJoyHat(int stick, int hat, JoyHatDir value, int button = JOY_CTRL_NONE) { return false; }
virtual bool handleEvent(Event::Type event) { return false; } virtual bool handleEvent(Event::Type event) { return false; }
void setDirty() override; void setDirty() override;