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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
|
|
|
|
2007-06-30 12:43:53 +00:00
|
|
|
#include "common/config-manager.h"
|
2007-03-17 00:07:34 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "backends/events/default/default-events.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
|
|
|
|
|
|
|
DefaultEventManager::DefaultEventManager(OSystem *boss) :
|
|
|
|
_boss(boss),
|
|
|
|
_buttonState(0),
|
|
|
|
_modifierState(0),
|
|
|
|
_shouldQuit(false) {
|
|
|
|
|
|
|
|
assert(_boss);
|
2007-03-17 15:44:26 +00:00
|
|
|
|
|
|
|
// Reset key repeat
|
|
|
|
_currentKeyDown.keycode = 0;
|
2007-03-17 00:07:34 +00:00
|
|
|
}
|
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
bool DefaultEventManager::pollEvent(Common::Event &event) {
|
2007-03-17 15:44:26 +00:00
|
|
|
uint32 time = _boss->getMillis();
|
2007-03-17 00:07:34 +00:00
|
|
|
bool result;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-03-17 00:07:34 +00:00
|
|
|
result = _boss->pollEvent(event);
|
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
|
|
|
|
// 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;
|
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;
|
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;
|
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;
|
|
|
|
|
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")) {
|
2007-07-01 18:22:25 +00:00
|
|
|
if (g_engine)
|
|
|
|
g_engine->pauseEngine(true);
|
2007-06-30 12:43:53 +00:00
|
|
|
GUI::MessageDialog alert("Do you really want to quit?", "Yes", "No");
|
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);
|
2007-06-30 12:43:53 +00:00
|
|
|
} else
|
|
|
|
_shouldQuit = true;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
|