Cleaned up the various methods for setting default mappings for the keyboard

and joysticks.  It's now easier to read/follow, and has less code.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3110 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-12-19 21:32:19 +00:00
parent b0e27be2e3
commit f5ceb39149
3 changed files with 112 additions and 113 deletions

View File

@ -38,7 +38,7 @@ CartridgeWDWidget::CartridgeWDWidget(
" $F000 - $F03F (R), $F040 - $F07F (W)\n";
int xpos = 10,
ypos = addBaseInformation(myCart.mySize, "Wickstead Design", info) + myLineHeight;
ypos = addBaseInformation(myCart.mySize, "Wickstead Design", info, 12) + myLineHeight;
VariantList items;
VarList::push_back(items, "0 ($30) [0,0,1,2]", 0);

View File

@ -1372,10 +1372,6 @@ void EventHandler::setDefaultMapping(Event::Type event, EventMode mode)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setDefaultKeymap(Event::Type event, EventMode mode)
{
#define SET_DEFAULT_KEY(sdk_key, sdk_mode, sdk_event, sdk_cmp_event) \
if(eraseAll || sdk_cmp_event == sdk_event) \
myKeyTable[sdk_key][sdk_mode] = sdk_event;
// If event is 'NoType', erase and reset all mappings
// Otherwise, only reset the given event
bool eraseAll = (event == Event::NoType);
@ -1386,88 +1382,94 @@ void EventHandler::setDefaultKeymap(Event::Type event, EventMode mode)
myKeyTable[i][mode] = Event::NoType;
}
auto setDefaultKey = [&](StellaKey key, Event::Type k_event)
{
if(eraseAll || k_event == event)
myKeyTable[key][mode] = k_event;
};
switch(mode)
{
case kEmulationMode:
SET_DEFAULT_KEY(KBDK_1, mode, Event::KeyboardZero1, event);
SET_DEFAULT_KEY(KBDK_2, mode, Event::KeyboardZero2, event);
SET_DEFAULT_KEY(KBDK_3, mode, Event::KeyboardZero3, event);
SET_DEFAULT_KEY(KBDK_Q, mode, Event::KeyboardZero4, event);
SET_DEFAULT_KEY(KBDK_W, mode, Event::KeyboardZero5, event);
SET_DEFAULT_KEY(KBDK_E, mode, Event::KeyboardZero6, event);
SET_DEFAULT_KEY(KBDK_A, mode, Event::KeyboardZero7, event);
SET_DEFAULT_KEY(KBDK_S, mode, Event::KeyboardZero8, event);
SET_DEFAULT_KEY(KBDK_D, mode, Event::KeyboardZero9, event);
SET_DEFAULT_KEY(KBDK_Z, mode, Event::KeyboardZeroStar, event);
SET_DEFAULT_KEY(KBDK_X, mode, Event::KeyboardZero0, event);
SET_DEFAULT_KEY(KBDK_C, mode, Event::KeyboardZeroPound, event);
setDefaultKey( KBDK_1, Event::KeyboardZero1 );
setDefaultKey( KBDK_2, Event::KeyboardZero2 );
setDefaultKey( KBDK_3, Event::KeyboardZero3 );
setDefaultKey( KBDK_Q, Event::KeyboardZero4 );
setDefaultKey( KBDK_W, Event::KeyboardZero5 );
setDefaultKey( KBDK_E, Event::KeyboardZero6 );
setDefaultKey( KBDK_A, Event::KeyboardZero7 );
setDefaultKey( KBDK_S, Event::KeyboardZero8 );
setDefaultKey( KBDK_D, Event::KeyboardZero9 );
setDefaultKey( KBDK_Z, Event::KeyboardZeroStar );
setDefaultKey( KBDK_X, Event::KeyboardZero0 );
setDefaultKey( KBDK_C, Event::KeyboardZeroPound );
SET_DEFAULT_KEY(KBDK_8, mode, Event::KeyboardOne1, event);
SET_DEFAULT_KEY(KBDK_9, mode, Event::KeyboardOne2, event);
SET_DEFAULT_KEY(KBDK_0, mode, Event::KeyboardOne3, event);
SET_DEFAULT_KEY(KBDK_I, mode, Event::KeyboardOne4, event);
SET_DEFAULT_KEY(KBDK_O, mode, Event::KeyboardOne5, event);
SET_DEFAULT_KEY(KBDK_P, mode, Event::KeyboardOne6, event);
SET_DEFAULT_KEY(KBDK_K, mode, Event::KeyboardOne7, event);
SET_DEFAULT_KEY(KBDK_L, mode, Event::KeyboardOne8, event);
SET_DEFAULT_KEY(KBDK_SEMICOLON, mode, Event::KeyboardOne9, event);
SET_DEFAULT_KEY(KBDK_COMMA, mode, Event::KeyboardOneStar, event);
SET_DEFAULT_KEY(KBDK_PERIOD, mode, Event::KeyboardOne0, event);
SET_DEFAULT_KEY(KBDK_SLASH, mode, Event::KeyboardOnePound, event);
setDefaultKey( KBDK_8, Event::KeyboardOne1 );
setDefaultKey( KBDK_9, Event::KeyboardOne2 );
setDefaultKey( KBDK_0, Event::KeyboardOne3 );
setDefaultKey( KBDK_I, Event::KeyboardOne4 );
setDefaultKey( KBDK_O, Event::KeyboardOne5 );
setDefaultKey( KBDK_P, Event::KeyboardOne6 );
setDefaultKey( KBDK_K, Event::KeyboardOne7 );
setDefaultKey( KBDK_L, Event::KeyboardOne8 );
setDefaultKey( KBDK_SEMICOLON, Event::KeyboardOne9 );
setDefaultKey( KBDK_COMMA, Event::KeyboardOneStar );
setDefaultKey( KBDK_PERIOD, Event::KeyboardOne0 );
setDefaultKey( KBDK_SLASH, Event::KeyboardOnePound );
SET_DEFAULT_KEY(KBDK_UP, mode, Event::JoystickZeroUp, event);
SET_DEFAULT_KEY(KBDK_DOWN, mode, Event::JoystickZeroDown, event);
SET_DEFAULT_KEY(KBDK_LEFT, mode, Event::JoystickZeroLeft, event);
SET_DEFAULT_KEY(KBDK_RIGHT, mode, Event::JoystickZeroRight, event);
SET_DEFAULT_KEY(KBDK_SPACE, mode, Event::JoystickZeroFire, event);
SET_DEFAULT_KEY(KBDK_LCTRL, mode, Event::JoystickZeroFire, event);
SET_DEFAULT_KEY(KBDK_4, mode, Event::JoystickZeroFire5, event);
SET_DEFAULT_KEY(KBDK_5, mode, Event::JoystickZeroFire9, event);
setDefaultKey( KBDK_UP, Event::JoystickZeroUp );
setDefaultKey( KBDK_DOWN, Event::JoystickZeroDown );
setDefaultKey( KBDK_LEFT, Event::JoystickZeroLeft );
setDefaultKey( KBDK_RIGHT, Event::JoystickZeroRight );
setDefaultKey( KBDK_SPACE, Event::JoystickZeroFire );
setDefaultKey( KBDK_LCTRL, Event::JoystickZeroFire );
setDefaultKey( KBDK_4, Event::JoystickZeroFire5 );
setDefaultKey( KBDK_5, Event::JoystickZeroFire9 );
SET_DEFAULT_KEY(KBDK_Y, mode, Event::JoystickOneUp, event);
SET_DEFAULT_KEY(KBDK_H, mode, Event::JoystickOneDown, event);
SET_DEFAULT_KEY(KBDK_G, mode, Event::JoystickOneLeft, event);
SET_DEFAULT_KEY(KBDK_J, mode, Event::JoystickOneRight, event);
SET_DEFAULT_KEY(KBDK_F, mode, Event::JoystickOneFire, event);
SET_DEFAULT_KEY(KBDK_6, mode, Event::JoystickOneFire5, event);
SET_DEFAULT_KEY(KBDK_7, mode, Event::JoystickOneFire9, event);
setDefaultKey( KBDK_Y, Event::JoystickOneUp );
setDefaultKey( KBDK_H, Event::JoystickOneDown );
setDefaultKey( KBDK_G, Event::JoystickOneLeft );
setDefaultKey( KBDK_J, Event::JoystickOneRight );
setDefaultKey( KBDK_F, Event::JoystickOneFire );
setDefaultKey( KBDK_6, Event::JoystickOneFire5 );
setDefaultKey( KBDK_7, Event::JoystickOneFire9 );
SET_DEFAULT_KEY(KBDK_F1, mode, Event::ConsoleSelect, event);
SET_DEFAULT_KEY(KBDK_F2, mode, Event::ConsoleReset, event);
SET_DEFAULT_KEY(KBDK_F3, mode, Event::ConsoleColor, event);
SET_DEFAULT_KEY(KBDK_F4, mode, Event::ConsoleBlackWhite, event);
SET_DEFAULT_KEY(KBDK_F5, mode, Event::ConsoleLeftDiffA, event);
SET_DEFAULT_KEY(KBDK_F6, mode, Event::ConsoleLeftDiffB, event);
SET_DEFAULT_KEY(KBDK_F7, mode, Event::ConsoleRightDiffA, event);
SET_DEFAULT_KEY(KBDK_F8, mode, Event::ConsoleRightDiffB, event);
SET_DEFAULT_KEY(KBDK_F9, mode, Event::SaveState, event);
SET_DEFAULT_KEY(KBDK_F10, mode, Event::ChangeState, event);
SET_DEFAULT_KEY(KBDK_F11, mode, Event::LoadState, event);
SET_DEFAULT_KEY(KBDK_F12, mode, Event::TakeSnapshot, event);
SET_DEFAULT_KEY(KBDK_BACKSPACE, mode, Event::Fry, event);
SET_DEFAULT_KEY(KBDK_PAUSE, mode, Event::PauseMode, event);
SET_DEFAULT_KEY(KBDK_TAB, mode, Event::MenuMode, event);
SET_DEFAULT_KEY(KBDK_BACKSLASH, mode, Event::CmdMenuMode, event);
SET_DEFAULT_KEY(KBDK_GRAVE, mode, Event::DebuggerMode, event);
SET_DEFAULT_KEY(KBDK_ESCAPE, mode, Event::LauncherMode, event);
setDefaultKey( KBDK_F1, Event::ConsoleSelect );
setDefaultKey( KBDK_F2, Event::ConsoleReset );
setDefaultKey( KBDK_F3, Event::ConsoleColor );
setDefaultKey( KBDK_F4, Event::ConsoleBlackWhite );
setDefaultKey( KBDK_F5, Event::ConsoleLeftDiffA );
setDefaultKey( KBDK_F6, Event::ConsoleLeftDiffB );
setDefaultKey( KBDK_F7, Event::ConsoleRightDiffA );
setDefaultKey( KBDK_F8, Event::ConsoleRightDiffB );
setDefaultKey( KBDK_F9, Event::SaveState );
setDefaultKey( KBDK_F10, Event::ChangeState );
setDefaultKey( KBDK_F11, Event::LoadState );
setDefaultKey( KBDK_F12, Event::TakeSnapshot );
setDefaultKey( KBDK_BACKSPACE, Event::Fry );
setDefaultKey( KBDK_PAUSE, Event::PauseMode );
setDefaultKey( KBDK_TAB, Event::MenuMode );
setDefaultKey( KBDK_BACKSLASH, Event::CmdMenuMode );
setDefaultKey( KBDK_GRAVE, Event::DebuggerMode );
setDefaultKey( KBDK_ESCAPE, Event::LauncherMode );
break;
case kMenuMode:
SET_DEFAULT_KEY(KBDK_UP, mode, Event::UIUp, event);
SET_DEFAULT_KEY(KBDK_DOWN, mode, Event::UIDown, event);
SET_DEFAULT_KEY(KBDK_LEFT, mode, Event::UILeft, event);
SET_DEFAULT_KEY(KBDK_RIGHT, mode, Event::UIRight, event);
setDefaultKey( KBDK_UP, Event::UIUp );
setDefaultKey( KBDK_DOWN, Event::UIDown );
setDefaultKey( KBDK_LEFT, Event::UILeft );
setDefaultKey( KBDK_RIGHT, Event::UIRight );
SET_DEFAULT_KEY(KBDK_HOME, mode, Event::UIHome, event);
SET_DEFAULT_KEY(KBDK_END, mode, Event::UIEnd, event);
SET_DEFAULT_KEY(KBDK_PAGEUP, mode, Event::UIPgUp, event);
SET_DEFAULT_KEY(KBDK_PAGEDOWN, mode, Event::UIPgDown, event);
setDefaultKey( KBDK_HOME, Event::UIHome );
setDefaultKey( KBDK_END, Event::UIEnd );
setDefaultKey( KBDK_PAGEUP, Event::UIPgUp );
setDefaultKey( KBDK_PAGEDOWN, Event::UIPgDown );
SET_DEFAULT_KEY(KBDK_RETURN, mode, Event::UISelect, event);
SET_DEFAULT_KEY(KBDK_ESCAPE, mode, Event::UICancel, event);
setDefaultKey( KBDK_RETURN, Event::UISelect );
setDefaultKey( KBDK_ESCAPE, Event::UICancel );
SET_DEFAULT_KEY(KBDK_BACKSPACE, mode, Event::UIPrevDir, event);
setDefaultKey( KBDK_BACKSPACE, Event::UIPrevDir );
break;
default:

View File

@ -445,23 +445,20 @@ void EventHandler::JoystickHandler::setStickDefaultMapping(int stick,
EventHandler& handler = myOSystem.eventHandler();
bool eraseAll = (event == Event::NoType);
auto setDefaultAxis = [&](Event::Type event, EventMode mode,
int stick, int axis, int value, Event::Type cmp_event)
auto setDefaultAxis = [&](int stick, int axis, int value, Event::Type a_event)
{
if(eraseAll || cmp_event == event)
handler.addJoyAxisMapping(event, mode, stick, axis, value, false);
if(eraseAll || a_event == event)
handler.addJoyAxisMapping(a_event, mode, stick, axis, value, false);
};
auto setDefaultBtn = [&](Event::Type event, EventMode mode,
int stick, int button, Event::Type cmp_event)
auto setDefaultBtn = [&](int stick, int button, Event::Type b_event)
{
if(eraseAll || cmp_event == event)
handler.addJoyButtonMapping(event, mode, stick, button, false);
if(eraseAll || b_event == event)
handler.addJoyButtonMapping(b_event, mode, stick, button, false);
};
auto setDefaultHat = [&](Event::Type event, EventMode mode,
int stick, int hat, int dir, Event::Type cmp_event)
auto setDefaultHat = [&](int stick, int hat, int dir, Event::Type h_event)
{
if(eraseAll || cmp_event == event)
handler.addJoyHatMapping(event, mode, stick, hat, dir, false);
if(eraseAll || h_event == event)
handler.addJoyHatMapping(h_event, mode, stick, hat, dir, false);
};
switch(mode)
@ -470,56 +467,56 @@ void EventHandler::JoystickHandler::setStickDefaultMapping(int stick,
if(stick == 0)
{
// Left joystick left/right directions (assume joystick zero)
setDefaultAxis(Event::JoystickZeroLeft, mode, 0, 0, 0, event);
setDefaultAxis(Event::JoystickZeroRight, mode, 0, 0, 1, event);
setDefaultAxis( 0, 0, 0, Event::JoystickZeroLeft );
setDefaultAxis( 0, 0, 1, Event::JoystickZeroRight );
// Left joystick up/down directions (assume joystick zero)
setDefaultAxis(Event::JoystickZeroUp, mode, 0, 1, 0, event);
setDefaultAxis(Event::JoystickZeroDown, mode, 0, 1, 1, event);
setDefaultAxis( 0, 1, 0, Event::JoystickZeroUp );
setDefaultAxis( 0, 1, 1, Event::JoystickZeroDown );
// Left joystick (assume joystick zero, button zero)
setDefaultBtn(Event::JoystickZeroFire, mode, 0, 0, event);
setDefaultBtn( 0, 0, Event::JoystickZeroFire );
// Left joystick left/right directions (assume joystick zero and hat 0)
setDefaultHat(Event::JoystickZeroLeft, mode, 0, 0, EVENT_HATLEFT, event);
setDefaultHat(Event::JoystickZeroRight, mode, 0, 0, EVENT_HATRIGHT, event);
setDefaultHat( 0, 0, EVENT_HATLEFT, Event::JoystickZeroLeft );
setDefaultHat( 0, 0, EVENT_HATRIGHT, Event::JoystickZeroRight );
// Left joystick up/down directions (assume joystick zero and hat 0)
setDefaultHat(Event::JoystickZeroUp, mode, 0, 0, EVENT_HATUP, event);
setDefaultHat(Event::JoystickZeroDown, mode, 0, 0, EVENT_HATDOWN, event);
setDefaultHat( 0, 0, EVENT_HATUP, Event::JoystickZeroUp );
setDefaultHat( 0, 0, EVENT_HATDOWN, Event::JoystickZeroDown );
}
else if(stick == 1)
{
// Right joystick left/right directions (assume joystick one)
setDefaultAxis(Event::JoystickOneLeft, mode, 1, 0, 0, event);
setDefaultAxis(Event::JoystickOneRight, mode, 1, 0, 1, event);
setDefaultAxis( 1, 0, 0, Event::JoystickOneLeft );
setDefaultAxis( 1, 0, 1, Event::JoystickOneRight );
// Right joystick left/right directions (assume joystick one)
setDefaultAxis(Event::JoystickOneUp, mode, 1, 1, 0, event);
setDefaultAxis(Event::JoystickOneDown, mode, 1, 1, 1, event);
setDefaultAxis( 1, 1, 0, Event::JoystickOneUp );
setDefaultAxis( 1, 1, 1, Event::JoystickOneDown );
// Right joystick (assume joystick one, button zero)
setDefaultBtn(Event::JoystickOneFire, mode, 1, 0, event);
setDefaultBtn( 1, 0, Event::JoystickOneFire );
// Right joystick left/right directions (assume joystick one and hat 0)
setDefaultHat(Event::JoystickOneLeft, mode, 1, 0, EVENT_HATLEFT, event);
setDefaultHat(Event::JoystickOneRight, mode, 1, 0, EVENT_HATRIGHT, event);
setDefaultHat( 1, 0, EVENT_HATLEFT, Event::JoystickOneLeft );
setDefaultHat( 1, 0, EVENT_HATRIGHT, Event::JoystickOneRight );
// Right joystick up/down directions (assume joystick one and hat 0)
setDefaultHat(Event::JoystickOneUp, mode, 1, 0, EVENT_HATUP, event);
setDefaultHat(Event::JoystickOneDown, mode, 1, 0, EVENT_HATDOWN, event);
setDefaultHat( 1, 0, EVENT_HATUP, Event::JoystickOneUp );
setDefaultHat( 1, 0, EVENT_HATDOWN, Event::JoystickOneDown );
}
break;
case kMenuMode: // Default menu/UI events
if(stick == 0)
{
setDefaultAxis(Event::UILeft, mode, 0, 0, 0, event);
setDefaultAxis(Event::UIRight, mode, 0, 0, 1, event);
setDefaultAxis(Event::UIUp, mode, 0, 1, 0, event);
setDefaultAxis(Event::UIDown, mode, 0, 1, 1, event);
setDefaultAxis( 0, 0, 0, Event::UILeft );
setDefaultAxis( 0, 0, 1, Event::UIRight );
setDefaultAxis( 0, 1, 0, Event::UIUp );
setDefaultAxis( 0, 1, 1, Event::UIDown );
// Left joystick (assume joystick zero, button zero)
setDefaultBtn(Event::UISelect, mode, 0, 0, event);
setDefaultBtn( 0, 0, Event::UISelect );
// Right joystick (assume joystick one, button zero)
setDefaultBtn(Event::UISelect, mode, 1, 0, event);
setDefaultBtn( 1, 0, Event::UISelect );
setDefaultHat(Event::UILeft, mode, 0, 0, EVENT_HATLEFT, event);
setDefaultHat(Event::UIRight, mode, 0, 0, EVENT_HATRIGHT, event);
setDefaultHat(Event::UIUp, mode, 0, 0, EVENT_HATUP, event);
setDefaultHat(Event::UIDown, mode, 0, 0, EVENT_HATDOWN, event);
setDefaultHat( 0, 0, EVENT_HATLEFT, Event::UILeft );
setDefaultHat( 0, 0, EVENT_HATRIGHT, Event::UIRight );
setDefaultHat( 0, 0, EVENT_HATUP, Event::UIUp );
setDefaultHat( 0, 0, EVENT_HATDOWN, Event::UIDown );
}
break;