diff options
-rw-r--r-- | backends/events/default/default-events.cpp | 33 | ||||
-rw-r--r-- | backends/events/default/default-events.h | 13 | ||||
-rw-r--r-- | common/system.h | 4 | ||||
-rw-r--r-- | engines/agi/agi.cpp | 24 | ||||
-rw-r--r-- | engines/agos/agos.cpp | 2 | ||||
-rw-r--r-- | engines/agos/agos.h | 2 | ||||
-rw-r--r-- | engines/agos/event.cpp | 12 | ||||
-rw-r--r-- | engines/kyra/gui.cpp | 26 | ||||
-rw-r--r-- | engines/kyra/kyra.h | 8 | ||||
-rw-r--r-- | engines/saga/input.cpp | 3 | ||||
-rw-r--r-- | engines/saga/interface.cpp | 44 | ||||
-rw-r--r-- | engines/saga/interface.h | 10 | ||||
-rw-r--r-- | engines/sword1/control.cpp | 17 | ||||
-rw-r--r-- | engines/sword1/control.h | 2 | ||||
-rw-r--r-- | engines/sword2/sword2.cpp | 17 | ||||
-rw-r--r-- | engines/sword2/sword2.h | 1 | ||||
-rw-r--r-- | gui/newgui.cpp | 28 | ||||
-rw-r--r-- | gui/newgui.h | 8 |
18 files changed, 78 insertions, 176 deletions
diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp index 3b7315a2d4..f4c2623f0d 100644 --- a/backends/events/default/default-events.cpp +++ b/backends/events/default/default-events.cpp @@ -33,19 +33,40 @@ DefaultEventManager::DefaultEventManager(OSystem *boss) : _shouldQuit(false) { assert(_boss); + + // Reset key repeat + _currentKeyDown.keycode = 0; } bool DefaultEventManager::pollEvent(OSystem::Event &event) { + uint32 time = _boss->getMillis(); bool result; result = _boss->pollEvent(event); if (result) { + event.synthetic = false; switch (event.type) { case OSystem::EVENT_KEYDOWN: + _modifierState = event.kbd.flags; + + // init continuous event stream + // not done on PalmOS because keyboard is emulated and keyup is not generated +#if !defined(PALMOS_MODE) + _currentKeyDown.ascii = event.kbd.ascii; + _currentKeyDown.keycode = event.kbd.keycode; + _currentKeyDown.flags = event.kbd.flags; + _keyRepeatTime = time + kKeyRepeatInitialDelay; +#endif + break; case OSystem::EVENT_KEYUP: _modifierState = event.kbd.flags; + if (event.kbd.keycode == _currentKeyDown.keycode) { + // Only stop firing events if it's the current key + _currentKeyDown.keycode = 0; + } break; + case OSystem::EVENT_MOUSEMOVE: _mousePos = event.mouse; break; @@ -75,6 +96,18 @@ bool DefaultEventManager::pollEvent(OSystem::Event &event) { default: break; } + } else { + // Check if event should be sent again (keydown) + if (_currentKeyDown.keycode != 0 && _keyRepeatTime < time) { + // fire event + event.type = OSystem::EVENT_KEYDOWN; + event.synthetic = true; + event.kbd.ascii = _currentKeyDown.ascii; + event.kbd.keycode = _currentKeyDown.keycode; + event.kbd.flags = _currentKeyDown.flags; + _keyRepeatTime = time + kKeyRepeatSustainDelay; + result = true; + } } return result; diff --git a/backends/events/default/default-events.h b/backends/events/default/default-events.h index 1b6c821c23..229249a44d 100644 --- a/backends/events/default/default-events.h +++ b/backends/events/default/default-events.h @@ -46,6 +46,19 @@ class DefaultEventManager : public Common::EventManager { int _modifierState; bool _shouldQuit; + // for continuous events (keyDown) + enum { + kKeyRepeatInitialDelay = 400, + kKeyRepeatSustainDelay = 100 + }; + + struct { + uint16 ascii; + byte flags; + int keycode; + } _currentKeyDown; + uint32 _keyRepeatTime; + public: DefaultEventManager(OSystem *boss); diff --git a/common/system.h b/common/system.h index b9e46906f8..9e7e19afa0 100644 --- a/common/system.h +++ b/common/system.h @@ -743,6 +743,10 @@ public: struct Event { /** The type of the event. */ EventType type; + /** Flag to indicate if the event is real or synthetic. E.g. keyboard + * repeat events are synthetic. + */ + bool synthetic; /** * Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and * EVENT_KEYUP). For all other event types, content is undefined. diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index c15428e7c5..03b1615e85 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -113,35 +113,43 @@ void AgiEngine::processEvents() { switch (key = event.kbd.keycode) { case 256 + 20: // left arrow case 260: // key pad 4 - key = KEY_LEFT; + if (!event.synthetic) + key = KEY_LEFT; break; case 256 + 19: // right arrow case 262: // key pad 6 - key = KEY_RIGHT; + if (!event.synthetic) + key = KEY_RIGHT; break; case 256 + 17: // up arrow case 264: // key pad 8 - key = KEY_UP; + if (!event.synthetic) + key = KEY_UP; break; case 256 + 18: // down arrow case 258: // key pad 2 - key = KEY_DOWN; + if (!event.synthetic) + key = KEY_DOWN; break; case 256 + 24: // page up case 265: // key pad 9 - key = KEY_UP_RIGHT; + if (!event.synthetic) + key = KEY_UP_RIGHT; break; case 256 + 25: // page down case 259: // key pad 3 - key = KEY_DOWN_RIGHT; + if (!event.synthetic) + key = KEY_DOWN_RIGHT; break; case 256 + 22: // home case 263: // key pad 7 - key = KEY_UP_LEFT; + if (!event.synthetic) + key = KEY_UP_LEFT; break; case 256 + 23: // end case 257: // key pad 1 - key = KEY_DOWN_LEFT; + if (!event.synthetic) + key = KEY_DOWN_LEFT; break; case 261: // key pad 5 key = KEY_STATIONARY; diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp index 851b089020..95727a6a6f 100644 --- a/engines/agos/agos.cpp +++ b/engines/agos/agos.cpp @@ -81,8 +81,6 @@ AGOSEngine::AGOSEngine(OSystem *syst) _debugger = 0; _keyPressed = 0; - _keyRepeatKey = 0; - _keyRepeatTime = 0; _gameFile = 0; diff --git a/engines/agos/agos.h b/engines/agos/agos.h index 1bb2790fab..10fb0ddec5 100644 --- a/engines/agos/agos.h +++ b/engines/agos/agos.h @@ -200,8 +200,6 @@ protected: const GameSpecificSettings *gss; byte _keyPressed; - byte _keyRepeatKey; - uint32 _keyRepeatTime; typedef enum { FORMAT_NONE, diff --git a/engines/agos/event.cpp b/engines/agos/event.cpp index 7008d9a04e..4d8f8189ed 100644 --- a/engines/agos/event.cpp +++ b/engines/agos/event.cpp @@ -375,13 +375,6 @@ void AGOSEngine::delay(uint amount) { _keyPressed = 8; else _keyPressed = (byte)event.kbd.ascii; - - _keyRepeatTime = _system->getMillis() + 400; - _keyRepeatKey = _keyPressed; - break; - case OSystem::EVENT_KEYUP: - _keyRepeatKey = 0; - _keyRepeatTime = 0; break; case OSystem::EVENT_MOUSEMOVE: _sdlMouseX = event.mouse.x; @@ -435,11 +428,6 @@ void AGOSEngine::delay(uint amount) { cur = _system->getMillis(); } while (cur < start + amount); - - if (_keyPressed == 0 && _keyRepeatKey != 0 && _keyRepeatTime != 0 && cur >= _keyRepeatTime) { - _keyPressed = _keyRepeatKey; - _keyRepeatTime = cur + 100; - } } void AGOSEngine::timer_callback() { diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp index 0ca9fd6be2..f68b38eec1 100644 --- a/engines/kyra/gui.cpp +++ b/engines/kyra/gui.cpp @@ -597,8 +597,7 @@ int KyraEngine::buttonMenuCallback(Button *caller) { calcCoords(_menu[i]); _menuRestoreScreen = true; - _keyboardEvent.pending = 0; - _keyboardEvent.repeat = 0; + _keyPressed = 0; _mousePressFlag = false; _toplevelMenu = 0; @@ -835,12 +834,7 @@ void KyraEngine::gui_getInput() { _mouseWheel = 1; break; case OSystem::EVENT_KEYDOWN: - _keyboardEvent.pending = true; - _keyboardEvent.repeat = now + 400; - _keyboardEvent.ascii = event.kbd.ascii; - break; - case OSystem::EVENT_KEYUP: - _keyboardEvent.repeat = 0; + _keyPressed = event.kbd.ascii; break; default: break; @@ -852,10 +846,6 @@ void KyraEngine::gui_getInput() { lastScreenUpdate = now; } - if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) { - _keyboardEvent.pending = true; - _keyboardEvent.repeat = now + 100; - } _system->delayMillis(3); } @@ -1020,26 +1010,26 @@ void KyraEngine::gui_redrawTextfield() { void KyraEngine::gui_updateSavegameString() { int length; - if (_keyboardEvent.pending && _keyboardEvent.ascii) { + if (_keyPressed) { length = strlen(_savegameName); - if (_keyboardEvent.ascii > 31 && _keyboardEvent.ascii < 127) { + if (_keyPressed > 31 && _keyPressed < 127) { if (length < 31) { - _savegameName[length] = _keyboardEvent.ascii; + _savegameName[length] = _keyPressed; _savegameName[length+1] = 0; gui_redrawTextfield(); } - } else if (_keyboardEvent.ascii == 8 ||_keyboardEvent.ascii == 127) { + } else if (_keyPressed == 8 ||_keyPressed == 127) { if (length > 0) { _savegameName[length-1] = 0; gui_redrawTextfield(); } - } else if (_keyboardEvent.ascii == 13) { + } else if (_keyPressed == 13) { _displaySubMenu = false; } } - _keyboardEvent.pending = false; + _keyPressed = 0; } int KyraEngine::gui_saveGame(Button *button) { diff --git a/engines/kyra/kyra.h b/engines/kyra/kyra.h index 6722f84f51..21d32988ef 100644 --- a/engines/kyra/kyra.h +++ b/engines/kyra/kyra.h @@ -227,12 +227,6 @@ struct Menu { MenuItem item[6]; }; -struct KeyboardEvent { - bool pending; - uint32 repeat; - uint8 ascii; -}; - class KyraEngine : public Engine { friend class MusicPlayer; friend class Debugger; @@ -839,7 +833,7 @@ protected: int _gameToLoad; char _savegameName[31]; const char *_specialSavegameString; - KeyboardEvent _keyboardEvent; + uint8 _keyPressed; struct KyragemState { uint16 nextOperation; diff --git a/engines/saga/input.cpp b/engines/saga/input.cpp index ae14a43b9b..fdac5c2fc0 100644 --- a/engines/saga/input.cpp +++ b/engines/saga/input.cpp @@ -121,9 +121,6 @@ int SagaEngine::processInput() { break; } break; - case OSystem::EVENT_KEYUP: - _interface->processKeyUp(event.kbd.ascii); - break; case OSystem::EVENT_LBUTTONUP: _leftMouseButtonPressed = false; break; diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp index 0ff1396a49..7c37126d59 100644 --- a/engines/saga/interface.cpp +++ b/engines/saga/interface.cpp @@ -212,7 +212,6 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { error("Interface::Interface(): not enough memory"); } - _textInputRepeatPhase = 0; _textInput = false; _statusTextInput = false; _statusTextInputState = kStatusTextInputFirstRun; @@ -316,7 +315,6 @@ void Interface::setMode(int mode) { _textInput = true; _textInputStringLength = strlen(_textInputString); _textInputPos = _textInputStringLength + 1; - _textInputRepeatPhase = 0; break; case kPanelMap: mapPanelShow(); @@ -337,14 +335,13 @@ void Interface::setMode(int mode) { _textInputString[0] = 0; _textInputStringLength = 0; _textInputPos = _textInputStringLength + 1; - _textInputRepeatPhase = 0; break; } draw(); } -bool Interface::processAscii(uint16 ascii, bool synthetic) { +bool Interface::processAscii(uint16 ascii) { // TODO: Checking for Esc and Enter below is a bit hackish, and // and probably only works with the English version. Maybe we should // add a flag to the button so it can indicate if it's the default or @@ -352,8 +349,6 @@ bool Interface::processAscii(uint16 ascii, bool synthetic) { int i; PanelButton *panelButton; - if (!synthetic) - _textInputRepeatPhase = 0; if (_statusTextInput) { processStatusTextInput(ascii); return true; @@ -536,40 +531,6 @@ bool Interface::processAscii(uint16 ascii, bool synthetic) { return false; } -#define KEYBOARD_REPEAT_DELAY1 300000L -#define KEYBOARD_REPEAT_DELAY2 50000L - -void Interface::textInputRepeatCallback(void *refCon) { - ((Interface *)refCon)->textInputRepeat(); -} - -void Interface::textInputStartRepeat(uint16 ascii) { - if (!_textInputRepeatPhase) { - _textInputRepeatPhase = 1; - _vm->_timer->removeTimerProc(&textInputRepeatCallback); - _vm->_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY1, this); - } - - _textInputRepeatChar = ascii; -} - -void Interface::textInputRepeat() { - if (_textInputRepeatPhase == 1) { - _textInputRepeatPhase = 2; - _vm->_timer->removeTimerProc(&textInputRepeatCallback); - _vm->_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY2, this); - } else if (_textInputRepeatPhase == 2) { - processAscii(_textInputRepeatChar, true); - } -} - -void Interface::processKeyUp(uint16 ascii) { - if (_textInputRepeatPhase) { - _vm->_timer->removeTimerProc(&textInputRepeatCallback); - _textInputRepeatPhase = 0; - } -} - void Interface::setStatusText(const char *text, int statusColor) { assert(text != NULL); assert(strlen(text) < STATUS_TEXT_LEN); @@ -928,7 +889,6 @@ void Interface::setLoad(PanelButton *panelButton) { void Interface::processStatusTextInput(uint16 ascii) { - textInputStartRepeat(ascii); switch (ascii) { case 27: // esc _statusTextInputState = kStatusTextInputAborted; @@ -968,8 +928,6 @@ bool Interface::processTextInput(uint16 ascii) { memset(tempString, 0, SAVE_TITLE_SIZE); ch[1] = 0; - textInputStartRepeat(ascii); - switch (ascii) { case 13: return false; diff --git a/engines/saga/interface.h b/engines/saga/interface.h index 5f8f0f61e3..6dfaaa4984 100644 --- a/engines/saga/interface.h +++ b/engines/saga/interface.h @@ -222,8 +222,7 @@ public: void drawStatusBar(); void setVerbState(int verb, int state); - bool processAscii(uint16 ascii, bool synthetic = false); - void processKeyUp(uint16 ascii); + bool processAscii(uint16 ascii); void keyBoss(); void keyBossExit(); @@ -243,8 +242,6 @@ public: } private: - static void textInputRepeatCallback(void *refCon); - void drawInventory(Surface *backBuffer); void updateInventory(int pos); void inventoryChangePos(int chg); @@ -343,8 +340,6 @@ private: void calcOptionSaveSlider(); bool processTextInput(uint16 ascii); void processStatusTextInput(uint16 ascii); - void textInputStartRepeat(uint16 ascii); - void textInputRepeat(void); public: void converseInit(void); @@ -452,9 +447,6 @@ private: uint _statusTextInputPos; - int _textInputRepeatPhase; - uint16 _textInputRepeatChar; - PalEntry _mapSavedPal[PAL_ENTRIES]; bool _mapPanelCrossHairState; diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp index 9a4b2fe46a..ec612ce1fc 100644 --- a/engines/sword1/control.cpp +++ b/engines/sword1/control.cpp @@ -42,11 +42,6 @@ namespace Sword1 { -enum { - kKeyRepeatInitialDelay = 400, - kKeyRepeatSustainDelay = 100 -}; - enum LangStrings { STR_PAUSED = 0, STR_INSERT_CD_A, @@ -171,8 +166,6 @@ Control::Control(Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMa _music = pMusic; _sound = pSound; _lStrings = _languageStrings + SwordEngine::_systemVars.language * 20; - _keyRepeat = 0; - _keyRepeatTime = 0; _selectedButton = 255; } @@ -1053,15 +1046,9 @@ void Control::delay(uint32 msecs) { _keyPressed = 8; else _keyPressed = (byte)event.kbd.ascii; - _keyRepeatTime = now + kKeyRepeatInitialDelay; - _keyRepeat = _keyPressed; // we skip the rest of the delay and return immediately // to handle keyboard input return; - case OSystem::EVENT_KEYUP: - _keyRepeatTime = 0; - _keyRepeat = 0; - break; case OSystem::EVENT_MOUSEMOVE: _mouseX = event.mouse.x; _mouseY = event.mouse.y; @@ -1093,10 +1080,6 @@ void Control::delay(uint32 msecs) { break; } } - if (_keyRepeatTime && now > _keyRepeatTime) { - _keyRepeatTime += kKeyRepeatSustainDelay; - _keyPressed = _keyRepeat; - } _system->updateScreen(); _system->delayMillis(10); diff --git a/engines/sword1/control.h b/engines/sword1/control.h index 686783012a..8cacbfb0b8 100644 --- a/engines/sword1/control.h +++ b/engines/sword1/control.h @@ -139,8 +139,6 @@ private: uint8 *_font, *_redFont; uint8 *_screenBuf; uint8 _keyPressed; - uint8 _keyRepeat; - uint32 _keyRepeatTime; void delay(uint32 msecs); uint16 _mouseX, _mouseY, _mouseState; bool _mouseDown; diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index d04cdadfa2..3e313fcdcc 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -187,7 +187,6 @@ Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) { _debugger = NULL; _keyboardEvent.pending = false; - _keyboardEvent.repeat = 0; _mouseEvent.pending = false; _wantSfxDebug = false; @@ -377,10 +376,6 @@ int Sword2Engine::go() { if (ke) { if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') { - // HACK: We have to clear the 'repeat' flag, or - // it will probably trigger a keyboard repeat - // immediately after the debug console closes. - _keyboardEvent.repeat = 0; _debugger->attach(); } else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) { switch (ke->keycode) { @@ -539,8 +534,6 @@ uint32 Sword2Engine::setInputEventFilter(uint32 filter) { void Sword2Engine::parseInputEvents() { OSystem::Event event; - uint32 now = _system->getMillis(); - Common::EventManager *eventMan = _system->getEventManager(); while (eventMan->pollEvent(event)) { switch (event.type) { @@ -555,15 +548,11 @@ void Sword2Engine::parseInputEvents() { } if (!(_inputEventFilter & RD_KEYDOWN)) { _keyboardEvent.pending = true; - _keyboardEvent.repeat = now + 400; _keyboardEvent.ascii = event.kbd.ascii; _keyboardEvent.keycode = event.kbd.keycode; _keyboardEvent.modifiers = event.kbd.flags; } break; - case OSystem::EVENT_KEYUP: - _keyboardEvent.repeat = 0; - break; case OSystem::EVENT_MOUSEMOVE: if (!(_inputEventFilter & RD_KEYDOWN)) { _mouse->setPos(event.mouse.x, event.mouse.y - MENUDEEP); @@ -612,12 +601,6 @@ void Sword2Engine::parseInputEvents() { break; } } - - // Handle keyboard auto-repeat - if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) { - _keyboardEvent.pending = true; - _keyboardEvent.repeat = now + 100; - } } void Sword2Engine::gameCycle() { diff --git a/engines/sword2/sword2.h b/engines/sword2/sword2.h index 3acdce0eeb..c3fc99268d 100644 --- a/engines/sword2/sword2.h +++ b/engines/sword2/sword2.h @@ -74,7 +74,6 @@ struct MouseEvent { struct KeyboardEvent { bool pending; - uint32 repeat; uint16 ascii; int keycode; int modifiers; diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 90a5c6d121..adb27b83df 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -50,9 +50,7 @@ namespace GUI { enum { kDoubleClickDelay = 500, // milliseconds - kCursorAnimateDelay = 250, - kKeyRepeatInitialDelay = 400, - kKeyRepeatSustainDelay = 100 + kCursorAnimateDelay = 250 }; void GuiObject::reflowLayout() { @@ -91,9 +89,6 @@ NewGui::NewGui() : _needRedraw(false), // Clear the cursor memset(_cursor, 0xFF, sizeof(_cursor)); - // Reset key repeat - _currentKeyDown.keycode = 0; - bool loadClassicTheme = true; #ifndef DISABLE_FANCY_THEMES ConfMan.registerDefault("gui_theme", "default"); @@ -272,21 +267,10 @@ void NewGui::runLoop() { switch (event.type) { case OSystem::EVENT_KEYDOWN: -#if !defined(PALMOS_MODE) - // init continuous event stream - // not done on PalmOS because keyboard is emulated and keyup is not generated - _currentKeyDown.ascii = event.kbd.ascii; - _currentKeyDown.keycode = event.kbd.keycode; - _currentKeyDown.flags = event.kbd.flags; - _keyRepeatTime = time + kKeyRepeatInitialDelay; -#endif activeDialog->handleKeyDown(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); break; case OSystem::EVENT_KEYUP: activeDialog->handleKeyUp(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); - if (event.kbd.keycode == _currentKeyDown.keycode) - // only stop firing events if it's the current key - _currentKeyDown.keycode = 0; break; case OSystem::EVENT_MOUSEMOVE: activeDialog->handleMouseMoved(mouse.x, mouse.y, 0); @@ -327,15 +311,6 @@ void NewGui::runLoop() { } } - // check if event should be sent again (keydown) - if (_currentKeyDown.keycode != 0 && activeDialog == getTopDialog()) { - if (_keyRepeatTime < time) { - // fire event - activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags); - _keyRepeatTime = time + kKeyRepeatSustainDelay; - } - } - // Delay for a moment _system->delayMillis(10); } @@ -353,7 +328,6 @@ void NewGui::runLoop() { void NewGui::saveState() { // Backup old cursor - _currentKeyDown.keycode = 0; _lastClick.x = _lastClick.y = 0; _lastClick.time = 0; _lastClick.count = 0; diff --git a/gui/newgui.h b/gui/newgui.h index 5a1c237475..70658abcb4 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -99,14 +99,6 @@ protected: bool _useStdCursor; - // for continuous events (keyDown) - struct { - uint16 ascii; - byte flags; - int keycode; - } _currentKeyDown; - uint32 _keyRepeatTime; - // position and time of last mouse click (used to detect double clicks) struct { int16 x, y; // Position of mouse when the click occured |