fix button modifier mappings

Stelladaptor specific code removeDialog
code cleanup
This commit is contained in:
thrust26 2019-06-22 16:54:21 +02:00
parent fbf05505d3
commit b2f285d723
14 changed files with 344 additions and 301 deletions

View File

@ -55,6 +55,15 @@ Event::Type JoyHatMap::get(const JoyHatMapping& mapping) const
if (find != myMap.end()) if (find != myMap.end())
return find->second; return find->second;
// try without button as modifier
JoyHatMapping m = mapping;
m.button = JOY_CTRL_NONE;
find = myMap.find(m);
if (find != myMap.end())
return find->second;
return Event::Type::NoType; return Event::Type::NoType;
} }

View File

@ -55,6 +55,15 @@ Event::Type JoyMap::get(const JoyMapping& mapping) const
if (find != myMap.end()) if (find != myMap.end())
return find->second; return find->second;
// try without button as modifier
JoyMapping m = mapping;
m.button = JOY_CTRL_NONE;
find = myMap.find(m);
if (find != myMap.end())
return find->second;
return Event::Type::NoType; return Event::Type::NoType;
} }

View File

@ -126,7 +126,7 @@ int PhysicalJoystickHandler::add(PhysicalJoystickPtr stick)
setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode); setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode);
} }
// We're potentially swapping out an input device behind the back of /*// We're potentially swapping out an input device behind the back of
// the Event system, so we make sure all Stelladaptor-generated events // the Event system, so we make sure all Stelladaptor-generated events
// are reset // are reset
for(int i = 0; i < NUM_PORTS; ++i) for(int i = 0; i < NUM_PORTS; ++i)
@ -137,7 +137,7 @@ int PhysicalJoystickHandler::add(PhysicalJoystickPtr stick)
myEvent.set(SA_Button[i][j], 0); myEvent.set(SA_Button[i][j], 0);
for(int j = 0; j < NUM_KEY_BTN; ++j) for(int j = 0; j < NUM_KEY_BTN; ++j)
myEvent.set(SA_Key[i][j], 0); myEvent.set(SA_Key[i][j], 0);
} }*/
return stick->ID; return stick->ID;
} }
@ -340,7 +340,10 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
case kMenuMode: // Default menu/UI events case kMenuMode: // Default menu/UI events
setDefaultAxis(Event::UINavPrev, stick, JoyAxis::X, JoyDir::NEG); setDefaultAxis(Event::UINavPrev, stick, JoyAxis::X, JoyDir::NEG);
setDefaultAxis(Event::UITabPrev, stick, JoyAxis::X, JoyDir::NEG, 0);
setDefaultAxis(Event::UINavNext, stick, JoyAxis::X, JoyDir::POS); setDefaultAxis(Event::UINavNext, stick, JoyAxis::X, JoyDir::POS);
setDefaultAxis(Event::UITabNext, stick, JoyAxis::X, JoyDir::POS, 0);
setDefaultAxis(Event::UIUp, stick, JoyAxis::Y, JoyDir::NEG); setDefaultAxis(Event::UIUp, stick, JoyAxis::Y, JoyDir::NEG);
setDefaultAxis(Event::UIDown, stick, JoyAxis::Y, JoyDir::POS); setDefaultAxis(Event::UIDown, stick, JoyAxis::Y, JoyDir::POS);
@ -362,6 +365,179 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::defineControllerMappings(const string& controllerName, Controller::Jack port)
{
// determine controller events to use
if ((controllerName == "KEYBOARD") || (controllerName == "KEYPAD"))
{
if (port == Controller::Jack::Left)
myLeftMode = kKeypadMode;
else
myRightMode = kKeypadMode;
}
else if (BSPF::startsWithIgnoreCase(controllerName, "PADDLES"))
{
if (port == Controller::Jack::Left)
myLeftMode = kPaddlesMode;
else
myRightMode = kPaddlesMode;
}
else if (controllerName == "CM")
{
myLeftMode = myRightMode = kCompuMateMode;
}
else
{
if (port == Controller::Jack::Left)
myLeftMode = kJoystickMode;
else
myRightMode = kJoystickMode;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::enableEmulationMappings()
{
for (auto& stick : mySticks)
{
const PhysicalJoystickPtr j = stick.second;
// start from scratch and enable common mappings
j->joyMap.eraseMode(kEmulationMode);
j->joyHatMap.eraseMode(kEmulationMode);
}
enableCommonMappings();
// enable right mode first, so that in case of mapping clashes the left controller has preference
switch (myRightMode)
{
case kPaddlesMode:
enableMappings(RightPaddlesEvents, kPaddlesMode);
break;
case kKeypadMode:
enableMappings(RightKeypadEvents, kKeypadMode);
break;
/*case kCompuMateMode:
// see below
break;*/
default:
enableMappings(RightJoystickEvents, kJoystickMode);
break;
}
switch (myLeftMode)
{
case kPaddlesMode:
enableMappings(LeftPaddlesEvents, kPaddlesMode);
break;
case kKeypadMode:
enableMappings(LeftKeypadEvents, kKeypadMode);
break;
/*case kCompuMateMode:
for (const auto& item : CompuMateMapping)
enableMapping(item.event, kCompuMateMode);
break;*/
default:
enableMappings(LeftJoystickEvents, kJoystickMode);
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::enableCommonMappings()
{
for (int i = Event::NoType + 1; i < Event::LastType; i++)
{
Event::Type event = static_cast<Event::Type>(i);
if (isCommonEvent(event))
enableMapping(event, kCommonMode);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::enableMappings(const Event::EventSet events, EventMode mode)
{
for (const auto& event : events)
enableMapping(event, mode);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::enableMapping(const Event::Type event, EventMode mode)
{
// copy from controller mode into emulation mode
for (auto& stick : mySticks)
{
const PhysicalJoystickPtr j = stick.second;
JoyMap::JoyMappingArray joyMappings = j->joyMap.getEventMapping(event, mode);
for (const auto& mapping : joyMappings)
j->joyMap.add(event, kEmulationMode, mapping.button, mapping.axis, mapping.adir);
JoyHatMap::JoyHatMappingArray joyHatMappings = j->joyHatMap.getEventMapping(event, mode);
for (const auto& mapping : joyHatMappings)
j->joyHatMap.add(event, kEmulationMode, mapping.button, mapping.hat, mapping.hdir);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventMode PhysicalJoystickHandler::getEventMode(const Event::Type event, const EventMode mode) const
{
if (mode == kEmulationMode)
{
if (isJoystickEvent(event))
return kJoystickMode;
if (isPaddleEvent(event))
return kPaddlesMode;
if (isKeypadEvent(event))
return kKeypadMode;
if (isCommonEvent(event))
return kCommonMode;
}
return mode;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::isJoystickEvent(const Event::Type event) const
{
return LeftJoystickEvents.find(event) != LeftJoystickEvents.end()
|| RightJoystickEvents.find(event) != RightJoystickEvents.end();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::isPaddleEvent(const Event::Type event) const
{
return LeftPaddlesEvents.find(event) != LeftPaddlesEvents.end()
|| RightPaddlesEvents.find(event) != RightPaddlesEvents.end();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::isKeypadEvent(const Event::Type event) const
{
return LeftKeypadEvents.find(event) != LeftKeypadEvents.end()
|| RightKeypadEvents.find(event) != RightKeypadEvents.end();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::isCommonEvent(const Event::Type event) const
{
return !(isJoystickEvent(event) || isPaddleEvent(event) || isKeypadEvent(event));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::eraseMapping(Event::Type event, EventMode mode) void PhysicalJoystickHandler::eraseMapping(Event::Type event, EventMode mode)
{ {
@ -404,140 +580,28 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode
{ {
uInt32 stick = s.first; uInt32 stick = s.first;
const PhysicalJoystickPtr j = s.second; const PhysicalJoystickPtr j = s.second;
if(!j) continue;
/*// Joystick button mapping/labeling if (j)
for(int button = 0; button < j->numButtons; ++button)
{ {
if(j->btnTable[button][mode] == event)
{
if(buf.str() != "")
buf << ", ";
buf << "J" << stick << "/B" << button;
}
}
// Joystick axis mapping/labeling
for(int axis = 0; axis < j->numAxes; ++axis)
{
for(int dir = 0; dir < NUM_JOY_DIRS; ++dir)
{
if(j->axisTable[axis][dir][mode] == event)
{
if(buf.str() != "")
buf << ", ";
buf << "J" << stick << "/A" << axis;
if(Event::isAnalog(event))
{
dir = NUM_JOY_DIRS; // Immediately exit the inner loop after this iteration
buf << "/+|-";
}
else if(dir == int(JoyDir::NEG))
buf << "/-";
else
buf << "/+";
}
}
}
// Joystick hat mapping/labeling
for(int hat = 0; hat < j->numHats; ++hat)
{
for(int dir = 0; dir < NUM_JOY_HAT_DIRS; ++dir)
{
if(j->hatTable[hat][dir][mode] == event)
{
if(buf.str() != "")
buf << ", ";
buf << "J" << stick << "/H" << hat;
switch(JoyHat(dir))
{
case JoyHat::UP: buf << "/up"; break;
case JoyHat::DOWN: buf << "/down"; break;
case JoyHat::LEFT: buf << "/left"; break;
case JoyHat::RIGHT: buf << "/right"; break;
default: break;
}
}
}
}*/
// new:
//Joystick button + axis mapping / labeling //Joystick button + axis mapping / labeling
if (j->joyMap.getEventMapping(event, mode).size())
{
if (buf.str() != "") if (buf.str() != "")
buf << ", "; buf << ", ";
if (j->joyMap.getEventMapping(event, mode).size())
buf << j->joyMap.getEventMappingDesc(stick, event, mode); buf << j->joyMap.getEventMappingDesc(stick, event, mode);
}
// Joystick hat mapping / labeling // Joystick hat mapping / labeling
if (j->joyHatMap.getEventMapping(event, mode).size()) if (j->joyHatMap.getEventMapping(event, mode).size())
{
if (buf.str() != "")
buf << ", ";
buf << j->joyHatMap.getEventMappingDesc(stick, event, mode); buf << j->joyHatMap.getEventMappingDesc(stick, event, mode);
} }
}
}
return buf.str(); return buf.str();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*bool PhysicalJoystickHandler::addAxisMapping(Event::Type event, EventMode mode,
int stick, int axis, int value)
{
const PhysicalJoystickPtr j = joy(stick);
if(j)
{
if(int(axis) >= 0 && int(axis) < j->numAxes && event < Event::LastType)
{
// 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->axisTable[axis][int(JoyDir::NEG)][mode] = j->axisTable[axis][int(JoyDir::POS)][mode] = event;
else
{
// Otherwise, turn off the analog event(s) for this axis
if(Event::isAnalog(j->axisTable[axis][int(JoyDir::NEG)][mode]))
j->axisTable[axis][int(JoyDir::NEG)][mode] = Event::NoType;
if(Event::isAnalog(j->axisTable[axis][int(JoyDir::POS)][mode]))
j->axisTable[axis][int(JoyDir::POS)][mode] = Event::NoType;
j->axisTable[axis][int(value > 0 ? JoyDir::POS : JoyDir::NEG)][mode] = event;
}
return true;
}
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::addBtnMapping(Event::Type event, EventMode mode,
int stick, int button)
{
const PhysicalJoystickPtr j = joy(stick);
if(j)
{
if(button >= 0 && button < j->numButtons && event < Event::LastType)
{
j->btnTable[button][mode] = event;
return true;
}
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::addHatMapping(Event::Type event, EventMode mode,
int stick, int hat, JoyHat value)
{
const PhysicalJoystickPtr j = joy(stick);
if(j)
{
if(hat >= 0 && hat < j->numHats && event < Event::LastType &&
value != JoyHat::CENTER)
{
j->hatTable[hat][int(value)][mode] = event;
return true;
}
}
return false;
}*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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, int value)
@ -563,8 +627,7 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i
if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::POS))) if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::POS)))
j->joyMap.erase(mode, button, axis, JoyDir::POS); j->joyMap.erase(mode, button, axis, JoyDir::POS);
j->joyMap.add(event, mode, button, axis, j->joyMap.add(event, mode, button, axis, convertAxisValue(value));
value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG);
} }
return true; return true;
} }
@ -600,6 +663,10 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
switch (j->type) switch (j->type)
{ {
case PhysicalJoystick::JT_REGULAR: case PhysicalJoystick::JT_REGULAR:
case PhysicalJoystick::JT_STELLADAPTOR_LEFT:
case PhysicalJoystick::JT_2600DAPTOR_LEFT:
case PhysicalJoystick::JT_STELLADAPTOR_RIGHT:
case PhysicalJoystick::JT_2600DAPTOR_RIGHT:
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
@ -666,6 +733,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
cerr << "axis event" << endl;
myHandler.overlay().handleJoyAxisEvent(stick, axis, value, button); myHandler.overlay().handleJoyAxisEvent(stick, axis, value, button);
#endif #endif
j->axisLastValue[axis] = value; j->axisLastValue[axis] = value;
@ -673,7 +741,7 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
} }
break; // Regular joystick axis break; // Regular joystick axis
// Since the various controller classes deal with Stelladaptor /*// Since the various controller classes deal with Stelladaptor
// devices differently, we send the raw X and Y axis data directly, // devices differently, we send the raw X and Y axis data directly,
// and let the controller handle it // and let the controller handle it
// These events don't have to pass through handleEvent, since // These events don't have to pass through handleEvent, since
@ -687,7 +755,7 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
case PhysicalJoystick::JT_2600DAPTOR_RIGHT: case PhysicalJoystick::JT_2600DAPTOR_RIGHT:
if (axis < NUM_JOY_AXIS) if (axis < NUM_JOY_AXIS)
myEvent.set(SA_Axis[int(Controller::Jack::Right)][axis], value); myEvent.set(SA_Axis[int(Controller::Jack::Right)][axis], value);
break; // axis on right controller (1) break; // axis on right controller (1)*/
default: default:
break; break;
} }
@ -707,6 +775,11 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed
switch (j->type) switch (j->type)
{ {
case PhysicalJoystick::JT_REGULAR: case PhysicalJoystick::JT_REGULAR:
case PhysicalJoystick::JT_STELLADAPTOR_LEFT:
case PhysicalJoystick::JT_STELLADAPTOR_RIGHT:
case PhysicalJoystick::JT_2600DAPTOR_LEFT:
case PhysicalJoystick::JT_2600DAPTOR_RIGHT:
// Handle buttons which switch eventhandler state // Handle buttons which switch eventhandler state
if (pressed && myHandler.changeStateByEvent(j->joyMap.get(kEmulationMode, button))) if (pressed && myHandler.changeStateByEvent(j->joyMap.get(kEmulationMode, button)))
return; return;
@ -720,7 +793,7 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed
#endif #endif
break; // Regular button break; // Regular button
// These events don't have to pass through handleEvent, since /*// These events don't have to pass through handleEvent, since
// they can never be remapped // they can never be remapped
case PhysicalJoystick::JT_STELLADAPTOR_LEFT: case PhysicalJoystick::JT_STELLADAPTOR_LEFT:
case PhysicalJoystick::JT_STELLADAPTOR_RIGHT: case PhysicalJoystick::JT_STELLADAPTOR_RIGHT:
@ -757,7 +830,7 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed
if (button < NUM_JOY_BTN) myEvent.set(SA_Button[j->type - PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); if (button < NUM_JOY_BTN) myEvent.set(SA_Button[j->type - PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0);
} }
} }
break; // 2600DAPTOR button break; // 2600DAPTOR button*/
default: default:
break; break;
@ -839,7 +912,7 @@ ostream& operator<<(ostream& os, const PhysicalJoystickHandler& jh)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Used by the Stelladaptor to send absolute axis values /*// Used by the Stelladaptor to send absolute axis values
const Event::Type PhysicalJoystickHandler::SA_Axis[NUM_PORTS][NUM_JOY_AXIS] = { const Event::Type PhysicalJoystickHandler::SA_Axis[NUM_PORTS][NUM_JOY_AXIS] = {
{ Event::SALeftAxis0Value, Event::SALeftAxis1Value }, { Event::SALeftAxis0Value, Event::SALeftAxis1Value },
{ Event::SARightAxis0Value, Event::SARightAxis1Value } { Event::SARightAxis0Value, Event::SARightAxis1Value }
@ -866,4 +939,4 @@ const Event::Type PhysicalJoystickHandler::SA_Key[NUM_PORTS][NUM_KEY_BTN] = {
Event::KeyboardOne4, Event::KeyboardOne5, Event::KeyboardOne6, Event::KeyboardOne4, Event::KeyboardOne5, Event::KeyboardOne6,
Event::KeyboardOne7, Event::KeyboardOne8, Event::KeyboardOne9, Event::KeyboardOne7, Event::KeyboardOne8, Event::KeyboardOne9,
Event::KeyboardOneStar, Event::KeyboardOne0, Event::KeyboardOnePound } Event::KeyboardOneStar, Event::KeyboardOne0, Event::KeyboardOnePound }
}; };*/

View File

@ -69,6 +69,12 @@ class PhysicalJoystickHandler
bool remove(const string& name); bool remove(const string& name);
void mapStelladaptors(const string& saport); void mapStelladaptors(const string& saport);
void setDefaultMapping(Event::Type type, EventMode mode); void setDefaultMapping(Event::Type type, EventMode mode);
/** define mappings for current controllers */
void defineControllerMappings(const string& controllerName, Controller::Jack port);
/** enable mappings for emulation mode */
void enableEmulationMappings();
void eraseMapping(Event::Type event, EventMode mode); void eraseMapping(Event::Type event, EventMode mode);
void saveMapping(); void saveMapping();
string getMappingDesc(Event::Type, EventMode mode) const; string getMappingDesc(Event::Type, EventMode mode) const;
@ -86,8 +92,7 @@ class PhysicalJoystickHandler
Event::Type eventForAxis(EventMode mode, int stick, int axis, int value, int button) const { Event::Type eventForAxis(EventMode mode, int stick, int axis, int value, int button) const {
const PhysicalJoystickPtr j = joy(stick); const PhysicalJoystickPtr j = joy(stick);
return j->joyMap.get(mode, button, JoyAxis(axis), return j->joyMap.get(mode, button, JoyAxis(axis), convertAxisValue(value));
value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG);
} }
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);
@ -127,13 +132,34 @@ class PhysicalJoystickHandler
friend ostream& operator<<(ostream& os, const PhysicalJoystickHandler& jh); friend ostream& operator<<(ostream& os, const PhysicalJoystickHandler& jh);
JoyDir convertAxisValue(int value) const {
return value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG;
}
/** returns the event's controller mode */
EventMode getEventMode(const Event::Type event, const EventMode mode) const;
/** Checks event type. */
bool isJoystickEvent(const Event::Type event) const;
bool isPaddleEvent(const Event::Type event) const;
bool isKeypadEvent(const Event::Type event) const;
bool isCommonEvent(const Event::Type event) const;
void enableCommonMappings();
void enableMappings(const Event::EventSet events, EventMode mode);
void enableMapping(const Event::Type event, EventMode mode);
EventMode myLeftMode;
EventMode myRightMode;
// Static lookup tables for Stelladaptor/2600-daptor axis/button support // Static lookup tables for Stelladaptor/2600-daptor axis/button support
static const int NUM_JOY_BTN = 4; /*static const int NUM_JOY_BTN = 4;
static const int NUM_KEY_BTN = 12; static const int NUM_KEY_BTN = 12;
static const Event::Type SA_Axis[NUM_PORTS][NUM_JOY_AXIS]; static const Event::Type SA_Axis[NUM_PORTS][NUM_JOY_AXIS];
static const Event::Type SA_Button[NUM_PORTS][NUM_JOY_BTN]; static const Event::Type SA_Button[NUM_PORTS][NUM_JOY_BTN];
static const Event::Type SA_Key[NUM_PORTS][NUM_KEY_BTN]; static const Event::Type SA_Key[NUM_PORTS][NUM_KEY_BTN];*/
}; };
#endif #endif

View File

@ -186,7 +186,6 @@ void PhysicalKeyboardHandler::enableEmulationMappings()
// see below // see below
break; break;
default: default:
enableMappings(RightJoystickEvents, kJoystickMode); enableMappings(RightJoystickEvents, kJoystickMode);
break; break;
@ -226,7 +225,7 @@ void PhysicalKeyboardHandler::enableCommonMappings()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableMappings(const EventSet events, EventMode mode) void PhysicalKeyboardHandler::enableMappings(const Event::EventSet events, EventMode mode)
{ {
for (const auto& event : events) for (const auto& event : events)
enableMapping(event, mode); enableMapping(event, mode);
@ -387,46 +386,6 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool pre
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventSet PhysicalKeyboardHandler::LeftJoystickEvents = {
Event::JoystickZeroUp, Event::JoystickZeroDown, Event::JoystickZeroLeft, Event::JoystickZeroRight,
Event::JoystickZeroFire, Event::JoystickZeroFire5, Event::JoystickZeroFire9,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventSet PhysicalKeyboardHandler::RightJoystickEvents = {
Event::JoystickOneUp, Event::JoystickOneDown, Event::JoystickOneLeft, Event::JoystickOneRight,
Event::JoystickOneFire, Event::JoystickOneFire5, Event::JoystickOneFire9
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventSet PhysicalKeyboardHandler::LeftPaddlesEvents = {
Event::PaddleZeroDecrease, Event::PaddleZeroIncrease, Event::PaddleZeroAnalog, Event::PaddleZeroFire,
Event::PaddleOneDecrease, Event::PaddleOneIncrease, Event::PaddleOneAnalog, Event::PaddleOneFire,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventSet PhysicalKeyboardHandler::RightPaddlesEvents = {
Event::PaddleTwoDecrease, Event::PaddleTwoIncrease, Event::PaddleTwoAnalog, Event::PaddleTwoFire,
Event::PaddleThreeDecrease, Event::PaddleThreeIncrease, Event::PaddleThreeAnalog, Event::PaddleThreeFire,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventSet PhysicalKeyboardHandler::LeftKeypadEvents = {
Event::KeyboardZero1, Event::KeyboardZero2, Event::KeyboardZero3,
Event::KeyboardZero4, Event::KeyboardZero5, Event::KeyboardZero6,
Event::KeyboardZero7, Event::KeyboardZero8, Event::KeyboardZero9,
Event::KeyboardZeroStar, Event::KeyboardZero0, Event::KeyboardZeroPound,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventSet PhysicalKeyboardHandler::RightKeypadEvents = {
Event::KeyboardOne1, Event::KeyboardOne2, Event::KeyboardOne3,
Event::KeyboardOne4, Event::KeyboardOne5, Event::KeyboardOne6,
Event::KeyboardOne7, Event::KeyboardOne8, Event::KeyboardOne9,
Event::KeyboardOneStar, Event::KeyboardOne0, Event::KeyboardOnePound,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::DefaultCommonMapping = { PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::DefaultCommonMapping = {
{Event::ConsoleSelect, KBDK_F1}, {Event::ConsoleSelect, KBDK_F1},
@ -641,7 +600,6 @@ PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::DefaultKeypa
{Event::KeyboardOnePound, KBDK_SLASH}, {Event::KeyboardOnePound, KBDK_SLASH},
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::CompuMateMapping = { PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::CompuMateMapping = {
{Event::CompuMateShift, KBDK_LSHIFT}, {Event::CompuMateShift, KBDK_LSHIFT},

View File

@ -19,7 +19,6 @@
#define PHYSICAL_KEYBOARD_HANDLER_HXX #define PHYSICAL_KEYBOARD_HANDLER_HXX
#include <map> #include <map>
#include <set>
class OSystem; class OSystem;
class EventHandler; class EventHandler;
@ -29,8 +28,6 @@ class EventHandler;
#include "EventHandlerConstants.hxx" #include "EventHandlerConstants.hxx"
#include "KeyMap.hxx" #include "KeyMap.hxx"
using EventSet = std::set<Event::Type>;
/** /**
This class handles all physical keyboard-related operations in Stella. This class handles all physical keyboard-related operations in Stella.
@ -103,7 +100,7 @@ class PhysicalKeyboardHandler
void enableCommonMappings(); void enableCommonMappings();
void enableMappings(const EventSet events, EventMode mode); void enableMappings(const Event::EventSet events, EventMode mode);
void enableMapping(const Event::Type event, EventMode mode); void enableMapping(const Event::Type event, EventMode mode);
OSystem& myOSystem; OSystem& myOSystem;
@ -130,16 +127,10 @@ class PhysicalKeyboardHandler
uInt8 myAltKeyCounter; uInt8 myAltKeyCounter;
#endif #endif
// Hold controller related events // Controller menu and common emulation mappings
static EventSet LeftJoystickEvents;
static EventSet RightJoystickEvents;
static EventSet LeftPaddlesEvents;
static EventSet RightPaddlesEvents;
static EventSet LeftKeypadEvents;
static EventSet RightKeypadEvents;
static EventMappingArray DefaultMenuMapping; static EventMappingArray DefaultMenuMapping;
static EventMappingArray DefaultCommonMapping; static EventMappingArray DefaultCommonMapping;
// Controller specific mappings
static EventMappingArray DefaultJoystickMapping; static EventMappingArray DefaultJoystickMapping;
static EventMappingArray DefaultPaddleMapping; static EventMappingArray DefaultPaddleMapping;
static EventMappingArray DefaultKeypadMapping; static EventMappingArray DefaultKeypadMapping;

View File

@ -77,11 +77,8 @@ string PhysicalJoystick::getMap() const
// The mapping structure (for remappable devices) is defined as follows: // The mapping structure (for remappable devices) is defined as follows:
// <NAME>'$'<MODE>['|'(<EVENT>':'<BUTTON>','<AXIS>','<VALUE>)|(<EVENT>':'<BUTTON>','<HAT>','<HATDIR>)] // <NAME>'$'<MODE>['|'(<EVENT>':'<BUTTON>','<AXIS>','<VALUE>)|(<EVENT>':'<BUTTON>','<HAT>','<HATDIR>)]
/* if(type == JT_REGULAR)
{*/
ostringstream joybuf; ostringstream joybuf;
// new:
joybuf << name; joybuf << name;
for (int m = 0; m < kNumModes; ++m) for (int m = 0; m < kNumModes; ++m)
{ {
@ -90,8 +87,6 @@ string PhysicalJoystick::getMap() const
} }
return joybuf.str(); return joybuf.str();
/*}
return EmptyString;*/
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -804,6 +804,7 @@ void Console::setControllers(const string& rommd5)
myLeftControl = std::move(myCMHandler->leftController()); myLeftControl = std::move(myCMHandler->leftController());
myRightControl = std::move(myCMHandler->rightController()); myRightControl = std::move(myCMHandler->rightController());
myOSystem.eventHandler().defineKeyControllerMappings("CM", Controller::Jack::Left); myOSystem.eventHandler().defineKeyControllerMappings("CM", Controller::Jack::Left);
myOSystem.eventHandler().defineJoyControllerMappings("CM", Controller::Jack::Left);
} }
else else
{ {
@ -849,6 +850,7 @@ unique_ptr<Controller> Console::getControllerPort(const string& rommd5,
unique_ptr<Controller> controller = std::move(myLeftControl); unique_ptr<Controller> controller = std::move(myLeftControl);
myOSystem.eventHandler().defineKeyControllerMappings(controllerName, port); myOSystem.eventHandler().defineKeyControllerMappings(controllerName, port);
myOSystem.eventHandler().defineJoyControllerMappings(controllerName, port);
if(controllerName == "JOYSTICK") if(controllerName == "JOYSTICK")
{ {

View File

@ -19,12 +19,13 @@
#define EVENT_HXX #define EVENT_HXX
#include <mutex> #include <mutex>
#include <set>
#include "bspf.hxx" #include "bspf.hxx"
#include "StellaKeys.hxx" #include "StellaKeys.hxx"
/** /**
@author Stephen Anthony, Christian Speckner @author Stephen Anthony, Christian Speckner, Thomas Jentzsch
*/ */
class Event class Event
{ {
@ -129,6 +130,8 @@ class Event
// Event list version, update if the id of existing event types changed // Event list version, update if the id of existing event types changed
static constexpr Int32 VERSION = 2; static constexpr Int32 VERSION = 2;
using EventSet = std::set<Event::Type>;
public: public:
/** /**
Create a new event object. Create a new event object.
@ -200,4 +203,44 @@ class Event
Event& operator=(Event&&) = delete; Event& operator=(Event&&) = delete;
}; };
// Hold controller related events
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet LeftJoystickEvents = {
Event::JoystickZeroUp, Event::JoystickZeroDown, Event::JoystickZeroLeft, Event::JoystickZeroRight,
Event::JoystickZeroFire, Event::JoystickZeroFire5, Event::JoystickZeroFire9,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet RightJoystickEvents = {
Event::JoystickOneUp, Event::JoystickOneDown, Event::JoystickOneLeft, Event::JoystickOneRight,
Event::JoystickOneFire, Event::JoystickOneFire5, Event::JoystickOneFire9
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet LeftPaddlesEvents = {
Event::PaddleZeroDecrease, Event::PaddleZeroIncrease, Event::PaddleZeroAnalog, Event::PaddleZeroFire,
Event::PaddleOneDecrease, Event::PaddleOneIncrease, Event::PaddleOneAnalog, Event::PaddleOneFire,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet RightPaddlesEvents = {
Event::PaddleTwoDecrease, Event::PaddleTwoIncrease, Event::PaddleTwoAnalog, Event::PaddleTwoFire,
Event::PaddleThreeDecrease, Event::PaddleThreeIncrease, Event::PaddleThreeAnalog, Event::PaddleThreeFire,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet LeftKeypadEvents = {
Event::KeyboardZero1, Event::KeyboardZero2, Event::KeyboardZero3,
Event::KeyboardZero4, Event::KeyboardZero5, Event::KeyboardZero6,
Event::KeyboardZero7, Event::KeyboardZero8, Event::KeyboardZero9,
Event::KeyboardZeroStar, Event::KeyboardZero0, Event::KeyboardZeroPound,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet RightKeypadEvents = {
Event::KeyboardOne1, Event::KeyboardOne2, Event::KeyboardOne3,
Event::KeyboardOne4, Event::KeyboardOne5, Event::KeyboardOne6,
Event::KeyboardOne7, Event::KeyboardOne8, Event::KeyboardOne9,
Event::KeyboardOneStar, Event::KeyboardOne0, Event::KeyboardOnePound,
};
#endif #endif

View File

@ -1123,54 +1123,6 @@ bool EventHandler::addKeyMapping(Event::Type event, EventMode mode, StellaKey ke
return mapped; return mapped;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*bool EventHandler::addJoyAxisMapping(Event::Type event, EventMode mode,
int stick, int axis, int value,
bool updateMenus)
{
#ifdef JOYSTICK_SUPPORT
bool mapped = myPJoyHandler->addAxisMapping(event, mode, stick, axis, value);
if(mapped && updateMenus)
setActionMappings(mode);
return mapped;
#else
return false;
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventHandler::addJoyButtonMapping(Event::Type event, EventMode mode,
int stick, int button,
bool updateMenus)
{
#ifdef JOYSTICK_SUPPORT
bool mapped = myPJoyHandler->addBtnMapping(event, mode, stick, button);
if(mapped && updateMenus)
setActionMappings(mode);
return mapped;
#else
return false;
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode,
int stick, int hat, JoyHat value,
bool updateMenus)
{
#ifdef JOYSTICK_SUPPORT
bool mapped = myPJoyHandler->addHatMapping(event, mode, stick, hat, value);
if(mapped && updateMenus)
setActionMappings(mode);
return mapped;
#else
return false;
#endif
}*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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, int value,

View File

@ -208,60 +208,54 @@ class EventHandler
/** /**
Bind a physical joystick axis direction to an event/action and regenerate Bind a physical joystick axis direction to an event/action and regenerate
the mapping array(s). the mapping array(s). The axis can be combined with a button. The button
can also be mapped without an axis.
@param event The event we are remapping @param event The event we are remapping
@param mode The mode where this event is active @param mode The mode where this event is active
@param stick The joystick number @param stick The joystick number
@param button The joystick button
@param axis The joystick axis @param axis The joystick axis
@param value The value on the given axis @param value The value on 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 addJoyAxisMapping(Event::Type event, EventMode mode, bool addJoyMapping(Event::Type event, EventMode mode, int stick,
int stick, int axis, int value, int button, JoyAxis axis = JoyAxis::NONE, int value = 0,
bool updateMenus = true); bool updateMenus = true);
/** /**
Bind a physical joystick button to an event/action and regenerate the Bind a physical joystick hat direction to an event/action and regenerate
mapping array(s). the mapping array(s). The hat can be combined with a button.
@param event The event we are remapping @param event The event we are remapping
@param mode The mode where this event is active @param mode The mode where this event is active
@param stick The joystick number @param stick The joystick number
@param button The joystick button @param button The joystick button
@param updateMenus Whether to update the action mappings (normally
we want to do this, unless there are a batch of
'adds', in which case it's delayed until the end
*/
/*bool addJoyButtonMapping(Event::Type event, EventMode mode, int stick, int button,
bool updateMenus = true);
/**
Bind a physical joystick hat direction to an event/action and regenerate
the mapping array(s).
@param event The event we are remapping
@param mode The mode where this event is active
@param stick The joystick number
@param hat The joystick hat @param hat The joystick hat
@param value The value on the given hat @param value The value on the given hat
@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 addJoyHatMapping(Event::Type event, EventMode mode, bool addJoyHatMapping(Event::Type event, EventMode mode, int stick,
int stick, int hat, JoyHat value, int button, int hat, JoyHat dir,
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 addJoyHatMapping(Event::Type event, EventMode mode,
int stick, int button, int hat, JoyHat dir,
bool updateMenus = true); bool updateMenus = true);
/**
Enable controller specific keyboard event mappings.
*/
void defineJoyControllerMappings(const string& controllerName, Controller::Jack port) {
myPJoyHandler->defineControllerMappings(controllerName, port);
}
/**
Enable emulation keyboard event mappings.
*/
void enableEmulationJoyMappings() {
myPJoyHandler->enableEmulationMappings();
}
/** /**
Erase the specified mapping. Erase the specified mapping.

View File

@ -48,9 +48,9 @@ enum class JoyAxis {
}; };
enum class JoyDir { enum class JoyDir {
NEG = 0, NEG = -1,
POS = 1, POS = 1,
NONE = JOY_CTRL_NONE NONE = 0
}; };

View File

@ -307,10 +307,12 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value, int but
// 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 && value == 0)
{ {
cerr << "handleJoyAxisEvent 0" << endl;
myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1; myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1;
} }
else if(value != 0) // never repeat the 'off' event else if(value != 0) // never repeat the 'off' event
{ {
cerr << "handleJoyAxisEvent repeat" << endl;
// 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;

View File

@ -310,11 +310,8 @@ void EventMappingWidget::handleJoyUp(int stick, int button)
cerr << "remap button stop" << endl; cerr << "remap button stop" << endl;
// This maps solo button presses only // This maps solo button presses only
if (eh.addJoyMapping(event, myEventMode, stick, button)) // new if (eh.addJoyMapping(event, myEventMode, stick, button))
stopRemapping(); stopRemapping();
//if (eh.addJoyButtonMapping(event, myEventMode, stick, button))
// stopRemapping();
} }
} }
} }
@ -346,10 +343,7 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int butto
cerr << "remap stop" << endl; cerr << "remap stop" << endl;
if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue)) if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue))
stopRemapping(); // new stopRemapping();
//if(eh.addJoyAxisMapping(event, myEventMode, stick, axis, myLastValue))
// stopRemapping();
} }
} }
} }
@ -384,11 +378,6 @@ bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHat value, int butt
stopRemapping(); stopRemapping();
return true; return true;
} }
/*if(eh.addJoyHatMapping(event, myEventMode, stick, hat, myLastValue))
{
stopRemapping();
return true;
}*/
} }
} }