mirror of https://github.com/stella-emu/stella.git
implement rudimentary mapping
This commit is contained in:
parent
529c1fe7de
commit
8210a25f40
|
@ -35,9 +35,10 @@ void JoyHatMap::add(const Event::Type event, const JoyHatMapping& mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void JoyHatMap::add(const Event::Type event, const EventMode mode, const int hat, const JoyHat hdir)
|
void JoyHatMap::add(const Event::Type event, const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir)
|
||||||
{
|
{
|
||||||
add(event, JoyHatMapping(mode, hat, hdir));
|
add(event, JoyHatMapping(mode, button, hat, hdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -47,9 +48,10 @@ void JoyHatMap::erase(const JoyHatMapping& mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void JoyHatMap::erase(const EventMode mode, const int hat, const JoyHat hdir)
|
void JoyHatMap::erase(const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir)
|
||||||
{
|
{
|
||||||
erase(JoyHatMapping(mode, hat, hdir));
|
erase(JoyHatMapping(mode, button, hat, hdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -63,9 +65,10 @@ Event::Type JoyHatMap::get(const JoyHatMapping& mapping) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
Event::Type JoyHatMap::get(const EventMode mode, const int hat, const JoyHat hdir) const
|
Event::Type JoyHatMap::get(const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir) const
|
||||||
{
|
{
|
||||||
return get(JoyHatMapping(mode, hat, hdir));
|
return get(JoyHatMapping(mode, button, hat, hdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -77,9 +80,10 @@ bool JoyHatMap::check(const JoyHatMapping & mapping) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool JoyHatMap::check(const EventMode mode, const int hat, const JoyHat hdir) const
|
bool JoyHatMap::check(const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir) const
|
||||||
{
|
{
|
||||||
return check(JoyHatMapping(mode, hat, hdir));
|
return check(JoyHatMapping(mode, button, hat, hdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -90,7 +94,7 @@ string JoyHatMap::getDesc(const Event::Type event, const JoyHatMapping & mapping
|
||||||
//buf << "J" << mapping.stick;
|
//buf << "J" << mapping.stick;
|
||||||
|
|
||||||
// hat description
|
// hat description
|
||||||
if (mapping.hat != CTRL_NONE)
|
if (mapping.hat != JOY_CTRL_NONE)
|
||||||
{
|
{
|
||||||
buf << "/H" << mapping.hat;
|
buf << "/H" << mapping.hat;
|
||||||
switch (mapping.hdir)
|
switch (mapping.hdir)
|
||||||
|
@ -108,13 +112,14 @@ string JoyHatMap::getDesc(const Event::Type event, const JoyHatMapping & mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string JoyHatMap::getDesc(const Event::Type event, const EventMode mode, const int hat, const JoyHat hdir) const
|
string JoyHatMap::getDesc(const Event::Type event, const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir) const
|
||||||
{
|
{
|
||||||
return getDesc(event, JoyHatMapping(mode, hat, hdir));
|
return getDesc(event, JoyHatMapping(mode, button, hat, hdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string JoyHatMap::getEventMappingDesc(const Event::Type event, const EventMode mode) const
|
string JoyHatMap::getEventMappingDesc(const int stick, const Event::Type event, const EventMode mode) const
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
|
|
||||||
|
@ -124,7 +129,7 @@ string JoyHatMap::getEventMappingDesc(const Event::Type event, const EventMode m
|
||||||
{
|
{
|
||||||
if (buf.str() != "")
|
if (buf.str() != "")
|
||||||
buf << ", ";
|
buf << ", ";
|
||||||
buf << getDesc(event, item.first);
|
buf << "J" << stick << getDesc(event, item.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf.str();
|
return buf.str();
|
||||||
|
@ -169,10 +174,10 @@ int JoyHatMap::loadMapping(string & list, const EventMode mode)
|
||||||
std::replace(list.begin(), list.end(), ':', ' ');
|
std::replace(list.begin(), list.end(), ':', ' ');
|
||||||
std::replace(list.begin(), list.end(), ',', ' ');
|
std::replace(list.begin(), list.end(), ',', ' ');
|
||||||
istringstream buf(list);
|
istringstream buf(list);
|
||||||
int event, stick, hat, hdir, i = 0;
|
int event, stick, button, hat, hdir, i = 0;
|
||||||
|
|
||||||
while (buf >> event && buf >> stick && buf >> hat && buf >> hdir && ++i)
|
while (buf >> event && buf >> stick && buf >> button && buf >> hat && buf >> hdir && ++i)
|
||||||
add(Event::Type(event), EventMode(mode), hat, JoyHat(hdir));
|
add(Event::Type(event), EventMode(mode), button, hat, JoyHat(hdir));
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,19 +34,21 @@ public:
|
||||||
struct JoyHatMapping
|
struct JoyHatMapping
|
||||||
{
|
{
|
||||||
EventMode mode;
|
EventMode mode;
|
||||||
|
int button; // button number
|
||||||
int hat; // hat number
|
int hat; // hat number
|
||||||
JoyHat hdir; // hat direction (left/right/up/down)
|
JoyHat hdir; // hat direction (left/right/up/down)
|
||||||
|
|
||||||
JoyHatMapping()
|
JoyHatMapping()
|
||||||
: mode(EventMode(0)), hat(0), hdir(JoyHat(0)) { }
|
: mode(EventMode(0)), button(0), hat(0), hdir(JoyHat(0)) { }
|
||||||
JoyHatMapping(const JoyHatMapping& m)
|
JoyHatMapping(const JoyHatMapping& m)
|
||||||
: mode(m.mode), hat(m.hat), hdir(m.hdir) { }
|
: mode(m.mode), button(m.button), hat(m.hat), hdir(m.hdir) { }
|
||||||
explicit JoyHatMapping(EventMode c_mode, int c_hat, JoyHat c_hdir)
|
explicit JoyHatMapping(EventMode c_mode, int c_button, int c_hat, JoyHat c_hdir)
|
||||||
: mode(c_mode), hat(c_hat), hdir(c_hdir) { }
|
: mode(c_mode), button(c_button), hat(c_hat), hdir(c_hdir) { }
|
||||||
|
|
||||||
bool operator==(const JoyHatMapping& other) const
|
bool operator==(const JoyHatMapping& other) const
|
||||||
{
|
{
|
||||||
return (mode == other.mode
|
return (mode == other.mode
|
||||||
|
&& button == other.button
|
||||||
&& hat == other.hat
|
&& hat == other.hat
|
||||||
&& hdir == other.hdir
|
&& hdir == other.hdir
|
||||||
);
|
);
|
||||||
|
@ -59,26 +61,31 @@ public:
|
||||||
|
|
||||||
/** Add new mapping for given event */
|
/** Add new mapping for given event */
|
||||||
void add(const Event::Type event, const JoyHatMapping& mapping);
|
void add(const Event::Type event, const JoyHatMapping& mapping);
|
||||||
void add(const Event::Type event, const EventMode mode, const int hat, const JoyHat hdir);
|
void add(const Event::Type event, const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir);
|
||||||
|
|
||||||
/** Erase mapping */
|
/** Erase mapping */
|
||||||
void erase(const JoyHatMapping& mapping);
|
void erase(const JoyHatMapping& mapping);
|
||||||
void erase(const EventMode mode, const int hat, const JoyHat hdir);
|
void erase(const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir);
|
||||||
|
|
||||||
/** Get event for mapping */
|
/** Get event for mapping */
|
||||||
Event::Type get(const JoyHatMapping& mapping) const;
|
Event::Type get(const JoyHatMapping& mapping) const;
|
||||||
Event::Type get(const EventMode mode, const int hat, const JoyHat hdir) const;
|
Event::Type get(const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir) const;
|
||||||
|
|
||||||
/** Check if a mapping exists */
|
/** Check if a mapping exists */
|
||||||
bool check(const JoyHatMapping& mapping) const;
|
bool check(const JoyHatMapping& mapping) const;
|
||||||
bool check(const EventMode mode, const int hat, const JoyHat hdir) const;
|
bool check(const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir) const;
|
||||||
|
|
||||||
/** Get mapping description */
|
/** Get mapping description */
|
||||||
string getDesc(const Event::Type event, const JoyHatMapping& mapping) const;
|
string getDesc(const Event::Type event, const JoyHatMapping& mapping) const;
|
||||||
string getDesc(const Event::Type event, const EventMode mode, const int hat, const JoyHat hdir) const;
|
string getDesc(const Event::Type event, const EventMode mode,
|
||||||
|
const int button, const int hat, const JoyHat hdir) const;
|
||||||
|
|
||||||
/** Get the mapping description(s) for given event and mode */
|
/** Get the mapping description(s) for given stick, event and mode */
|
||||||
string getEventMappingDesc(const Event::Type event, const EventMode mode) const;
|
string getEventMappingDesc(const int stick, const Event::Type event, const EventMode mode) const;
|
||||||
|
|
||||||
JoyHatMappingArray getEventMapping(const Event::Type event, const EventMode mode) const;
|
JoyHatMappingArray getEventMapping(const Event::Type event, const EventMode mode) const;
|
||||||
|
|
||||||
|
@ -97,8 +104,9 @@ private:
|
||||||
struct JoyHatHash {
|
struct JoyHatHash {
|
||||||
size_t operator()(const JoyHatMapping& m)const {
|
size_t operator()(const JoyHatMapping& m)const {
|
||||||
return std::hash<uInt64>()((uInt64(m.mode)) // 3 bit
|
return std::hash<uInt64>()((uInt64(m.mode)) // 3 bit
|
||||||
^ ((uInt64(m.hat)) << 3) // 1 bit
|
^ ((uInt64(m.button)) << 3) // 2 bits
|
||||||
^ ((uInt64(m.hdir)) << 4) // 2 bits
|
^ ((uInt64(m.hat)) << 5) // 1 bit
|
||||||
|
^ ((uInt64(m.hdir)) << 6) // 2 bits
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -94,18 +94,19 @@ string JoyMap::getDesc(const Event::Type event, const JoyMapping& mapping) const
|
||||||
//buf << "J" << mapping.stick;
|
//buf << "J" << mapping.stick;
|
||||||
|
|
||||||
// button description
|
// button description
|
||||||
if (mapping.button != CTRL_NONE)
|
if (mapping.button != JOY_CTRL_NONE)
|
||||||
buf << "/B" << mapping.button;
|
buf << "/B" << mapping.button;
|
||||||
|
|
||||||
// axis description
|
// axis description
|
||||||
if (int(mapping.axis) != CTRL_NONE)
|
if (mapping.axis != JoyAxis::NONE)
|
||||||
{
|
{
|
||||||
buf << "/A";
|
buf << "/A";
|
||||||
switch (mapping.axis)
|
switch (mapping.axis)
|
||||||
{
|
{
|
||||||
case JoyAxis::X: buf << "X"; break;
|
case JoyAxis::X: buf << "X"; break;
|
||||||
case JoyAxis::Y: buf << "Y"; break;
|
case JoyAxis::Y: buf << "Y"; break;
|
||||||
default: break;
|
case JoyAxis::Z: buf << "Z"; break;
|
||||||
|
default: buf << int(mapping.axis); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Event::isAnalog(event))
|
if (Event::isAnalog(event))
|
||||||
|
@ -127,7 +128,7 @@ string JoyMap::getDesc(const Event::Type event, const EventMode mode, const int
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string JoyMap::getEventMappingDesc(const Event::Type event, const EventMode mode) const
|
string JoyMap::getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ string JoyMap::getEventMappingDesc(const Event::Type event, const EventMode mode
|
||||||
{
|
{
|
||||||
if (buf.str() != "")
|
if (buf.str() != "")
|
||||||
buf << ", ";
|
buf << ", ";
|
||||||
buf << getDesc(event, item.first);
|
buf << "J" << stick << getDesc(event, item.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf.str();
|
return buf.str();
|
||||||
|
@ -166,7 +167,7 @@ string JoyMap::saveMapping(const EventMode mode) const
|
||||||
{
|
{
|
||||||
if (buf.str() != "")
|
if (buf.str() != "")
|
||||||
buf << "|";
|
buf << "|";
|
||||||
buf << item.second << ":" /*<< item.first.stick*/ << "," << item.first.button << ","
|
buf << item.second << ":" << item.first.button << ","
|
||||||
<< int(item.first.axis) << "," << int(item.first.adir);
|
<< int(item.first.axis) << "," << int(item.first.adir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ class JoyMap
|
||||||
/** 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, const JoyDir adir) const;
|
const JoyAxis axis = JoyAxis::NONE, const JoyDir adir = JoyDir::NONE) const;
|
||||||
|
|
||||||
/** Check if a mapping exists */
|
/** Check if a mapping exists */
|
||||||
bool check(const JoyMapping& mapping) const;
|
bool check(const JoyMapping& mapping) const;
|
||||||
|
@ -88,8 +88,8 @@ class JoyMap
|
||||||
string getDesc(const Event::Type event, const EventMode mode, const int button,
|
string getDesc(const Event::Type event, const EventMode mode, const int button,
|
||||||
const JoyAxis axis, const JoyDir adir) const;
|
const JoyAxis axis, const JoyDir adir) const;
|
||||||
|
|
||||||
/** Get the mapping description(s) for given event and mode */
|
/** Get the mapping description(s) for given stick, event and mode */
|
||||||
string getEventMappingDesc(const Event::Type event, const EventMode mode) const;
|
string getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const;
|
||||||
|
|
||||||
JoyMappingArray getEventMapping(const Event::Type event, const EventMode mode) const;
|
JoyMappingArray getEventMapping(const Event::Type event, const EventMode mode) const;
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ PhysicalJoystickHandler::PhysicalJoystickHandler(
|
||||||
|
|
||||||
// First compare if event list version has changed, and disregard the entire mapping if true
|
// First compare if event list version has changed, and disregard the entire mapping if true
|
||||||
getline(buf, joymap, '^'); // event list size, ignore
|
getline(buf, joymap, '^'); // event list size, ignore
|
||||||
if(version == Event::VERSION)
|
if(version != Event::VERSION)
|
||||||
{
|
{
|
||||||
// Otherwise, put each joystick mapping entry into the database
|
// Otherwise, put each joystick mapping entry into the database
|
||||||
while(getline(buf, joymap, '^'))
|
while(getline(buf, joymap, '^'))
|
||||||
|
@ -251,20 +251,29 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
|
||||||
{
|
{
|
||||||
bool eraseAll = (event == Event::NoType);
|
bool eraseAll = (event == Event::NoType);
|
||||||
|
|
||||||
auto setDefaultAxis = [&](int a_stick, JoyAxis a_axis, JoyDir a_value, Event::Type a_event)
|
auto setDefaultAxis = [&](Event::Type a_event, int stick, JoyAxis axis, JoyDir value, int button = JOY_CTRL_NONE)
|
||||||
{
|
{
|
||||||
if(eraseAll || a_event == event)
|
if (eraseAll || a_event == event)
|
||||||
myHandler.addJoyAxisMapping(a_event, mode, a_stick, int(a_axis), int(a_value), false);
|
{
|
||||||
|
//myHandler.addJoyAxisMapping(a_event, mode, stick, int(axis), int(value), false);
|
||||||
|
myHandler.addJoyMapping(a_event, mode, stick, button, axis, int(value), false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
auto setDefaultBtn = [&](int b_stick, int b_button, Event::Type b_event)
|
auto setDefaultBtn = [&](Event::Type b_event, int stick, int button)
|
||||||
{
|
{
|
||||||
if(eraseAll || b_event == event)
|
if (eraseAll || b_event == event)
|
||||||
myHandler.addJoyButtonMapping(b_event, mode, b_stick, b_button, false);
|
{
|
||||||
|
//myHandler.addJoyButtonMapping(b_event, mode, stick, button, false);
|
||||||
|
myHandler.addJoyMapping(b_event, mode, stick, button, JoyAxis::NONE, int(JoyDir::NONE), false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
auto setDefaultHat = [&](int h_stick, int h_hat, JoyHat h_dir, Event::Type h_event)
|
auto setDefaultHat = [&](Event::Type h_event, int stick, int hat, JoyHat dir, int button = JOY_CTRL_NONE)
|
||||||
{
|
{
|
||||||
if(eraseAll || h_event == event)
|
if (eraseAll || h_event == event)
|
||||||
myHandler.addJoyHatMapping(h_event, mode, h_stick, h_hat, h_dir, false);
|
{
|
||||||
|
//myHandler.addJoyHatMapping(h_event, mode, stick, hat, dir, false);
|
||||||
|
myHandler.addJoyHatMapping(h_event, mode, stick, button, hat, dir, false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
switch(mode)
|
switch(mode)
|
||||||
|
@ -275,54 +284,54 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
|
||||||
case 0:
|
case 0:
|
||||||
case 2:
|
case 2:
|
||||||
// Left joystick left/right directions (assume joystick zero or two)
|
// Left joystick left/right directions (assume joystick zero or two)
|
||||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::NEG, Event::JoystickZeroLeft);
|
setDefaultAxis(Event::JoystickZeroLeft, stick, JoyAxis::X, JoyDir::NEG);
|
||||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::POS, Event::JoystickZeroRight);
|
setDefaultAxis(Event::JoystickZeroRight, stick, JoyAxis::X, JoyDir::POS);
|
||||||
// Left joystick up/down directions (assume joystick zero or two)
|
// Left joystick up/down directions (assume joystick zero or two)
|
||||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::NEG, Event::JoystickZeroUp);
|
setDefaultAxis(Event::JoystickZeroUp, stick, JoyAxis::Y, JoyDir::NEG);
|
||||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::POS, Event::JoystickZeroDown);
|
setDefaultAxis(Event::JoystickZeroDown, stick, JoyAxis::Y, JoyDir::POS);
|
||||||
// Left joystick (assume joystick zero or two, buttons zero..two)
|
// Left joystick (assume joystick zero or two, buttons zero..two)
|
||||||
setDefaultBtn(stick, 0, Event::JoystickZeroFire);
|
setDefaultBtn(Event::JoystickZeroFire, stick, 0);
|
||||||
setDefaultBtn(stick, 1, Event::JoystickZeroFire5);
|
setDefaultBtn(Event::JoystickZeroFire5, stick, 1);
|
||||||
setDefaultBtn(stick, 2, Event::JoystickZeroFire9);
|
setDefaultBtn(Event::JoystickZeroFire9, stick, 2);
|
||||||
// Left joystick left/right directions (assume joystick zero or two and hat 0)
|
// Left joystick left/right directions (assume joystick zero or two and hat 0)
|
||||||
setDefaultHat(stick, 0, JoyHat::LEFT, Event::JoystickZeroLeft);
|
setDefaultHat(Event::JoystickZeroLeft, stick, 0, JoyHat::LEFT);
|
||||||
setDefaultHat(stick, 0, JoyHat::RIGHT, Event::JoystickZeroRight);
|
setDefaultHat(Event::JoystickZeroRight, stick, 0, JoyHat::RIGHT);
|
||||||
// Left joystick up/down directions (assume joystick zero or two and hat 0)
|
// Left joystick up/down directions (assume joystick zero or two and hat 0)
|
||||||
setDefaultHat(stick, 0, JoyHat::UP, Event::JoystickZeroUp);
|
setDefaultHat(Event::JoystickZeroUp, stick, 0, JoyHat::UP);
|
||||||
setDefaultHat(stick, 0, JoyHat::DOWN, Event::JoystickZeroDown);
|
setDefaultHat(Event::JoystickZeroDown, stick, 0, JoyHat::DOWN);
|
||||||
#if defined(RETRON77)
|
#if defined(RETRON77)
|
||||||
// Left joystick (assume joystick zero or two, buttons two..four)
|
// Left joystick (assume joystick zero or two, buttons two..four)
|
||||||
setDefaultBtn(stick, 2, Event::CmdMenuMode);
|
setDefaultBtn(Event::CmdMenuMode, stick, 2);
|
||||||
setDefaultBtn(stick, 3, Event::OptionsMenuMode);
|
setDefaultBtn(Event::OptionsMenuMode, stick, 3);
|
||||||
setDefaultBtn(stick, 4, Event::ExitMode);
|
setDefaultBtn(Event::ExitMode, stick, 4);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
case 3:
|
case 3:
|
||||||
// Right joystick left/right directions (assume joystick one or three)
|
// Right joystick left/right directions (assume joystick one or three)
|
||||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::NEG, Event::JoystickOneLeft);
|
setDefaultAxis(Event::JoystickOneLeft, stick, JoyAxis::X, JoyDir::NEG);
|
||||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::POS, Event::JoystickOneRight);
|
setDefaultAxis(Event::JoystickOneRight, stick, JoyAxis::X, JoyDir::POS);
|
||||||
// Right joystick left/right directions (assume joystick one or three)
|
// Right joystick left/right directions (assume joystick one or three)
|
||||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::NEG, Event::JoystickOneUp);
|
setDefaultAxis(Event::JoystickOneUp, stick, JoyAxis::Y, JoyDir::NEG);
|
||||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::POS, Event::JoystickOneDown);
|
setDefaultAxis(Event::JoystickOneDown, stick, JoyAxis::Y, JoyDir::POS);
|
||||||
// Right joystick (assume joystick one or three, buttons zero..two)
|
// Right joystick (assume joystick one or three, buttons zero..two)
|
||||||
setDefaultBtn(stick, 0, Event::JoystickOneFire);
|
setDefaultBtn(Event::JoystickOneFire, stick, 0);
|
||||||
setDefaultBtn(stick, 1, Event::JoystickOneFire5);
|
setDefaultBtn(Event::JoystickOneFire5, stick, 1);
|
||||||
setDefaultBtn(stick, 2, Event::JoystickOneFire9);
|
setDefaultBtn(Event::JoystickOneFire9, stick, 2);
|
||||||
// Right joystick left/right directions (assume joystick one or three and hat 0)
|
// Right joystick left/right directions (assume joystick one or three and hat 0)
|
||||||
setDefaultHat(stick, 0, JoyHat::LEFT, Event::JoystickOneLeft);
|
setDefaultHat(Event::JoystickOneLeft, stick, 0, JoyHat::LEFT);
|
||||||
setDefaultHat(stick, 0, JoyHat::RIGHT, Event::JoystickOneRight);
|
setDefaultHat(Event::JoystickOneRight, stick, 0, JoyHat::RIGHT);
|
||||||
// Right joystick up/down directions (assume joystick one or three and hat 0)
|
// Right joystick up/down directions (assume joystick one or three and hat 0)
|
||||||
setDefaultHat(stick, 0, JoyHat::UP, Event::JoystickOneUp);
|
setDefaultHat(Event::JoystickOneUp, stick, 0, JoyHat::UP);
|
||||||
setDefaultHat(stick, 0, JoyHat::DOWN, Event::JoystickOneDown);
|
setDefaultHat(Event::JoystickOneDown, stick, 0, JoyHat::DOWN);
|
||||||
#if defined(RETRON77)
|
#if defined(RETRON77)
|
||||||
// Right joystick (assume joystick one or three, buttons two..four)
|
// Right joystick (assume joystick one or three, buttons two..four)
|
||||||
setDefaultBtn(stick, 2, Event::CmdMenuMode);
|
setDefaultBtn(Event::CmdMenuMode, stick, 2);
|
||||||
setDefaultBtn(stick, 3, Event::OptionsMenuMode);
|
setDefaultBtn(Event::OptionsMenuMode, stick, 3);
|
||||||
setDefaultBtn(stick, 4, Event::ExitMode);
|
setDefaultBtn(Event::ExitMode, stick, 4);
|
||||||
setDefaultBtn(stick, 5, Event::RewindPause);
|
setDefaultBtn(Event::RewindPause, stick, 5);
|
||||||
setDefaultBtn(stick, 7, Event::ConsoleSelect);
|
setDefaultBtn(Event::ConsoleSelect, stick, 7);
|
||||||
setDefaultBtn(stick, 8, Event::ConsoleReset);
|
setDefaultBtn(Event::ConsoleReset, stick, 8);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -331,28 +340,27 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMenuMode: // Default menu/UI events
|
case kMenuMode: // Default menu/UI events
|
||||||
setDefaultAxis( stick, JoyAxis::X, JoyDir::NEG, Event::UINavPrev );
|
setDefaultAxis(Event::UINavPrev, stick, JoyAxis::X, JoyDir::NEG);
|
||||||
setDefaultAxis( stick, JoyAxis::X, JoyDir::POS, Event::UINavNext );
|
setDefaultAxis(Event::UINavNext, stick, JoyAxis::X, JoyDir::POS);
|
||||||
setDefaultAxis( stick, JoyAxis::Y, JoyDir::NEG, Event::UIUp );
|
setDefaultAxis(Event::UIUp, stick, JoyAxis::Y, JoyDir::NEG);
|
||||||
setDefaultAxis( stick, JoyAxis::Y, JoyDir::POS, Event::UIDown );
|
setDefaultAxis(Event::UIDown, stick, JoyAxis::Y, JoyDir::POS);
|
||||||
|
|
||||||
// joystick (assume buttons zero..three)
|
// joystick (assume buttons zero..three)
|
||||||
setDefaultBtn( stick, 0, Event::UISelect );
|
setDefaultBtn(Event::UISelect, stick, 0);
|
||||||
setDefaultBtn( stick, 1, Event::UIOK );
|
setDefaultBtn(Event::UIOK, stick, 1);
|
||||||
setDefaultBtn( stick, 2, Event::UITabNext);
|
setDefaultBtn(Event::UITabNext, stick, 2);
|
||||||
setDefaultBtn( stick, 3, Event::UITabPrev );
|
setDefaultBtn(Event::UITabPrev, stick, 3);
|
||||||
setDefaultBtn( stick, 5, Event::UICancel);
|
setDefaultBtn(Event::UICancel, stick, 5);
|
||||||
|
|
||||||
setDefaultHat( stick, 0, JoyHat::LEFT, Event::UINavPrev );
|
setDefaultHat(Event::UINavPrev, stick, 0, JoyHat::LEFT);
|
||||||
setDefaultHat( stick, 0, JoyHat::RIGHT, Event::UINavNext );
|
setDefaultHat(Event::UINavNext, stick, 0, JoyHat::RIGHT);
|
||||||
setDefaultHat( stick, 0, JoyHat::UP, Event::UIUp );
|
setDefaultHat(Event::UIUp, stick, 0, JoyHat::UP);
|
||||||
setDefaultHat( stick, 0, JoyHat::DOWN, Event::UIDown );
|
setDefaultHat(Event::UIDown, stick, 0, JoyHat::DOWN);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -378,13 +386,14 @@ void PhysicalJoystickHandler::saveMapping()
|
||||||
// Save the joystick mapping hash table, making sure to update it with
|
// Save the joystick mapping hash table, making sure to update it with
|
||||||
// any changes that have been made during the program run
|
// any changes that have been made during the program run
|
||||||
ostringstream joybuf;
|
ostringstream joybuf;
|
||||||
joybuf << Event::LastType;
|
//joybuf << Event::LastType;
|
||||||
|
|
||||||
for(const auto& i: myDatabase)
|
for(const auto& i: myDatabase)
|
||||||
{
|
{
|
||||||
const string& map = i.second.joy ? i.second.joy->getMap() : i.second.mapping;
|
const string& map = i.second.joy ? i.second.joy->getMap() : i.second.mapping;
|
||||||
if(map != "")
|
if(map != "")
|
||||||
joybuf << "^" << map;
|
//joybuf << "^" << map;
|
||||||
|
joybuf << map;
|
||||||
}
|
}
|
||||||
myOSystem.settings().setValue("joymap", joybuf.str());
|
myOSystem.settings().setValue("joymap", joybuf.str());
|
||||||
}
|
}
|
||||||
|
@ -400,7 +409,7 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode
|
||||||
const PhysicalJoystickPtr j = s.second;
|
const PhysicalJoystickPtr j = s.second;
|
||||||
if(!j) continue;
|
if(!j) continue;
|
||||||
|
|
||||||
// Joystick button mapping/labeling
|
/*// Joystick button mapping/labeling
|
||||||
for(int button = 0; button < j->numButtons; ++button)
|
for(int button = 0; button < j->numButtons; ++button)
|
||||||
{
|
{
|
||||||
if(j->btnTable[button][mode] == event)
|
if(j->btnTable[button][mode] == event)
|
||||||
|
@ -454,13 +463,21 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
// new:
|
||||||
|
//Joystick button + axis mapping / labeling
|
||||||
|
if (j->joyMap.getEventMapping(event, mode).size())
|
||||||
|
buf << j->joyMap.getEventMappingDesc(stick, event, mode);
|
||||||
|
// Joystick hat mapping/labeling
|
||||||
|
if (j->joyHatMap.getEventMapping(event, mode).size())
|
||||||
|
buf << j->joyHatMap.getEventMappingDesc(stick, event, mode);
|
||||||
}
|
}
|
||||||
return buf.str();
|
return buf.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool PhysicalJoystickHandler::addAxisMapping(Event::Type event, EventMode mode,
|
/*bool PhysicalJoystickHandler::addAxisMapping(Event::Type event, EventMode mode,
|
||||||
int stick, int axis, int value)
|
int stick, int axis, int value)
|
||||||
{
|
{
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
|
@ -519,24 +536,55 @@ bool PhysicalJoystickHandler::addHatMapping(Event::Type event, EventMode mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, int stick,
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
int button, JoyAxis axis, JoyDir adir)
|
bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, int stick,
|
||||||
|
int button, JoyAxis axis, int value)
|
||||||
{
|
{
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
|
|
||||||
j->joyMap.add(event, mode, button, axis, adir);
|
if (j && event < Event::LastType &&
|
||||||
|
button >= JOY_CTRL_NONE && button < j->numButtons &&
|
||||||
|
axis >= JoyAxis::NONE && int(axis) < j->numAxes)
|
||||||
|
{
|
||||||
|
// This confusing code is because each axis has two associated values,
|
||||||
|
// but analog events only affect one of the axis.
|
||||||
|
if (Event::isAnalog(event))
|
||||||
|
{
|
||||||
|
j->joyMap.add(event, mode, button, axis, JoyDir::NEG);
|
||||||
|
j->joyMap.add(event, mode, button, axis, JoyDir::POS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Otherwise, turn off the analog event(s) for this axis
|
||||||
|
if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::NEG)))
|
||||||
|
j->joyMap.erase(mode, button, axis, JoyDir::NEG);
|
||||||
|
if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::POS)))
|
||||||
|
j->joyMap.erase(mode, button, axis, JoyDir::POS);
|
||||||
|
|
||||||
|
j->joyMap.add(event, mode, button, axis, value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
bool PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
||||||
int hat, JoyHat hdir)
|
int button, int hat, JoyHat dir)
|
||||||
{
|
{
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
|
|
||||||
j->joyHatMap.add(event, mode, hat, hdir);
|
if (j && event < Event::LastType &&
|
||||||
|
button >= JOY_CTRL_NONE && button < j->numButtons &&
|
||||||
|
hat >= 0 && hat < j->numHats && dir != JoyHat::CENTER)
|
||||||
|
{
|
||||||
|
j->joyHatMap.add(event, mode, button, hat, dir);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -552,8 +600,10 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
|
||||||
if(myHandler.state() == EventHandlerState::EMULATION)
|
if(myHandler.state() == EventHandlerState::EMULATION)
|
||||||
{
|
{
|
||||||
// Every axis event has two associated values, negative and positive
|
// Every axis event has two associated values, negative and positive
|
||||||
Event::Type eventAxisNeg = j->axisTable[axis][int(JoyDir::NEG)][kEmulationMode];
|
//Event::Type eventAxisNeg = j->axisTable[axis][int(JoyDir::NEG)][kEmulationMode];
|
||||||
Event::Type eventAxisPos = j->axisTable[axis][int(JoyDir::POS)][kEmulationMode];
|
//Event::Type eventAxisPos = j->axisTable[axis][int(JoyDir::POS)][kEmulationMode];
|
||||||
|
Event::Type eventAxisNeg = j->joyMap.get(kEmulationMode, j->buttonLast[stick], JoyAxis(axis), JoyDir::NEG);
|
||||||
|
Event::Type eventAxisPos = j->joyMap.get(kEmulationMode, j->buttonLast[stick], JoyAxis(axis), JoyDir::POS);
|
||||||
|
|
||||||
// Check for analog events, which are handled differently
|
// Check for analog events, which are handled differently
|
||||||
// We'll pass them off as Stelladaptor events, and let the controllers
|
// We'll pass them off as Stelladaptor events, and let the controllers
|
||||||
|
@ -647,18 +697,21 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed
|
||||||
{
|
{
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
if(!j) return;
|
if(!j) return;
|
||||||
|
j->buttonLast[stick] = pressed ? button : JOY_CTRL_NONE;
|
||||||
|
|
||||||
// Stelladaptors handle buttons differently than regular joysticks
|
// Stelladaptors handle buttons differently than regular joysticks
|
||||||
switch(j->type)
|
switch(j->type)
|
||||||
{
|
{
|
||||||
case PhysicalJoystick::JT_REGULAR:
|
case PhysicalJoystick::JT_REGULAR:
|
||||||
// Handle buttons which switch eventhandler state
|
// Handle buttons which switch eventhandler state
|
||||||
if(pressed && myHandler.changeStateByEvent(j->btnTable[button][kEmulationMode]))
|
//if(pressed && myHandler.changeStateByEvent(j->btnTable[button][kEmulationMode]))
|
||||||
|
if (pressed && myHandler.changeStateByEvent(j->joyMap.get(kEmulationMode, button)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Determine which mode we're in, then send the event to the appropriate place
|
// Determine which mode we're in, then send the event to the appropriate place
|
||||||
if(myHandler.state() == EventHandlerState::EMULATION)
|
if(myHandler.state() == EventHandlerState::EMULATION)
|
||||||
myHandler.handleEvent(j->btnTable[button][kEmulationMode], pressed);
|
//myHandler.handleEvent(j->btnTable[button][kEmulationMode], pressed);
|
||||||
|
myHandler.handleEvent(j->joyMap.get(kEmulationMode, button), pressed);
|
||||||
#ifdef GUI_SUPPORT
|
#ifdef GUI_SUPPORT
|
||||||
else if(myHandler.hasOverlay())
|
else if(myHandler.hasOverlay())
|
||||||
myHandler.overlay().handleJoyBtnEvent(stick, button, pressed);
|
myHandler.overlay().handleJoyBtnEvent(stick, button, pressed);
|
||||||
|
@ -718,14 +771,17 @@ void PhysicalJoystickHandler::handleHatEvent(int stick, int hat, int value)
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
if(!j) return;
|
if(!j) return;
|
||||||
|
|
||||||
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::UP)][kEmulationMode],
|
/*myHandler.handleEvent(j->hatTable[hat][int(JoyHat::UP)][kEmulationMode],
|
||||||
value & EVENT_HATUP_M);
|
value & EVENT_HATUP_M);
|
||||||
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::RIGHT)][kEmulationMode],
|
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::RIGHT)][kEmulationMode],
|
||||||
value & EVENT_HATRIGHT_M);
|
value & EVENT_HATRIGHT_M);
|
||||||
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::DOWN)][kEmulationMode],
|
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::DOWN)][kEmulationMode],
|
||||||
value & EVENT_HATDOWN_M);
|
value & EVENT_HATDOWN_M);
|
||||||
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::LEFT)][kEmulationMode],
|
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::LEFT)][kEmulationMode],
|
||||||
value & EVENT_HATLEFT_M);
|
value & EVENT_HATLEFT_M);*/
|
||||||
|
|
||||||
|
// TODO: 4 different events
|
||||||
|
myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, JOY_CTRL_NONE, hat, JoyHat(value)));
|
||||||
}
|
}
|
||||||
#ifdef GUI_SUPPORT
|
#ifdef GUI_SUPPORT
|
||||||
else if(myHandler.hasOverlay())
|
else if(myHandler.hasOverlay())
|
||||||
|
|
|
@ -74,15 +74,15 @@ class PhysicalJoystickHandler
|
||||||
string getMappingDesc(Event::Type, EventMode mode) const;
|
string getMappingDesc(Event::Type, EventMode mode) const;
|
||||||
|
|
||||||
/** Bind a physical joystick event to a virtual event/action. */
|
/** Bind a physical joystick event to a virtual event/action. */
|
||||||
bool addAxisMapping(Event::Type event, EventMode mode, int stick, int axis, int value);
|
/*bool addAxisMapping(Event::Type event, EventMode mode, int stick, int axis, int value);
|
||||||
bool addBtnMapping(Event::Type event, EventMode mode, int stick, int button);
|
bool addBtnMapping(Event::Type event, EventMode mode, int stick, int button);
|
||||||
bool addHatMapping(Event::Type event, EventMode mode, int stick, int hat, JoyHat value);
|
bool addHatMapping(Event::Type event, EventMode mode, int stick, int hat, JoyHat value);*/
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void addJoyMapping(Event::Type event, EventMode mode, int stick,
|
bool addJoyMapping(Event::Type event, EventMode mode, int stick,
|
||||||
int button, JoyAxis axis, JoyDir adir);
|
int button, JoyAxis axis, int value);
|
||||||
void addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
bool addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
||||||
int hat, JoyHat hdir);
|
int button, int hat, JoyHat 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);
|
||||||
|
@ -91,16 +91,19 @@ class PhysicalJoystickHandler
|
||||||
|
|
||||||
Event::Type eventForAxis(int stick, int axis, int joyDir, EventMode mode) const {
|
Event::Type eventForAxis(int stick, int axis, int joyDir, EventMode mode) const {
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
return (j && joyDir != int(JoyDir::NEG))
|
//return (j && joyDir != int(JoyDir::NEG))
|
||||||
? j->axisTable[axis][(joyDir > int(JoyDir::NEG))][mode] : Event::NoType;
|
// ? j->axisTable[axis][(joyDir > int(JoyDir::NEG))][mode] : Event::NoType;
|
||||||
|
return j->joyMap.get(mode, JOY_CTRL_NONE, JoyAxis(axis), JoyDir(joyDir));
|
||||||
}
|
}
|
||||||
Event::Type eventForButton(int stick, int button, EventMode mode) const {
|
Event::Type eventForButton(int stick, int button, EventMode mode) const {
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
return j ? j->btnTable[button][mode] : Event::NoType;
|
// return j ? j->btnTable[button][mode] : Event::NoType;
|
||||||
|
return j->joyMap.get(mode, button);
|
||||||
}
|
}
|
||||||
Event::Type eventForHat(int stick, int hat, JoyHat hatDir, EventMode mode) const {
|
Event::Type eventForHat(int stick, int hat, JoyHat hatDir, EventMode mode) const {
|
||||||
const PhysicalJoystickPtr j = joy(stick);
|
const PhysicalJoystickPtr j = joy(stick);
|
||||||
return j ? j->hatTable[hat][int(hatDir)][mode] : Event::NoType;
|
//return j ? j->hatTable[hat][int(hatDir)][mode] : Event::NoType;
|
||||||
|
return j->joyHatMap.get(mode, JOY_CTRL_NONE, hat, hatDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a list of pairs consisting of joystick name and associated ID. */
|
/** Returns a list of pairs consisting of joystick name and associated ID. */
|
||||||
|
|
|
@ -31,20 +31,22 @@ PhysicalJoystick::PhysicalJoystick()
|
||||||
numAxes(0),
|
numAxes(0),
|
||||||
numButtons(0),
|
numButtons(0),
|
||||||
numHats(0),
|
numHats(0),
|
||||||
axisTable(nullptr),
|
/*axisTable(nullptr),
|
||||||
btnTable(nullptr),
|
btnTable(nullptr),
|
||||||
hatTable(nullptr),
|
hatTable(nullptr),*/
|
||||||
axisLastValue(nullptr)
|
axisLastValue(nullptr),
|
||||||
|
buttonLast(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
PhysicalJoystick::~PhysicalJoystick()
|
PhysicalJoystick::~PhysicalJoystick()
|
||||||
{
|
{
|
||||||
delete[] axisTable;
|
/*delete[] axisTable;
|
||||||
delete[] btnTable;
|
delete[] btnTable;
|
||||||
delete[] hatTable;
|
delete[] hatTable;*/
|
||||||
delete[] axisLastValue;
|
delete[] axisLastValue;
|
||||||
|
delete[] buttonLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -59,24 +61,28 @@ void PhysicalJoystick::initialize(int index, const string& desc,
|
||||||
numAxes = axes;
|
numAxes = axes;
|
||||||
numButtons = buttons;
|
numButtons = buttons;
|
||||||
numHats = hats;
|
numHats = hats;
|
||||||
if(numAxes)
|
/*if(numAxes)
|
||||||
axisTable = new Event::Type[numAxes][NUM_JOY_DIRS][kNumModes];
|
axisTable = new Event::Type[numAxes][NUM_JOY_DIRS][kNumModes];
|
||||||
if(numButtons)
|
if(numButtons)
|
||||||
btnTable = new Event::Type[numButtons][kNumModes];
|
btnTable = new Event::Type[numButtons][kNumModes];
|
||||||
if(numHats)
|
if(numHats)
|
||||||
hatTable = new Event::Type[numHats][NUM_JOY_HAT_DIRS][kNumModes];
|
hatTable = new Event::Type[numHats][NUM_JOY_HAT_DIRS][kNumModes];*/
|
||||||
axisLastValue = new int[numAxes];
|
axisLastValue = new int[numAxes];
|
||||||
|
buttonLast = new int[numButtons];
|
||||||
|
|
||||||
|
for (int b = 0; b < numButtons; ++b)
|
||||||
|
buttonLast[b] = JOY_CTRL_NONE;
|
||||||
|
|
||||||
// Erase the joystick axis mapping array and last axis value
|
// Erase the joystick axis mapping array and last axis value
|
||||||
for(int a = 0; a < numAxes; ++a)
|
for(int a = 0; a < numAxes; ++a)
|
||||||
{
|
{
|
||||||
axisLastValue[a] = 0;
|
axisLastValue[a] = 0;
|
||||||
for(int m = 0; m < kNumModes; ++m)
|
/*for(int m = 0; m < kNumModes; ++m)
|
||||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||||
axisTable[a][d][m] = Event::NoType;
|
axisTable[a][d][m] = Event::NoType;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erase the joystick button mapping array
|
/*// Erase the joystick button mapping array
|
||||||
for(int b = 0; b < numButtons; ++b)
|
for(int b = 0; b < numButtons; ++b)
|
||||||
for(int m = 0; m < kNumModes; ++m)
|
for(int m = 0; m < kNumModes; ++m)
|
||||||
btnTable[b][m] = Event::NoType;
|
btnTable[b][m] = Event::NoType;
|
||||||
|
@ -85,7 +91,10 @@ void PhysicalJoystick::initialize(int index, const string& desc,
|
||||||
for(int h = 0; h < numHats; ++h)
|
for(int h = 0; h < numHats; ++h)
|
||||||
for(int m = 0; m < kNumModes; ++m)
|
for(int m = 0; m < kNumModes; ++m)
|
||||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||||
hatTable[h][d][m] = Event::NoType;
|
hatTable[h][d][m] = Event::NoType;*/
|
||||||
|
|
||||||
|
for (int m = 0; m < kNumModes; ++m)
|
||||||
|
eraseMap(EventMode(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -97,7 +106,7 @@ string PhysicalJoystick::getMap() const
|
||||||
if(type == JT_REGULAR)
|
if(type == JT_REGULAR)
|
||||||
{
|
{
|
||||||
ostringstream joybuf;
|
ostringstream joybuf;
|
||||||
joybuf << name << "|" << numAxes;
|
/*joybuf << name << "|" << numAxes;
|
||||||
for(int m = 0; m < kNumModes; ++m)
|
for(int m = 0; m < kNumModes; ++m)
|
||||||
for(int a = 0; a < numAxes; ++a)
|
for(int a = 0; a < numAxes; ++a)
|
||||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||||
|
@ -110,7 +119,12 @@ string PhysicalJoystick::getMap() const
|
||||||
for(int m = 0; m < kNumModes; ++m)
|
for(int m = 0; m < kNumModes; ++m)
|
||||||
for(int h = 0; h < numHats; ++h)
|
for(int h = 0; h < numHats; ++h)
|
||||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||||
joybuf << " " << hatTable[h][d][m];
|
joybuf << " " << hatTable[h][d][m];*/
|
||||||
|
|
||||||
|
// new:
|
||||||
|
joybuf << name;
|
||||||
|
for (int m = 0; m < kNumModes; ++m)
|
||||||
|
joybuf << "|" << m << "|" << joyMap.saveMapping(EventMode(m));
|
||||||
|
|
||||||
return joybuf.str();
|
return joybuf.str();
|
||||||
}
|
}
|
||||||
|
@ -133,7 +147,7 @@ bool PhysicalJoystick::setMap(const string& mapString)
|
||||||
IntArray map;
|
IntArray map;
|
||||||
|
|
||||||
// Parse axis/button/hat values
|
// Parse axis/button/hat values
|
||||||
getValues(items[1], map);
|
/*getValues(items[1], map);
|
||||||
if(int(map.size()) == numAxes * NUM_JOY_DIRS * kNumModes)
|
if(int(map.size()) == numAxes * NUM_JOY_DIRS * kNumModes)
|
||||||
{
|
{
|
||||||
// Fill the axes table with events
|
// Fill the axes table with events
|
||||||
|
@ -161,7 +175,7 @@ bool PhysicalJoystick::setMap(const string& mapString)
|
||||||
for(int h = 0; h < numHats; ++h)
|
for(int h = 0; h < numHats; ++h)
|
||||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||||
hatTable[h][d][m] = Event::Type(*event++);
|
hatTable[h][d][m] = Event::Type(*event++);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +183,7 @@ bool PhysicalJoystick::setMap(const string& mapString)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PhysicalJoystick::eraseMap(EventMode mode)
|
void PhysicalJoystick::eraseMap(EventMode mode)
|
||||||
{
|
{
|
||||||
// Erase axis mappings
|
/*// Erase axis mappings
|
||||||
for(int a = 0; a < numAxes; ++a)
|
for(int a = 0; a < numAxes; ++a)
|
||||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||||
axisTable[a][d][mode] = Event::NoType;
|
axisTable[a][d][mode] = Event::NoType;
|
||||||
|
@ -181,13 +195,18 @@ void PhysicalJoystick::eraseMap(EventMode mode)
|
||||||
// Erase hat mappings
|
// Erase hat mappings
|
||||||
for(int h = 0; h < numHats; ++h)
|
for(int h = 0; h < numHats; ++h)
|
||||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||||
hatTable[h][d][mode] = Event::NoType;
|
hatTable[h][d][mode] = Event::NoType;*/
|
||||||
|
|
||||||
|
// Erase button and axis mappings
|
||||||
|
joyMap.eraseMode(mode);
|
||||||
|
// Erase button and axis mappings
|
||||||
|
joyHatMap.eraseMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PhysicalJoystick::eraseEvent(Event::Type event, EventMode mode)
|
void PhysicalJoystick::eraseEvent(Event::Type event, EventMode mode)
|
||||||
{
|
{
|
||||||
// Erase axis mappings
|
/*// Erase axis mappings
|
||||||
for(int a = 0; a < numAxes; ++a)
|
for(int a = 0; a < numAxes; ++a)
|
||||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||||
if(axisTable[a][d][mode] == event)
|
if(axisTable[a][d][mode] == event)
|
||||||
|
@ -202,7 +221,12 @@ void PhysicalJoystick::eraseEvent(Event::Type event, EventMode mode)
|
||||||
for(int h = 0; h < numHats; ++h)
|
for(int h = 0; h < numHats; ++h)
|
||||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||||
if(hatTable[h][d][mode] == event)
|
if(hatTable[h][d][mode] == event)
|
||||||
hatTable[h][d][mode] = Event::NoType;
|
hatTable[h][d][mode] = Event::NoType;*/
|
||||||
|
|
||||||
|
// Erase button and axis mappings
|
||||||
|
joyMap.eraseEvent(event, mode);
|
||||||
|
// Erase hat mappings
|
||||||
|
joyHatMap.eraseEvent(event, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -67,10 +67,12 @@ class PhysicalJoystick
|
||||||
int ID;
|
int ID;
|
||||||
string name;
|
string name;
|
||||||
int numAxes, numButtons, numHats;
|
int numAxes, numButtons, numHats;
|
||||||
Event::Type (*axisTable)[NUM_JOY_DIRS][kNumModes];
|
/*Event::Type (*axisTable)[NUM_JOY_DIRS][kNumModes];
|
||||||
Event::Type (*btnTable)[kNumModes];
|
Event::Type (*btnTable)[kNumModes];
|
||||||
Event::Type (*hatTable)[NUM_JOY_HAT_DIRS][kNumModes];
|
Event::Type (*hatTable)[NUM_JOY_HAT_DIRS][kNumModes];*/
|
||||||
int* axisLastValue;
|
int* axisLastValue;
|
||||||
|
int* buttonLast;
|
||||||
|
|
||||||
|
|
||||||
// Hashmaps of controller events
|
// Hashmaps of controller events
|
||||||
JoyMap joyMap;
|
JoyMap joyMap;
|
||||||
|
|
|
@ -1124,7 +1124,7 @@ bool EventHandler::addKeyMapping(Event::Type event, EventMode mode, StellaKey ke
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool EventHandler::addJoyAxisMapping(Event::Type event, EventMode mode,
|
/*bool EventHandler::addJoyAxisMapping(Event::Type event, EventMode mode,
|
||||||
int stick, int axis, int value,
|
int stick, int axis, int value,
|
||||||
bool updateMenus)
|
bool updateMenus)
|
||||||
{
|
{
|
||||||
|
@ -1169,8 +1169,41 @@ bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode,
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool EventHandler::addJoyMapping(Event::Type event, EventMode mode,
|
||||||
|
int stick, int button, JoyAxis axis, int value,
|
||||||
|
bool updateMenus)
|
||||||
|
{
|
||||||
|
#ifdef JOYSTICK_SUPPORT
|
||||||
|
bool mapped = myPJoyHandler->addJoyMapping(event, mode, stick, button, axis, value);
|
||||||
|
if (mapped && updateMenus)
|
||||||
|
setActionMappings(mode);
|
||||||
|
|
||||||
|
return mapped;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode,
|
||||||
|
int stick, int button, int hat, JoyHat dir,
|
||||||
|
bool updateMenus)
|
||||||
|
{
|
||||||
|
#ifdef JOYSTICK_SUPPORT
|
||||||
|
bool mapped = myPJoyHandler->addJoyHatMapping(event, mode, stick, button, hat, dir);
|
||||||
|
if (mapped && updateMenus)
|
||||||
|
setActionMappings(mode);
|
||||||
|
|
||||||
|
return mapped;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EventHandler::eraseMapping(Event::Type event, EventMode mode)
|
void EventHandler::eraseMapping(Event::Type event, EventMode mode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -219,7 +219,7 @@ class EventHandler
|
||||||
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 addJoyAxisMapping(Event::Type event, EventMode mode,
|
/*bool addJoyAxisMapping(Event::Type event, EventMode mode,
|
||||||
int stick, int axis, int value,
|
int stick, int axis, int value,
|
||||||
bool updateMenus = true);
|
bool updateMenus = true);
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ class EventHandler
|
||||||
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 addJoyButtonMapping(Event::Type event, EventMode mode, int stick, int button,
|
/*bool addJoyButtonMapping(Event::Type event, EventMode mode, int stick, int button,
|
||||||
bool updateMenus = true);
|
bool updateMenus = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -251,9 +251,17 @@ class EventHandler
|
||||||
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 addJoyHatMapping(Event::Type event, EventMode mode,
|
/*bool addJoyHatMapping(Event::Type event, EventMode mode,
|
||||||
int stick, int hat, JoyHat value,
|
int stick, int hat, JoyHat value,
|
||||||
|
bool updateMenus = true);*/
|
||||||
|
|
||||||
|
bool addJoyMapping(Event::Type event, EventMode mode,
|
||||||
|
int stick, int button, JoyAxis axis = JoyAxis::NONE, int value = 0,
|
||||||
bool updateMenus = true);
|
bool updateMenus = true);
|
||||||
|
bool addJoyHatMapping(Event::Type event, EventMode mode,
|
||||||
|
int stick, int button, int hat, JoyHat dir,
|
||||||
|
bool updateMenus = true);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Erase the specified mapping.
|
Erase the specified mapping.
|
||||||
|
|
|
@ -38,16 +38,19 @@ enum class MouseButton {
|
||||||
NONE
|
NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr int CTRL_NONE = -1;
|
static constexpr int JOY_CTRL_NONE = -1;
|
||||||
|
|
||||||
enum class JoyAxis {
|
enum class JoyAxis {
|
||||||
X = 0,
|
X = 0,
|
||||||
Y = 1,
|
Y = 1,
|
||||||
|
Z = 2,
|
||||||
|
NONE = JOY_CTRL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class JoyDir {
|
enum class JoyDir {
|
||||||
NEG = 0,
|
NEG = 0,
|
||||||
POS = 1,
|
POS = 1,
|
||||||
|
NONE = JOY_CTRL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
myLastAxis(0),
|
myLastAxis(0),
|
||||||
myLastHat(0),
|
myLastHat(0),
|
||||||
myLastValue(0),
|
myLastValue(0),
|
||||||
|
myLastButton(JOY_CTRL_NONE),
|
||||||
myFirstTime(true)
|
myFirstTime(true)
|
||||||
{
|
{
|
||||||
const int fontHeight = font.getFontHeight(),
|
const int fontHeight = font.getFontHeight(),
|
||||||
|
@ -159,9 +160,10 @@ void EventMappingWidget::startRemapping()
|
||||||
|
|
||||||
// Reset all previous events for determining correct axis/hat values
|
// Reset all previous events for determining correct axis/hat values
|
||||||
myLastStick = myLastAxis = myLastHat = myLastValue = -1;
|
myLastStick = myLastAxis = myLastHat = myLastValue = -1;
|
||||||
|
myLastButton = JOY_CTRL_NONE;
|
||||||
|
|
||||||
// Reset the previously aggregated key mappings
|
// Reset the previously aggregated key mappings
|
||||||
myMod = myKey = 0;
|
myMod = myLastKey = 0;
|
||||||
|
|
||||||
// Disable all other widgets while in remap mode, except enable 'Cancel'
|
// Disable all other widgets while in remap mode, except enable 'Cancel'
|
||||||
enableButtons(false);
|
enableButtons(false);
|
||||||
|
@ -213,6 +215,7 @@ void EventMappingWidget::stopRemapping()
|
||||||
|
|
||||||
// Reset all previous events for determining correct axis/hat values
|
// Reset all previous events for determining correct axis/hat values
|
||||||
myLastStick = myLastAxis = myLastHat = myLastValue = -1;
|
myLastStick = myLastAxis = myLastHat = myLastValue = -1;
|
||||||
|
myLastButton = JOY_CTRL_NONE;
|
||||||
|
|
||||||
// And re-enable all the widgets
|
// And re-enable all the widgets
|
||||||
enableButtons(true);
|
enableButtons(true);
|
||||||
|
@ -257,7 +260,7 @@ bool EventMappingWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
||||||
// Remap keys in remap mode
|
// Remap keys in remap mode
|
||||||
if (myRemapStatus && myActionSelected >= 0)
|
if (myRemapStatus && myActionSelected >= 0)
|
||||||
{
|
{
|
||||||
myKey = key;
|
myLastKey = key;
|
||||||
myMod |= mod;
|
myMod |= mod;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -272,7 +275,7 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod)
|
||||||
{
|
{
|
||||||
Event::Type event =
|
Event::Type event =
|
||||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
||||||
if (instance().eventHandler().addKeyMapping(event, myEventMode, StellaKey(myKey), StellaMod(myMod)))
|
if (instance().eventHandler().addKeyMapping(event, myEventMode, StellaKey(myLastKey), StellaMod(myMod)))
|
||||||
stopRemapping();
|
stopRemapping();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -281,19 +284,42 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EventMappingWidget::handleJoyDown(int stick, int button)
|
void EventMappingWidget::handleJoyDown(int stick, int button)
|
||||||
{
|
{
|
||||||
|
cerr << "handleJoyDown" << endl;
|
||||||
// Remap joystick buttons in remap mode
|
// Remap joystick buttons in remap mode
|
||||||
if(myRemapStatus && myActionSelected >= 0)
|
if(myRemapStatus && myActionSelected >= 0)
|
||||||
{
|
{
|
||||||
Event::Type event =
|
myLastStick = stick;
|
||||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
myLastButton = button;
|
||||||
if(instance().eventHandler().addJoyButtonMapping(event, myEventMode, stick, button))
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void EventMappingWidget::handleJoyUp(int stick, int button)
|
||||||
|
{
|
||||||
|
cerr << "handleJoyUp" << endl;
|
||||||
|
// Remap joystick buttons in remap mode
|
||||||
|
if (myRemapStatus && myActionSelected >= 0)
|
||||||
|
{
|
||||||
|
if (myLastStick == stick && myLastButton == button)
|
||||||
|
{
|
||||||
|
EventHandler& eh = instance().eventHandler();
|
||||||
|
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
|
||||||
|
|
||||||
|
cerr << "remap" << endl;
|
||||||
|
// This maps solo button presses only
|
||||||
|
if (eh.addJoyMapping(event, myEventMode, stick, button)) // new
|
||||||
stopRemapping();
|
stopRemapping();
|
||||||
|
|
||||||
|
//if (eh.addJoyButtonMapping(event, myEventMode, stick, button))
|
||||||
|
// stopRemapping();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
|
void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
|
||||||
{
|
{
|
||||||
|
cerr << "handleJoyAxis:" << axis << ", " << value << ", (" << stick << ", " << myLastStick << "), (" << axis << ", " << myLastAxis << ")" << endl;
|
||||||
// Remap joystick axes in remap mode
|
// Remap joystick axes in remap mode
|
||||||
// There are two phases to detection:
|
// There are two phases to detection:
|
||||||
// First, detect an axis 'on' event
|
// First, detect an axis 'on' event
|
||||||
|
@ -301,8 +327,9 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
|
||||||
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 && myLastAxis == -1 && value != 0)
|
if((myLastStick == -1 || myLastStick == stick) && myLastAxis == -1 && value != 0)
|
||||||
{
|
{
|
||||||
|
cerr << "remap start" << endl;
|
||||||
myLastStick = stick;
|
myLastStick = stick;
|
||||||
myLastAxis = axis;
|
myLastAxis = axis;
|
||||||
myLastValue = value;
|
myLastValue = value;
|
||||||
|
@ -311,13 +338,15 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
|
||||||
// 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 && value == 0)
|
||||||
{
|
{
|
||||||
value = myLastValue;
|
EventHandler& eh = instance().eventHandler();
|
||||||
|
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
|
||||||
|
|
||||||
Event::Type event =
|
cerr << "remap stop" << endl;
|
||||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue))
|
||||||
if(instance().eventHandler().addJoyAxisMapping(event, myEventMode,
|
stopRemapping(); // new
|
||||||
stick, axis, value))
|
|
||||||
stopRemapping();
|
//if(eh.addJoyAxisMapping(event, myEventMode, stick, axis, myLastValue))
|
||||||
|
// stopRemapping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,7 +361,7 @@ bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHat value)
|
||||||
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 && myLastHat == -1 && value != JoyHat::CENTER)
|
if((myLastStick == -1 || myLastStick == stick) && myLastHat == -1 && value != JoyHat::CENTER)
|
||||||
{
|
{
|
||||||
myLastStick = stick;
|
myLastStick = stick;
|
||||||
myLastHat = hat;
|
myLastHat = hat;
|
||||||
|
@ -344,16 +373,19 @@ bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHat value)
|
||||||
// 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 && value == JoyHat::CENTER)
|
||||||
{
|
{
|
||||||
value = JoyHat(myLastValue);
|
EventHandler& eh = instance().eventHandler();
|
||||||
|
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
|
||||||
|
|
||||||
Event::Type event =
|
if (eh.addJoyHatMapping(event, myEventMode, stick, myLastButton, hat, JoyHat(myLastValue)))
|
||||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
|
||||||
if(instance().eventHandler().addJoyHatMapping(event, myEventMode,
|
|
||||||
stick, hat, value))
|
|
||||||
{
|
{
|
||||||
stopRemapping();
|
stopRemapping();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
/*if(eh.addJoyHatMapping(event, myEventMode, stick, hat, myLastValue))
|
||||||
|
{
|
||||||
|
stopRemapping();
|
||||||
|
return true;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ class EventMappingWidget : public Widget, public CommandSender
|
||||||
bool handleKeyDown(StellaKey key, StellaMod mod) override;
|
bool handleKeyDown(StellaKey key, StellaMod mod) override;
|
||||||
bool handleKeyUp(StellaKey key, StellaMod mod) override;
|
bool handleKeyUp(StellaKey key, StellaMod mod) override;
|
||||||
void handleJoyDown(int stick, int button) override;
|
void handleJoyDown(int stick, int button) override;
|
||||||
|
void handleJoyUp(int stick, int button) override;
|
||||||
void handleJoyAxis(int stick, int axis, int value) override;
|
void handleJoyAxis(int stick, int axis, int value) override;
|
||||||
bool handleJoyHat(int stick, int hat, JoyHat value) override;
|
bool handleJoyHat(int stick, int hat, JoyHat value) override;
|
||||||
|
|
||||||
|
@ -108,7 +109,9 @@ class EventMappingWidget : public Widget, public CommandSender
|
||||||
// Aggregates the modifier flags of the mapping
|
// Aggregates the modifier flags of the mapping
|
||||||
int myMod;
|
int myMod;
|
||||||
// Saves the last *pressed* key
|
// Saves the last *pressed* key
|
||||||
int myKey;
|
int myLastKey;
|
||||||
|
// Saves the last *pressed* button
|
||||||
|
int myLastButton;
|
||||||
|
|
||||||
bool myFirstTime;
|
bool myFirstTime;
|
||||||
|
|
||||||
|
|
|
@ -480,6 +480,18 @@ void InputDialog::handleJoyDown(int stick, int button)
|
||||||
Dialog::handleJoyDown(stick, button);
|
Dialog::handleJoyDown(stick, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void InputDialog::handleJoyUp(int stick, int button)
|
||||||
|
{
|
||||||
|
// Remap joystick buttons in remap mode, otherwise pass to parent dialog
|
||||||
|
if (myEmulEventMapper->remapMode())
|
||||||
|
myEmulEventMapper->handleJoyUp(stick, button);
|
||||||
|
else if (myMenuEventMapper->remapMode())
|
||||||
|
myMenuEventMapper->handleJoyUp(stick, button);
|
||||||
|
else
|
||||||
|
Dialog::handleJoyUp(stick, button);
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void InputDialog::handleJoyAxis(int stick, int axis, int value)
|
void InputDialog::handleJoyAxis(int stick, int axis, int value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,7 @@ class InputDialog : public Dialog
|
||||||
void handleKeyDown(StellaKey key, StellaMod mod) override;
|
void handleKeyDown(StellaKey key, StellaMod mod) override;
|
||||||
void handleKeyUp(StellaKey key, StellaMod mod) override;
|
void handleKeyUp(StellaKey key, StellaMod mod) override;
|
||||||
void handleJoyDown(int stick, int button) override;
|
void handleJoyDown(int stick, int button) override;
|
||||||
|
void handleJoyUp(int stick, int button) override;
|
||||||
void handleJoyAxis(int stick, int axis, int value) override;
|
void handleJoyAxis(int stick, int axis, int value) override;
|
||||||
bool handleJoyHat(int stick, int hat, JoyHat value) override;
|
bool handleJoyHat(int stick, int hat, JoyHat value) override;
|
||||||
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
|
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
|
||||||
|
|
Loading…
Reference in New Issue