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.
|
2002-07-05 16:56:53 +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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2002-07-05 16:56:53 +00:00
|
|
|
*/
|
|
|
|
|
2007-03-17 00:53:21 +00:00
|
|
|
#include "common/events.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/util.h"
|
2008-12-27 16:07:10 +00:00
|
|
|
#include "common/config-manager.h"
|
2009-01-02 20:03:45 +00:00
|
|
|
#include "common/algorithm.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/rect.h"
|
|
|
|
#include "common/textconsole.h"
|
2010-06-15 10:44:51 +00:00
|
|
|
#include "common/translation.h"
|
2013-05-16 21:18:09 +00:00
|
|
|
#include "gui/EventRecorder.h"
|
2008-12-27 16:07:10 +00:00
|
|
|
|
2009-01-11 00:20:27 +00:00
|
|
|
#include "backends/keymapper/keymapper.h"
|
|
|
|
|
2010-11-16 10:24:16 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2004-03-13 13:03:25 +00:00
|
|
|
#include "gui/dialog.h"
|
2008-09-02 17:51:08 +00:00
|
|
|
#include "gui/ThemeEngine.h"
|
2008-11-08 01:30:32 +00:00
|
|
|
#include "gui/ThemeEval.h"
|
2010-11-16 10:29:31 +00:00
|
|
|
#include "gui/Tooltip.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "gui/widget.h"
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2008-12-27 16:07:10 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2006-01-27 15:43:23 +00:00
|
|
|
|
2011-06-27 23:06:23 +00:00
|
|
|
namespace Common {
|
2010-11-16 08:23:13 +00:00
|
|
|
DECLARE_SINGLETON(GUI::GuiManager);
|
2011-06-27 23:06:23 +00:00
|
|
|
}
|
2007-05-27 11:40:03 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2002-09-30 12:56:59 +00:00
|
|
|
enum {
|
2003-03-06 19:52:54 +00:00
|
|
|
kDoubleClickDelay = 500, // milliseconds
|
2010-07-23 19:36:47 +00:00
|
|
|
kCursorAnimateDelay = 250,
|
|
|
|
kTooltipDelay = 1250
|
2002-09-30 12:56:59 +00:00
|
|
|
};
|
|
|
|
|
2002-09-19 17:44:41 +00:00
|
|
|
// Constructor
|
2010-11-18 18:17:00 +00:00
|
|
|
GuiManager::GuiManager() : _redrawStatus(kRedrawDisabled), _stateIsSaved(false),
|
|
|
|
_cursorAnimateCounter(0), _cursorAnimateTimer(0) {
|
2006-10-08 12:00:19 +00:00
|
|
|
_theme = 0;
|
2006-10-08 20:37:39 +00:00
|
|
|
_useStdCursor = false;
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2006-04-02 14:16:31 +00:00
|
|
|
_system = g_system;
|
2006-08-04 18:11:00 +00:00
|
|
|
_lastScreenChangeID = _system->getScreenChangeID();
|
2010-03-12 23:02:24 +00:00
|
|
|
_width = _system->getOverlayWidth();
|
|
|
|
_height = _system->getOverlayHeight();
|
2003-11-02 02:18:16 +00:00
|
|
|
|
2015-11-11 20:36:27 +00:00
|
|
|
_launched = false;
|
|
|
|
|
2002-09-19 23:06:54 +00:00
|
|
|
// Clear the cursor
|
|
|
|
memset(_cursor, 0xFF, sizeof(_cursor));
|
2010-10-12 02:18:11 +00:00
|
|
|
|
2010-11-30 18:50:19 +00:00
|
|
|
#ifdef USE_TRANSLATION
|
2010-09-25 22:47:00 +00:00
|
|
|
// Enable translation
|
|
|
|
TransMan.setLanguage(ConfMan.get("gui_language").c_str());
|
2010-11-30 18:50:19 +00:00
|
|
|
#endif // USE_TRANSLATION
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2009-01-02 20:03:45 +00:00
|
|
|
ConfMan.registerDefault("gui_theme", "scummmodern");
|
2008-08-13 16:50:50 +00:00
|
|
|
Common::String themefile(ConfMan.get("gui_theme"));
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-10-29 20:45:28 +00:00
|
|
|
ConfMan.registerDefault("gui_renderer", ThemeEngine::findModeConfigName(ThemeEngine::_defaultRendererMode));
|
|
|
|
ThemeEngine::GraphicsMode gfxMode = (ThemeEngine::GraphicsMode)ThemeEngine::findMode(ConfMan.get("gui_renderer"));
|
2006-10-08 18:22:28 +00:00
|
|
|
|
2011-05-21 14:45:51 +00:00
|
|
|
#ifdef __DS__
|
|
|
|
// Searching for the theme file takes ~10 seconds on the DS.
|
|
|
|
// Disable this search here because external themes are not supported.
|
|
|
|
if (!loadNewTheme("builtin", gfxMode)) {
|
|
|
|
// Loading the built-in theme failed as well. Bail out
|
|
|
|
error("Failed to load any GUI theme, aborting");
|
|
|
|
}
|
2011-06-01 13:15:31 +00:00
|
|
|
#else
|
2009-01-01 21:41:55 +00:00
|
|
|
// Try to load the theme
|
|
|
|
if (!loadNewTheme(themefile, gfxMode)) {
|
|
|
|
// Loading the theme failed, try to load the built-in theme
|
|
|
|
if (!loadNewTheme("builtin", gfxMode)) {
|
|
|
|
// Loading the built-in theme failed as well. Bail out
|
2010-06-26 18:07:41 +00:00
|
|
|
error("Failed to load any GUI theme, aborting");
|
2009-01-01 21:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-21 14:45:51 +00:00
|
|
|
#endif
|
2006-10-08 18:22:28 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
GuiManager::~GuiManager() {
|
2008-03-27 11:06:29 +00:00
|
|
|
delete _theme;
|
|
|
|
}
|
|
|
|
|
2009-05-10 22:05:04 +00:00
|
|
|
#ifdef ENABLE_KEYMAPPER
|
|
|
|
void GuiManager::initKeymap() {
|
|
|
|
using namespace Common;
|
|
|
|
|
|
|
|
Keymapper *mapper = _system->getEventManager()->getKeymapper();
|
|
|
|
|
|
|
|
// Do not try to recreate same keymap over again
|
2011-12-30 19:03:39 +00:00
|
|
|
if (mapper->getKeymap(kGuiKeymapName) != 0)
|
2009-05-10 22:05:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Action *act;
|
2011-10-22 03:54:33 +00:00
|
|
|
Keymap *guiMap = new Keymap(kGuiKeymapName);
|
2009-05-10 22:05:04 +00:00
|
|
|
|
2012-02-21 12:57:32 +00:00
|
|
|
act = new Action(guiMap, "CLOS", _("Close"));
|
2009-05-10 22:05:04 +00:00
|
|
|
act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2012-02-21 12:57:32 +00:00
|
|
|
act = new Action(guiMap, "CLIK", _("Mouse click"));
|
2009-05-10 22:05:04 +00:00
|
|
|
act->addLeftClickEvent();
|
|
|
|
|
2012-02-19 04:17:48 +00:00
|
|
|
#ifdef ENABLE_VKEYBD
|
2012-02-21 12:57:32 +00:00
|
|
|
act = new Action(guiMap, "VIRT", _("Display keyboard"));
|
2012-02-19 04:17:48 +00:00
|
|
|
act->addEvent(EVENT_VIRTUAL_KEYBOARD);
|
|
|
|
#endif
|
2009-05-10 22:05:04 +00:00
|
|
|
|
2012-02-21 12:57:32 +00:00
|
|
|
act = new Action(guiMap, "REMP", _("Remap keys"));
|
2012-02-19 04:17:48 +00:00
|
|
|
act->addEvent(EVENT_KEYMAPPER_REMAP);
|
2009-05-10 22:05:04 +00:00
|
|
|
|
2014-08-19 18:32:00 +00:00
|
|
|
act = new Action(guiMap, "FULS", _("Toggle fullscreen"));
|
2012-02-05 01:53:16 +00:00
|
|
|
act->addKeyEvent(KeyState(KEYCODE_RETURN, ASCII_RETURN, KBD_ALT));
|
|
|
|
|
2009-05-10 22:05:04 +00:00
|
|
|
mapper->addGlobalKeymap(guiMap);
|
|
|
|
}
|
2011-10-22 03:54:33 +00:00
|
|
|
|
|
|
|
void GuiManager::pushKeymap() {
|
|
|
|
_system->getEventManager()->getKeymapper()->pushKeymap(Common::kGuiKeymapName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiManager::popKeymap() {
|
2012-01-08 04:07:16 +00:00
|
|
|
_system->getEventManager()->getKeymapper()->popKeymap(Common::kGuiKeymapName);
|
2011-10-22 03:54:33 +00:00
|
|
|
}
|
2009-05-10 22:05:04 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-15 10:44:51 +00:00
|
|
|
bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx, bool forced) {
|
2009-01-01 21:41:55 +00:00
|
|
|
// If we are asked to reload the currently active theme, just do nothing
|
|
|
|
// FIXME: Actually, why? It might be desirable at times to force a theme reload...
|
2010-06-15 10:44:51 +00:00
|
|
|
if (!forced)
|
|
|
|
if (_theme && id == _theme->getThemeId() && gfx == _theme->getGraphicsMode())
|
|
|
|
return true;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2009-01-01 21:41:55 +00:00
|
|
|
ThemeEngine *newTheme = 0;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-09-02 17:51:08 +00:00
|
|
|
if (gfx == ThemeEngine::kGfxDisabled)
|
2008-10-29 20:45:28 +00:00
|
|
|
gfx = ThemeEngine::_defaultRendererMode;
|
2006-10-08 20:37:39 +00:00
|
|
|
|
2009-01-01 21:41:55 +00:00
|
|
|
// Try to load the new theme
|
2009-01-02 21:24:13 +00:00
|
|
|
newTheme = new ThemeEngine(id, gfx);
|
2009-01-01 21:41:55 +00:00
|
|
|
assert(newTheme);
|
|
|
|
|
|
|
|
if (!newTheme->init())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Disable and delete the old theme
|
|
|
|
//
|
2006-10-08 20:37:39 +00:00
|
|
|
if (_theme)
|
|
|
|
_theme->disable();
|
2009-01-01 21:41:55 +00:00
|
|
|
delete _theme;
|
2006-10-08 20:37:39 +00:00
|
|
|
|
|
|
|
if (_useStdCursor) {
|
2007-02-12 00:04:56 +00:00
|
|
|
CursorMan.popCursorPalette();
|
2006-10-08 20:37:39 +00:00
|
|
|
CursorMan.popCursor();
|
|
|
|
}
|
|
|
|
|
2009-01-01 21:41:55 +00:00
|
|
|
//
|
|
|
|
// Enable the new theme
|
|
|
|
//
|
|
|
|
_theme = newTheme;
|
2009-07-05 14:11:54 +00:00
|
|
|
_useStdCursor = !_theme->ownCursor();
|
|
|
|
|
|
|
|
// If _stateIsSaved is set, we know that a Theme is already initialized,
|
|
|
|
// thus we initialize the new theme properly
|
|
|
|
if (_stateIsSaved) {
|
|
|
|
_theme->enable();
|
|
|
|
|
|
|
|
if (_useStdCursor)
|
|
|
|
setupCursor();
|
|
|
|
}
|
2006-10-08 18:22:28 +00:00
|
|
|
|
2009-01-02 01:23:17 +00:00
|
|
|
// refresh all dialogs
|
2012-02-22 19:20:55 +00:00
|
|
|
for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i)
|
2009-01-02 01:23:17 +00:00
|
|
|
_dialogStack[i]->reflowLayout();
|
|
|
|
|
|
|
|
// We need to redraw immediately. Otherwise
|
|
|
|
// some other event may cause a widget to be
|
|
|
|
// redrawn before redraw() has been called.
|
|
|
|
_redrawStatus = kRedrawFull;
|
2009-01-02 01:36:38 +00:00
|
|
|
redraw();
|
|
|
|
_system->updateScreen();
|
2009-01-02 01:23:17 +00:00
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
return true;
|
2005-01-06 19:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::redraw() {
|
2009-04-11 17:12:17 +00:00
|
|
|
ThemeEngine::ShadingStyle shading;
|
2006-06-03 10:48:37 +00:00
|
|
|
|
2009-04-11 17:12:17 +00:00
|
|
|
if (_redrawStatus == kRedrawDisabled || _dialogStack.empty())
|
2008-07-17 21:58:43 +00:00
|
|
|
return;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2009-04-11 17:12:17 +00:00
|
|
|
shading = (ThemeEngine::ShadingStyle)xmlEval()->getVar("Dialog." + _dialogStack.top()->_name + ".Shading", 0);
|
|
|
|
|
|
|
|
// Tanoku: Do not apply shading more than once when opening many dialogs
|
|
|
|
// on top of each other. Screen ends up being too dark and it's a
|
|
|
|
// performance hog.
|
2016-06-06 09:08:44 +00:00
|
|
|
if (_redrawStatus == kRedrawOpenDialog && _dialogStack.size() > 3)
|
2009-04-11 17:12:17 +00:00
|
|
|
shading = ThemeEngine::kShadingNone;
|
2007-11-04 00:30:53 +00:00
|
|
|
|
2009-02-06 23:28:08 +00:00
|
|
|
switch (_redrawStatus) {
|
|
|
|
case kRedrawCloseDialog:
|
|
|
|
case kRedrawFull:
|
|
|
|
case kRedrawTopDialog:
|
|
|
|
_theme->clearAll();
|
2009-04-11 17:12:17 +00:00
|
|
|
_theme->openDialog(true, ThemeEngine::kShadingNone);
|
2009-02-06 23:28:08 +00:00
|
|
|
|
2012-02-22 19:20:55 +00:00
|
|
|
for (DialogStack::size_type i = 0; i < _dialogStack.size() - 1; i++)
|
2009-02-06 23:28:08 +00:00
|
|
|
_dialogStack[i]->drawDialog();
|
2008-07-17 21:58:43 +00:00
|
|
|
|
2009-02-06 23:28:08 +00:00
|
|
|
_theme->finishBuffering();
|
2008-07-21 21:23:23 +00:00
|
|
|
|
2011-02-24 21:32:32 +00:00
|
|
|
// fall through
|
|
|
|
|
2009-02-06 23:28:08 +00:00
|
|
|
case kRedrawOpenDialog:
|
2011-02-24 21:32:32 +00:00
|
|
|
_theme->updateScreen(false);
|
2009-04-11 17:12:17 +00:00
|
|
|
_theme->openDialog(true, shading);
|
2009-02-06 23:28:08 +00:00
|
|
|
_dialogStack.top()->drawDialog();
|
|
|
|
_theme->finishBuffering();
|
|
|
|
break;
|
2008-07-18 16:44:42 +00:00
|
|
|
|
2009-02-06 23:28:08 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2006-06-15 14:25:59 +00:00
|
|
|
|
2007-11-04 00:30:53 +00:00
|
|
|
_theme->updateScreen();
|
2008-07-17 21:58:43 +00:00
|
|
|
_redrawStatus = kRedrawDisabled;
|
2006-06-03 10:48:37 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
Dialog *GuiManager::getTopDialog() const {
|
2006-12-27 22:51:14 +00:00
|
|
|
if (_dialogStack.empty())
|
|
|
|
return 0;
|
|
|
|
return _dialogStack.top();
|
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::runLoop() {
|
2010-11-18 21:32:42 +00:00
|
|
|
Dialog * const activeDialog = getTopDialog();
|
2002-10-16 17:37:30 +00:00
|
|
|
bool didSaveState = false;
|
2002-07-26 19:41:20 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
if (activeDialog == 0)
|
|
|
|
return;
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2013-07-07 03:54:45 +00:00
|
|
|
#ifdef ENABLE_EVENTRECORDER
|
2013-05-16 21:18:09 +00:00
|
|
|
// Suspend recording while GUI is shown
|
|
|
|
g_eventRec.suspendRecording();
|
2013-07-07 03:54:45 +00:00
|
|
|
#endif
|
2013-05-16 21:18:09 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
if (!_stateIsSaved) {
|
|
|
|
saveState();
|
2006-01-27 15:43:23 +00:00
|
|
|
_theme->enable();
|
2002-10-16 17:37:30 +00:00
|
|
|
didSaveState = true;
|
2002-07-13 22:41:29 +00:00
|
|
|
|
2006-10-08 20:37:39 +00:00
|
|
|
_useStdCursor = !_theme->ownCursor();
|
|
|
|
if (_useStdCursor)
|
|
|
|
setupCursor();
|
2009-01-02 01:23:17 +00:00
|
|
|
|
|
|
|
// _theme->refresh();
|
|
|
|
|
|
|
|
_redrawStatus = kRedrawFull;
|
|
|
|
redraw();
|
2006-10-08 20:37:39 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-03-17 00:53:21 +00:00
|
|
|
Common::EventManager *eventMan = _system->getEventManager();
|
2008-08-04 16:59:55 +00:00
|
|
|
uint32 lastRedraw = 0;
|
2016-04-05 08:29:14 +00:00
|
|
|
const uint32 waitTime = 1000 / 60;
|
2006-05-20 08:29:50 +00:00
|
|
|
|
2012-01-30 21:59:09 +00:00
|
|
|
while (!_dialogStack.empty() && activeDialog == getTopDialog() && !eventMan->shouldQuit()) {
|
2008-07-17 21:58:43 +00:00
|
|
|
redraw();
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2006-05-27 22:57:00 +00:00
|
|
|
// Don't "tickle" the dialog until the theme has had a chance
|
|
|
|
// to re-allocate buffers in case of a scaler change.
|
|
|
|
|
|
|
|
activeDialog->handleTickle();
|
|
|
|
|
2006-10-08 20:37:39 +00:00
|
|
|
if (_useStdCursor)
|
2006-04-19 03:17:00 +00:00
|
|
|
animateCursor();
|
2008-08-04 16:59:55 +00:00
|
|
|
// _theme->updateScreen();
|
|
|
|
// _system->updateScreen();
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
if (lastRedraw + waitTime < _system->getMillis(true)) {
|
2016-04-05 08:06:41 +00:00
|
|
|
lastRedraw = _system->getMillis(true);
|
2008-08-04 16:59:55 +00:00
|
|
|
_theme->updateScreen();
|
|
|
|
_system->updateScreen();
|
|
|
|
}
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
Common::Event event;
|
2010-06-15 10:52:35 +00:00
|
|
|
|
2007-03-17 00:53:21 +00:00
|
|
|
while (eventMan->pollEvent(event)) {
|
2013-10-17 22:51:52 +00:00
|
|
|
// We will need to check whether the screen changed while polling
|
|
|
|
// for an event here. While we do send EVENT_SCREEN_CHANGED
|
|
|
|
// whenever this happens we still cannot be sure that we get such
|
|
|
|
// an event immediately. For example, we might have an mouse move
|
|
|
|
// event queued before an screen changed event. In some rare cases
|
|
|
|
// this would make the GUI redraw (with the code a few lines
|
|
|
|
// below) when it is not yet updated for new overlay dimensions.
|
|
|
|
// As a result ScummVM would crash because it tries to copy data
|
|
|
|
// outside the actual overlay screen.
|
|
|
|
if (event.type != Common::EVENT_SCREEN_CHANGED) {
|
|
|
|
checkScreenChange();
|
|
|
|
}
|
|
|
|
|
2009-01-01 21:41:55 +00:00
|
|
|
// The top dialog can change during the event loop. In that case, flush all the
|
|
|
|
// dialog-related events since they were probably generated while the old dialog
|
2009-01-01 22:15:21 +00:00
|
|
|
// was still visible, and therefore not intended for the new one.
|
2009-01-01 21:41:55 +00:00
|
|
|
//
|
2011-05-25 14:31:37 +00:00
|
|
|
// This hopefully fixes strange behavior/crashes with pop-up widgets. (Most easily
|
2009-01-01 22:15:21 +00:00
|
|
|
// triggered in 3x mode or when running ScummVM under Valgrind.)
|
2016-03-24 13:55:17 +00:00
|
|
|
if (activeDialog != getTopDialog() && event.type != Common::EVENT_SCREEN_CHANGED) {
|
|
|
|
processEvent(event, getTopDialog());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
processEvent(event, activeDialog);
|
2016-03-24 13:55:17 +00:00
|
|
|
|
2010-07-23 19:36:47 +00:00
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
if (lastRedraw + waitTime < _system->getMillis(true)) {
|
2016-04-05 08:06:41 +00:00
|
|
|
lastRedraw = _system->getMillis(true);
|
2011-04-05 10:28:39 +00:00
|
|
|
_theme->updateScreen();
|
|
|
|
_system->updateScreen();
|
|
|
|
}
|
2002-07-13 18:32:09 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 14:22:02 +00:00
|
|
|
if (_lastMousePosition.time + kTooltipDelay < _system->getMillis(true)) {
|
2010-11-18 18:17:00 +00:00
|
|
|
Widget *wdg = activeDialog->findWidget(_lastMousePosition.x, _lastMousePosition.y);
|
2012-06-20 01:31:50 +00:00
|
|
|
if (wdg && wdg->hasTooltip() && !(wdg->getFlags() & WIDGET_PRESSED)) {
|
2010-11-18 18:17:00 +00:00
|
|
|
Tooltip *tooltip = new Tooltip();
|
|
|
|
tooltip->setup(activeDialog, wdg, _lastMousePosition.x, _lastMousePosition.y);
|
|
|
|
tooltip->runModal();
|
|
|
|
delete tooltip;
|
|
|
|
}
|
2010-06-15 10:52:35 +00:00
|
|
|
}
|
|
|
|
|
2002-09-22 04:03:45 +00:00
|
|
|
// Delay for a moment
|
2004-09-28 20:19:37 +00:00
|
|
|
_system->delayMillis(10);
|
2002-07-18 14:47:25 +00:00
|
|
|
}
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2012-01-30 21:59:09 +00:00
|
|
|
// WORKAROUND: When quitting we might not properly close the dialogs on
|
|
|
|
// the dialog stack, thus we do this here to avoid any problems.
|
|
|
|
// This is most noticable in bug #3481395 "LAUNCHER: Can't quit from unsupported game dialog".
|
|
|
|
// It seems that Dialog::runModal never removes the dialog from the dialog
|
|
|
|
// stack, thus if the dialog does not call Dialog::close to close itself
|
|
|
|
// it will never be removed. Since we can have multiple run loops being
|
|
|
|
// called we cannot rely on catching EVENT_QUIT in the event loop above,
|
|
|
|
// since it would only catch it for the top run loop.
|
|
|
|
if (eventMan->shouldQuit() && activeDialog == getTopDialog())
|
|
|
|
getTopDialog()->close();
|
|
|
|
|
2006-01-27 15:43:23 +00:00
|
|
|
if (didSaveState) {
|
|
|
|
_theme->disable();
|
2006-06-13 09:57:16 +00:00
|
|
|
restoreState();
|
2006-10-08 20:37:39 +00:00
|
|
|
_useStdCursor = false;
|
2010-11-18 18:17:00 +00:00
|
|
|
}
|
2013-05-16 21:18:09 +00:00
|
|
|
|
2013-07-07 03:54:45 +00:00
|
|
|
#ifdef ENABLE_EVENTRECORDER
|
2013-05-16 21:18:09 +00:00
|
|
|
// Resume recording once GUI is shown
|
|
|
|
g_eventRec.resumeRecording();
|
2013-07-07 03:54:45 +00:00
|
|
|
#endif
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::saveState() {
|
2012-01-08 02:48:49 +00:00
|
|
|
#ifdef ENABLE_KEYMAPPER
|
|
|
|
initKeymap();
|
|
|
|
pushKeymap();
|
|
|
|
#endif
|
2002-07-05 16:56:53 +00:00
|
|
|
// Backup old cursor
|
2002-10-16 17:37:30 +00:00
|
|
|
_lastClick.x = _lastClick.y = 0;
|
|
|
|
_lastClick.time = 0;
|
|
|
|
_lastClick.count = 0;
|
|
|
|
|
|
|
|
_stateIsSaved = true;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::restoreState() {
|
2012-01-08 02:48:49 +00:00
|
|
|
#ifdef ENABLE_KEYMAPPER
|
|
|
|
popKeymap();
|
|
|
|
#endif
|
2006-10-08 20:37:39 +00:00
|
|
|
if (_useStdCursor) {
|
|
|
|
CursorMan.popCursor();
|
2007-02-12 00:04:56 +00:00
|
|
|
CursorMan.popCursorPalette();
|
2006-10-08 20:37:39 +00:00
|
|
|
}
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
_stateIsSaved = false;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::openDialog(Dialog *dialog) {
|
2016-04-06 14:22:02 +00:00
|
|
|
giveFocusToDialog(dialog);
|
2012-05-03 16:32:08 +00:00
|
|
|
|
|
|
|
if (!_dialogStack.empty())
|
|
|
|
getTopDialog()->lostFocus();
|
|
|
|
|
2002-07-07 21:46:53 +00:00
|
|
|
_dialogStack.push(dialog);
|
2009-02-06 23:28:08 +00:00
|
|
|
if (_redrawStatus != kRedrawFull)
|
|
|
|
_redrawStatus = kRedrawOpenDialog;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2006-08-04 18:11:00 +00:00
|
|
|
// We reflow the dialog just before opening it. If the screen changed
|
|
|
|
// since the last time we looked, also refresh the loaded theme,
|
|
|
|
// and reflow all other open dialogs, too.
|
2009-01-01 21:41:55 +00:00
|
|
|
if (!checkScreenChange())
|
2006-08-12 16:42:19 +00:00
|
|
|
dialog->reflowLayout();
|
2002-07-07 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::closeTopDialog() {
|
2002-07-10 16:49:45 +00:00
|
|
|
// Don't do anything if no dialog is open
|
|
|
|
if (_dialogStack.empty())
|
|
|
|
return;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-10 16:49:45 +00:00
|
|
|
// Remove the dialog from the stack
|
2012-05-03 16:32:08 +00:00
|
|
|
_dialogStack.pop()->lostFocus();
|
|
|
|
|
2016-04-06 14:22:02 +00:00
|
|
|
if (!_dialogStack.empty()) {
|
|
|
|
Dialog *dialog = getTopDialog();
|
|
|
|
giveFocusToDialog(dialog);
|
|
|
|
}
|
2012-05-03 16:32:08 +00:00
|
|
|
|
2009-02-06 23:28:08 +00:00
|
|
|
if (_redrawStatus != kRedrawFull)
|
|
|
|
_redrawStatus = kRedrawCloseDialog;
|
2009-04-11 17:12:17 +00:00
|
|
|
|
|
|
|
redraw();
|
2002-07-07 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::setupCursor() {
|
2006-10-08 18:22:28 +00:00
|
|
|
const byte palette[] = {
|
2011-02-13 13:58:44 +00:00
|
|
|
255, 255, 255,
|
|
|
|
255, 255, 255,
|
|
|
|
171, 171, 171,
|
|
|
|
87, 87, 87
|
2006-10-08 18:22:28 +00:00
|
|
|
};
|
|
|
|
|
2007-02-12 00:04:56 +00:00
|
|
|
CursorMan.pushCursorPalette(palette, 0, 4);
|
2010-01-07 15:07:36 +00:00
|
|
|
CursorMan.pushCursor(NULL, 0, 0, 0, 0, 0);
|
2006-10-08 18:22:28 +00:00
|
|
|
CursorMan.showMouse(true);
|
|
|
|
}
|
|
|
|
|
2006-05-20 08:29:50 +00:00
|
|
|
// Draw the mouse cursor (animated). This is pretty much the same as in old
|
|
|
|
// SCUMM games, but the code no longer resembles what we have in cursor.cpp
|
|
|
|
// very much. We could plug in a different cursor here if we like to.
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::animateCursor() {
|
2013-05-16 21:18:09 +00:00
|
|
|
int time = _system->getMillis(true);
|
2002-09-22 04:03:45 +00:00
|
|
|
if (time > _cursorAnimateTimer + kCursorAnimateDelay) {
|
2006-05-20 08:29:50 +00:00
|
|
|
for (int i = 0; i < 15; i++) {
|
2002-09-28 15:58:25 +00:00
|
|
|
if ((i < 6) || (i > 8)) {
|
2006-05-20 08:29:50 +00:00
|
|
|
_cursor[16 * 7 + i] = _cursorAnimateCounter;
|
|
|
|
_cursor[16 * i + 7] = _cursorAnimateCounter;
|
2002-09-19 23:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2010-01-07 15:07:36 +00:00
|
|
|
CursorMan.replaceCursor(_cursor, 16, 16, 7, 7, 255);
|
2002-09-22 04:03:45 +00:00
|
|
|
|
|
|
|
_cursorAnimateTimer = time;
|
|
|
|
_cursorAnimateCounter = (_cursorAnimateCounter + 1) % 4;
|
2002-09-19 23:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-30 13:57:57 +00:00
|
|
|
|
2009-01-01 21:41:55 +00:00
|
|
|
bool GuiManager::checkScreenChange() {
|
|
|
|
int tmpScreenChangeID = _system->getScreenChangeID();
|
|
|
|
if (_lastScreenChangeID != tmpScreenChangeID) {
|
2010-03-11 23:40:40 +00:00
|
|
|
screenChange();
|
2009-01-01 21:41:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-25 23:55:36 +00:00
|
|
|
void GuiManager::screenChange() {
|
2006-10-08 18:22:28 +00:00
|
|
|
_lastScreenChangeID = _system->getScreenChangeID();
|
2010-03-12 23:02:24 +00:00
|
|
|
_width = _system->getOverlayWidth();
|
|
|
|
_height = _system->getOverlayHeight();
|
2006-10-08 18:22:28 +00:00
|
|
|
|
|
|
|
// reinit the whole theme
|
|
|
|
_theme->refresh();
|
2009-01-02 01:23:17 +00:00
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
// refresh all dialogs
|
2012-02-22 19:20:55 +00:00
|
|
|
for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) {
|
2006-10-08 18:22:28 +00:00
|
|
|
_dialogStack[i]->reflowLayout();
|
|
|
|
}
|
|
|
|
// We need to redraw immediately. Otherwise
|
|
|
|
// some other event may cause a widget to be
|
|
|
|
// redrawn before redraw() has been called.
|
2008-07-17 21:58:43 +00:00
|
|
|
_redrawStatus = kRedrawFull;
|
2006-10-08 18:22:28 +00:00
|
|
|
redraw();
|
2008-08-15 17:57:12 +00:00
|
|
|
_system->updateScreen();
|
2006-10-08 18:22:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
void GuiManager::processEvent(const Common::Event &event, Dialog *const activeDialog) {
|
2016-03-24 13:55:17 +00:00
|
|
|
if (activeDialog == 0)
|
|
|
|
return;
|
2013-05-16 21:18:09 +00:00
|
|
|
int button;
|
|
|
|
uint32 time;
|
|
|
|
Common::Point mouse(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y);
|
2016-04-06 14:22:02 +00:00
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
activeDialog->handleKeyDown(event.kbd);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_KEYUP:
|
|
|
|
activeDialog->handleKeyUp(event.kbd);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2016-04-06 14:22:02 +00:00
|
|
|
_globalMousePosition.x = event.mouse.x;
|
|
|
|
_globalMousePosition.y = event.mouse.y;
|
2013-05-16 21:18:09 +00:00
|
|
|
activeDialog->handleMouseMoved(mouse.x, mouse.y, 0);
|
|
|
|
|
|
|
|
if (mouse.x != _lastMousePosition.x || mouse.y != _lastMousePosition.y) {
|
2016-04-06 14:22:02 +00:00
|
|
|
setLastMousePos(mouse.x, mouse.y);
|
2013-05-16 21:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
// We don't distinguish between mousebuttons (for now at least)
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
button = (event.type == Common::EVENT_LBUTTONDOWN ? 1 : 2);
|
|
|
|
time = _system->getMillis(true);
|
|
|
|
if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay)
|
|
|
|
&& ABS(_lastClick.x - event.mouse.x) < 3
|
|
|
|
&& ABS(_lastClick.y - event.mouse.y) < 3) {
|
|
|
|
_lastClick.count++;
|
|
|
|
} else {
|
|
|
|
_lastClick.x = event.mouse.x;
|
|
|
|
_lastClick.y = event.mouse.y;
|
|
|
|
_lastClick.count = 1;
|
|
|
|
}
|
|
|
|
_lastClick.time = time;
|
|
|
|
activeDialog->handleMouseDown(mouse.x, mouse.y, button, _lastClick.count);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
|
|
|
button = (event.type == Common::EVENT_LBUTTONUP ? 1 : 2);
|
|
|
|
activeDialog->handleMouseUp(mouse.x, mouse.y, button, _lastClick.count);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_WHEELUP:
|
|
|
|
activeDialog->handleMouseWheel(mouse.x, mouse.y, -1);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_WHEELDOWN:
|
|
|
|
activeDialog->handleMouseWheel(mouse.x, mouse.y, 1);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_SCREEN_CHANGED:
|
|
|
|
screenChange();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef ENABLE_KEYMAPPER
|
|
|
|
activeDialog->handleOtherEvent(event);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 11:29:01 +00:00
|
|
|
void GuiManager::doFullRedraw() {
|
|
|
|
_redrawStatus = kRedrawFull;
|
|
|
|
redraw();
|
|
|
|
_system->updateScreen();
|
|
|
|
}
|
|
|
|
|
2016-04-06 14:22:02 +00:00
|
|
|
void GuiManager::giveFocusToDialog(Dialog *dialog) {
|
|
|
|
int16 dialogX = _globalMousePosition.x - dialog->_x;
|
|
|
|
int16 dialogY = _globalMousePosition.y - dialog->_y;
|
|
|
|
dialog->receivedFocus(dialogX, dialogY);
|
|
|
|
setLastMousePos(dialogX, dialogY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiManager::setLastMousePos(int16 x, int16 y) {
|
|
|
|
_lastMousePosition.x = x;
|
|
|
|
_lastMousePosition.y = y;
|
|
|
|
_lastMousePosition.time = _system->getMillis(true);
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|