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
|
|
|
*
|
2021-12-26 17:47:58 +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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2002-07-05 16:56:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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"
|
2010-06-15 10:44:51 +00:00
|
|
|
#include "common/translation.h"
|
2023-01-07 00:29:43 +00:00
|
|
|
#include "common/zip-set.h"
|
2013-05-16 21:18:09 +00:00
|
|
|
#include "gui/EventRecorder.h"
|
2008-12-27 16:07:10 +00:00
|
|
|
|
2017-08-11 11:57:28 +00:00
|
|
|
#include "backends/keymapper/action.h"
|
2017-08-13 15:04:45 +00:00
|
|
|
#include "backends/keymapper/keymap.h"
|
|
|
|
#include "backends/keymapper/keymapper.h"
|
2020-01-26 15:33:25 +00:00
|
|
|
#include "backends/keymapper/standard-actions.h"
|
2009-01-11 00:20:27 +00:00
|
|
|
|
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
|
|
|
|
2017-07-10 19:17:41 +00:00
|
|
|
namespace Common {
|
|
|
|
DECLARE_SINGLETON(GUI::GuiManager);
|
|
|
|
}
|
|
|
|
|
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,
|
2021-06-18 11:27:36 +00:00
|
|
|
kTooltipDelay = 1250,
|
|
|
|
kTooltipSameWidgetDelay = 7000
|
2002-09-30 12:56:59 +00:00
|
|
|
};
|
|
|
|
|
2002-09-19 17:44:41 +00:00
|
|
|
// Constructor
|
2022-06-28 00:17:06 +00:00
|
|
|
GuiManager::GuiManager() : CommandSender(nullptr), _redrawStatus(kRedrawDisabled), _stateIsSaved(false),
|
2021-04-15 19:20:04 +00:00
|
|
|
_cursorAnimateCounter(0), _cursorAnimateTimer(0) {
|
2020-01-05 16:48:04 +00:00
|
|
|
_theme = nullptr;
|
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();
|
2003-11-02 02:18:16 +00:00
|
|
|
|
2020-10-26 17:27:06 +00:00
|
|
|
computeScaleFactor();
|
|
|
|
|
2015-11-11 20:36:27 +00:00
|
|
|
_launched = false;
|
|
|
|
|
2020-05-07 21:21:22 +00:00
|
|
|
_useRTL = false;
|
2020-05-11 22:07:40 +00:00
|
|
|
|
2022-06-28 00:17:06 +00:00
|
|
|
_iconsSetChanged = false;
|
|
|
|
|
2020-05-14 00:12:19 +00:00
|
|
|
_topDialogLeftPadding = 0;
|
|
|
|
_topDialogRightPadding = 0;
|
2020-05-07 21:21:22 +00:00
|
|
|
|
2022-10-01 14:57:03 +00:00
|
|
|
_displayTopDialogOnly = 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());
|
2020-05-30 11:46:23 +00:00
|
|
|
setLanguageRTL();
|
2010-11-30 18:50:19 +00:00
|
|
|
#endif // USE_TRANSLATION
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2019-07-12 20:16:44 +00:00
|
|
|
initTextToSpeech();
|
2021-11-12 13:14:03 +00:00
|
|
|
initIconsSet();
|
2022-08-16 05:25:04 +00:00
|
|
|
_iconsSetChanged = false;
|
2019-07-12 20:16:44 +00:00
|
|
|
|
2019-03-29 05:03:03 +00:00
|
|
|
ConfMan.registerDefault("gui_theme", "scummremastered");
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2021-11-12 13:14:03 +00:00
|
|
|
void GuiManager::initIconsSet() {
|
2022-06-28 00:09:47 +00:00
|
|
|
Common::StackLock lock(_iconsMutex);
|
2021-11-12 13:14:03 +00:00
|
|
|
|
2021-11-19 23:46:47 +00:00
|
|
|
_iconsSet.clear();
|
|
|
|
|
2023-01-07 00:29:43 +00:00
|
|
|
_iconsSetChanged = Common::generateZipSet(_iconsSet, "gui-icons.dat", "gui-icons*.dat");
|
2021-11-12 13:14:03 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 17:27:06 +00:00
|
|
|
void GuiManager::computeScaleFactor() {
|
2021-04-11 19:43:58 +00:00
|
|
|
uint16 w = g_system->getOverlayWidth();
|
|
|
|
uint16 h = g_system->getOverlayHeight();
|
2020-10-26 17:27:06 +00:00
|
|
|
|
2021-08-10 22:37:32 +00:00
|
|
|
_scaleFactor = g_system->getHiDPIScreenFactor();
|
|
|
|
if (ConfMan.hasKey("gui_scale"))
|
|
|
|
_scaleFactor *= ConfMan.getInt("gui_scale") / 100.f;
|
2020-10-26 17:27:06 +00:00
|
|
|
|
2021-08-10 22:37:32 +00:00
|
|
|
_baseHeight = (int16)((float)h / _scaleFactor);
|
2020-10-26 22:11:25 +00:00
|
|
|
_baseWidth = (int16)((float)w / _scaleFactor);
|
2020-10-26 17:27:06 +00:00
|
|
|
|
2021-08-15 08:51:43 +00:00
|
|
|
// Never go below 320x200. Our GUI layout is not designed to go below that.
|
2021-08-20 16:43:19 +00:00
|
|
|
// On the DS, this causes issues at 256x192 due to the use of non-scalable
|
|
|
|
// BDF fonts.
|
|
|
|
#ifndef __DS__
|
2021-08-15 08:51:43 +00:00
|
|
|
if (_baseHeight < 200) {
|
|
|
|
_baseHeight = 200;
|
|
|
|
_scaleFactor = (float)h / (float)_baseHeight;
|
|
|
|
_baseWidth = (int16)((float)w / _scaleFactor);
|
|
|
|
}
|
|
|
|
if (_baseWidth < 320) {
|
|
|
|
_baseWidth = 320;
|
|
|
|
_scaleFactor = (float)w / (float)_baseWidth;
|
|
|
|
_baseHeight = (int16)((float)h / _scaleFactor);
|
|
|
|
}
|
2021-08-20 16:43:19 +00:00
|
|
|
#endif
|
2021-08-15 08:51:43 +00:00
|
|
|
|
2020-11-07 13:58:14 +00:00
|
|
|
if (_theme)
|
|
|
|
_theme->setBaseResolution(_baseWidth, _baseHeight, _scaleFactor);
|
|
|
|
|
2020-11-02 08:42:46 +00:00
|
|
|
debug(3, "Setting %d x %d -> %d x %d -- %g", w, h, _baseWidth, _baseHeight, _scaleFactor);
|
2020-10-26 17:27:06 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 09:50:52 +00:00
|
|
|
Common::Keymap *GuiManager::getKeymap() const {
|
|
|
|
using namespace Common;
|
2009-05-10 22:05:04 +00:00
|
|
|
|
2020-01-28 17:44:08 +00:00
|
|
|
Keymap *guiMap = new Keymap(Keymap::kKeymapTypeGui, kGuiKeymapName, _("GUI"));
|
2009-05-10 22:05:04 +00:00
|
|
|
|
|
|
|
Action *act;
|
|
|
|
|
2020-01-26 15:33:25 +00:00
|
|
|
act = new Action(Common::kStandardActionInteract, _("Interact"));
|
|
|
|
act->addDefaultInputMapping("JOY_A");
|
|
|
|
act->setLeftClickEvent();
|
|
|
|
guiMap->addAction(act);
|
|
|
|
|
2020-01-23 09:50:51 +00:00
|
|
|
act = new Action("CLOS", _("Close"));
|
2017-08-14 15:11:33 +00:00
|
|
|
act->addDefaultInputMapping("ESCAPE");
|
2020-01-26 15:33:25 +00:00
|
|
|
act->addDefaultInputMapping("JOY_Y");
|
2017-08-11 12:51:27 +00:00
|
|
|
act->setKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
|
2020-01-23 09:50:51 +00:00
|
|
|
guiMap->addAction(act);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2020-02-09 06:18:13 +00:00
|
|
|
act = new Action(kStandardActionMoveUp, _("Up"));
|
|
|
|
act->setKeyEvent(KEYCODE_UP);
|
|
|
|
act->addDefaultInputMapping("JOY_UP");
|
|
|
|
guiMap->addAction(act);
|
|
|
|
|
|
|
|
act = new Action(kStandardActionMoveDown, _("Down"));
|
|
|
|
act->setKeyEvent(KEYCODE_DOWN);
|
|
|
|
act->addDefaultInputMapping("JOY_DOWN");
|
|
|
|
guiMap->addAction(act);
|
|
|
|
|
|
|
|
act = new Action(kStandardActionMoveLeft, _("Left"));
|
|
|
|
act->setKeyEvent(KEYCODE_LEFT);
|
|
|
|
act->addDefaultInputMapping("JOY_LEFT");
|
|
|
|
guiMap->addAction(act);
|
|
|
|
|
|
|
|
act = new Action(kStandardActionMoveRight, _("Right"));
|
|
|
|
act->setKeyEvent(KEYCODE_RIGHT);
|
|
|
|
act->addDefaultInputMapping("JOY_RIGHT");
|
|
|
|
guiMap->addAction(act);
|
|
|
|
|
2021-04-18 09:47:03 +00:00
|
|
|
act = new Action(kStandardActionEE, _("???"));
|
|
|
|
act->setKeyEvent(KEYCODE_v);
|
|
|
|
guiMap->addAction(act);
|
|
|
|
|
2020-01-23 09:50:52 +00:00
|
|
|
return guiMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiManager::initKeymap() {
|
|
|
|
using namespace Common;
|
|
|
|
|
|
|
|
Keymapper *mapper = _system->getEventManager()->getKeymapper();
|
|
|
|
|
|
|
|
// Do not try to recreate same keymap over again
|
|
|
|
if (mapper->getKeymap(kGuiKeymapName) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Keymap *guiMap = getKeymap();
|
2009-05-10 22:05:04 +00:00
|
|
|
mapper->addGlobalKeymap(guiMap);
|
|
|
|
}
|
2011-10-22 03:54:33 +00:00
|
|
|
|
2017-08-13 15:04:45 +00:00
|
|
|
void GuiManager::enableKeymap(bool enabled) {
|
|
|
|
Common::Keymapper *keymapper = _system->getEventManager()->getKeymapper();
|
|
|
|
keymapper->setEnabledKeymapType(enabled ? Common::Keymap::kKeymapTypeGui : Common::Keymap::kKeymapTypeGame);
|
2011-10-22 03:54:33 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-01-05 16:48:04 +00:00
|
|
|
ThemeEngine *newTheme = nullptr;
|
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);
|
2020-11-07 13:58:14 +00:00
|
|
|
newTheme->setBaseResolution(_baseWidth, _baseHeight, _scaleFactor);
|
2009-01-01 21:41:55 +00:00
|
|
|
|
2020-12-01 17:37:17 +00:00
|
|
|
if (!newTheme->init()) {
|
|
|
|
delete newTheme;
|
2009-01-01 21:41:55 +00:00
|
|
|
return false;
|
2020-12-01 17:37:17 +00:00
|
|
|
}
|
2009-01-01 21:41:55 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2019-10-06 22:11:48 +00:00
|
|
|
void GuiManager::redrawFull() {
|
|
|
|
_redrawStatus = kRedrawFull;
|
|
|
|
redraw();
|
|
|
|
_system->updateScreen();
|
|
|
|
}
|
|
|
|
|
2022-10-01 14:57:03 +00:00
|
|
|
void GuiManager::displayTopDialogOnly(bool mode) {
|
|
|
|
if (mode == _displayTopDialogOnly)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_displayTopDialogOnly = mode;
|
|
|
|
|
|
|
|
redrawFull();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
if (_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.
|
2021-07-27 23:31:51 +00:00
|
|
|
if (_redrawStatus == kRedrawOpenDialog && _dialogStack.size() > 2)
|
2009-04-11 17:12:17 +00:00
|
|
|
shading = ThemeEngine::kShadingNone;
|
2007-11-04 00:30:53 +00:00
|
|
|
|
2021-07-28 08:37:25 +00:00
|
|
|
// Reset any custom RTL paddings set by stacked dialogs when we go back to the top
|
|
|
|
if (useRTL() && _dialogStack.size() == 1) {
|
|
|
|
setDialogPaddings(0, 0);
|
|
|
|
}
|
|
|
|
|
2009-02-06 23:28:08 +00:00
|
|
|
switch (_redrawStatus) {
|
|
|
|
case kRedrawCloseDialog:
|
|
|
|
case kRedrawFull:
|
|
|
|
case kRedrawTopDialog:
|
|
|
|
_theme->clearAll();
|
2018-01-07 09:39:22 +00:00
|
|
|
_theme->drawToBackbuffer();
|
2009-02-06 23:28:08 +00:00
|
|
|
|
2022-10-01 14:57:03 +00:00
|
|
|
if (!_displayTopDialogOnly) {
|
|
|
|
for (DialogStack::size_type i = 0; i < _dialogStack.size() - 1; i++) {
|
|
|
|
_dialogStack[i]->drawDialog(kDrawLayerBackground);
|
|
|
|
_dialogStack[i]->drawDialog(kDrawLayerForeground);
|
|
|
|
}
|
2018-01-07 09:39:22 +00:00
|
|
|
}
|
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:
|
2018-01-07 09:39:22 +00:00
|
|
|
// This case is an optimization to avoid redrawing the whole dialog
|
|
|
|
// stack when opening a new dialog.
|
|
|
|
|
2022-11-01 16:01:08 +00:00
|
|
|
if (_displayTopDialogOnly) {
|
|
|
|
// When displaying only the top dialog clear the screen
|
|
|
|
if (_redrawStatus == kRedrawOpenDialog) {
|
|
|
|
_theme->clearAll();
|
|
|
|
_theme->drawToBackbuffer();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_theme->drawToBackbuffer();
|
2018-01-07 09:39:22 +00:00
|
|
|
|
2022-11-01 16:01:08 +00:00
|
|
|
if (_redrawStatus == kRedrawOpenDialog && _dialogStack.size() > 1) {
|
|
|
|
Dialog *previousDialog = _dialogStack[_dialogStack.size() - 2];
|
|
|
|
previousDialog->drawDialog(kDrawLayerForeground);
|
|
|
|
}
|
2018-01-07 09:39:22 +00:00
|
|
|
|
2022-10-01 15:21:58 +00:00
|
|
|
_theme->applyScreenShading(shading);
|
2022-11-01 16:01:08 +00:00
|
|
|
}
|
2022-10-01 15:21:58 +00:00
|
|
|
|
2018-01-07 09:39:22 +00:00
|
|
|
_dialogStack.top()->drawDialog(kDrawLayerBackground);
|
|
|
|
|
|
|
|
_theme->drawToScreen();
|
|
|
|
_theme->copyBackBufferToScreen();
|
|
|
|
|
|
|
|
_dialogStack.top()->drawDialog(kDrawLayerForeground);
|
2009-02-06 23:28:08 +00:00
|
|
|
break;
|
2008-07-18 16:44:42 +00:00
|
|
|
|
2009-02-06 23:28:08 +00:00
|
|
|
default:
|
2018-01-06 13:40:02 +00:00
|
|
|
break;
|
2009-02-06 23:28:08 +00:00
|
|
|
}
|
2006-06-15 14:25:59 +00:00
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
// Redraw the widgets that are marked as dirty
|
2018-01-07 09:39:22 +00:00
|
|
|
_theme->drawToScreen();
|
2018-01-06 13:40:02 +00:00
|
|
|
_dialogStack.top()->drawWidgets();
|
|
|
|
|
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())
|
2020-01-05 16:48:04 +00:00
|
|
|
return nullptr;
|
2006-12-27 22:51:14 +00:00
|
|
|
return _dialogStack.top();
|
|
|
|
}
|
|
|
|
|
2021-11-14 13:38:55 +00:00
|
|
|
void GuiManager::addToTrash(GuiObject* object, Dialog *parent) {
|
2017-03-13 07:59:10 +00:00
|
|
|
debug(7, "Adding Gui Object %p to trash", (void *)object);
|
2017-03-10 02:02:58 +00:00
|
|
|
GuiObjectTrashItem t;
|
|
|
|
t.object = object;
|
2020-01-05 16:48:04 +00:00
|
|
|
t.parent = nullptr;
|
2017-03-10 02:02:58 +00:00
|
|
|
// If a dialog was provided, check it is in the dialog stack
|
2020-01-05 16:48:04 +00:00
|
|
|
if (parent != nullptr) {
|
2017-03-18 15:17:10 +00:00
|
|
|
for (uint i = 0 ; i < _dialogStack.size() ; ++i) {
|
2017-03-10 02:02:58 +00:00
|
|
|
if (_dialogStack[i] == parent) {
|
|
|
|
t.parent = parent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-14 13:38:55 +00:00
|
|
|
|
|
|
|
for (auto it = _guiObjectTrash.begin(); it != _guiObjectTrash.end(); ++it) {
|
|
|
|
if (it->object == object) {
|
|
|
|
debug(6, "The object %p was already scheduled for deletion, skipping", (void *)(*it).object);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 02:02:58 +00:00
|
|
|
_guiObjectTrash.push_back(t);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-01-05 16:48:04 +00:00
|
|
|
if (activeDialog == nullptr)
|
2002-10-16 17:37:30 +00:00
|
|
|
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
|
2021-08-27 12:22:28 +00:00
|
|
|
g_eventRec.acquireRecording();
|
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();
|
2018-01-01 04:40:41 +00:00
|
|
|
const uint32 targetFrameDuration = 1000 / 60;
|
2006-05-20 08:29:50 +00:00
|
|
|
|
2021-01-21 00:06:20 +00:00
|
|
|
while (!_dialogStack.empty() && activeDialog == getTopDialog() && !eventMan->shouldQuit() && (!g_engine || !eventMan->shouldReturnToLauncher())) {
|
2018-01-01 04:40:41 +00:00
|
|
|
uint32 frameStartTime = _system->getMillis(true);
|
|
|
|
|
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-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
|
2023-03-09 16:37:11 +00:00
|
|
|
// an event immediately. For example, we might have a mouse move
|
|
|
|
// event queued before a screen changed event. In some rare cases
|
2013-10-17 22:51:52 +00:00
|
|
|
// 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());
|
2017-03-13 07:59:22 +00:00
|
|
|
continue;
|
2016-03-24 13:55:17 +00:00
|
|
|
}
|
2017-03-13 07:59:22 +00:00
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
processEvent(event, activeDialog);
|
2002-07-13 18:32:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 00:17:06 +00:00
|
|
|
// If iconsSet was modified, notify dialogs so that they can be updated if needed
|
|
|
|
_iconsMutex.lock();
|
|
|
|
bool iconsChanged = _iconsSetChanged;
|
|
|
|
_iconsSetChanged = false;
|
|
|
|
_iconsMutex.unlock();
|
|
|
|
if (iconsChanged) {
|
|
|
|
for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) {
|
|
|
|
setTarget(_dialogStack[i]);
|
|
|
|
sendCommand(kIconsSetLoadedCmd, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 02:02:58 +00:00
|
|
|
// Delete GuiObject that have been added to the trash for a delayed deletion
|
|
|
|
Common::List<GuiObjectTrashItem>::iterator it = _guiObjectTrash.begin();
|
|
|
|
while (it != _guiObjectTrash.end()) {
|
2020-01-05 16:48:04 +00:00
|
|
|
if ((*it).parent == nullptr || (*it).parent == activeDialog) {
|
2017-03-13 07:59:10 +00:00
|
|
|
debug(7, "Delayed deletion of Gui Object %p", (void *)(*it).object);
|
2017-03-10 02:02:58 +00:00
|
|
|
delete (*it).object;
|
|
|
|
it = _guiObjectTrash.erase(it);
|
|
|
|
} else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2021-06-18 11:27:36 +00:00
|
|
|
// Handle tooltip for the widget under the mouse cursor.
|
|
|
|
// 1. Only try to show a tooltip if the mouse cursor was actually moved
|
|
|
|
// and sufficient time (kTooltipDelay) passed since mouse cursor rested in-place.
|
|
|
|
// Note, Dialog objects acquiring or losing focus lead to a _lastMousePosition update,
|
|
|
|
// which may lead to a change of its time and x,y coordinate values.
|
|
|
|
// See: GuiManager::giveFocusToDialog()
|
|
|
|
// We avoid updating _lastMousePosition when giving focus to the Tooltip object
|
|
|
|
// by having the Tooltip objects set a false value for their (inherited) member
|
|
|
|
// var _mouseUpdatedOnFocus (in Tooltip::setup()).
|
|
|
|
// However, when the tooltip loses focus, _lastMousePosition will be updated.
|
|
|
|
// If the mouse had stayed in the same position in the meantime,
|
|
|
|
// then at the time of the tooltip losing focus
|
|
|
|
// the _lastMousePosition.time will be new, but the x,y cordinates
|
|
|
|
// will be the same as the stored ones in _lastTooltipShown.
|
|
|
|
// 2. If the mouse was moved but ended on the same (tooltip enabled) widget,
|
|
|
|
// then delay showing the tooltip based on the value of kTooltipSameWidgetDelay.
|
|
|
|
uint32 systemMillisNowForTooltipCheck = _system->getMillis(true);
|
|
|
|
if ((_lastTooltipShown.x != _lastMousePosition.x || _lastTooltipShown.y != _lastMousePosition.y)
|
|
|
|
&& _lastMousePosition.time + kTooltipDelay < systemMillisNowForTooltipCheck) {
|
2010-11-18 18:17:00 +00:00
|
|
|
Widget *wdg = activeDialog->findWidget(_lastMousePosition.x, _lastMousePosition.y);
|
2021-06-18 11:27:36 +00:00
|
|
|
if (wdg && wdg->hasTooltip() && !(wdg->getFlags() & WIDGET_PRESSED)
|
|
|
|
&& (_lastTooltipShown.wdg != wdg || _lastTooltipShown.time + kTooltipSameWidgetDelay < systemMillisNowForTooltipCheck)) {
|
|
|
|
_lastTooltipShown.time = systemMillisNowForTooltipCheck;
|
|
|
|
_lastTooltipShown.wdg = wdg;
|
|
|
|
_lastTooltipShown.x = _lastMousePosition.x;
|
|
|
|
_lastTooltipShown.y = _lastMousePosition.y;
|
|
|
|
if (wdg->getType() != kEditTextWidget || activeDialog->getFocusWidget() != wdg) {
|
|
|
|
Tooltip *tooltip = new Tooltip();
|
|
|
|
tooltip->setup(activeDialog, wdg, _lastMousePosition.x, _lastMousePosition.y);
|
|
|
|
tooltip->runModal();
|
|
|
|
delete tooltip;
|
|
|
|
}
|
2010-11-18 18:17:00 +00:00
|
|
|
}
|
2010-06-15 10:52:35 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
redraw();
|
2018-01-01 04:40:41 +00:00
|
|
|
|
2021-11-13 22:11:45 +00:00
|
|
|
// Delay until the allocated frame time is elapsed to match the target frame rate.
|
2021-11-20 11:19:28 +00:00
|
|
|
// In case we have vsync enabled, we should rely on vsync to do take care about frame times.
|
|
|
|
// With vsync enabled, we currently have to force a frame time of 1ms since otherwise
|
|
|
|
// CPU usage will skyrocket on one thread as soon as no updateScreen(); calls happening.
|
2021-11-13 22:35:31 +00:00
|
|
|
if (g_system->getFeatureState(OSystem::kFeatureVSync)) {
|
2021-11-13 22:11:45 +00:00
|
|
|
_system->delayMillis(1);
|
|
|
|
} else {
|
|
|
|
uint32 actualFrameDuration = _system->getMillis(true) - frameStartTime;
|
|
|
|
if (actualFrameDuration < targetFrameDuration) {
|
|
|
|
_system->delayMillis(targetFrameDuration - actualFrameDuration);
|
|
|
|
}
|
2018-01-01 04:40:41 +00:00
|
|
|
}
|
|
|
|
_system->updateScreen();
|
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.
|
2021-10-31 14:10:19 +00:00
|
|
|
// This is most noticeable in bug #5954 "LAUNCHER: Can't quit from unsupported game dialog".
|
2012-01-30 21:59:09 +00:00
|
|
|
// 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.
|
2021-01-21 00:06:20 +00:00
|
|
|
if ((eventMan->shouldQuit() || (g_engine && eventMan->shouldReturnToLauncher())) && activeDialog == getTopDialog())
|
2012-01-30 21:59:09 +00:00
|
|
|
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
|
2021-08-27 12:22:28 +00:00
|
|
|
g_eventRec.releaseRecording();
|
2013-07-07 03:54:45 +00:00
|
|
|
#endif
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 05:01:06 +00:00
|
|
|
void GuiManager::exitLoop() {
|
|
|
|
while (!_dialogStack.empty())
|
|
|
|
getTopDialog()->close();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
initKeymap();
|
2017-08-13 15:04:45 +00:00
|
|
|
enableKeymap(true);
|
2017-08-14 15:28:19 +00:00
|
|
|
|
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() {
|
2017-08-13 15:04:45 +00:00
|
|
|
enableKeymap(false);
|
2017-08-14 15:28:19 +00:00
|
|
|
|
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);
|
2020-01-05 16:48:04 +00:00
|
|
|
CursorMan.pushCursor(nullptr, 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() {
|
2021-08-27 12:22:28 +00:00
|
|
|
#ifdef ENABLE_EVENTRECORDER
|
|
|
|
// Suspend recording while GUI is redrawn.
|
|
|
|
// We need this in addition to the lock in runLoop, as EVENT_SCREEN_CHANGED can
|
|
|
|
// be fired by in-game GUI components (such as the event recorder itself)
|
|
|
|
g_eventRec.acquireRecording();
|
|
|
|
#endif
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
_lastScreenChangeID = _system->getScreenChangeID();
|
|
|
|
|
2020-10-26 17:27:06 +00:00
|
|
|
computeScaleFactor();
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
// reinit the whole theme
|
2020-11-07 13:58:14 +00:00
|
|
|
_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();
|
2021-08-27 12:22:28 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_EVENTRECORDER
|
|
|
|
// Resume recording once GUI has redrawn
|
|
|
|
g_eventRec.releaseRecording();
|
|
|
|
#endif
|
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) {
|
2020-01-05 16:48:04 +00:00
|
|
|
if (activeDialog == nullptr)
|
2016-03-24 13:55:17 +00:00
|
|
|
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);
|
2020-05-11 22:07:40 +00:00
|
|
|
if (g_gui.useRTL()) {
|
2020-05-18 18:16:20 +00:00
|
|
|
mouse.x = g_system->getOverlayWidth() - event.mouse.x - activeDialog->_x + g_gui.getOverlayOffset();
|
2020-05-11 22:07:40 +00:00
|
|
|
}
|
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:
|
2020-05-11 22:07:40 +00:00
|
|
|
if (g_gui.useRTL()) {
|
2020-05-18 18:16:20 +00:00
|
|
|
_globalMousePosition.x = g_system->getOverlayWidth() - event.mouse.x + g_gui.getOverlayOffset();
|
2020-05-11 22:07:40 +00:00
|
|
|
} else {
|
2020-05-07 21:21:22 +00:00
|
|
|
_globalMousePosition.x = event.mouse.x;
|
|
|
|
}
|
2016-04-06 14:22:02 +00:00
|
|
|
_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:
|
|
|
|
activeDialog->handleOtherEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-06 15:13:29 +00:00
|
|
|
void GuiManager::scheduleTopDialogRedraw() {
|
|
|
|
_redrawStatus = kRedrawTopDialog;
|
2016-06-22 11:29:01 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2021-06-18 11:27:36 +00:00
|
|
|
if (dialog->isMouseUpdatedOnFocus()) {
|
|
|
|
setLastMousePos(dialogX, dialogY);
|
|
|
|
}
|
2016-04-06 14:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiManager::setLastMousePos(int16 x, int16 y) {
|
|
|
|
_lastMousePosition.x = x;
|
|
|
|
_lastMousePosition.y = y;
|
|
|
|
_lastMousePosition.time = _system->getMillis(true);
|
|
|
|
}
|
|
|
|
|
2020-05-30 11:46:23 +00:00
|
|
|
void GuiManager::setLanguageRTL() {
|
2020-06-05 23:33:43 +00:00
|
|
|
if (ConfMan.hasKey("guiRTL")) { // Put guiRTL = yes to your scummvm.ini to force RTL GUI
|
2020-05-30 11:46:23 +00:00
|
|
|
_useRTL = ConfMan.getBool("guiRTL");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef USE_TRANSLATION
|
|
|
|
Common::String language = TransMan.getCurrentLanguage();
|
2020-06-03 20:12:56 +00:00
|
|
|
if (language.equals("he")) { // GUI TODO: modify when we'll support other RTL languages, such as Arabic and Farsi
|
2020-05-30 11:46:23 +00:00
|
|
|
_useRTL = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif // USE_TRANSLATION
|
|
|
|
|
|
|
|
_useRTL = false;
|
|
|
|
}
|
|
|
|
|
2020-05-14 00:12:19 +00:00
|
|
|
void GuiManager::setDialogPaddings(int l, int r) {
|
|
|
|
_topDialogLeftPadding = l;
|
|
|
|
_topDialogRightPadding = r;
|
2020-05-11 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 20:16:44 +00:00
|
|
|
void GuiManager::initTextToSpeech() {
|
2019-07-14 21:39:26 +00:00
|
|
|
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
|
2019-07-16 04:09:36 +00:00
|
|
|
if (ttsMan == nullptr)
|
|
|
|
return;
|
2022-04-10 19:31:35 +00:00
|
|
|
ttsMan->enable(ConfMan.hasKey("tts_enabled", "scummvm") ? ConfMan.getBool("tts_enabled", "scummvm") : false);
|
2019-07-14 21:39:26 +00:00
|
|
|
#ifdef USE_TRANSLATION
|
|
|
|
Common::String currentLanguage = TransMan.getCurrentLanguage();
|
2019-07-19 07:56:26 +00:00
|
|
|
ttsMan->setLanguage(currentLanguage);
|
2019-07-14 17:28:04 +00:00
|
|
|
#endif
|
2019-07-14 21:46:00 +00:00
|
|
|
int volume = (ConfMan.getInt("speech_volume", "scummvm") * 100) / 256;
|
|
|
|
if (ConfMan.hasKey("mute", "scummvm") && ConfMan.getBool("mute", "scummvm"))
|
|
|
|
volume = 0;
|
|
|
|
ttsMan->setVolume(volume);
|
|
|
|
|
2019-07-23 15:54:31 +00:00
|
|
|
unsigned voice;
|
2020-06-21 15:01:39 +00:00
|
|
|
if(ConfMan.hasKey("tts_voice")) {
|
2019-07-12 20:16:44 +00:00
|
|
|
voice = ConfMan.getInt("tts_voice", "scummvm");
|
2020-06-21 15:01:39 +00:00
|
|
|
if (voice >= ttsMan->getVoicesArray().size())
|
|
|
|
voice = ttsMan->getDefaultVoice();
|
|
|
|
} else
|
|
|
|
voice = ttsMan->getDefaultVoice();
|
2019-07-14 21:39:26 +00:00
|
|
|
ttsMan->setVoice(voice);
|
2019-07-12 20:16:44 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|