refactored/renamed key state parameters (pressed vs. released)

This commit is contained in:
thrust26 2019-03-29 23:49:29 +01:00
parent 0666be24e6
commit 39884db86f
12 changed files with 102 additions and 101 deletions

View File

@ -123,7 +123,7 @@ void EventHandlerSDL2::pollEvent()
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
{ {
handleJoyBtnEvent(myEvent.jbutton.which, myEvent.jbutton.button, handleJoyBtnEvent(myEvent.jbutton.which, myEvent.jbutton.button,
myEvent.jbutton.state == SDL_PRESSED ? 1 : 0); myEvent.jbutton.state == SDL_PRESSED);
break; break;
} }
@ -165,7 +165,7 @@ void EventHandlerSDL2::pollEvent()
case SDL_QUIT: case SDL_QUIT:
{ {
handleEvent(Event::Quit, 1); handleEvent(Event::Quit);
break; // SDL_QUIT break; // SDL_QUIT
} }

View File

@ -528,9 +528,9 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
{ {
// Otherwise, we know the event is digital // Otherwise, we know the event is digital
if(value > Joystick::deadzone()) if(value > Joystick::deadzone())
myHandler.handleEvent(eventAxisPos, 1); myHandler.handleEvent(eventAxisPos);
else if(value < -Joystick::deadzone()) else if(value < -Joystick::deadzone())
myHandler.handleEvent(eventAxisNeg, 1); myHandler.handleEvent(eventAxisNeg);
else else
{ {
// Treat any deadzone value as zero // Treat any deadzone value as zero
@ -542,8 +542,8 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
{ {
// Turn off both events, since we don't know exactly which one // Turn off both events, since we don't know exactly which one
// was previously activated. // was previously activated.
myHandler.handleEvent(eventAxisNeg, 0); myHandler.handleEvent(eventAxisNeg, false);
myHandler.handleEvent(eventAxisPos, 0); myHandler.handleEvent(eventAxisPos, false);
} }
} }
j->axisLastValue[axis] = value; j->axisLastValue[axis] = value;
@ -593,7 +593,7 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, uInt8 state) void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed)
{ {
const PhysicalJoystickPtr j = joy(stick); const PhysicalJoystickPtr j = joy(stick);
if(!j) return; if(!j) return;
@ -603,14 +603,14 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, uInt8 state)
{ {
case PhysicalJoystick::JT_REGULAR: case PhysicalJoystick::JT_REGULAR:
// Handle buttons which switch eventhandler state // Handle buttons which switch eventhandler state
if(state && myHandler.changeStateByEvent(j->btnTable[button][kEmulationMode])) if(pressed && myHandler.changeStateByEvent(j->btnTable[button][kEmulationMode]))
return; return;
// Determine which mode we're in, then send the event to the appropriate place // Determine which mode we're in, then send the event to the appropriate place
if(myHandler.state() == EventHandlerState::EMULATION) if(myHandler.state() == EventHandlerState::EMULATION)
myHandler.handleEvent(j->btnTable[button][kEmulationMode], state); myHandler.handleEvent(j->btnTable[button][kEmulationMode], pressed);
else if(myHandler.hasOverlay()) else if(myHandler.hasOverlay())
myHandler.overlay().handleJoyBtnEvent(stick, button, state); myHandler.overlay().handleJoyBtnEvent(stick, button, pressed);
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
@ -620,7 +620,7 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, uInt8 state)
// The 'type-2' here refers to the fact that 'PhysicalJoystick::JT_STELLADAPTOR_LEFT' // The 'type-2' here refers to the fact that 'PhysicalJoystick::JT_STELLADAPTOR_LEFT'
// and 'PhysicalJoystick::JT_STELLADAPTOR_RIGHT' are at index 2 and 3 in the JoyType // and 'PhysicalJoystick::JT_STELLADAPTOR_RIGHT' are at index 2 and 3 in the JoyType
// enum; subtracting two gives us Controller 0 and 1 // enum; subtracting two gives us Controller 0 and 1
if(button < 2) myEvent.set(SA_Button[j->type-2][button], state); if(button < 2) myEvent.set(SA_Button[j->type-2][button], pressed ? 1 : 0);
break; // Stelladaptor button break; // Stelladaptor button
case PhysicalJoystick::JT_2600DAPTOR_LEFT: case PhysicalJoystick::JT_2600DAPTOR_LEFT:
case PhysicalJoystick::JT_2600DAPTOR_RIGHT: case PhysicalJoystick::JT_2600DAPTOR_RIGHT:
@ -632,18 +632,18 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, uInt8 state)
switch(myOSystem.console().leftController().type()) switch(myOSystem.console().leftController().type())
{ {
case Controller::Keyboard: case Controller::Keyboard:
if(button < 12) myEvent.set(SA_Key[j->type-4][button], state); if(button < 12) myEvent.set(SA_Key[j->type-4][button], pressed ? 1 : 0);
break; break;
default: default:
if(button < 4) myEvent.set(SA_Button[j->type-4][button], state); if(button < 4) myEvent.set(SA_Button[j->type-4][button], pressed ? 1 : 0);
} }
switch(myOSystem.console().rightController().type()) switch(myOSystem.console().rightController().type())
{ {
case Controller::Keyboard: case Controller::Keyboard:
if(button < 12) myEvent.set(SA_Key[j->type-4][button], state); if(button < 12) myEvent.set(SA_Key[j->type-4][button], pressed ? 1 : 0);
break; break;
default: default:
if(button < 4) myEvent.set(SA_Button[j->type-4][button], state); if(button < 4) myEvent.set(SA_Button[j->type-4][button], pressed ? 1 : 0);
} }
} }
break; // 2600DAPTOR button break; // 2600DAPTOR button

View File

@ -80,7 +80,7 @@ class PhysicalJoystickHandler
/** Handle a physical joystick event. */ /** Handle a physical joystick event. */
void handleAxisEvent(int stick, int axis, int value); void handleAxisEvent(int stick, int axis, int value);
void handleBtnEvent(int stick, int button, uInt8 state); void handleBtnEvent(int stick, int button, bool pressed);
void handleHatEvent(int stick, int hat, int value); void handleHatEvent(int stick, int hat, int value);
Event::Type eventForAxis(int stick, int axis, int value, EventMode mode) const { Event::Type eventForAxis(int stick, int axis, int value, EventMode mode) const {

View File

@ -237,7 +237,7 @@ bool PhysicalKeyboardHandler::addMapping(Event::Type event, EventMode mode,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool state) void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool pressed)
{ {
// Swallow KBDK_TAB under certain conditions // Swallow KBDK_TAB under certain conditions
// See commments on 'myAltKeyCounter' for more information // See commments on 'myAltKeyCounter' for more information
@ -253,17 +253,17 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
EventHandlerState estate = myHandler.state(); EventHandlerState estate = myHandler.state();
// Immediately store the key state // Immediately store the key state
myEvent.setKey(key, state); myEvent.setKey(key, pressed);
// An attempt to speed up event processing; we quickly check for // An attempt to speed up event processing; we quickly check for
// Control or Alt/Cmd combos first // Control or Alt/Cmd combos first
if(StellaModTest::isAlt(mod) && state) if(StellaModTest::isAlt(mod) && pressed)
{ {
#ifdef BSPF_MACOS #ifdef BSPF_MACOS
// These keys work in all states // These keys work in all states
if(key == KBDK_Q) if(key == KBDK_Q)
{ {
myHandler.handleEvent(Event::Quit, 1); myHandler.handleEvent(Event::Quit);
} }
else else
#endif #endif
@ -283,11 +283,12 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
switch(key) switch(key)
{ {
case KBDK_LEFT: // Alt-left(-shift) rewinds 1(10) states case KBDK_LEFT: // Alt-left(-shift) rewinds 1(10) states
myHandler.enterTimeMachineMenuMode((StellaModTest::isShift(mod) && state) ? 10 : 1, false); //if (!myEvent.getKeys()[KBDK_SPACE])
myHandler.enterTimeMachineMenuMode((StellaModTest::isShift(mod) && pressed) ? 10 : 1, false);
break; break;
case KBDK_RIGHT: // Alt-right(-shift) unwinds 1(10) states case KBDK_RIGHT: // Alt-right(-shift) unwinds 1(10) states
myHandler.enterTimeMachineMenuMode((StellaModTest::isShift(mod) && state) ? 10 : 1, true); myHandler.enterTimeMachineMenuMode((StellaModTest::isShift(mod) && pressed) ? 10 : 1, true);
break; break;
case KBDK_DOWN: // Alt-down rewinds to start of list case KBDK_DOWN: // Alt-down rewinds to start of list
@ -471,12 +472,12 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
else else
handled = false; handled = false;
} }
else if(StellaModTest::isControl(mod) && state && myUseCtrlKeyFlag) else if(StellaModTest::isControl(mod) && pressed && myUseCtrlKeyFlag)
{ {
// These keys work in all states // These keys work in all states
if(key == KBDK_Q) if(key == KBDK_Q)
{ {
myHandler.handleEvent(Event::Quit, 1); myHandler.handleEvent(Event::Quit);
} }
// These only work when in emulation mode // These only work when in emulation mode
else if(estate == EventHandlerState::EMULATION || estate == EventHandlerState::PAUSE) else if(estate == EventHandlerState::EMULATION || estate == EventHandlerState::PAUSE)
@ -539,7 +540,7 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
{ {
// Special handling for Escape key // Special handling for Escape key
// Basically, exit whichever mode we're currently in // Basically, exit whichever mode we're currently in
if(state && key == KBDK_ESCAPE) if(pressed && key == KBDK_ESCAPE)
{ {
switch(estate) switch(estate)
{ {
@ -563,7 +564,7 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
} }
// Handle keys which switch eventhandler state // Handle keys which switch eventhandler state
if(!state && myHandler.changeStateByEvent(myKeyTable[key][kEmulationMode])) if(!pressed && myHandler.changeStateByEvent(myKeyTable[key][kEmulationMode]))
return; return;
} }
@ -571,7 +572,7 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
switch(estate) switch(estate)
{ {
case EventHandlerState::EMULATION: case EventHandlerState::EMULATION:
myHandler.handleEvent(myKeyTable[key][kEmulationMode], state); myHandler.handleEvent(myKeyTable[key][kEmulationMode], pressed);
break; break;
case EventHandlerState::PAUSE: case EventHandlerState::PAUSE:
@ -579,7 +580,7 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
{ {
case Event::TakeSnapshot: case Event::TakeSnapshot:
case Event::DebuggerMode: case Event::DebuggerMode:
myHandler.handleEvent(myKeyTable[key][kEmulationMode], state); myHandler.handleEvent(myKeyTable[key][kEmulationMode], pressed);
break; break;
default: default:
@ -589,7 +590,7 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool sta
default: default:
if(myHandler.hasOverlay()) if(myHandler.hasOverlay())
myHandler.overlay().handleKeyEvent(key, mod, state); myHandler.overlay().handleKeyEvent(key, mod, pressed);
break; break;
} }
} }

View File

@ -52,7 +52,7 @@ class PhysicalKeyboardHandler
bool addMapping(Event::Type event, EventMode mode, StellaKey key); bool addMapping(Event::Type event, EventMode mode, StellaKey key);
/** Handle a physical keyboard event. */ /** Handle a physical keyboard event. */
void handleEvent(StellaKey key, StellaMod mod, bool state); void handleEvent(StellaKey key, StellaMod mod, bool pressed);
Event::Type eventForKey(StellaKey key, EventMode mode) const { Event::Type eventForKey(StellaKey key, EventMode mode) const {
return myKeyTable[key][mode]; return myKeyTable[key][mode];

View File

@ -154,7 +154,7 @@ bool Debugger::startWithFatalError(const string& message)
void Debugger::quit(bool exitrom) void Debugger::quit(bool exitrom)
{ {
if(exitrom) if(exitrom)
myOSystem.eventHandler().handleEvent(Event::LauncherMode, 1); myOSystem.eventHandler().handleEvent(Event::LauncherMode, true);
else else
{ {
myOSystem.eventHandler().leaveDebugMode(); myOSystem.eventHandler().leaveDebugMode();

View File

@ -160,10 +160,10 @@ class Event
/** /**
Set the value associated with the event of the specified type. Set the value associated with the event of the specified type.
*/ */
void setKey(StellaKey key, bool state) { void setKey(StellaKey key, bool pressed) {
std::lock_guard<std::mutex> lock(myMutex); std::lock_guard<std::mutex> lock(myMutex);
myKeyTable[key] = state; myKeyTable[key] = pressed;
} }
/** /**

View File

@ -312,7 +312,7 @@ void EventHandler::handleSystemEvent(SystemEvent e, int, int)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleEvent(Event::Type event, Int32 state) void EventHandler::handleEvent(Event::Type event, bool pressed)
{ {
// Take care of special events that aren't part of the emulation core // Take care of special events that aren't part of the emulation core
// or need to be preprocessed before passing them on // or need to be preprocessed before passing them on
@ -321,93 +321,93 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// If enabled, make sure 'impossible' joystick directions aren't allowed // If enabled, make sure 'impossible' joystick directions aren't allowed
case Event::JoystickZeroUp: case Event::JoystickZeroUp:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickZeroDown, 0); myEvent.set(Event::JoystickZeroDown, 0);
break; break;
case Event::JoystickZeroDown: case Event::JoystickZeroDown:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickZeroUp, 0); myEvent.set(Event::JoystickZeroUp, 0);
break; break;
case Event::JoystickZeroLeft: case Event::JoystickZeroLeft:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickZeroRight, 0); myEvent.set(Event::JoystickZeroRight, 0);
break; break;
case Event::JoystickZeroRight: case Event::JoystickZeroRight:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickZeroLeft, 0); myEvent.set(Event::JoystickZeroLeft, 0);
break; break;
case Event::JoystickOneUp: case Event::JoystickOneUp:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickOneDown, 0); myEvent.set(Event::JoystickOneDown, 0);
break; break;
case Event::JoystickOneDown: case Event::JoystickOneDown:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickOneUp, 0); myEvent.set(Event::JoystickOneUp, 0);
break; break;
case Event::JoystickOneLeft: case Event::JoystickOneLeft:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickOneRight, 0); myEvent.set(Event::JoystickOneRight, 0);
break; break;
case Event::JoystickOneRight: case Event::JoystickOneRight:
if(!myAllowAllDirectionsFlag && state) if(!myAllowAllDirectionsFlag && pressed)
myEvent.set(Event::JoystickOneLeft, 0); myEvent.set(Event::JoystickOneLeft, 0);
break; break;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
case Event::Fry: case Event::Fry:
if(myPKeyHandler->useCtrlKey()) myFryingFlag = bool(state); if(myPKeyHandler->useCtrlKey()) myFryingFlag = bool(pressed);
return; return;
case Event::VolumeDecrease: case Event::VolumeDecrease:
if(state) myOSystem.sound().adjustVolume(-1); if(pressed) myOSystem.sound().adjustVolume(-1);
return; return;
case Event::VolumeIncrease: case Event::VolumeIncrease:
if(state) myOSystem.sound().adjustVolume(+1); if(pressed) myOSystem.sound().adjustVolume(+1);
return; return;
case Event::SoundToggle: case Event::SoundToggle:
if(state) myOSystem.sound().toggleMute(); if(pressed) myOSystem.sound().toggleMute();
return; return;
case Event::SaveState: case Event::SaveState:
if(state) myOSystem.state().saveState(); if(pressed) myOSystem.state().saveState();
return; return;
case Event::ChangeState: case Event::ChangeState:
if(state) myOSystem.state().changeState(); if(pressed) myOSystem.state().changeState();
return; return;
case Event::LoadState: case Event::LoadState:
if(state) myOSystem.state().loadState(); if(pressed) myOSystem.state().loadState();
return; return;
case Event::TakeSnapshot: case Event::TakeSnapshot:
if(state) myOSystem.frameBuffer().tiaSurface().saveSnapShot(); if(pressed) myOSystem.frameBuffer().tiaSurface().saveSnapShot();
return; return;
case Event::LauncherMode: case Event::LauncherMode:
if((myState == EventHandlerState::EMULATION || myState == EventHandlerState::CMDMENU || if((myState == EventHandlerState::EMULATION || myState == EventHandlerState::CMDMENU ||
myState == EventHandlerState::DEBUGGER) && state) myState == EventHandlerState::DEBUGGER) && pressed)
{ {
// Go back to the launcher, or immediately quit // Go back to the launcher, or immediately quit
if(myOSystem.settings().getBool("exitlauncher") || if(myOSystem.settings().getBool("exitlauncher") ||
myOSystem.launcherUsed()) myOSystem.launcherUsed())
myOSystem.createLauncher(); myOSystem.createLauncher();
else else
handleEvent(Event::Quit, 1); handleEvent(Event::Quit);
} }
return; return;
case Event::Quit: case Event::Quit:
if(state) if(pressed)
{ {
saveKeyMapping(); saveKeyMapping();
saveJoyMapping(); saveJoyMapping();
@ -436,28 +436,28 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
case Event::Combo16: case Event::Combo16:
for(int i = 0, combo = event - Event::Combo1; i < kEventsPerCombo; ++i) for(int i = 0, combo = event - Event::Combo1; i < kEventsPerCombo; ++i)
if(myComboTable[combo][i] != Event::NoType) if(myComboTable[combo][i] != Event::NoType)
handleEvent(myComboTable[combo][i], state); handleEvent(myComboTable[combo][i], pressed);
return; return;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Events which relate to switches() // Events which relate to switches()
case Event::ConsoleColor: case Event::ConsoleColor:
if(state) if(pressed)
{ {
myEvent.set(Event::ConsoleBlackWhite, 0); myEvent.set(Event::ConsoleBlackWhite, 0);
myOSystem.frameBuffer().showMessage(myIs7800 ? "Pause released" : "Color Mode"); myOSystem.frameBuffer().showMessage(myIs7800 ? "Pause released" : "Color Mode");
} }
break; break;
case Event::ConsoleBlackWhite: case Event::ConsoleBlackWhite:
if(state) if(pressed)
{ {
myEvent.set(Event::ConsoleColor, 0); myEvent.set(Event::ConsoleColor, 0);
myOSystem.frameBuffer().showMessage(myIs7800 ? "Pause pushed" : "B/W Mode"); myOSystem.frameBuffer().showMessage(myIs7800 ? "Pause pushed" : "B/W Mode");
} }
break; break;
case Event::ConsoleColorToggle: case Event::ConsoleColorToggle:
if(state) if(pressed)
{ {
if(myOSystem.console().switches().tvColor()) if(myOSystem.console().switches().tvColor())
{ {
@ -476,7 +476,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
return; return;
case Event::Console7800Pause: case Event::Console7800Pause:
if(state) if(pressed)
{ {
myEvent.set(Event::ConsoleBlackWhite, 0); myEvent.set(Event::ConsoleBlackWhite, 0);
myEvent.set(Event::ConsoleColor, 0); myEvent.set(Event::ConsoleColor, 0);
@ -486,21 +486,21 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
break; break;
case Event::ConsoleLeftDiffA: case Event::ConsoleLeftDiffA:
if(state) if(pressed)
{ {
myEvent.set(Event::ConsoleLeftDiffB, 0); myEvent.set(Event::ConsoleLeftDiffB, 0);
myOSystem.frameBuffer().showMessage("Left Difficulty A"); myOSystem.frameBuffer().showMessage("Left Difficulty A");
} }
break; break;
case Event::ConsoleLeftDiffB: case Event::ConsoleLeftDiffB:
if(state) if(pressed)
{ {
myEvent.set(Event::ConsoleLeftDiffA, 0); myEvent.set(Event::ConsoleLeftDiffA, 0);
myOSystem.frameBuffer().showMessage("Left Difficulty B"); myOSystem.frameBuffer().showMessage("Left Difficulty B");
} }
break; break;
case Event::ConsoleLeftDiffToggle: case Event::ConsoleLeftDiffToggle:
if(state) if(pressed)
{ {
if(myOSystem.console().switches().leftDifficultyA()) if(myOSystem.console().switches().leftDifficultyA())
{ {
@ -519,21 +519,21 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
return; return;
case Event::ConsoleRightDiffA: case Event::ConsoleRightDiffA:
if(state) if(pressed)
{ {
myEvent.set(Event::ConsoleRightDiffB, 0); myEvent.set(Event::ConsoleRightDiffB, 0);
myOSystem.frameBuffer().showMessage("Right Difficulty A"); myOSystem.frameBuffer().showMessage("Right Difficulty A");
} }
break; break;
case Event::ConsoleRightDiffB: case Event::ConsoleRightDiffB:
if(state) if(pressed)
{ {
myEvent.set(Event::ConsoleRightDiffA, 0); myEvent.set(Event::ConsoleRightDiffA, 0);
myOSystem.frameBuffer().showMessage("Right Difficulty B"); myOSystem.frameBuffer().showMessage("Right Difficulty B");
} }
break; break;
case Event::ConsoleRightDiffToggle: case Event::ConsoleRightDiffToggle:
if(state) if(pressed)
{ {
if(myOSystem.console().switches().rightDifficultyA()) if(myOSystem.console().switches().rightDifficultyA())
{ {
@ -560,7 +560,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
} }
// Otherwise, pass it to the emulation core // Otherwise, pass it to the emulation core
myEvent.set(event, state); myEvent.set(event, pressed);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -569,40 +569,40 @@ void EventHandler::handleConsoleStartupEvents()
bool update = false; bool update = false;
if(myOSystem.settings().getBool("holdreset")) if(myOSystem.settings().getBool("holdreset"))
{ {
handleEvent(Event::ConsoleReset, 1); handleEvent(Event::ConsoleReset);
update = true; update = true;
} }
if(myOSystem.settings().getBool("holdselect")) if(myOSystem.settings().getBool("holdselect"))
{ {
handleEvent(Event::ConsoleSelect, 1); handleEvent(Event::ConsoleSelect);
update = true; update = true;
} }
const string& holdjoy0 = myOSystem.settings().getString("holdjoy0"); const string& holdjoy0 = myOSystem.settings().getString("holdjoy0");
update = update || holdjoy0 != ""; update = update || holdjoy0 != "";
if(BSPF::containsIgnoreCase(holdjoy0, "U")) if(BSPF::containsIgnoreCase(holdjoy0, "U"))
handleEvent(Event::JoystickZeroUp, 1); handleEvent(Event::JoystickZeroUp);
if(BSPF::containsIgnoreCase(holdjoy0, "D")) if(BSPF::containsIgnoreCase(holdjoy0, "D"))
handleEvent(Event::JoystickZeroDown, 1); handleEvent(Event::JoystickZeroDown);
if(BSPF::containsIgnoreCase(holdjoy0, "L")) if(BSPF::containsIgnoreCase(holdjoy0, "L"))
handleEvent(Event::JoystickZeroLeft, 1); handleEvent(Event::JoystickZeroLeft);
if(BSPF::containsIgnoreCase(holdjoy0, "R")) if(BSPF::containsIgnoreCase(holdjoy0, "R"))
handleEvent(Event::JoystickZeroRight, 1); handleEvent(Event::JoystickZeroRight);
if(BSPF::containsIgnoreCase(holdjoy0, "F")) if(BSPF::containsIgnoreCase(holdjoy0, "F"))
handleEvent(Event::JoystickZeroFire, 1); handleEvent(Event::JoystickZeroFire);
const string& holdjoy1 = myOSystem.settings().getString("holdjoy1"); const string& holdjoy1 = myOSystem.settings().getString("holdjoy1");
update = update || holdjoy1 != ""; update = update || holdjoy1 != "";
if(BSPF::containsIgnoreCase(holdjoy1, "U")) if(BSPF::containsIgnoreCase(holdjoy1, "U"))
handleEvent(Event::JoystickOneUp, 1); handleEvent(Event::JoystickOneUp);
if(BSPF::containsIgnoreCase(holdjoy1, "D")) if(BSPF::containsIgnoreCase(holdjoy1, "D"))
handleEvent(Event::JoystickOneDown, 1); handleEvent(Event::JoystickOneDown);
if(BSPF::containsIgnoreCase(holdjoy1, "L")) if(BSPF::containsIgnoreCase(holdjoy1, "L"))
handleEvent(Event::JoystickOneLeft, 1); handleEvent(Event::JoystickOneLeft);
if(BSPF::containsIgnoreCase(holdjoy1, "R")) if(BSPF::containsIgnoreCase(holdjoy1, "R"))
handleEvent(Event::JoystickOneRight, 1); handleEvent(Event::JoystickOneRight);
if(BSPF::containsIgnoreCase(holdjoy1, "F")) if(BSPF::containsIgnoreCase(holdjoy1, "F"))
handleEvent(Event::JoystickOneFire, 1); handleEvent(Event::JoystickOneFire);
if(update) if(update)
myOSystem.console().riot().update(); myOSystem.console().riot().update();

View File

@ -115,7 +115,7 @@ class EventHandler
/** /**
This method indicates that the system should terminate. This method indicates that the system should terminate.
*/ */
void quit() { handleEvent(Event::Quit, 1); } void quit() { handleEvent(Event::Quit, true); }
/** /**
Sets the mouse axes and buttons to act as the controller specified in Sets the mouse axes and buttons to act as the controller specified in
@ -137,10 +137,10 @@ class EventHandler
Send an event directly to the event handler. Send an event directly to the event handler.
These events cannot be remapped. These events cannot be remapped.
@param type The event @param type The event
@param value The value for the event @param pressed Pressed (true) or released (false)
*/ */
void handleEvent(Event::Type type, Int32 value); void handleEvent(Event::Type type, bool pressed = true);
/** /**
Handle events that must be processed each time a new console is Handle events that must be processed each time a new console is
@ -314,11 +314,11 @@ class EventHandler
void handleTextEvent(char text); void handleTextEvent(char text);
void handleMouseMotionEvent(int x, int y, int xrel, int yrel); void handleMouseMotionEvent(int x, int y, int xrel, int yrel);
void handleMouseButtonEvent(MouseButton b, bool pressed, int x, int y); void handleMouseButtonEvent(MouseButton b, bool pressed, int x, int y);
void handleKeyEvent(StellaKey key, StellaMod mod, bool state) { void handleKeyEvent(StellaKey key, StellaMod mod, bool pressed) {
myPKeyHandler->handleEvent(key, mod, state); myPKeyHandler->handleEvent(key, mod, pressed);
} }
void handleJoyBtnEvent(int stick, int button, uInt8 state) { void handleJoyBtnEvent(int stick, int button, bool pressed) {
myPJoyHandler->handleBtnEvent(stick, button, state); myPJoyHandler->handleBtnEvent(stick, button, pressed);
} }
void handleJoyAxisEvent(int stick, int axis, int value) { void handleJoyAxisEvent(int stick, int axis, int value) {
myPJoyHandler->handleAxisEvent(stick, axis, value); myPJoyHandler->handleAxisEvent(stick, axis, value);

View File

@ -185,7 +185,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd,
case kSnapshotCmd: case kSnapshotCmd:
instance().eventHandler().leaveMenuMode(); instance().eventHandler().leaveMenuMode();
instance().eventHandler().handleEvent(Event::TakeSnapshot, 1); instance().eventHandler().handleEvent(Event::TakeSnapshot);
break; break;
case kTimeMachineCmd: case kTimeMachineCmd:
@ -194,7 +194,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd,
break; break;
case kExitCmd: case kExitCmd:
instance().eventHandler().handleEvent(Event::LauncherMode, 1); instance().eventHandler().handleEvent(Event::LauncherMode);
break; break;
// Column 3 // Column 3
@ -227,18 +227,18 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd,
break; break;
} }
// Console commands show be performed right away, after leaving the menu // Console commands should be performed right away, after leaving the menu
// State commands require you to exit the menu manually // State commands require you to exit the menu manually
if(consoleCmd) if(consoleCmd)
{ {
instance().eventHandler().leaveMenuMode(); instance().eventHandler().leaveMenuMode();
instance().eventHandler().handleEvent(event, 1); instance().eventHandler().handleEvent(event);
instance().console().switches().update(); instance().console().switches().update();
instance().console().tia().update(); instance().console().tia().update();
instance().eventHandler().handleEvent(event, 0); instance().eventHandler().handleEvent(event, false);
} }
else if(stateCmd) else if(stateCmd)
instance().eventHandler().handleEvent(event, 1); instance().eventHandler().handleEvent(event);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -175,14 +175,14 @@ void DialogContainer::handleTextEvent(char text)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleKeyEvent(StellaKey key, StellaMod mod, bool state) void DialogContainer::handleKeyEvent(StellaKey key, StellaMod mod, bool pressed)
{ {
if(myDialogStack.empty()) if(myDialogStack.empty())
return; return;
// Send the event to the dialog box on the top of the stack // Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top(); Dialog* activeDialog = myDialogStack.top();
if(state) if(pressed)
{ {
myCurrentKeyDown.key = key; myCurrentKeyDown.key = key;
myCurrentKeyDown.mod = mod; myCurrentKeyDown.mod = mod;
@ -290,7 +290,7 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, bool pressed,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleJoyBtnEvent(int stick, int button, uInt8 state) void DialogContainer::handleJoyBtnEvent(int stick, int button, bool pressed)
{ {
if(myDialogStack.empty()) if(myDialogStack.empty())
return; return;
@ -298,7 +298,7 @@ void DialogContainer::handleJoyBtnEvent(int stick, int button, uInt8 state)
// Send the event to the dialog box on the top of the stack // Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top(); Dialog* activeDialog = myDialogStack.top();
if(state == 1) if(pressed)
{ {
myCurrentButtonDown.stick = stick; myCurrentButtonDown.stick = stick;
myCurrentButtonDown.button = button; myCurrentButtonDown.button = button;

View File

@ -68,11 +68,11 @@ class DialogContainer
/** /**
Handle a keyboard single-key event. Handle a keyboard single-key event.
@param key Actual key symbol @param key Actual key symbol
@param mod Modifiers @param mod Modifiers
@param state Pressed (true) or released (false) @param pressed Pressed (true) or released (false)
*/ */
void handleKeyEvent(StellaKey key, StellaMod mod, bool state); void handleKeyEvent(StellaKey key, StellaMod mod, bool pressed);
/** /**
Handle a mouse motion event. Handle a mouse motion event.
@ -97,9 +97,9 @@ class DialogContainer
@param stick The joystick number @param stick The joystick number
@param button The joystick button @param button The joystick button
@param state The state (pressed or released) @param pressed Pressed (true) or released (false)
*/ */
void handleJoyBtnEvent(int stick, int button, uInt8 state); void handleJoyBtnEvent(int stick, int button, bool pressed);
/** /**
Handle a joystick axis event. Handle a joystick axis event.