mirror of https://github.com/stella-emu/stella.git
Refactor EventHandler kbdXXX functions into StellaKeys:
- These functions did not really have anything to do with EventHandler - StellaKeys is the proper place, since they're testing against a StellaMod - This removes the need to include 'EventHandler.hxx' in many header files, again reducing dependencies
This commit is contained in:
parent
e37b5305cf
commit
4250f5d102
|
@ -412,4 +412,27 @@ enum StellaMod
|
|||
KBDM_GUI = (KBDM_LGUI|KBDM_RGUI)
|
||||
};
|
||||
|
||||
// Test if specified modifier is pressed
|
||||
namespace StellaModTest
|
||||
{
|
||||
inline bool isAlt(int mod)
|
||||
{
|
||||
#if defined(BSPF_MAC_OSX) || defined(OSX_KEYS)
|
||||
return (mod & KBDM_GUI);
|
||||
#else
|
||||
return (mod & KBDM_ALT);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool isControl(int mod)
|
||||
{
|
||||
return (mod & KBDM_CTRL);
|
||||
}
|
||||
|
||||
inline bool isShift(int mod)
|
||||
{
|
||||
return (mod & KBDM_SHIFT);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* StellaKeys */
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
#include "Dialog.hxx"
|
||||
#include "Font.hxx"
|
||||
#include "Debugger.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "FrameBuffer.hxx"
|
||||
#include "FBSurface.hxx"
|
||||
#include "DataGridWidget.hxx"
|
||||
#include "DataGridOpsWidget.hxx"
|
||||
#include "RamWidget.hxx"
|
||||
#include "ScrollBarWidget.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
DataGridWidget::DataGridWidget(GuiObject* boss, const GUI::Font& font,
|
||||
|
@ -332,8 +332,7 @@ bool DataGridWidget::handleText(char text)
|
|||
bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
||||
{
|
||||
// Ignore all mod keys
|
||||
if(instance().eventHandler().kbdControl(mod) ||
|
||||
instance().eventHandler().kbdAlt(mod))
|
||||
if(StellaModTest::isControl(mod) || StellaModTest::isAlt(mod))
|
||||
return true;
|
||||
|
||||
bool handled = true;
|
||||
|
@ -415,7 +414,7 @@ bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_PAGEUP:
|
||||
if(instance().eventHandler().kbdShift(mod) && _scrollBar)
|
||||
if(StellaModTest::isShift(mod) && _scrollBar)
|
||||
handleMouseWheel(0, 0, -1);
|
||||
else if (_currentRow > 0)
|
||||
{
|
||||
|
@ -425,7 +424,7 @@ bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_PAGEDOWN:
|
||||
if(instance().eventHandler().kbdShift(mod) && _scrollBar)
|
||||
if(StellaModTest::isShift(mod) && _scrollBar)
|
||||
handleMouseWheel(0, 0, +1);
|
||||
else if (_currentRow < int(_rows) - 1)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "Widget.hxx"
|
||||
#include "Dialog.hxx"
|
||||
#include "Settings.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "TabWidget.hxx"
|
||||
#include "TiaInfoWidget.hxx"
|
||||
|
@ -84,7 +85,7 @@ void DebuggerDialog::loadConfig()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void DebuggerDialog::handleKeyDown(StellaKey key, StellaMod mod)
|
||||
{
|
||||
if(key == KBDK_GRAVE && !instance().eventHandler().kbdShift(mod))
|
||||
if(key == KBDK_GRAVE && !StellaModTest::isShift(mod))
|
||||
{
|
||||
// Swallow backtick, so we don't see it when exiting the debugger
|
||||
instance().eventHandler().enableTextEvents(false);
|
||||
|
@ -93,22 +94,22 @@ void DebuggerDialog::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
{
|
||||
instance().debugger().parser().run("savesnap");
|
||||
}
|
||||
else if(instance().eventHandler().kbdControl(mod))
|
||||
else if(StellaModTest::isControl(mod))
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case KBDK_R:
|
||||
if(instance().eventHandler().kbdAlt(mod))
|
||||
if(StellaModTest::isAlt(mod))
|
||||
doRewindAll();
|
||||
else if(instance().eventHandler().kbdShift(mod))
|
||||
else if(StellaModTest::isShift(mod))
|
||||
doRewind10();
|
||||
else
|
||||
doRewind();
|
||||
break;
|
||||
case KBDK_Y:
|
||||
if(instance().eventHandler().kbdAlt(mod))
|
||||
if(StellaModTest::isAlt(mod))
|
||||
doUnwindAll();
|
||||
else if(instance().eventHandler().kbdShift(mod))
|
||||
else if(StellaModTest::isShift(mod))
|
||||
doUnwind10();
|
||||
else
|
||||
doUnwind();
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "ScrollBarWidget.hxx"
|
||||
#include "FBSurface.hxx"
|
||||
#include "Font.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
#include "Version.hxx"
|
||||
#include "Debugger.hxx"
|
||||
#include "DebuggerDialog.hxx"
|
||||
|
@ -329,7 +329,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_PAGEUP:
|
||||
if (instance().eventHandler().kbdShift(mod))
|
||||
if (StellaModTest::isShift(mod))
|
||||
{
|
||||
// Don't scroll up when at top of buffer
|
||||
if(_scrollLine < _linesPerPage)
|
||||
|
@ -345,7 +345,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_PAGEDOWN:
|
||||
if (instance().eventHandler().kbdShift(mod))
|
||||
if (StellaModTest::isShift(mod))
|
||||
{
|
||||
// Don't scroll down when at bottom of buffer
|
||||
if(_scrollLine >= _promptEndPos / _lineWidth)
|
||||
|
@ -361,7 +361,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_HOME:
|
||||
if (instance().eventHandler().kbdShift(mod))
|
||||
if (StellaModTest::isShift(mod))
|
||||
{
|
||||
_scrollLine = _firstLineInBuffer + _linesPerPage - 1;
|
||||
updateScrollBuffer();
|
||||
|
@ -373,7 +373,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_END:
|
||||
if (instance().eventHandler().kbdShift(mod))
|
||||
if (StellaModTest::isShift(mod))
|
||||
{
|
||||
_scrollLine = _promptEndPos / _lineWidth;
|
||||
if (_scrollLine < _linesPerPage - 1)
|
||||
|
@ -387,7 +387,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_UP:
|
||||
if (instance().eventHandler().kbdShift(mod))
|
||||
if (StellaModTest::isShift(mod))
|
||||
{
|
||||
if(_scrollLine <= _firstLineInBuffer + _linesPerPage - 1)
|
||||
break;
|
||||
|
@ -402,7 +402,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_DOWN:
|
||||
if (instance().eventHandler().kbdShift(mod))
|
||||
if (StellaModTest::isShift(mod))
|
||||
{
|
||||
// Don't scroll down when at bottom of buffer
|
||||
if(_scrollLine >= _promptEndPos / _lineWidth)
|
||||
|
@ -432,11 +432,11 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
default:
|
||||
if (instance().eventHandler().kbdControl(mod))
|
||||
if (StellaModTest::isControl(mod))
|
||||
{
|
||||
specialKeys(key);
|
||||
}
|
||||
else if (instance().eventHandler().kbdAlt(mod))
|
||||
else if (StellaModTest::isAlt(mod))
|
||||
{
|
||||
// Placeholder only - this will never be reached
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "DiStella.hxx"
|
||||
#include "PackedBitArray.hxx"
|
||||
#include "Widget.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
#include "FBSurface.hxx"
|
||||
#include "Font.hxx"
|
||||
#include "ScrollBarWidget.hxx"
|
||||
|
@ -303,7 +303,7 @@ bool RomListWidget::handleText(char text)
|
|||
bool RomListWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
||||
{
|
||||
// Ignore all Alt-mod keys
|
||||
if(instance().eventHandler().kbdAlt(mod))
|
||||
if(StellaModTest::isAlt(mod))
|
||||
return true;
|
||||
|
||||
bool handled = true;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//============================================================================
|
||||
|
||||
#include "OSystem.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
#include "Widget.hxx"
|
||||
#include "ToggleWidget.hxx"
|
||||
|
||||
|
@ -94,8 +94,7 @@ int ToggleWidget::findItem(int x, int y)
|
|||
bool ToggleWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
||||
{
|
||||
// Ignore all mod keys
|
||||
if(instance().eventHandler().kbdControl(mod) ||
|
||||
instance().eventHandler().kbdAlt(mod))
|
||||
if(StellaModTest::isControl(mod) || StellaModTest::isAlt(mod))
|
||||
return true;
|
||||
|
||||
bool handled = true;
|
||||
|
|
|
@ -274,7 +274,7 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state)
|
|||
|
||||
// An attempt to speed up event processing; we quickly check for
|
||||
// Control or Alt/Cmd combos first
|
||||
if(kbdAlt(mod) && state)
|
||||
if(StellaModTest::isAlt(mod) && state)
|
||||
{
|
||||
#ifdef BSPF_MAC_OSX
|
||||
// These keys work in all states
|
||||
|
@ -302,13 +302,13 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state)
|
|||
case KBDK_LEFT: // Alt-left(-shift) rewinds 1(10) states
|
||||
myOSystem.frameBuffer().setPauseDelay();
|
||||
setEventState(EventHandlerState::PAUSE);
|
||||
myOSystem.state().rewindState((kbdShift(mod) && state) ? 10 : 1);
|
||||
myOSystem.state().rewindState((StellaModTest::isShift(mod) && state) ? 10 : 1);
|
||||
break;
|
||||
|
||||
case KBDK_RIGHT: // Alt-right(-shift) unwinds 1(10) states
|
||||
myOSystem.frameBuffer().setPauseDelay();
|
||||
setEventState(EventHandlerState::PAUSE);
|
||||
myOSystem.state().unwindState((kbdShift(mod) && state) ? 10 : 1);
|
||||
myOSystem.state().unwindState((StellaModTest::isShift(mod) && state) ? 10 : 1);
|
||||
break;
|
||||
|
||||
case KBDK_DOWN: // Alt-down rewinds to start of list
|
||||
|
@ -531,7 +531,7 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state)
|
|||
else
|
||||
handled = false;
|
||||
}
|
||||
else if(kbdControl(mod) && state && myUseCtrlKeyFlag)
|
||||
else if(StellaModTest::isControl(mod) && state && myUseCtrlKeyFlag)
|
||||
{
|
||||
// These keys work in all states
|
||||
if(key == KBDK_Q)
|
||||
|
@ -616,7 +616,7 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state)
|
|||
|
||||
// Handle keys which switch eventhandler state
|
||||
// Arrange the logic to take advantage of short-circuit evaluation
|
||||
if(!(kbdControl(mod) || kbdShift(mod) || kbdAlt(mod)) &&
|
||||
if(!(StellaModTest::isControl(mod) || StellaModTest::isShift(mod) || StellaModTest::isAlt(mod)) &&
|
||||
!state && eventStateChange(myKeyTable[key][kEmulationMode]))
|
||||
return;
|
||||
|
||||
|
|
|
@ -133,25 +133,6 @@ class EventHandler
|
|||
*/
|
||||
void setContinuousSnapshots(uInt32 interval);
|
||||
|
||||
inline bool kbdAlt(int mod) const
|
||||
{
|
||||
#if defined(BSPF_MAC_OSX) || defined(OSX_KEYS)
|
||||
return (mod & KBDM_GUI);
|
||||
#else
|
||||
return (mod & KBDM_ALT);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool kbdControl(int mod) const
|
||||
{
|
||||
return (mod & KBDM_CTRL);
|
||||
}
|
||||
|
||||
inline bool kbdShift(int mod) const
|
||||
{
|
||||
return (mod & KBDM_SHIFT);
|
||||
}
|
||||
|
||||
void enterMenuMode(EventHandlerState state);
|
||||
void leaveMenuMode();
|
||||
bool enterDebugMode();
|
||||
|
|
|
@ -334,18 +334,18 @@ void Dialog::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
// Detect selection of previous and next tab headers and objects
|
||||
if(key == KBDK_TAB)
|
||||
{
|
||||
if(instance().eventHandler().kbdControl(mod))
|
||||
if(StellaModTest::isControl(mod))
|
||||
{
|
||||
// tab header navigation
|
||||
if(instance().eventHandler().kbdShift(mod) && cycleTab(-1))
|
||||
if(StellaModTest::isShift(mod) && cycleTab(-1))
|
||||
return;
|
||||
else if(!instance().eventHandler().kbdShift(mod) && cycleTab(+1))
|
||||
else if(!StellaModTest::isShift(mod) && cycleTab(+1))
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// object navigation
|
||||
if(instance().eventHandler().kbdShift(mod))
|
||||
if(StellaModTest::isShift(mod))
|
||||
e = Event::UINavPrev;
|
||||
else
|
||||
e = Event::UINavNext;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//============================================================================
|
||||
|
||||
#include "Dialog.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
#include "FBSurface.hxx"
|
||||
#include "Font.hxx"
|
||||
#include "EditableWidget.hxx"
|
||||
|
@ -113,7 +113,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
return true;
|
||||
|
||||
// Ignore all alt-mod keys
|
||||
if(instance().eventHandler().kbdAlt(mod))
|
||||
if(StellaModTest::isAlt(mod))
|
||||
return true;
|
||||
|
||||
bool handled = true;
|
||||
|
@ -146,14 +146,14 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_LEFT:
|
||||
if(instance().eventHandler().kbdControl(mod))
|
||||
if(StellaModTest::isControl(mod))
|
||||
dirty = specialKeys(key);
|
||||
else if(_caretPos > 0)
|
||||
dirty = setCaretPos(_caretPos - 1);
|
||||
break;
|
||||
|
||||
case KBDK_RIGHT:
|
||||
if(instance().eventHandler().kbdControl(mod))
|
||||
if(StellaModTest::isControl(mod))
|
||||
dirty = specialKeys(key);
|
||||
else if(_caretPos < int(_editString.size()))
|
||||
dirty = setCaretPos(_caretPos + 1);
|
||||
|
@ -168,7 +168,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
default:
|
||||
if (instance().eventHandler().kbdControl(mod))
|
||||
if (StellaModTest::isControl(mod))
|
||||
{
|
||||
dirty = specialKeys(key);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "OSystem.hxx"
|
||||
#include "FrameBuffer.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
#include "Props.hxx"
|
||||
#include "PropsSet.hxx"
|
||||
#include "RomInfoWidget.hxx"
|
||||
|
@ -424,7 +425,7 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
{
|
||||
// Grab the key before passing it to the actual dialog and check for
|
||||
// Control-R (reload ROM listing)
|
||||
if(instance().eventHandler().kbdControl(mod) && key == KBDK_R)
|
||||
if(StellaModTest::isControl(mod) && key == KBDK_R)
|
||||
updateListing();
|
||||
else
|
||||
Dialog::handleKeyDown(key, mod);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "ScrollBarWidget.hxx"
|
||||
#include "Dialog.hxx"
|
||||
#include "FrameBuffer.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaKeys.hxx"
|
||||
#include "ListWidget.hxx"
|
||||
#include "bspf.hxx"
|
||||
|
||||
|
@ -298,7 +298,7 @@ bool ListWidget::handleText(char text)
|
|||
bool ListWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
||||
{
|
||||
// Ignore all Alt-mod keys
|
||||
if(instance().eventHandler().kbdAlt(mod))
|
||||
if(StellaModTest::isAlt(mod))
|
||||
return true;
|
||||
|
||||
bool handled = true;
|
||||
|
|
Loading…
Reference in New Issue