2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2007-03-17 00:07:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-29 16:18:43 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2007-03-17 00:07:34 +00:00
|
|
|
#if !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
|
|
|
|
|
|
|
#include "common/system.h"
|
2007-09-19 13:55:05 +00:00
|
|
|
#include "common/config-manager.h"
|
2011-06-13 22:19:18 +01:00
|
|
|
#include "common/translation.h"
|
2007-03-17 00:07:34 +00:00
|
|
|
#include "backends/events/default/default-events.h"
|
2008-08-07 16:38:39 +00:00
|
|
|
#include "backends/keymapper/keymapper.h"
|
2008-08-08 14:23:59 +00:00
|
|
|
#include "backends/keymapper/remap-dialog.h"
|
2008-08-07 16:38:39 +00:00
|
|
|
#include "backends/vkeybd/virtual-keyboard.h"
|
2007-06-30 18:22:21 +00:00
|
|
|
|
|
|
|
#include "engines/engine.h"
|
2007-06-30 12:43:53 +00:00
|
|
|
#include "gui/message.h"
|
2007-03-17 00:07:34 +00:00
|
|
|
|
2009-07-25 00:59:03 +00:00
|
|
|
DefaultEventManager::DefaultEventManager(Common::EventSource *boss) :
|
2007-03-17 00:07:34 +00:00
|
|
|
_buttonState(0),
|
|
|
|
_modifierState(0),
|
2008-07-02 00:30:49 +00:00
|
|
|
_shouldQuit(false),
|
2009-01-02 01:21:38 +00:00
|
|
|
_shouldRTL(false),
|
|
|
|
_confirmExitDialogActive(false) {
|
2007-03-17 00:07:34 +00:00
|
|
|
|
2009-07-25 01:00:37 +00:00
|
|
|
assert(boss);
|
|
|
|
|
2009-07-25 01:01:22 +00:00
|
|
|
_dispatcher.registerSource(boss, false);
|
|
|
|
_dispatcher.registerSource(&_artificialEventSource, false);
|
2009-07-25 01:00:37 +00:00
|
|
|
|
2009-07-25 01:01:41 +00:00
|
|
|
_dispatcher.registerObserver(this, kEventManPriority, false);
|
2007-03-17 15:44:26 +00:00
|
|
|
|
|
|
|
// Reset key repeat
|
|
|
|
_currentKeyDown.keycode = 0;
|
2013-04-21 14:33:52 +03:00
|
|
|
_currentKeyDown.ascii = 0;
|
|
|
|
_currentKeyDown.flags = 0;
|
2007-09-19 13:55:05 +00:00
|
|
|
|
2013-09-22 11:47:37 +03:00
|
|
|
_keyRepeatTime = 0;
|
|
|
|
|
2008-09-30 13:51:01 +00:00
|
|
|
#ifdef ENABLE_VKEYBD
|
2008-07-07 15:42:26 +00:00
|
|
|
_vk = new Common::VirtualKeyboard();
|
2008-09-30 13:51:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_KEYMAPPER
|
2008-08-06 14:21:05 +00:00
|
|
|
_keymapper = new Common::Keymapper(this);
|
2009-07-25 01:01:05 +00:00
|
|
|
// EventDispatcher will automatically free the keymapper
|
2009-07-25 01:01:22 +00:00
|
|
|
_dispatcher.registerMapper(_keymapper);
|
2008-08-13 19:24:52 +00:00
|
|
|
_remap = false;
|
2012-02-17 14:42:17 -06:00
|
|
|
#else
|
|
|
|
_dispatcher.registerMapper(new Common::DefaultEventMapper());
|
2008-09-30 13:51:01 +00:00
|
|
|
#endif
|
2007-09-19 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DefaultEventManager::~DefaultEventManager() {
|
2008-09-30 13:51:01 +00:00
|
|
|
#ifdef ENABLE_VKEYBD
|
2008-07-09 13:33:36 +00:00
|
|
|
delete _vk;
|
2008-09-30 13:51:01 +00:00
|
|
|
#endif
|
2007-09-19 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2008-08-18 10:07:11 +00:00
|
|
|
void DefaultEventManager::init() {
|
2008-09-30 13:51:01 +00:00
|
|
|
#ifdef ENABLE_VKEYBD
|
2008-08-18 10:07:11 +00:00
|
|
|
if (ConfMan.hasKey("vkeybd_pack_name")) {
|
|
|
|
_vk->loadKeyboardPack(ConfMan.get("vkeybd_pack_name"));
|
|
|
|
} else {
|
2009-06-08 14:47:38 +00:00
|
|
|
_vk->loadKeyboardPack("vkeybd_default");
|
2008-08-18 10:07:11 +00:00
|
|
|
}
|
2008-09-30 13:51:01 +00:00
|
|
|
#endif
|
2008-08-18 10:07:11 +00:00
|
|
|
}
|
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
bool DefaultEventManager::pollEvent(Common::Event &event) {
|
2013-05-17 00:18:09 +03:00
|
|
|
// Skip recording of these events
|
|
|
|
uint32 time = g_system->getMillis(true);
|
2009-07-25 01:00:37 +00:00
|
|
|
bool result = false;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-07-25 01:01:22 +00:00
|
|
|
_dispatcher.dispatch();
|
2009-07-25 01:00:37 +00:00
|
|
|
if (!_eventQueue.empty()) {
|
|
|
|
event = _eventQueue.pop();
|
2008-07-07 22:34:45 +00:00
|
|
|
result = true;
|
2008-07-23 08:45:12 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-03-17 00:07:34 +00:00
|
|
|
if (result) {
|
2007-03-17 15:44:26 +00:00
|
|
|
event.synthetic = false;
|
2007-03-17 00:07:34 +00:00
|
|
|
switch (event.type) {
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
2007-03-17 15:44:26 +00:00
|
|
|
_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;
|
2010-07-17 18:41:38 +00:00
|
|
|
|
2012-02-18 22:17:48 -06:00
|
|
|
if (event.kbd.keycode == Common::KEYCODE_BACKSPACE) {
|
2009-09-01 13:02:24 +00:00
|
|
|
// 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.
|
2009-08-16 14:04:54 +00:00
|
|
|
event.kbd.ascii = Common::KEYCODE_BACKSPACE;
|
2010-10-03 14:59:36 +00:00
|
|
|
_currentKeyDown.ascii = Common::KEYCODE_BACKSPACE;
|
2009-08-16 14:04:54 +00:00
|
|
|
}
|
2007-03-17 15:44:26 +00:00
|
|
|
break;
|
2008-06-24 21:15:30 +00:00
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_KEYUP:
|
2007-03-17 00:07:34 +00:00
|
|
|
_modifierState = event.kbd.flags;
|
2007-03-17 15:44:26 +00:00
|
|
|
if (event.kbd.keycode == _currentKeyDown.keycode) {
|
|
|
|
// Only stop firing events if it's the current key
|
|
|
|
_currentKeyDown.keycode = 0;
|
|
|
|
}
|
2007-03-17 00:07:34 +00:00
|
|
|
break;
|
2007-03-17 15:44:26 +00:00
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2007-03-17 00:07:34 +00:00
|
|
|
_mousePos = event.mouse;
|
|
|
|
break;
|
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2007-03-17 00:07:34 +00:00
|
|
|
_mousePos = event.mouse;
|
|
|
|
_buttonState |= LBUTTON;
|
|
|
|
break;
|
2008-06-24 21:15:30 +00:00
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONUP:
|
2007-03-17 00:07:34 +00:00
|
|
|
_mousePos = event.mouse;
|
|
|
|
_buttonState &= ~LBUTTON;
|
|
|
|
break;
|
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2007-03-17 00:07:34 +00:00
|
|
|
_mousePos = event.mouse;
|
|
|
|
_buttonState |= RBUTTON;
|
|
|
|
break;
|
2008-06-24 21:15:30 +00:00
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_RBUTTONUP:
|
2007-03-17 00:07:34 +00:00
|
|
|
_mousePos = event.mouse;
|
|
|
|
_buttonState &= ~RBUTTON;
|
|
|
|
break;
|
|
|
|
|
2008-06-24 21:15:30 +00:00
|
|
|
case Common::EVENT_MAINMENU:
|
|
|
|
if (g_engine && !g_engine->isPaused())
|
2008-10-02 17:55:08 +00:00
|
|
|
g_engine->openMainMenuDialog();
|
2008-07-16 04:22:56 +00:00
|
|
|
|
2008-07-11 00:49:01 +00:00
|
|
|
if (_shouldQuit)
|
|
|
|
event.type = Common::EVENT_QUIT;
|
2008-07-16 04:22:56 +00:00
|
|
|
else if (_shouldRTL)
|
|
|
|
event.type = Common::EVENT_RTL;
|
2008-07-07 22:34:45 +00:00
|
|
|
break;
|
2012-02-18 22:17:48 -06:00
|
|
|
#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
|
2008-07-07 22:34:45 +00:00
|
|
|
case Common::EVENT_RTL:
|
2008-11-11 12:28:46 +00:00
|
|
|
if (ConfMan.getBool("confirm_exit")) {
|
|
|
|
if (g_engine)
|
|
|
|
g_engine->pauseEngine(true);
|
2011-06-13 22:19:18 +01:00
|
|
|
GUI::MessageDialog alert(_("Do you really want to return to the Launcher?"), _("Launcher"), _("Cancel"));
|
2008-11-11 12:28:46 +00:00
|
|
|
result = _shouldRTL = (alert.runModal() == GUI::kMessageOK);
|
|
|
|
if (g_engine)
|
|
|
|
g_engine->pauseEngine(false);
|
|
|
|
} else
|
|
|
|
_shouldRTL = true;
|
2008-07-07 22:34:45 +00:00
|
|
|
break;
|
2008-06-24 21:15:30 +00:00
|
|
|
|
2009-06-06 17:36:06 +00:00
|
|
|
case Common::EVENT_MUTE:
|
|
|
|
if (g_engine)
|
|
|
|
g_engine->flipMute();
|
|
|
|
break;
|
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_QUIT:
|
2007-06-30 12:43:53 +00:00
|
|
|
if (ConfMan.getBool("confirm_exit")) {
|
2009-01-02 01:21:38 +00:00
|
|
|
if (_confirmExitDialogActive) {
|
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_confirmExitDialogActive = true;
|
2007-07-01 18:22:25 +00:00
|
|
|
if (g_engine)
|
|
|
|
g_engine->pauseEngine(true);
|
2011-06-13 22:19:18 +01:00
|
|
|
GUI::MessageDialog alert(_("Do you really want to quit?"), _("Quit"), _("Cancel"));
|
2007-06-30 18:22:21 +00:00
|
|
|
result = _shouldQuit = (alert.runModal() == GUI::kMessageOK);
|
2007-07-01 18:22:25 +00:00
|
|
|
if (g_engine)
|
|
|
|
g_engine->pauseEngine(false);
|
2009-01-02 01:21:38 +00:00
|
|
|
_confirmExitDialogActive = false;
|
2007-06-30 12:43:53 +00:00
|
|
|
} else
|
|
|
|
_shouldQuit = true;
|
2008-07-02 00:30:49 +00:00
|
|
|
|
2007-03-17 00:07:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-03-17 15:44:26 +00:00
|
|
|
} else {
|
|
|
|
// Check if event should be sent again (keydown)
|
|
|
|
if (_currentKeyDown.keycode != 0 && _keyRepeatTime < time) {
|
|
|
|
// fire event
|
2007-03-17 19:02:05 +00:00
|
|
|
event.type = Common::EVENT_KEYDOWN;
|
2007-03-17 15:44:26 +00:00
|
|
|
event.synthetic = true;
|
|
|
|
event.kbd.ascii = _currentKeyDown.ascii;
|
2007-06-21 18:35:15 +00:00
|
|
|
event.kbd.keycode = (Common::KeyCode)_currentKeyDown.keycode;
|
2007-03-17 15:44:26 +00:00
|
|
|
event.kbd.flags = _currentKeyDown.flags;
|
|
|
|
_keyRepeatTime = time + kKeyRepeatSustainDelay;
|
|
|
|
result = true;
|
|
|
|
}
|
2007-03-17 00:07:34 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-03-17 00:07:34 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-07-21 18:53:55 +00:00
|
|
|
void DefaultEventManager::pushEvent(const Common::Event &event) {
|
2008-07-13 20:41:39 +00:00
|
|
|
// If already received an EVENT_QUIT, don't add another one
|
|
|
|
if (event.type == Common::EVENT_QUIT) {
|
|
|
|
if (!_shouldQuit)
|
2009-07-25 00:59:53 +00:00
|
|
|
_artificialEventSource.addEvent(event);
|
2009-01-01 15:06:43 +00:00
|
|
|
} else
|
2009-07-25 00:59:53 +00:00
|
|
|
_artificialEventSource.addEvent(event);
|
2008-07-07 22:34:45 +00:00
|
|
|
}
|
|
|
|
|
2007-03-17 00:07:34 +00:00
|
|
|
#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
|