diff options
Diffstat (limited to 'backends/events/default')
-rw-r--r-- | backends/events/default/default-events.cpp | 286 | ||||
-rw-r--r-- | backends/events/default/default-events.h | 8 |
2 files changed, 152 insertions, 142 deletions
diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp index ad7cfced86..40068e7b9e 100644 --- a/backends/events/default/default-events.cpp +++ b/backends/events/default/default-events.cpp @@ -50,10 +50,6 @@ DefaultEventManager::DefaultEventManager(Common::EventSource *boss) : _dispatcher.registerObserver(this, kEventManPriority, false); // Reset key repeat - _currentKeyDown.keycode = 0; - _currentKeyDown.ascii = 0; - _currentKeyDown.flags = 0; - _keyRepeatTime = 0; #ifdef ENABLE_VKEYBD @@ -86,143 +82,161 @@ void DefaultEventManager::init() { } bool DefaultEventManager::pollEvent(Common::Event &event) { - // Skip recording of these events - uint32 time = g_system->getMillis(true); - bool result = false; - _dispatcher.dispatch(); - if (!_eventQueue.empty()) { - event = _eventQueue.pop(); - result = true; - } - if (result) { - event.kbdRepeat = false; - switch (event.type) { - case Common::EVENT_KEYDOWN: - _modifierState = event.kbd.flags; - // init continuous event stream - _currentKeyDown.ascii = event.kbd.ascii; - _currentKeyDown.keycode = event.kbd.keycode; - _currentKeyDown.flags = event.kbd.flags; - _keyRepeatTime = time + kKeyRepeatInitialDelay; + handleKeyRepeat(); - if (event.kbd.keycode == Common::KEYCODE_BACKSPACE) { - // WORKAROUND: Some engines incorrectly attempt to use the - // ascii value instead of the keycode to detect the backspace - // key (a non-portable behavior). This fails at least on - // Mac OS X, possibly also on other systems. - // As a workaround, we force the ascii value for backspace - // key pressed. A better fix would be for engines to stop - // making invalid assumptions about ascii values. - event.kbd.ascii = Common::KEYCODE_BACKSPACE; - _currentKeyDown.ascii = Common::KEYCODE_BACKSPACE; - } - break; + if (_eventQueue.empty()) { + return false; + } - case Common::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; + event = _eventQueue.pop(); + bool forwardEvent = true; + + switch (event.type) { + case Common::EVENT_KEYDOWN: + _modifierState = event.kbd.flags; + + if (event.kbd.keycode == Common::KEYCODE_BACKSPACE) { + // WORKAROUND: Some engines incorrectly attempt to use the + // ascii value instead of the keycode to detect the backspace + // key (a non-portable behavior). This fails at least on + // Mac OS X, possibly also on other systems. + // As a workaround, we force the ascii value for backspace + // key pressed. A better fix would be for engines to stop + // making invalid assumptions about ascii values. + event.kbd.ascii = Common::KEYCODE_BACKSPACE; + _currentKeyDown.ascii = Common::KEYCODE_BACKSPACE; + } + break; + + case Common::EVENT_KEYUP: + _modifierState = event.kbd.flags; + break; + + case Common::EVENT_MOUSEMOVE: + _mousePos = event.mouse; + break; + + case Common::EVENT_LBUTTONDOWN: + _mousePos = event.mouse; + _buttonState |= LBUTTON; + break; + + case Common::EVENT_LBUTTONUP: + _mousePos = event.mouse; + _buttonState &= ~LBUTTON; + break; + + case Common::EVENT_RBUTTONDOWN: + _mousePos = event.mouse; + _buttonState |= RBUTTON; + break; + + case Common::EVENT_RBUTTONUP: + _mousePos = event.mouse; + _buttonState &= ~RBUTTON; + break; + + case Common::EVENT_MAINMENU: + if (g_engine && !g_engine->isPaused()) + g_engine->openMainMenuDialog(); + + if (_shouldQuit) + event.type = Common::EVENT_QUIT; + else if (_shouldRTL) + event.type = Common::EVENT_RTL; + break; +#ifdef ENABLE_VKEYBD + case Common::EVENT_VIRTUAL_KEYBOARD: + if (_vk->isDisplaying()) { + _vk->close(true); + } else { + if (g_engine) + g_engine->pauseEngine(true); + _vk->show(); + if (g_engine) + g_engine->pauseEngine(false); + forwardEvent = false; + } + break; +#endif +#ifdef ENABLE_KEYMAPPER + case Common::EVENT_KEYMAPPER_REMAP: + if (!_remap) { + _remap = true; + Common::RemapDialog _remapDialog; + if (g_engine) + g_engine->pauseEngine(true); + _remapDialog.runModal(); + if (g_engine) + g_engine->pauseEngine(false); + _remap = false; + } + break; +#endif + case Common::EVENT_RTL: + if (ConfMan.getBool("confirm_exit")) { + if (g_engine) + g_engine->pauseEngine(true); + GUI::MessageDialog alert(_("Do you really want to return to the Launcher?"), _("Launcher"), _("Cancel")); + forwardEvent = _shouldRTL = (alert.runModal() == GUI::kMessageOK); + if (g_engine) + g_engine->pauseEngine(false); + } else + _shouldRTL = true; + break; + + case Common::EVENT_MUTE: + if (g_engine) + g_engine->flipMute(); + break; + + case Common::EVENT_QUIT: + if (ConfMan.getBool("confirm_exit")) { + if (_confirmExitDialogActive) { + forwardEvent = false; + break; } - break; - - case Common::EVENT_MOUSEMOVE: - _mousePos = event.mouse; - break; - - case Common::EVENT_LBUTTONDOWN: - _mousePos = event.mouse; - _buttonState |= LBUTTON; - break; + _confirmExitDialogActive = true; + if (g_engine) + g_engine->pauseEngine(true); + GUI::MessageDialog alert(_("Do you really want to quit?"), _("Quit"), _("Cancel")); + forwardEvent = _shouldQuit = (alert.runModal() == GUI::kMessageOK); + if (g_engine) + g_engine->pauseEngine(false); + _confirmExitDialogActive = false; + } else + _shouldQuit = true; - case Common::EVENT_LBUTTONUP: - _mousePos = event.mouse; - _buttonState &= ~LBUTTON; - break; + break; - case Common::EVENT_RBUTTONDOWN: - _mousePos = event.mouse; - _buttonState |= RBUTTON; - break; + default: + break; + } - case Common::EVENT_RBUTTONUP: - _mousePos = event.mouse; - _buttonState &= ~RBUTTON; - break; + return forwardEvent; +} - case Common::EVENT_MAINMENU: - if (g_engine && !g_engine->isPaused()) - g_engine->openMainMenuDialog(); +void DefaultEventManager::handleKeyRepeat() { + uint32 time = g_system->getMillis(true); - if (_shouldQuit) - event.type = Common::EVENT_QUIT; - else if (_shouldRTL) - event.type = Common::EVENT_RTL; - break; -#ifdef ENABLE_VKEYBD - case Common::EVENT_VIRTUAL_KEYBOARD: - if (_vk->isDisplaying()) { - _vk->close(true); - } else { - if (g_engine) - g_engine->pauseEngine(true); - _vk->show(); - if (g_engine) - g_engine->pauseEngine(false); - result = false; - } - break; -#endif -#ifdef ENABLE_KEYMAPPER - case Common::EVENT_KEYMAPPER_REMAP: - if (!_remap) { - _remap = true; - Common::RemapDialog _remapDialog; - if (g_engine) - g_engine->pauseEngine(true); - _remapDialog.runModal(); - if (g_engine) - g_engine->pauseEngine(false); - _remap = false; - } - break; -#endif - case Common::EVENT_RTL: - if (ConfMan.getBool("confirm_exit")) { - if (g_engine) - g_engine->pauseEngine(true); - GUI::MessageDialog alert(_("Do you really want to return to the Launcher?"), _("Launcher"), _("Cancel")); - result = _shouldRTL = (alert.runModal() == GUI::kMessageOK); - if (g_engine) - g_engine->pauseEngine(false); - } else - _shouldRTL = true; - break; + if (!_eventQueue.empty()) { + // Peek in the event queue + const Common::Event &nextEvent = _eventQueue.front(); - case Common::EVENT_MUTE: - if (g_engine) - g_engine->flipMute(); + switch (nextEvent.type) { + case Common::EVENT_KEYDOWN: + // init continuous event stream + _currentKeyDown = nextEvent.kbd; + _keyRepeatTime = time + kKeyRepeatInitialDelay; break; - case Common::EVENT_QUIT: - if (ConfMan.getBool("confirm_exit")) { - if (_confirmExitDialogActive) { - result = false; - break; - } - _confirmExitDialogActive = true; - if (g_engine) - g_engine->pauseEngine(true); - GUI::MessageDialog alert(_("Do you really want to quit?"), _("Quit"), _("Cancel")); - result = _shouldQuit = (alert.runModal() == GUI::kMessageOK); - if (g_engine) - g_engine->pauseEngine(false); - _confirmExitDialogActive = false; - } else - _shouldQuit = true; - + case Common::EVENT_KEYUP: + if (nextEvent.kbd.keycode == _currentKeyDown.keycode) { + // Only stop firing events if it's the current key + _currentKeyDown.keycode = Common::KEYCODE_INVALID; + } break; default: @@ -230,19 +244,17 @@ bool DefaultEventManager::pollEvent(Common::Event &event) { } } else { // Check if event should be sent again (keydown) - if (_currentKeyDown.keycode != 0 && _keyRepeatTime < time) { + if (_currentKeyDown.keycode != Common::KEYCODE_INVALID && _keyRepeatTime < time) { // fire event - event.type = Common::EVENT_KEYDOWN; - event.kbdRepeat = true; - event.kbd.ascii = _currentKeyDown.ascii; - event.kbd.keycode = (Common::KeyCode)_currentKeyDown.keycode; - event.kbd.flags = _currentKeyDown.flags; + Common::Event repeatEvent; + repeatEvent.type = Common::EVENT_KEYDOWN; + repeatEvent.kbdRepeat = true; + repeatEvent.kbd = _currentKeyDown; _keyRepeatTime = time + kKeyRepeatSustainDelay; - result = true; + + _eventQueue.push(repeatEvent); } } - - return result; } void DefaultEventManager::pushEvent(const Common::Event &event) { diff --git a/backends/events/default/default-events.h b/backends/events/default/default-events.h index 38406c25aa..67c7f7708e 100644 --- a/backends/events/default/default-events.h +++ b/backends/events/default/default-events.h @@ -67,12 +67,10 @@ class DefaultEventManager : public Common::EventManager, Common::EventObserver { kKeyRepeatSustainDelay = 100 }; - struct { - uint16 ascii; - byte flags; - int keycode; - } _currentKeyDown; + Common::KeyState _currentKeyDown; uint32 _keyRepeatTime; + + void handleKeyRepeat(); public: DefaultEventManager(Common::EventSource *boss); ~DefaultEventManager(); |