refactored GlobalKeyHandler

This commit is contained in:
Thomas Jentzsch 2021-10-29 10:23:14 +02:00
parent 00bb3e392a
commit e6af23d6c1
4 changed files with 385 additions and 457 deletions

View File

@ -87,8 +87,6 @@ using StringList = std::vector<std::string>;
using ByteBuffer = std::unique_ptr<uInt8[]>; // NOLINT using ByteBuffer = std::unique_ptr<uInt8[]>; // NOLINT
using DWordBuffer = std::unique_ptr<uInt32[]>; // NOLINT using DWordBuffer = std::unique_ptr<uInt32[]>; // NOLINT
using AdjustFunction = std::function<void(int)>;
// We use KB a lot; let's make a literal for it // We use KB a lot; let's make a literal for it
constexpr size_t operator "" _KB(unsigned long long size) constexpr size_t operator "" _KB(unsigned long long size)
{ {

File diff suppressed because it is too large Load Diff

View File

@ -43,17 +43,17 @@ bool GlobalKeyHandler::handleEvent(const Event::Type event, bool pressed, bool r
// b) other keys have been pressed // b) other keys have been pressed
if(!myOSystem.frameBuffer().messageShown()) if(!myOSystem.frameBuffer().messageShown())
{ {
myAdjustActive = false; mySettingActive = false;
myAdjustDirect = AdjustSetting::NONE; myDirectSetting = Setting::NONE;
} }
const bool adjustActive = myAdjustActive; const bool settingActive = mySettingActive;
const AdjustSetting adjustAVDirect = myAdjustDirect; const Setting directSetting = myDirectSetting;
if(pressed) if(pressed)
{ {
myAdjustActive = false; mySettingActive = false;
myAdjustDirect = AdjustSetting::NONE; myDirectSetting = Setting::NONE;
} }
bool handled = true; bool handled = true;
@ -66,50 +66,35 @@ bool GlobalKeyHandler::handleEvent(const Event::Type event, bool pressed, bool r
case Event::NextSettingGroup: case Event::NextSettingGroup:
if(pressed && !repeated) if(pressed && !repeated)
{ {
const int direction = event == Event::PreviousSettingGroup ? -1 : +1; const int direction = (event == Event::PreviousSettingGroup ? -1 : +1);
AdjustGroup adjustGroup = AdjustGroup(BSPF::clampw(int(getAdjustGroup()) + direction, Group group = Group(BSPF::clampw(int(getGroup()) + direction,
0, int(AdjustGroup::NUM_GROUPS) - 1)); 0, int(Group::NUM_GROUPS) - 1));
string msg; const std::map<Group, GroupData> GroupMap = {
{Group::AV, {Setting::START_AV_ADJ, "Audio & Video"}},
{Group::INPUT, {Setting::START_INPUT_ADJ, "Input Devices & Ports"}},
{Group::DEBUG, {Setting::START_DEBUG_ADJ, "Debug"}},
};
const auto result = GroupMap.find(group);
switch(adjustGroup) myOSystem.frameBuffer().showTextMessage(result->second.name + " settings");
{ mySetting = result->second.start;
case AdjustGroup::AV: mySettingActive = false;
msg = "Audio & Video";
myAdjustSetting = AdjustSetting::START_AV_ADJ;
break;
case AdjustGroup::INPUT:
msg = "Input Devices & Ports";
myAdjustSetting = AdjustSetting::START_INPUT_ADJ;
break;
case AdjustGroup::DEBUG:
msg = "Debug";
myAdjustSetting = AdjustSetting::START_DEBUG_ADJ;
break;
default:
break;
}
myOSystem.frameBuffer().showTextMessage(msg + " settings");
myAdjustActive = false;
} }
break; break;
// Allow adjusting several (mostly repeated) settings using the same four hotkeys
case Event::PreviousSetting: case Event::PreviousSetting:
case Event::NextSetting: case Event::NextSetting:
if(pressed && !repeated) if(pressed && !repeated)
{ {
const int direction = event == Event::PreviousSetting ? -1 : +1; const int direction = (event == Event::PreviousSetting ? -1 : +1);
// Get (and display) the previous|next adjustment function, // Get (and display) the previous|next adjustment function,
// but do not change its value // but do not change its value
cycleAdjustSetting(adjustActive ? direction : 0)(0); cycleSetting(settingActive ? direction : 0)(0);
// Fallback message when no message is displayed by method // Fallback message when no message is displayed by method
//if(!myOSystem.frameBuffer().messageShown()) //if(!myOSystem.frameBuffer().messageShown())
// myOSystem.frameBuffer().showMessage("Message " + std::to_string(int(myAdjustSetting))); // myOSystem.frameBuffer().showMessage("Message " + std::to_string(int(mySetting)));
myAdjustActive = true; mySettingActive = true;
} }
break; break;
@ -117,23 +102,27 @@ bool GlobalKeyHandler::handleEvent(const Event::Type event, bool pressed, bool r
case Event::SettingIncrease: case Event::SettingIncrease:
if(pressed) if(pressed)
{ {
const int direction = event == Event::SettingDecrease ? -1 : +1; const int direction = (event == Event::SettingDecrease ? -1 : +1);
// if a "direct only" hotkey was pressed last, use this one // if a "direct only" hotkey was pressed last, use this one
if(adjustAVDirect != AdjustSetting::NONE) if(directSetting != Setting::NONE)
{ {
myAdjustDirect = adjustAVDirect; const SettingData& data = getSettingData(directSetting);
if(!repeated || isAdjustRepeated(myAdjustDirect))
getAdjustSetting(myAdjustDirect)(direction); myDirectSetting = directSetting;
if(!repeated || data.repeated)
data.function(direction);
} }
else else
{ {
// Get (and display) the current adjustment function, // Get (and display) the current adjustment function,
// but only change its value if the function was already active before // but only change its value if the function was already active before
if(!repeated || isAdjustRepeated(myAdjustSetting)) const SettingData& data = getSettingData(mySetting);
if(!repeated || data.repeated)
{ {
getAdjustSetting(myAdjustSetting)(adjustActive ? direction : 0); data.function(settingActive ? direction : 0);
myAdjustActive = true; mySettingActive = true;
} }
} }
} }
@ -146,27 +135,28 @@ bool GlobalKeyHandler::handleEvent(const Event::Type event, bool pressed, bool r
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GlobalKeyHandler::setAdjustSetting(const AdjustSetting setting) void GlobalKeyHandler::setSetting(const Setting setting)
{ {
myAdjustSetting = setting; mySetting = setting;
myAdjustActive = true; mySettingActive = true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GlobalKeyHandler::setAdjustDirect(const AdjustSetting setting) void GlobalKeyHandler::setDirectSetting(const Setting setting)
{ {
myAdjustDirect = setting; myDirectSetting = setting;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const GlobalKeyHandler::AdjustGroup GlobalKeyHandler::getAdjustGroup() const const GlobalKeyHandler::Group GlobalKeyHandler::getGroup() const
{ {
if(myAdjustSetting >= AdjustSetting::START_DEBUG_ADJ && myAdjustSetting <= AdjustSetting::END_DEBUG_ADJ) if(mySetting >= Setting::START_DEBUG_ADJ && mySetting <= Setting::END_DEBUG_ADJ)
return AdjustGroup::DEBUG; return Group::DEBUG;
if(myAdjustSetting >= AdjustSetting::START_INPUT_ADJ && myAdjustSetting <= AdjustSetting::END_INPUT_ADJ)
return AdjustGroup::INPUT;
return AdjustGroup::AV; if(mySetting >= Setting::START_INPUT_ADJ && mySetting <= Setting::END_INPUT_ADJ)
return Group::INPUT;
return Group::AV;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -210,17 +200,17 @@ bool GlobalKeyHandler::skipAVSetting() const
const bool isSoftwareRenderer = const bool isSoftwareRenderer =
myOSystem.settings().getString("video") == "software"; myOSystem.settings().getString("video") == "software";
return (myAdjustSetting == AdjustSetting::OVERSCAN && !isFullScreen) return (mySetting == Setting::OVERSCAN && !isFullScreen)
#ifdef ADAPTABLE_REFRESH_SUPPORT #ifdef ADAPTABLE_REFRESH_SUPPORT
|| (myAdjustSetting == AdjustSetting::ADAPT_REFRESH && !isFullScreen) || (mySetting == Setting::ADAPT_REFRESH && !isFullScreen)
#endif #endif
|| (myAdjustSetting >= AdjustSetting::PALETTE_PHASE || (mySetting >= Setting::PALETTE_PHASE
&& myAdjustSetting <= AdjustSetting::PALETTE_BLUE_SHIFT && mySetting <= Setting::PALETTE_BLUE_SHIFT
&& !isCustomPalette) && !isCustomPalette)
|| (myAdjustSetting >= AdjustSetting::NTSC_SHARPNESS || (mySetting >= Setting::NTSC_SHARPNESS
&& myAdjustSetting <= AdjustSetting::NTSC_BLEEDING && mySetting <= Setting::NTSC_BLEEDING
&& !isCustomFilter) && !isCustomFilter)
|| (myAdjustSetting == AdjustSetting::INTERPOLATION && isSoftwareRenderer); || (mySetting == Setting::INTERPOLATION && isSoftwareRenderer);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -244,32 +234,32 @@ bool GlobalKeyHandler::skipInputSetting() const
&& analog); && analog);
const bool stelladapter = joyHandler().hasStelladaptors(); const bool stelladapter = joyHandler().hasStelladaptors();
return (!grabMouseAllowed && myAdjustSetting == AdjustSetting::GRAB_MOUSE) return (!grabMouseAllowed && mySetting == Setting::GRAB_MOUSE)
|| (!joystick || (!joystick
&& (myAdjustSetting == AdjustSetting::DEADZONE && (mySetting == Setting::DEADZONE
|| myAdjustSetting == AdjustSetting::FOUR_DIRECTIONS)) || mySetting == Setting::FOUR_DIRECTIONS))
|| (!paddle || (!paddle
&& (myAdjustSetting == AdjustSetting::ANALOG_DEADZONE && (mySetting == Setting::ANALOG_DEADZONE
|| myAdjustSetting == AdjustSetting::ANALOG_SENSITIVITY || mySetting == Setting::ANALOG_SENSITIVITY
|| myAdjustSetting == AdjustSetting::ANALOG_LINEARITY || mySetting == Setting::ANALOG_LINEARITY
|| myAdjustSetting == AdjustSetting::DEJITTER_AVERAGING || mySetting == Setting::DEJITTER_AVERAGING
|| myAdjustSetting == AdjustSetting::DEJITTER_REACTION || mySetting == Setting::DEJITTER_REACTION
|| myAdjustSetting == AdjustSetting::DIGITAL_SENSITIVITY || mySetting == Setting::DIGITAL_SENSITIVITY
|| myAdjustSetting == AdjustSetting::SWAP_PADDLES || mySetting == Setting::SWAP_PADDLES
|| myAdjustSetting == AdjustSetting::PADDLE_CENTER_X || mySetting == Setting::PADDLE_CENTER_X
|| myAdjustSetting == AdjustSetting::PADDLE_CENTER_Y)) || mySetting == Setting::PADDLE_CENTER_Y))
|| ((!paddle || !useMouse) || ((!paddle || !useMouse)
&& myAdjustSetting == AdjustSetting::PADDLE_SENSITIVITY) && mySetting == Setting::PADDLE_SENSITIVITY)
|| ((!trackball || !useMouse) || ((!trackball || !useMouse)
&& myAdjustSetting == AdjustSetting::TRACKBALL_SENSITIVITY) && mySetting == Setting::TRACKBALL_SENSITIVITY)
|| (!driving || (!driving
&& myAdjustSetting == AdjustSetting::DRIVING_SENSITIVITY) // also affects digital device input sensitivity && mySetting == Setting::DRIVING_SENSITIVITY) // also affects digital device input sensitivity
|| ((!myOSystem.eventHandler().hasMouseControl() || !useMouse) || ((!myOSystem.eventHandler().hasMouseControl() || !useMouse)
&& myAdjustSetting == AdjustSetting::MOUSE_CONTROL) && mySetting == Setting::MOUSE_CONTROL)
|| ((!paddle || !useMouse) || ((!paddle || !useMouse)
&& myAdjustSetting == AdjustSetting::MOUSE_RANGE) && mySetting == Setting::MOUSE_RANGE)
|| (!stelladapter || (!stelladapter
&& myAdjustSetting == AdjustSetting::SA_PORT_ORDER); && mySetting == Setting::SA_PORT_ORDER);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -277,37 +267,38 @@ bool GlobalKeyHandler::skipDebugSetting() const
{ {
const bool isPAL = myOSystem.console().timing() == ConsoleTiming::pal; const bool isPAL = myOSystem.console().timing() == ConsoleTiming::pal;
return (myAdjustSetting == AdjustSetting::COLOR_LOSS && !isPAL); return (mySetting == Setting::COLOR_LOSS && !isPAL);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const AdjustFunction GlobalKeyHandler::cycleAdjustSetting(int direction) const GlobalKeyHandler::Function GlobalKeyHandler::cycleSetting(int direction)
{ {
bool skip = false; bool skip = false;
do do
{ {
switch(getAdjustGroup()) switch(getGroup())
{ {
case AdjustGroup::AV: case Group::AV:
myAdjustSetting = mySetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction, Setting(BSPF::clampw(int(mySetting) + direction,
int(AdjustSetting::START_AV_ADJ), int(AdjustSetting::END_AV_ADJ))); int(Setting::START_AV_ADJ), int(Setting::END_AV_ADJ)));
// skip currently non-relevant adjustments // skip currently non-relevant adjustments
skip = skipAVSetting(); skip = skipAVSetting();
break; break;
case AdjustGroup::INPUT: case Group::INPUT:
myAdjustSetting = mySetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction, Setting(BSPF::clampw(int(mySetting) + direction,
int(AdjustSetting::START_INPUT_ADJ), int(AdjustSetting::END_INPUT_ADJ))); int(Setting::START_INPUT_ADJ), int(Setting::END_INPUT_ADJ)));
// skip currently non-relevant adjustments // skip currently non-relevant adjustments
skip = skipInputSetting(); skip = skipInputSetting();
break; break;
case AdjustGroup::DEBUG: case Group::DEBUG:
myAdjustSetting = mySetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction, Setting(BSPF::clampw(int(mySetting) + direction,
int(AdjustSetting::START_DEBUG_ADJ), int(AdjustSetting::END_DEBUG_ADJ))); int(Setting::START_DEBUG_ADJ), int(Setting::END_DEBUG_ADJ)));
// skip currently non-relevant adjustments // skip currently non-relevant adjustments
skip = skipDebugSetting(); skip = skipDebugSetting();
break; break;
@ -320,222 +311,130 @@ const AdjustFunction GlobalKeyHandler::cycleAdjustSetting(int direction)
direction = 1; direction = 1;
} while(skip); } while(skip);
return getAdjustSetting(myAdjustSetting); return getSettingData(mySetting).function;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const AdjustFunction GlobalKeyHandler::getAdjustSetting(const AdjustSetting setting) const const GlobalKeyHandler::SettingData GlobalKeyHandler::getSettingData(const Setting setting) const
{ {
// Notes: // Notes:
// - All methods MUST show a message // - all setting methods MUST always display a message
// - This array MUST have the same order as AdjustSetting // - some settings reset the repeat state, therefore the code cannot detect repeats
const AdjustFunction ADJUST_FUNCTIONS[int(AdjustSetting::NUM_ADJ)] = const std::map<Setting, SettingData> SettingMap = {
{
// *** Audio & Video settings ***
std::bind(&Sound::adjustVolume, &myOSystem.sound(), _1),
std::bind(&FrameBuffer::switchVideoMode, &myOSystem.frameBuffer(), _1),
std::bind(&FrameBuffer::toggleFullscreen, &myOSystem.frameBuffer(), _1),
#ifdef ADAPTABLE_REFRESH_SUPPORT
std::bind(&FrameBuffer::toggleAdaptRefresh, &myOSystem.frameBuffer(), _1),
#endif
std::bind(&FrameBuffer::changeOverscan, &myOSystem.frameBuffer(), _1),
std::bind(&Console::selectFormat, &myOSystem.console(), _1), // property, not persisted
std::bind(&Console::changeVerticalCenter, &myOSystem.console(), _1), // property, not persisted
std::bind(&Console::toggleCorrectAspectRatio, &myOSystem.console(), _1),
std::bind(&Console::changeVSizeAdjust, &myOSystem.console(), _1),
// Palette adjustables
std::bind(&PaletteHandler::cyclePalette, &myOSystem.frameBuffer().tiaSurface().paletteHandler(), _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::PHASE_SHIFT, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::RED_SCALE, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::RED_SHIFT, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::GREEN_SCALE, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::GREEN_SHIFT, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::BLUE_SCALE, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::BLUE_SHIFT, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::HUE, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::SATURATION, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::CONTRAST, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::BRIGHTNESS, _1),
std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::GAMMA, _1),
// NTSC filter adjustables
std::bind(&TIASurface::changeNTSC, &myOSystem.frameBuffer().tiaSurface(), _1),
std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::SHARPNESS), _1),
std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::RESOLUTION), _1),
std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::ARTIFACTS), _1),
std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::FRINGING), _1),
std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::BLEEDING), _1),
std::bind(&Console::changePhosphor, &myOSystem.console(), _1),
std::bind(&TIASurface::setScanlineIntensity, &myOSystem.frameBuffer().tiaSurface(), _1),
std::bind(&Console::toggleInter, &myOSystem.console(), _1),
// *** Input settings ***
std::bind(&PhysicalJoystickHandler::changeDigitalDeadZone, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeAnalogPaddleDeadZone, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeAnalogPaddleSensitivity, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeAnalogPaddleLinearity, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changePaddleDejitterAveraging, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changePaddleDejitterReaction, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeDigitalPaddleSensitivity, &joyHandler(), _1),
std::bind(&Console::changeAutoFireRate, &myOSystem.console(), _1),
std::bind(&EventHandler::toggleAllow4JoyDirections, &myOSystem.eventHandler(), _1),
std::bind(&PhysicalKeyboardHandler::toggleModKeys, &keyHandler(), _1),
std::bind(&EventHandler::toggleSAPortOrder, &myOSystem.eventHandler(), _1),
std::bind(&EventHandler::changeMouseControllerMode, &myOSystem.eventHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeMousePaddleSensitivity, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeMouseTrackballSensitivity, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeDrivingSensitivity, &joyHandler(), _1),
std::bind(&EventHandler::changeMouseCursor, &myOSystem.eventHandler(), _1),
std::bind(&FrameBuffer::toggleGrabMouse, &myOSystem.frameBuffer(), _1),
// Game properties/Controllers
std::bind(&Console::changeLeftController, &myOSystem.console(), _1), // property, not persisted
std::bind(&Console::changeRightController, &myOSystem.console(), _1), // property, not persisted
std::bind(&Console::toggleSwapPorts, &myOSystem.console(), _1), // property, not persisted
std::bind(&Console::toggleSwapPaddles, &myOSystem.console(), _1), // property, not persisted
std::bind(&Console::changePaddleCenterX, &myOSystem.console(), _1), // property, not persisted
std::bind(&Console::changePaddleCenterY, &myOSystem.console(), _1), // property, not persisted
std::bind(&EventHandler::changeMouseControl, &myOSystem.eventHandler(), _1), // property, not persisted
std::bind(&Console::changePaddleAxesRange, &myOSystem.console(), _1), // property, not persisted
// *** Debug settings ***
std::bind(&FrameBuffer::toggleFrameStats, &myOSystem.frameBuffer(), _1),
std::bind(&Console::toggleP0Bit, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleP1Bit, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleM0Bit, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleM1Bit, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleBLBit, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::togglePFBit, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleBits, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleP0Collision, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleP1Collision, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleM0Collision, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleM1Collision, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleBLCollision, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::togglePFCollision, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleCollisions, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleFixedColors, &myOSystem.console(), _1), // debug, not persisted
std::bind(&Console::toggleColorLoss, &myOSystem.console(), _1),
std::bind(&Console::toggleJitter, &myOSystem.console(), _1),
// *** Following functions are not used when cycling settings, but for "direct only" hotkeys ***
std::bind(&StateManager::changeState, &myOSystem.state(), _1), // temporary, not persisted
std::bind(&PaletteHandler::changeCurrentAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(), _1),
std::bind(&TIASurface::changeCurrentNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(), _1),
std::bind(&Console::changeSpeed, &myOSystem.console(), _1),
};
return ADJUST_FUNCTIONS[int(setting)];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool GlobalKeyHandler::isAdjustRepeated(const AdjustSetting setting) const
{
const bool ADJUST_REPEATED[int(AdjustSetting::NUM_ADJ)] =
{
// *** Audio & Video group *** // *** Audio & Video group ***
true, // VOLUME {Setting::VOLUME, {true, std::bind(&Sound::adjustVolume, &myOSystem.sound(), _1)}},
false, // ZOOM (always repeating) {Setting::ZOOM, {false, std::bind(&FrameBuffer::switchVideoMode, &myOSystem.frameBuffer(), _1)}}, // always repeating
false, // FULLSCREEN (always repeating) {Setting::FULLSCREEN, {false, std::bind(&FrameBuffer::toggleFullscreen, &myOSystem.frameBuffer(), _1)}}, // always repeating
#ifdef ADAPTABLE_REFRESH_SUPPORT #ifdef ADAPTABLE_REFRESH_SUPPORT
false, // ADAPT_REFRESH (always repeating) {Setting::ADAPT_REFRESH, {false, std::bind(&FrameBuffer::toggleAdaptRefresh, &myOSystem.frameBuffer(), _1)}}, // always repeating
#endif #endif
true, // OVERSCAN {Setting::OVERSCAN, {true, std::bind(&FrameBuffer::changeOverscan, &myOSystem.frameBuffer(), _1)}},
false, // TVFORMAT {Setting::TVFORMAT, {false, std::bind(&Console::selectFormat, &myOSystem.console(), _1)}}, // property, not persisted
true, // VCENTER {Setting::VCENTER, {true, std::bind(&Console::changeVerticalCenter, &myOSystem.console(), _1)}}, // property, not persisted
false, // ASPECT_RATIO (always repeating) {Setting::ASPECT_RATIO, {false, std::bind(&Console::toggleCorrectAspectRatio, &myOSystem.console(), _1)}}, // always repeating
true, // VSIZE {Setting::VSIZE, {true, std::bind(&Console::changeVSizeAdjust, &myOSystem.console(), _1)}},
// Palette adjustables // Palette adjustables
false, // PALETTE {Setting::PALETTE, {false, std::bind(&PaletteHandler::cyclePalette,
true, // PALETTE_PHASE &myOSystem.frameBuffer().tiaSurface().paletteHandler(), _1)}},
true, // PALETTE_RED_SCALE {Setting::PALETTE_PHASE, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
true, // PALETTE_RED_SHIFT PaletteHandler::PHASE_SHIFT, _1)}},
true, // PALETTE_GREEN_SCALE {Setting::PALETTE_RED_SCALE, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
true, // PALETTE_GREEN_SHIFT PaletteHandler::RED_SCALE, _1)}},
true, // PALETTE_BLUE_SCALE {Setting::PALETTE_RED_SHIFT, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
true, // PALETTE_BLUE_SHIFT PaletteHandler::RED_SHIFT, _1)}},
true, // PALETTE_HUE {Setting::PALETTE_GREEN_SCALE, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
true, // PALETTE_SATURATION PaletteHandler::GREEN_SCALE, _1)}},
true, // PALETTE_CONTRAST {Setting::PALETTE_GREEN_SHIFT, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
true, // PALETTE_BRIGHTNESS PaletteHandler::GREEN_SHIFT, _1)}},
true, // PALETTE_GAMMA {Setting::PALETTE_BLUE_SCALE, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::BLUE_SCALE, _1)}},
{Setting::PALETTE_BLUE_SHIFT, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::BLUE_SHIFT, _1)}},
{Setting::PALETTE_HUE, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::HUE, _1)}},
{Setting::PALETTE_SATURATION, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::SATURATION, _1)}},
{Setting::PALETTE_CONTRAST, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::CONTRAST, _1)}},
{Setting::PALETTE_BRIGHTNESS, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::BRIGHTNESS, _1)}},
{Setting::PALETTE_GAMMA, {true, std::bind(&PaletteHandler::changeAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(),
PaletteHandler::GAMMA, _1)}},
// NTSC filter adjustables // NTSC filter adjustables
false, // NTSC_PRESET {Setting::NTSC_PRESET, {false, std::bind(&TIASurface::changeNTSC, &myOSystem.frameBuffer().tiaSurface(), _1)}},
true, // NTSC_SHARPNESS {Setting::NTSC_SHARPNESS, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
true, // NTSC_RESOLUTION int(NTSCFilter::Adjustables::SHARPNESS), _1)}},
true, // NTSC_ARTIFACTS {Setting::NTSC_RESOLUTION, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
true, // NTSC_FRINGING int(NTSCFilter::Adjustables::RESOLUTION), _1)}},
true, // NTSC_BLEEDING {Setting::NTSC_ARTIFACTS, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::ARTIFACTS), _1)}},
{Setting::NTSC_FRINGING, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::FRINGING), _1)}},
{Setting::NTSC_BLEEDING, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(),
int(NTSCFilter::Adjustables::BLEEDING), _1)}},
// Other TV effects adjustables // Other TV effects adjustables
true, // PHOSPHOR {Setting::PHOSPHOR, {true, std::bind(&Console::changePhosphor, &myOSystem.console(), _1)}},
true, // SCANLINES {Setting::SCANLINES, {true, std::bind(&TIASurface::setScanlineIntensity, &myOSystem.frameBuffer().tiaSurface(), _1)}},
false, // INTERPOLATION {Setting::INTERPOLATION, {false, std::bind(&Console::toggleInter, &myOSystem.console(), _1)}},
// *** Input group *** // *** Input group ***
true, // DEADZONE {Setting::DEADZONE, {true, std::bind(&PhysicalJoystickHandler::changeDigitalDeadZone, &joyHandler(), _1)}},
true, // ANALOG_DEADZONE {Setting::ANALOG_DEADZONE, {true, std::bind(&PhysicalJoystickHandler::changeAnalogPaddleDeadZone, &joyHandler(), _1)}},
true, // ANALOG_SENSITIVITY {Setting::ANALOG_SENSITIVITY, {true, std::bind(&PhysicalJoystickHandler::changeAnalogPaddleSensitivity, &joyHandler(), _1)}},
true, // ANALOG_LINEARITY {Setting::ANALOG_LINEARITY, {true, std::bind(&PhysicalJoystickHandler::changeAnalogPaddleLinearity, &joyHandler(), _1)}},
true, // DEJITTER_AVERAGING {Setting::DEJITTER_AVERAGING, {true, std::bind(&PhysicalJoystickHandler::changePaddleDejitterAveraging, &joyHandler(), _1)}},
true, // DEJITTER_REACTION {Setting::DEJITTER_REACTION, {true, std::bind(&PhysicalJoystickHandler::changePaddleDejitterReaction, &joyHandler(), _1)}},
true, // DIGITAL_SENSITIVITY {Setting::DIGITAL_SENSITIVITY, {true, std::bind(&PhysicalJoystickHandler::changeDigitalPaddleSensitivity, &joyHandler(), _1)}},
true, // AUTO_FIRE {Setting::AUTO_FIRE, {true, std::bind(&Console::changeAutoFireRate, &myOSystem.console(), _1)}},
false, // FOUR_DIRECTIONS {Setting::FOUR_DIRECTIONS, {false, std::bind(&EventHandler::toggleAllow4JoyDirections, &myOSystem.eventHandler(), _1)}},
false, // MOD_KEY_COMBOS {Setting::MOD_KEY_COMBOS, {false, std::bind(&PhysicalKeyboardHandler::toggleModKeys, &keyHandler(), _1)}},
false, // SA_PORT_ORDER {Setting::SA_PORT_ORDER, {false, std::bind(&EventHandler::toggleSAPortOrder, &myOSystem.eventHandler(), _1)}},
false, // USE_MOUSE {Setting::USE_MOUSE, {false, std::bind(&EventHandler::changeMouseControllerMode, &myOSystem.eventHandler(), _1)}},
true, // PADDLE_SENSITIVITY {Setting::PADDLE_SENSITIVITY, {true, std::bind(&PhysicalJoystickHandler::changeMousePaddleSensitivity, &joyHandler(), _1)}},
true, // TRACKBALL_SENSITIVITY {Setting::TRACKBALL_SENSITIVITY, {true, std::bind(&PhysicalJoystickHandler::changeMouseTrackballSensitivity, &joyHandler(), _1)}},
true, // DRIVING_SENSITIVITY {Setting::DRIVING_SENSITIVITY, {true, std::bind(&PhysicalJoystickHandler::changeDrivingSensitivity, &joyHandler(), _1)}},
false, // MOUSE_CURSOR {Setting::MOUSE_CURSOR, {false, std::bind(&EventHandler::changeMouseCursor, &myOSystem.eventHandler(), _1)}},
false, // GRAB_MOUSE {Setting::GRAB_MOUSE, {false, std::bind(&FrameBuffer::toggleGrabMouse, &myOSystem.frameBuffer(), _1)}},
false, // LEFT_PORT // Game properties/Controllers
false, // RIGHT_PORT {Setting::LEFT_PORT, {false, std::bind(&Console::changeLeftController, &myOSystem.console(), _1)}}, // property, not persisted
false, // SWAP_PORTS {Setting::RIGHT_PORT, {false, std::bind(&Console::changeRightController, &myOSystem.console(), _1)}}, // property, not persisted
false, // SWAP_PADDLES {Setting::SWAP_PORTS, {false, std::bind(&Console::toggleSwapPorts, &myOSystem.console(), _1)}}, // property, not persisted
true, // PADDLE_CENTER_X {Setting::SWAP_PADDLES, {false, std::bind(&Console::toggleSwapPaddles, &myOSystem.console(), _1)}}, // property, not persisted
true, // PADDLE_CENTER_Y {Setting::PADDLE_CENTER_X, {true, std::bind(&Console::changePaddleCenterX, &myOSystem.console(), _1)}}, // property, not persisted
false, // MOUSE_CONTROL {Setting::PADDLE_CENTER_Y, {true, std::bind(&Console::changePaddleCenterY, &myOSystem.console(), _1)}}, // property, not persisted
true, // MOUSE_RANGE {Setting::MOUSE_CONTROL, {false, std::bind(&EventHandler::changeMouseControl, &myOSystem.eventHandler(), _1)}}, // property, not persisted
{Setting::MOUSE_RANGE, {true, std::bind(&Console::changePaddleAxesRange, &myOSystem.console(), _1)}}, // property, not persisted
// *** Debug group *** // *** Debug group ***
false, // STATS {Setting::STATS, {false, std::bind(&FrameBuffer::toggleFrameStats, &myOSystem.frameBuffer(), _1)}},
false, // P0_ENAM {Setting::P0_ENAM, {false, std::bind(&Console::toggleP0Bit, &myOSystem.console(), _1)}}, // debug, not persisted
false, // P1_ENAM {Setting::P1_ENAM, {false, std::bind(&Console::toggleP1Bit, &myOSystem.console(), _1)}}, // debug, not persisted
false, // M0_ENAM {Setting::M0_ENAM, {false, std::bind(&Console::toggleM0Bit, &myOSystem.console(), _1)}}, // debug, not persisted
false, // M1_ENAM {Setting::M1_ENAM, {false, std::bind(&Console::toggleM1Bit, &myOSystem.console(), _1)}}, // debug, not persisted
false, // BL_ENAM {Setting::BL_ENAM, {false, std::bind(&Console::toggleBLBit, &myOSystem.console(), _1)}}, // debug, not persisted
false, // PF_ENAM {Setting::PF_ENAM, {false, std::bind(&Console::togglePFBit, &myOSystem.console(), _1)}}, // debug, not persisted
false, // ALL_ENAM {Setting::ALL_ENAM, {false, std::bind(&Console::toggleBits, &myOSystem.console(), _1)}}, // debug, not persisted
false, // P0_CX {Setting::P0_CX, {false, std::bind(&Console::toggleP0Collision, &myOSystem.console(), _1)}}, // debug, not persisted
false, // P1_CX {Setting::P1_CX, {false, std::bind(&Console::toggleP1Collision, &myOSystem.console(), _1)}}, // debug, not persisted
false, // M0_CX {Setting::M0_CX, {false, std::bind(&Console::toggleM0Collision, &myOSystem.console(), _1)}}, // debug, not persisted
false, // M1_CX {Setting::M1_CX, {false, std::bind(&Console::toggleM1Collision, &myOSystem.console(), _1)}}, // debug, not persisted
false, // BL_CX {Setting::BL_CX, {false, std::bind(&Console::toggleBLCollision, &myOSystem.console(), _1)}}, // debug, not persisted
false, // PF_CX {Setting::PF_CX, {false, std::bind(&Console::togglePFCollision, &myOSystem.console(), _1)}}, // debug, not persisted
false, // ALL_CX {Setting::ALL_CX, {false, std::bind(&Console::toggleCollisions, &myOSystem.console(), _1)}}, // debug, not persisted
false, // FIXED_COL {Setting::FIXED_COL, {false, std::bind(&Console::toggleFixedColors, &myOSystem.console(), _1)}}, // debug, not persisted
false, // COLOR_LOSS {Setting::COLOR_LOSS, {false, std::bind(&Console::toggleColorLoss, &myOSystem.console(), _1)}},
false, // JITTER {Setting::JITTER, {false, std::bind(&Console::toggleJitter, &myOSystem.console(), _1)}},
// *** Only used via direct hotkeys *** // *** Following functions are not used when cycling settings, but for "direct only" hotkeys ***
true, // STATE {Setting::STATE, {true, std::bind(&StateManager::changeState, &myOSystem.state(), _1)}}, // temporary, not persisted
true, // PALETTE_CHANGE_ATTRIBUTE {Setting::PALETTE_ATTRIBUTE, {true, std::bind(&PaletteHandler::changeCurrentAdjustable, &myOSystem.frameBuffer().tiaSurface().paletteHandler(), _1)}},
true, // NTSC_CHANGE_ATTRIBUTE {Setting::NTSC_ATTRIBUTE, {true, std::bind(&TIASurface::changeCurrentNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(), _1)}},
true, // CHANGE_SPEED {Setting::CHANGE_SPEED, {true, std::bind(&Console::changeSpeed, &myOSystem.console(), _1)}},
}; };
const auto result = SettingMap.find(setting);
return ADJUST_REPEATED[int(setting)]; if(result != SettingMap.end())
return result->second;
else
{
cerr << "Error: setting " << int(setting) << " missing in SettingMap!" << endl;
return SettingMap.find(Setting::VOLUME)->second; // default function!
}
} }

View File

@ -31,7 +31,7 @@ class GlobalKeyHandler
GlobalKeyHandler(OSystem& osystem); GlobalKeyHandler(OSystem& osystem);
public: public:
enum class AdjustSetting enum class Setting
{ {
NONE = -1, NONE = -1,
// *** Audio & Video group *** // *** Audio & Video group ***
@ -118,8 +118,8 @@ class GlobalKeyHandler
JITTER, JITTER,
// *** Only used via direct hotkeys *** // *** Only used via direct hotkeys ***
STATE, STATE,
PALETTE_CHANGE_ATTRIBUTE, PALETTE_ATTRIBUTE,
NTSC_CHANGE_ATTRIBUTE, NTSC_ATTRIBUTE,
CHANGE_SPEED, CHANGE_SPEED,
// *** Ranges *** // *** Ranges ***
NUM_ADJ, NUM_ADJ,
@ -133,11 +133,13 @@ class GlobalKeyHandler
public: public:
bool handleEvent(const Event::Type event, bool pressed, bool repeated); bool handleEvent(const Event::Type event, bool pressed, bool repeated);
void setAdjustSetting(const AdjustSetting setting); void setSetting(const Setting setting);
void setAdjustDirect(const AdjustSetting setting); void setDirectSetting(const Setting setting);
private: private:
enum class AdjustGroup using Function = std::function<void(int)>;
enum class Group
{ {
AV, AV,
INPUT, INPUT,
@ -145,18 +147,30 @@ class GlobalKeyHandler
NUM_GROUPS NUM_GROUPS
}; };
struct GroupData
{
Setting start{Setting::NONE};
string name{EmptyString};
};
struct SettingData
{
bool repeated{true};
Function function{nullptr};
};
private: private:
// The following methods are used for adjusting several settings using global hotkeys // Get group based on given setting
// They return the function used to adjust the currenly selected setting const Group getGroup() const;
const AdjustGroup getAdjustGroup() const; // Cycle settings using given direction (can be 0)
const AdjustFunction cycleAdjustSetting(int direction); const Function cycleSetting(int direction);
const AdjustFunction getAdjustSetting(const AdjustSetting setting) const; // Get adjustment function and if it is repeated
// Check if the current adjustment should be repeated const SettingData getSettingData(const Setting setting) const;
bool isAdjustRepeated(const AdjustSetting setting) const;
PhysicalJoystickHandler& joyHandler() const { return myOSystem.eventHandler().joyHandler(); } PhysicalJoystickHandler& joyHandler() const { return myOSystem.eventHandler().joyHandler(); }
PhysicalKeyboardHandler& keyHandler() const { return myOSystem.eventHandler().keyHandler(); } PhysicalKeyboardHandler& keyHandler() const { return myOSystem.eventHandler().keyHandler(); }
// Check if controller type is used (skips related input settings if not)
bool isJoystick(const Controller& controller) const; bool isJoystick(const Controller& controller) const;
bool isPaddle(const Controller& controller) const; bool isPaddle(const Controller& controller) const;
bool isTrackball(const Controller& controller) const; bool isTrackball(const Controller& controller) const;
@ -171,13 +185,16 @@ class GlobalKeyHandler
OSystem& myOSystem; OSystem& myOSystem;
// If true, the setting's message is visible and its value can be changed // If true, the setting's message is visible and its value can be changed
bool myAdjustActive{false}; bool mySettingActive{false};
// ID of the currently selected global setting // Currently selected setting
AdjustSetting myAdjustSetting{AdjustSetting::START_AV_ADJ}; Setting mySetting{Setting::VOLUME};
// ID of the currently selected direct hotkey setting (0 if none) // Currently selected direct setting (0 if none). These settings are not
AdjustSetting myAdjustDirect{AdjustSetting::NONE}; // selected using global hotkeys, but direct hotkeys only. Nevertheless
// they can be changed with global hotkeys while their message is still
// displayed
Setting myDirectSetting{Setting::NONE};
}; };
#endif #endif