First pass at converting text input to the new SDL2 scheme. Basically,

the old way mixed both single-key events and Unicode input into one
method, and the new way separates them (using a new handleText method).

Currently it seems to be working fine in the ROM launcher (yay!, I
can now quickly jump to ROMs by name again).  There are still some
issues in the debugger, which I'll work on next.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2913 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-06-10 16:43:35 +00:00
parent d66226c210
commit 90248b2701
30 changed files with 291 additions and 220 deletions

View File

@ -26,7 +26,6 @@ EventHandlerSDL2::EventHandlerSDL2(OSystem& osystem)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandlerSDL2::~EventHandlerSDL2()
{
@ -46,45 +45,59 @@ void EventHandlerSDL2::initializeJoysticks()
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandlerSDL2::enableTextEvents(bool enable)
{
if(enable)
SDL_StartTextInput();
else
SDL_StopTextInput();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandlerSDL2::pollEvent()
{
while(SDL_PollEvent(&event))
while(SDL_PollEvent(&myEvent))
{
switch(event.type)
switch(myEvent.type)
{
// keyboard events
case SDL_KEYUP:
case SDL_KEYDOWN:
{
if(!event.key.repeat)
handleKeyEvent((StellaKey)event.key.keysym.scancode,
(StellaMod)event.key.keysym.mod,
'x', //FIXSDL event.key.keysym.scancode,
event.key.type == SDL_KEYDOWN);
if(!myEvent.key.repeat)
handleKeyEvent((StellaKey)myEvent.key.keysym.scancode,
(StellaMod)myEvent.key.keysym.mod,
myEvent.key.type == SDL_KEYDOWN);
break;
}
case SDL_TEXTINPUT:
{
handleTextEvent(*(myEvent.text.text));
break;
}
case SDL_MOUSEMOTION:
{
handleMouseMotionEvent(event.motion.x, event.motion.y,
event.motion.xrel, event.motion.yrel, 0);
handleMouseMotionEvent(myEvent.motion.x, myEvent.motion.y,
myEvent.motion.xrel, myEvent.motion.yrel, 0);
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
bool pressed = event.button.type == SDL_MOUSEBUTTONDOWN;
switch(event.button.button)
bool pressed = myEvent.button.type == SDL_MOUSEBUTTONDOWN;
switch(myEvent.button.button)
{
case SDL_BUTTON_LEFT:
handleMouseButtonEvent(pressed ? EVENT_LBUTTONDOWN : EVENT_LBUTTONUP,
event.button.x, event.button.y);
myEvent.button.x, myEvent.button.y);
break;
case SDL_BUTTON_RIGHT:
handleMouseButtonEvent(pressed ? EVENT_RBUTTONDOWN : EVENT_RBUTTONUP,
event.button.x, event.button.y);
myEvent.button.x, myEvent.button.y);
break;
}
break;
@ -92,10 +105,10 @@ void EventHandlerSDL2::pollEvent()
case SDL_MOUSEWHEEL:
{
if(event.wheel.y < 0)
handleMouseButtonEvent(EVENT_WHEELDOWN, 0, event.wheel.y);
else if(event.wheel.y > 0)
handleMouseButtonEvent(EVENT_WHEELUP, 0, event.wheel.y);
if(myEvent.wheel.y < 0)
handleMouseButtonEvent(EVENT_WHEELDOWN, 0, myEvent.wheel.y);
else if(myEvent.wheel.y > 0)
handleMouseButtonEvent(EVENT_WHEELUP, 0, myEvent.wheel.y);
break;
}
@ -103,38 +116,40 @@ void EventHandlerSDL2::pollEvent()
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
{
handleJoyEvent(event.jbutton.which, event.jbutton.button,
event.jbutton.state == SDL_PRESSED ? 1 : 0);
handleJoyEvent(myEvent.jbutton.which, myEvent.jbutton.button,
myEvent.jbutton.state == SDL_PRESSED ? 1 : 0);
break;
}
case SDL_JOYAXISMOTION:
{
handleJoyAxisEvent(event.jaxis.which, event.jaxis.axis,
event.jaxis.value);
handleJoyAxisEvent(myEvent.jaxis.which, myEvent.jaxis.axis,
myEvent.jaxis.value);
break;
}
case SDL_JOYHATMOTION:
{
int v = event.jhat.value, value = 0;
int v = myEvent.jhat.value, value = 0;
if(v & SDL_HAT_UP) value |= EVENT_HATUP_M;
if(v & SDL_HAT_DOWN) value |= EVENT_HATDOWN_M;
if(v & SDL_HAT_LEFT) value |= EVENT_HATLEFT_M;
if(v & SDL_HAT_RIGHT) value |= EVENT_HATRIGHT_M;
if(v == SDL_HAT_CENTERED) value = EVENT_HATCENTER_M;
handleJoyHatEvent(event.jhat.which, event.jhat.hat, value);
handleJoyHatEvent(myEvent.jhat.which, myEvent.jhat.hat, value);
break; // SDL_JOYHATMOTION
}
#endif
case SDL_QUIT:
{
handleEvent(Event::Quit, 1);
break; // SDL_QUIT
}
case SDL_WINDOWEVENT:
switch(event.window.event)
switch(myEvent.window.event)
{
case SDL_WINDOWEVENT_SHOWN:
handleSystemEvent(EVENT_WINDOW_SHOWN);
@ -147,11 +162,11 @@ void EventHandlerSDL2::pollEvent()
break;
case SDL_WINDOWEVENT_MOVED:
handleSystemEvent(EVENT_WINDOW_MOVED,
event.window.data1, event.window.data1);
myEvent.window.data1, myEvent.window.data1);
break;
case SDL_WINDOWEVENT_RESIZED:
handleSystemEvent(EVENT_WINDOW_RESIZED,
event.window.data1, event.window.data1);
myEvent.window.data1, myEvent.window.data1);
break;
case SDL_WINDOWEVENT_MINIMIZED:
handleSystemEvent(EVENT_WINDOW_MINIMIZED);
@ -183,21 +198,22 @@ void EventHandlerSDL2::pollEvent()
#ifdef JOYSTICK_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandlerSDL2::JoystickSDL2::JoystickSDL2(int idx)
: stick(NULL)
: myStick(NULL)
{
stick = SDL_JoystickOpen(idx);
if(stick)
myStick = SDL_JoystickOpen(idx);
if(myStick)
{
initialize(SDL_JoystickName(stick), SDL_JoystickNumAxes(stick),
SDL_JoystickNumButtons(stick), SDL_JoystickNumHats(stick));
initialize(SDL_JoystickName(myStick),
SDL_JoystickNumAxes(myStick), SDL_JoystickNumButtons(myStick),
SDL_JoystickNumHats(myStick), SDL_JoystickNumBalls(myStick));
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandlerSDL2::JoystickSDL2::~JoystickSDL2()
{
if(stick)
SDL_JoystickClose(stick);
stick = NULL;
if(myStick)
SDL_JoystickClose(myStick);
myStick = NULL;
}
#endif

View File

@ -50,13 +50,18 @@ class EventHandlerSDL2 : public EventHandler
*/
void initializeJoysticks();
/**
Enable/disable text events (distinct from single-key events).
*/
void enableTextEvents(bool enable);
/**
Collects and dispatches any pending SDL2 events.
*/
void pollEvent();
private:
SDL_Event event;
SDL_Event myEvent;
#ifdef JOYSTICK_SUPPORT
// A thin wrapper around a basic StellaJoystick, holding the pointer to
@ -68,7 +73,7 @@ class EventHandlerSDL2 : public EventHandler
virtual ~JoystickSDL2();
private:
SDL_Joystick* stick;
SDL_Joystick* myStick;
};
#endif
};

View File

@ -280,7 +280,22 @@ int DataGridWidget::findItem(int x, int y)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool DataGridWidget::handleText(char text)
{
if (_editMode)
{
// Class EditableWidget handles all text editing related key presses for us
if(EditableWidget::handleText(text))
{
setDirty(); draw();
return true;
}
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod)
{
// Ignore all mod keys
if(instance().eventHandler().kbdControl(mod) ||
@ -290,16 +305,8 @@ bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool handled = true;
bool dirty = false;
if (_editMode)
if (!_editMode)
{
// Class EditableWidget handles all text editing related key presses for us
handled = EditableWidget::handleKeyDown(key, mod, ascii);
if(handled)
setDirty(); draw();
}
else
{
// not editmode
switch(key)
{
case KBDK_RETURN:
@ -409,53 +416,39 @@ bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
negateCell();
break;
case KBDK_I: // invert
if(_editable)
invertCell();
break;
case KBDK_MINUS: // decrement
if(_editable)
decrementCell();
break;
case KBDK_EQUALS: // increment
if(_editable)
incrementCell();
break;
case KBDK_COMMA: // shift left
if(_editable)
lshiftCell();
break;
case KBDK_PERIOD: // shift right
if(_editable)
rshiftCell();
break;
case KBDK_Z: // zero
if(_editable)
zeroCell();
break;
default:
handled = false;
}
if(!handled)
{
handled = true;
switch(ascii)
{
case 'i': // invert
case '!':
if(_editable)
invertCell();
break;
case '-': // decrement
if(_editable)
decrementCell();
break;
case '+': // increment
case '=':
if(_editable)
incrementCell();
break;
case '<': // shift left
case ',':
if(_editable)
lshiftCell();
break;
case '>': // shift right
case '.':
if(_editable)
rshiftCell();
break;
case 'z': // zero
if(_editable)
zeroCell();
break;
default:
handled = false;
}
}
}
if (dirty)
@ -474,7 +467,7 @@ bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DataGridWidget::handleKeyUp(StellaKey key, StellaMod mod, char ascii)
bool DataGridWidget::handleKeyUp(StellaKey key, StellaMod mod)
{
if (key == _currentKeyDown)
_currentKeyDown = KBDK_UNKNOWN;
@ -506,7 +499,7 @@ void DataGridWidget::lostFocusWidget()
void DataGridWidget::handleCommand(CommandSender* sender, int cmd,
int data, int id)
{
switch (cmd)
switch(cmd)
{
case kSetPositionCmd:
// Chain access; pass to parent

View File

@ -75,8 +75,9 @@ class DataGridWidget : public EditableWidget
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
virtual bool handleKeyDown(StellaKey key, StellaMod mod, char ascii);
virtual bool handleKeyUp(StellaKey key, StellaMod mod, char ascii);
virtual bool handleText(char text);
virtual bool handleKeyDown(StellaKey key, StellaMod mod);
virtual bool handleKeyUp(StellaKey key, StellaMod mod);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
virtual bool wantsFocus() { return true; }

View File

@ -86,26 +86,26 @@ void DebuggerDialog::loadConfig()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DebuggerDialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
void DebuggerDialog::handleKeyDown(StellaKey key, StellaMod mod)
{
bool handled = instance().eventHandler().kbdAlt(mod);
if(handled)
{
switch(ascii)
switch(key)
{
case 's':
case KBDK_S:
doStep();
break;
case 't':
case KBDK_T:
doTrace();
break;
case 'f':
case KBDK_F:
doAdvance();
break;
case 'l':
case KBDK_L:
doScanlineAdvance();
break;
case 'r':
case KBDK_R:
doRewind();
break;
default:
@ -114,7 +114,7 @@ void DebuggerDialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
}
}
if(!handled)
Dialog::handleKeyDown(key, mod, ascii);
Dialog::handleKeyDown(key, mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -67,7 +67,7 @@ class DebuggerDialog : public Dialog
private:
void loadConfig();
void handleKeyDown(StellaKey key, StellaMod mod, char ascii);
void handleKeyDown(StellaKey key, StellaMod mod);
void handleCommand(CommandSender* sender, int cmd, int data, int id);
void doStep();

View File

@ -272,7 +272,18 @@ void RomListWidget::handleMouseWheel(int x, int y, int direction)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RomListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool RomListWidget::handleText(char text)
{
if(_editMode)
{
// Class EditableWidget handles all text editing related key presses for us
return EditableWidget::handleText(text);
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RomListWidget::handleKeyDown(StellaKey key, StellaMod mod)
{
// Ignore all Alt-mod keys
if(instance().eventHandler().kbdAlt(mod))
@ -281,14 +292,8 @@ bool RomListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool handled = true;
int oldSelectedItem = _selectedItem;
if (_editMode)
if(!_editMode)
{
// Class EditableWidget handles all text editing related key presses for us
handled = EditableWidget::handleKeyDown(key, mod, ascii);
}
else
{
// not editmode
switch (key)
{
case KBDK_SPACE:
@ -316,7 +321,7 @@ bool RomListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RomListWidget::handleKeyUp(StellaKey key, StellaMod mod, char ascii)
bool RomListWidget::handleKeyUp(StellaKey key, StellaMod mod)
{
if (key == _currentKeyDown)
_currentKeyDown = KBDK_UNKNOWN;

View File

@ -68,8 +68,9 @@ class RomListWidget : public EditableWidget
void handleMouseDown(int x, int y, int button, int clickCount);
void handleMouseUp(int x, int y, int button, int clickCount);
void handleMouseWheel(int x, int y, int direction);
bool handleKeyDown(StellaKey key, StellaMod mod, char ascii);
bool handleKeyUp(StellaKey key, StellaMod mod, char ascii);
bool handleText(char text);
bool handleKeyDown(StellaKey key, StellaMod mod);
bool handleKeyUp(StellaKey key, StellaMod mod);
bool handleEvent(Event::Type e);
void handleCommand(CommandSender* sender, int cmd, int data, int id);

View File

@ -47,8 +47,8 @@ class TiaOutputWidget : public Widget, public CommandSender
/*
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
virtual bool handleKeyDown(StellaKey key, StellaMod mod, char ascii);
virtual bool handleKeyUp(StellaKey key, StellaMod mod, char ascii);
virtual bool handleKeyDown(StellaKey key, StellaMod mod);
virtual bool handleKeyUp(StellaKey key, StellaMod mod);
*/
protected:

View File

@ -93,7 +93,7 @@ int ToggleWidget::findItem(int x, int y)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ToggleWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool ToggleWidget::handleKeyDown(StellaKey key, StellaMod mod)
{
// Ignore all mod keys
if(instance().eventHandler().kbdControl(mod) ||

View File

@ -44,7 +44,7 @@ class ToggleWidget : public Widget, public CommandSender
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual bool handleKeyDown(StellaKey key, StellaMod mod, char ascii);
virtual bool handleKeyDown(StellaKey key, StellaMod mod);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
virtual bool wantsFocus() { return true; }

View File

@ -19,7 +19,6 @@
#include <sstream>
#include <map>
#include <SDL.h>
#include "bspf.hxx"
@ -155,7 +154,7 @@ void EventHandler::reset(State state)
// We wait a little while, since 'hold' events may be present, and we want
// time for the ROM to process them
if(state == S_EMULATE)
SDL_AddTimer(500, resetEventsCallback, (void*)this);
SDL_AddTimer(500, resetEventsCallback, (void*)this); //FIXSDL
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -338,7 +337,15 @@ void EventHandler::poll(uInt64 time)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, char ascii, bool state)
void EventHandler::handleTextEvent(char text)
{
// Text events are only used in GUI mode
if(myOverlay != NULL)
myOverlay->handleTextEvent(text);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state)
{
bool handled = true;
@ -632,7 +639,7 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, char ascii, bool
if(myState == S_EMULATE)
handleEvent(myKeyTable[key][kEmulationMode], state);
else if(myOverlay != NULL)
myOverlay->handleKeyEvent(key, mod, ascii, state);
myOverlay->handleKeyEvent(key, mod, state);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2059,14 +2066,14 @@ void EventHandler::setEventState(State state)
// For certain ROMs it may be forced off, whatever the setting
myUseCtrlKeyFlag = myOSystem.settings().getBool("ctrlcombo");
// Only enable Unicode in GUI modes, since there we need it for ascii data
// Otherwise, it causes a performance hit, so leave it off
// Only enable text input in GUI modes, since in emulation mode the
// keyboard acts as one large joystick with many (single) buttons
switch(myState)
{
case S_EMULATE:
myOverlay = NULL;
myOSystem.sound().mute(false);
//FIXME SDL_EnableUNICODE(0);
enableTextEvents(false);
if(myOSystem.console().controller(Controller::Left).type() ==
Controller::CompuMate)
myUseCtrlKeyFlag = false;
@ -2075,28 +2082,28 @@ void EventHandler::setEventState(State state)
case S_PAUSE:
myOverlay = NULL;
myOSystem.sound().mute(true);
//FIXME SDL_EnableUNICODE(0);
enableTextEvents(false);
break;
case S_MENU:
myOverlay = &myOSystem.menu();
//FIXME SDL_EnableUNICODE(1);
enableTextEvents(true);
break;
case S_CMDMENU:
myOverlay = &myOSystem.commandMenu();
//FIXME SDL_EnableUNICODE(1);
enableTextEvents(true);
break;
case S_LAUNCHER:
myOverlay = &myOSystem.launcher();
//FIXME SDL_EnableUNICODE(1);
enableTextEvents(true);
break;
#ifdef DEBUGGER_SUPPORT
case S_DEBUGGER:
myOverlay = &myOSystem.debugger();
//FIXME SDL_EnableUNICODE(1);
enableTextEvents(true);
break;
#endif
@ -2551,7 +2558,7 @@ EventHandler::StellaJoystick::~StellaJoystick()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::StellaJoystick::initialize(const string& desc,
int axes, int buttons, int hats)
int axes, int buttons, int hats, int /*balls*/)
{
name = desc;

View File

@ -325,8 +325,8 @@ class EventHandler
Methods which are called by derived classes to handle specific types
of input.
*/
// TODO - adapt these to SDL2
void handleKeyEvent(StellaKey key, StellaMod mod, char ascii, bool state);
void handleTextEvent(char text);
void handleKeyEvent(StellaKey key, StellaMod mod, bool state);
void handleMouseMotionEvent(int x, int y, int xrel, int yrel, int button);
void handleMouseButtonEvent(MouseButton b, int x, int y);
void handleJoyEvent(int stick, int button, uInt8 state);
@ -338,6 +338,11 @@ class EventHandler
*/
virtual void initializeJoysticks() = 0;
/**
Enable/disable text events (distinct from single-key events).
*/
virtual void enableTextEvents(bool enable) = 0;
/**
Collects and dispatches any pending events.
*/
@ -381,7 +386,7 @@ class EventHandler
string about() const;
protected:
void initialize(const string& desc, int axes, int buttons, int hats);
void initialize(const string& desc, int axes, int buttons, int hats, int balls);
private:
enum JoyType {
@ -495,9 +500,8 @@ class EventHandler
// a Ctrl combo when it isn't wanted)
bool myUseCtrlKeyFlag;
// A bug in the SDL video handler creates an extraneous mouse motion
// event after a video state change
// We detect when this happens and discard the event
// Sometimes an extraneous mouse motion event occurs after a video
// state change; we detect when this happens and discard the event
bool mySkipMouseMotion;
// Used for continuous snapshot mode

View File

@ -288,7 +288,7 @@ void ContextMenu::handleMouseWheel(int x, int y, int direction)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ContextMenu::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
void ContextMenu::handleKeyDown(StellaKey key, StellaMod mod)
{
handleEvent(instance().eventHandler().eventForKey(key, kMenuMode));
}

View File

@ -88,7 +88,7 @@ class ContextMenu : public Dialog, public CommandSender
void handleMouseMoved(int x, int y, int button);
bool handleMouseClicks(int x, int y, int button);
void handleMouseWheel(int x, int y, int direction);
void handleKeyDown(StellaKey key, StellaMod mod, char ascii);
void handleKeyDown(StellaKey key, StellaMod mod);
void handleJoyDown(int stick, int button);
void handleJoyAxis(int stick, int axis, int value);
bool handleJoyHat(int stick, int hat, int value);

View File

@ -319,7 +319,15 @@ void Dialog::drawDialog()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
void Dialog::handleText(char text)
{
// Focused widget receives text events
if(_focusedWidget)
_focusedWidget->handleText(text);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyDown(StellaKey key, StellaMod mod)
{
// Test for TAB character
// Shift-left/shift-right cursor selects next tab
@ -328,8 +336,6 @@ void Dialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
Event::Type e = Event::NoType;
// Detect selection of previous and next tab headers and objects
// For some strange reason, 'tab' needs to be interpreted as keycode,
// not ascii??
if(instance().eventHandler().kbdShift(mod))
{
if(key == KBDK_LEFT && cycleTab(-1))
@ -352,18 +358,18 @@ void Dialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
if(!handleNavEvent(e) && _focusedWidget)
{
if(_focusedWidget->wantsRaw() || e == Event::NoType)
_focusedWidget->handleKeyDown(key, mod, ascii);
_focusedWidget->handleKeyDown(key, mod);
else
_focusedWidget->handleEvent(e);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyUp(StellaKey key, StellaMod mod, char ascii)
void Dialog::handleKeyUp(StellaKey key, StellaMod mod)
{
// Focused widget receives keyup events
if(_focusedWidget)
_focusedWidget->handleKeyUp(key, mod, ascii);
_focusedWidget->handleKeyUp(key, mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -78,8 +78,9 @@ class Dialog : public GuiObject
virtual void draw();
void releaseFocus();
virtual void handleKeyDown(StellaKey key, StellaMod modifiers, char ascii);
virtual void handleKeyUp(StellaKey key, StellaMod modifiers, char ascii);
virtual void handleText(char text);
virtual void handleKeyDown(StellaKey key, StellaMod modifiers);
virtual void handleKeyUp(StellaKey key, StellaMod modifiers);
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);

View File

@ -56,8 +56,7 @@ void DialogContainer::updateTime(uInt64 time)
// Key still pressed
if(myCurrentKeyDown.keycode != 0 && myKeyRepeatTime < myTime)
{
activeDialog->handleKeyDown(myCurrentKeyDown.keycode, myCurrentKeyDown.flags,
myCurrentKeyDown.ascii);
activeDialog->handleKeyDown(myCurrentKeyDown.keycode, myCurrentKeyDown.flags);
myKeyRepeatTime = myTime + kRepeatSustainDelay;
}
@ -143,8 +142,18 @@ void DialogContainer::reStack()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleKeyEvent(StellaKey key, StellaMod mod,
char ascii, bool state)
void DialogContainer::handleTextEvent(char text)
{
if(myDialogStack.empty())
return;
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
activeDialog->handleText(text);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleKeyEvent(StellaKey key, StellaMod mod, bool state)
{
if(myDialogStack.empty())
return;
@ -155,14 +164,13 @@ void DialogContainer::handleKeyEvent(StellaKey key, StellaMod mod,
{
myCurrentKeyDown.keycode = key;
myCurrentKeyDown.flags = mod;
myCurrentKeyDown.ascii = ascii;
myKeyRepeatTime = myTime + kRepeatInitialDelay;
activeDialog->handleKeyDown(key, mod, ascii);
activeDialog->handleKeyDown(key, mod);
}
else
{
activeDialog->handleKeyUp(key, mod, ascii);
activeDialog->handleKeyUp(key, mod);
// Only stop firing events if it's the current key
if (key == myCurrentKeyDown.keycode)

View File

@ -65,14 +65,20 @@ class DialogContainer
void updateTime(uInt64 time);
/**
Handle a keyboard event.
Handle a keyboard Unicode text event.
@param key Actual key symbol
@param mod Modifiers
@param ascii ASCII translation
@param state Pressed (true) or released (false)
@param text Unicode character string
*/
void handleKeyEvent(StellaKey key, StellaMod mod, char ascii, bool state);
void handleTextEvent(char text);
/**
Handle a keyboard single-key event.
@param key Actual key symbol
@param mod Modifiers
@param state Pressed (true) or released (false)
*/
void handleKeyEvent(StellaKey key, StellaMod mod, bool state);
/**
Handle a mouse motion event.
@ -166,7 +172,6 @@ class DialogContainer
struct {
StellaKey keycode;
StellaMod flags;
char ascii;
} myCurrentKeyDown;
uInt64 myKeyRepeatTime;

View File

@ -87,7 +87,23 @@ bool EditableWidget::tryInsertChar(char c, int pos)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool EditableWidget::handleText(char text)
{
if(!_editable)
return true;
if(tryInsertChar(text, _caretPos))
{
_caretPos++;
sendCommand(EditableWidget::kChangedCmd, 0, _id);
setDirty(); draw();
return true;
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod)
{
if(!_editable)
return true;
@ -117,24 +133,24 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
case KBDK_BACKSPACE:
dirty = killChar(-1);
if(dirty) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(dirty) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_DELETE:
dirty = killChar(+1);
if(dirty) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(dirty) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_LEFT:
if(instance().eventHandler().kbdControl(mod))
dirty = specialKeys(key, ascii);
dirty = specialKeys(key);
else if(_caretPos > 0)
dirty = setCaretPos(_caretPos - 1);
break;
case KBDK_RIGHT:
if(instance().eventHandler().kbdControl(mod))
dirty = specialKeys(key, ascii);
dirty = specialKeys(key);
else if(_caretPos < (int)_editString.size())
dirty = setCaretPos(_caretPos + 1);
break;
@ -150,13 +166,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
default:
if (instance().eventHandler().kbdControl(mod))
{
dirty = specialKeys(key, ascii);
}
else if (tryInsertChar(ascii, _caretPos))
{
_caretPos++;
sendCommand(EditableWidget::kChangedCmd, ascii, _id);
dirty = true;
dirty = specialKeys(key);
}
else
handled = false;
@ -250,7 +260,7 @@ bool EditableWidget::adjustOffset()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EditableWidget::specialKeys(StellaKey key, char ascii)
bool EditableWidget::specialKeys(StellaKey key)
{
bool handled = true;
@ -262,7 +272,7 @@ bool EditableWidget::specialKeys(StellaKey key, char ascii)
case KBDK_C:
copySelectedText();
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_E:
@ -271,27 +281,27 @@ bool EditableWidget::specialKeys(StellaKey key, char ascii)
case KBDK_D:
handled = killChar(+1);
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_K:
handled = killLine(+1);
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_U:
handled = killLine(-1);
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_V:
pasteSelectedText();
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_W:
handled = killLastWord();
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_LEFT:

View File

@ -47,7 +47,8 @@ class EditableWidget : public Widget, public CommandSender
bool isEditable() const { return _editable; }
void setEditable(bool editable);
virtual bool handleKeyDown(StellaKey key, StellaMod mod, char ascii);
virtual bool handleText(char text);
virtual bool handleKeyDown(StellaKey key, StellaMod mod);
// We only want to focus this widget when we can edit its contents
virtual bool wantsFocus() { return _editable; }
@ -67,7 +68,7 @@ class EditableWidget : public Widget, public CommandSender
private:
// Line editing
bool specialKeys(StellaKey key, char ascii);
bool specialKeys(StellaKey key);
bool killChar(int direction);
bool killLine(int direction);
bool killLastWord();

View File

@ -247,7 +247,7 @@ void EventMappingWidget::enableButtons(bool state)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventMappingWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool EventMappingWidget::handleKeyDown(StellaKey key, StellaMod mod)
{
// Remap keys in remap mode
if(myRemapStatus && myActionSelected >= 0)

View File

@ -46,7 +46,7 @@ class EventMappingWidget : public Widget, public CommandSender
const StringList& actions, EventMode mode);
~EventMappingWidget();
bool handleKeyDown(StellaKey key, StellaMod mod, char ascii);
bool handleKeyDown(StellaKey key, StellaMod mod);
void handleJoyDown(int stick, int button);
void handleJoyAxis(int stick, int axis, int value);
bool handleJoyHat(int stick, int hat, int value);

View File

@ -338,15 +338,15 @@ void InputDialog::setDefaults()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputDialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
void InputDialog::handleKeyDown(StellaKey key, StellaMod mod)
{
// Remap key events in remap mode, otherwise pass to parent dialog
if(myEmulEventMapper->remapMode())
myEmulEventMapper->handleKeyDown(key, mod, ascii);
myEmulEventMapper->handleKeyDown(key, mod);
else if(myMenuEventMapper->remapMode())
myMenuEventMapper->handleKeyDown(key, mod, ascii);
myMenuEventMapper->handleKeyDown(key, mod);
else
Dialog::handleKeyDown(key, mod, ascii);
Dialog::handleKeyDown(key, mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -41,7 +41,7 @@ class InputDialog : public Dialog
~InputDialog();
protected:
virtual void handleKeyDown(StellaKey key, StellaMod mod, char ascii);
virtual void handleKeyDown(StellaKey key, StellaMod mod);
virtual void handleJoyDown(int stick, int button);
virtual void handleJoyAxis(int stick, int axis, int value);
virtual bool handleJoyHat(int stick, int hat, int value);

View File

@ -453,14 +453,14 @@ bool LauncherDialog::matchPattern(const string& s, const string& pattern) const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
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)
updateListing();
else
Dialog::handleKeyDown(key, mod, ascii);
Dialog::handleKeyDown(key, mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -80,9 +80,9 @@ class LauncherDialog : public Dialog
void reload() { updateListing(); }
protected:
virtual void handleKeyDown(StellaKey key, StellaMod mod, char ascii);
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
void handleKeyDown(StellaKey key, StellaMod mod);
void handleMouseDown(int x, int y, int button, int clickCount);
void handleCommand(CommandSender* sender, int cmd, int data, int id);
void loadConfig();
void updateListing(const string& nameToSelect = "");

View File

@ -240,17 +240,12 @@ int ListWidget::findItem(int x, int y) const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
bool ListWidget::handleText(char text)
{
// Ignore all Alt-mod keys
if(instance().eventHandler().kbdAlt(mod))
return true;
bool handled = true;
int oldSelectedItem = _selectedItem;
if (!_editMode && _quickSelect &&
((isalnum(ascii)) || isspace(ascii)))
if (!_editMode && _quickSelect)//FIXSDL && ((isalnum(ascii)) || isspace(ascii)))
{
// Quick selection mode: Go to first list item starting with this key
// (or a substring accumulated from the last couple key presses).
@ -259,9 +254,9 @@ bool ListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
// method "enableQuickSelect()" or so ?
uInt64 time = instance().getTicks() / 1000;
if (_quickSelectTime < time)
_quickSelectStr = ascii;
_quickSelectStr = text;
else
_quickSelectStr += ascii;
_quickSelectStr += text;
_quickSelectTime = time + _QUICK_SELECT_DELAY;
// FIXME: This is bad slow code (it scans the list linearly each time a
@ -282,11 +277,30 @@ bool ListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
else if (_editMode)
{
// Class EditableWidget handles all text editing related key presses for us
handled = EditableWidget::handleKeyDown(key, mod, ascii);
handled = EditableWidget::handleText(text);
}
else
if (_selectedItem != oldSelectedItem)
{
_scrollBar->draw();
scrollToSelected();
sendCommand(ListWidget::kSelectionChangedCmd, _selectedItem, _id);
}
return handled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ListWidget::handleKeyDown(StellaKey key, StellaMod mod)
{
// Ignore all Alt-mod keys
if(instance().eventHandler().kbdAlt(mod))
return true;
bool handled = true;
if (!_editMode)
{
// not editmode
switch(key)
{
case KBDK_SPACE:
@ -303,20 +317,12 @@ bool ListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
}
}
if (_selectedItem != oldSelectedItem)
{
_scrollBar->draw();
scrollToSelected();
sendCommand(ListWidget::kSelectionChangedCmd, _selectedItem, _id);
}
_currentKeyDown = key;
return handled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ListWidget::handleKeyUp(StellaKey key, StellaMod mod, char ascii)
bool ListWidget::handleKeyUp(StellaKey key, StellaMod mod)
{
if (key == _currentKeyDown)
_currentKeyDown = KBDK_UNKNOWN;

View File

@ -66,8 +66,9 @@ class ListWidget : public EditableWidget
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
virtual bool handleKeyDown(StellaKey key, StellaMod mod, char ascii);
virtual bool handleKeyUp(StellaKey key, StellaMod mod, char ascii);
virtual bool handleText(char text);
virtual bool handleKeyDown(StellaKey key, StellaMod mod);
virtual bool handleKeyUp(StellaKey key, StellaMod mod);
virtual bool handleEvent(Event::Type e);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);

View File

@ -67,8 +67,9 @@ class Widget : public GuiObject
virtual int getAbsX() const { return _x + _boss->getChildX(); }
virtual int getAbsY() const { return _y + _boss->getChildY(); }
virtual bool handleKeyDown(StellaKey key, StellaMod mod, char ascii) { return false; }
virtual bool handleKeyUp(StellaKey key, StellaMod mod, char ascii) { return false; }
virtual bool handleText(char text) { return false; }
virtual bool handleKeyDown(StellaKey key, StellaMod mod) { return false; }
virtual bool handleKeyUp(StellaKey key, StellaMod mod) { return false; }
virtual void handleMouseDown(int x, int y, int button, int clickCount) {}
virtual void handleMouseUp(int x, int y, int button, int clickCount) {}
virtual void handleMouseEntered(int button) {}