2002-07-05 16:56:53 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2002-2006 The ScummVM project
|
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.
|
2002-07-05 16:56:53 +00:00
|
|
|
*
|
2006-02-11 10:08:56 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-07-05 16:56:53 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.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"
|
2006-05-25 22:51:42 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2006-05-20 10:59:25 +00:00
|
|
|
#include "graphics/paletteman.h"
|
2004-03-13 13:03:25 +00:00
|
|
|
#include "gui/newgui.h"
|
|
|
|
#include "gui/dialog.h"
|
2006-03-24 14:15:45 +00:00
|
|
|
#include "gui/eval.h"
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2006-01-27 15:43:23 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
2004-12-28 20:29:42 +00:00
|
|
|
DECLARE_SINGLETON(GUI::NewGui);
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
/*
|
|
|
|
* TODO list
|
2002-09-22 04:03:45 +00:00
|
|
|
* - add more widgets: edit field, popup, radio buttons, ...
|
|
|
|
*
|
|
|
|
* Other ideas:
|
2002-07-08 01:04:29 +00:00
|
|
|
* - allow multi line (l/c/r aligned) text via StaticTextWidget ?
|
2002-07-07 22:44:30 +00:00
|
|
|
* - add "close" widget to all dialogs (with a flag to turn it off) ?
|
|
|
|
* - make dialogs "moveable" ?
|
2005-01-06 19:09:34 +00:00
|
|
|
* - come up with a new look & feel / theme for the GUI
|
2002-07-07 22:44:30 +00:00
|
|
|
* - ...
|
|
|
|
*/
|
|
|
|
|
2002-09-30 12:56:59 +00:00
|
|
|
enum {
|
2003-03-06 19:52:54 +00:00
|
|
|
kDoubleClickDelay = 500, // milliseconds
|
2003-08-28 19:20:30 +00:00
|
|
|
kCursorAnimateDelay = 250,
|
2002-09-30 12:56:59 +00:00
|
|
|
kKeyRepeatInitialDelay = 400,
|
2002-12-25 00:48:13 +00:00
|
|
|
kKeyRepeatSustainDelay = 100
|
2002-09-30 12:56:59 +00:00
|
|
|
};
|
|
|
|
|
2006-06-08 19:43:37 +00:00
|
|
|
// HACK. FIXME. This doesn't belong here. But otherwise it creates compilation problems
|
2006-06-03 13:33:39 +00:00
|
|
|
GuiObject::GuiObject(const Common::String &name) : _firstWidget(0) {
|
2006-03-07 13:41:36 +00:00
|
|
|
_name = name;
|
2006-03-07 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2006-08-04 13:55:53 +00:00
|
|
|
void GuiObject::reflowLayout() {
|
2006-07-23 15:08:48 +00:00
|
|
|
if (!_name.empty()) {
|
2006-04-19 01:05:28 +00:00
|
|
|
if ((_x = g_gui.evaluator()->getVar(_name + ".x")) == EVAL_UNDEF_VAR)
|
|
|
|
error("Undefined variable %s.x", _name.c_str());
|
|
|
|
if ((_y = g_gui.evaluator()->getVar(_name + ".y")) == EVAL_UNDEF_VAR)
|
|
|
|
error("Undefined variable %s.y", _name.c_str());
|
|
|
|
_w = g_gui.evaluator()->getVar(_name + ".w");
|
|
|
|
_h = g_gui.evaluator()->getVar(_name + ".h");
|
|
|
|
|
2006-07-14 13:33:58 +00:00
|
|
|
if (_x < 0)
|
2006-04-19 01:05:28 +00:00
|
|
|
error("Widget <%s> has x < 0", _name.c_str());
|
2006-07-14 13:33:58 +00:00
|
|
|
if (_x >= g_system->getOverlayWidth())
|
2006-04-19 01:05:28 +00:00
|
|
|
error("Widget <%s> has x > %d", _name.c_str(), g_system->getOverlayWidth());
|
2006-07-14 13:33:58 +00:00
|
|
|
if (_x + _w > g_system->getOverlayWidth())
|
2006-04-19 01:05:28 +00:00
|
|
|
error("Widget <%s> has x + w > %d (%d)", _name.c_str(), g_system->getOverlayWidth(), _x + _w);
|
2006-07-14 13:33:58 +00:00
|
|
|
if (_y < 0)
|
2006-04-19 01:05:28 +00:00
|
|
|
error("Widget <%s> has y < 0", _name.c_str());
|
2006-07-14 13:33:58 +00:00
|
|
|
if (_y >= g_system->getOverlayWidth())
|
2006-04-19 01:05:28 +00:00
|
|
|
error("Widget <%s> has y > %d", _name.c_str(), g_system->getOverlayHeight());
|
2006-07-14 13:33:58 +00:00
|
|
|
if (_y + _h > g_system->getOverlayWidth())
|
2006-04-19 01:05:28 +00:00
|
|
|
error("Widget <%s> has y + h > %d (%d)", _name.c_str(), g_system->getOverlayHeight(), _y + _h);
|
|
|
|
}
|
|
|
|
}
|
2006-03-07 05:39:52 +00:00
|
|
|
|
2002-09-19 17:44:41 +00:00
|
|
|
// Constructor
|
2005-06-02 12:29:01 +00:00
|
|
|
NewGui::NewGui() : _needRedraw(false),
|
2006-01-27 15:43:23 +00:00
|
|
|
_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();
|
2003-11-02 02:18:16 +00:00
|
|
|
|
2002-09-19 23:06:54 +00:00
|
|
|
// Clear the cursor
|
|
|
|
memset(_cursor, 0xFF, sizeof(_cursor));
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-11-22 14:02:54 +00:00
|
|
|
// Reset key repeat
|
|
|
|
_currentKeyDown.keycode = 0;
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2006-02-13 21:02:31 +00:00
|
|
|
#ifndef DISABLE_FANCY_THEMES
|
2006-04-14 13:20:39 +00:00
|
|
|
ConfMan.registerDefault("gui_theme", "default");
|
2006-06-03 13:33:39 +00:00
|
|
|
Common::String style(ConfMan.get("gui_theme"));
|
2006-04-14 13:20:39 +00:00
|
|
|
// The default theme for now is the 'modern' theme.
|
2006-10-08 12:00:19 +00:00
|
|
|
if (style.compareToIgnoreCase("default") == 0)
|
2006-04-14 13:20:39 +00:00
|
|
|
style = "modern";
|
|
|
|
|
2006-10-08 12:00:19 +00:00
|
|
|
Common::String styleType;
|
|
|
|
Common::ConfigFile cfg;
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!loadNewTheme(style)) {
|
|
|
|
warning("falling back to classic style");
|
|
|
|
_theme = new ThemeClassic(_system);
|
|
|
|
assert(_theme);
|
|
|
|
if (!_theme->init()) {
|
|
|
|
error("Couldn't initialize classic theme");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_theme->resetDrawArea();
|
|
|
|
_themeChange = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NewGui::loadNewTheme(const Common::String &style) {
|
|
|
|
Common::String styleType;
|
|
|
|
Common::ConfigFile cfg;
|
|
|
|
|
|
|
|
Common::String oldTheme = (_theme != 0) ? _theme->getStylefileName() : "";
|
2006-10-08 20:37:39 +00:00
|
|
|
|
|
|
|
if (_theme)
|
|
|
|
_theme->disable();
|
|
|
|
|
|
|
|
if (_useStdCursor) {
|
|
|
|
PaletteMan.popCursorPalette();
|
|
|
|
CursorMan.popCursor();
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
delete _theme;
|
|
|
|
|
2006-10-08 19:24:31 +00:00
|
|
|
if (style.compareToIgnoreCase("classic (builtin)") == 0) {
|
|
|
|
_theme = new ThemeClassic(_system, style);
|
2006-10-08 18:49:25 +00:00
|
|
|
} else {
|
|
|
|
if (Theme::themeConfigUseable(style, "", &styleType, &cfg)) {
|
|
|
|
if (0 == styleType.compareToIgnoreCase("classic"))
|
|
|
|
_theme = new ThemeClassic(_system, style, &cfg);
|
2006-10-08 18:22:28 +00:00
|
|
|
#ifndef DISABLE_FANCY_THEMES
|
2006-10-08 18:49:25 +00:00
|
|
|
else if (0 == styleType.compareToIgnoreCase("modern"))
|
|
|
|
_theme = new ThemeNew(_system, style, &cfg);
|
2006-10-08 18:22:28 +00:00
|
|
|
#endif
|
2006-10-08 18:49:25 +00:00
|
|
|
else
|
|
|
|
warning("Unsupported theme type '%s'", styleType.c_str());
|
|
|
|
} else {
|
|
|
|
warning("Config '%s' is NOT usable for themes or not found", style.c_str());
|
|
|
|
}
|
2006-01-27 15:43:23 +00:00
|
|
|
}
|
2006-10-08 12:00:19 +00:00
|
|
|
cfg.clear();
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
if (!_theme)
|
|
|
|
return (!oldTheme.empty() ? loadNewTheme(oldTheme) : false);
|
2006-01-27 15:43:23 +00:00
|
|
|
|
|
|
|
if (!_theme->init()) {
|
2006-10-08 18:22:28 +00:00
|
|
|
warning("Could not initialize your preferred theme");
|
2006-01-27 15:43:23 +00:00
|
|
|
delete _theme;
|
2006-10-08 18:22:28 +00:00
|
|
|
_theme = 0;
|
|
|
|
loadNewTheme(oldTheme);
|
|
|
|
return false;
|
2005-06-02 12:29:01 +00:00
|
|
|
}
|
2006-01-27 15:43:23 +00:00
|
|
|
_theme->resetDrawArea();
|
2006-10-08 18:22:28 +00:00
|
|
|
|
|
|
|
if (!oldTheme.empty())
|
|
|
|
screenChange();
|
|
|
|
|
|
|
|
_themeChange = true;
|
|
|
|
|
|
|
|
return true;
|
2005-01-06 19:09:34 +00:00
|
|
|
}
|
|
|
|
|
2006-06-03 10:48:37 +00:00
|
|
|
void NewGui::redraw() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Restore the overlay to its initial state, then draw all dialogs.
|
|
|
|
// This is necessary to get the blending right.
|
|
|
|
_theme->clearAll();
|
|
|
|
|
|
|
|
for (i = 0; i < _dialogStack.size(); ++i) {
|
|
|
|
_theme->closeDialog();
|
|
|
|
}
|
|
|
|
for (i = 0; i < _dialogStack.size(); i++) {
|
|
|
|
// Special treatment when topmost dialog has dimsInactive() set to false
|
|
|
|
// This is the case for PopUpWidget which should not dim a dialog
|
|
|
|
// which it belongs to
|
|
|
|
if ((i == _dialogStack.size() - 2) && !_dialogStack[i + 1]->dimsInactive())
|
|
|
|
_theme->openDialog(true);
|
|
|
|
else if ((i != (_dialogStack.size() - 1)) || !_dialogStack[i]->dimsInactive())
|
|
|
|
_theme->openDialog(false);
|
|
|
|
else
|
|
|
|
_theme->openDialog(true);
|
|
|
|
|
|
|
|
_dialogStack[i]->drawDialog();
|
|
|
|
}
|
2006-06-15 14:25:59 +00:00
|
|
|
|
|
|
|
_theme->drawAll();
|
2006-06-03 10:48:37 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::runLoop() {
|
2002-10-16 17:37:30 +00:00
|
|
|
Dialog *activeDialog = _dialogStack.top();
|
|
|
|
bool didSaveState = false;
|
2005-01-06 22:51:25 +00:00
|
|
|
int button;
|
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
|
|
|
|
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();
|
|
|
|
}
|
2006-05-20 08:29:50 +00:00
|
|
|
|
2002-12-25 00:46:34 +00:00
|
|
|
while (!_dialogStack.empty() && activeDialog == _dialogStack.top()) {
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_needRedraw) {
|
2006-06-03 10:48:37 +00:00
|
|
|
redraw();
|
2002-09-28 16:19:28 +00:00
|
|
|
_needRedraw = false;
|
2002-09-22 04:03:45 +00:00
|
|
|
}
|
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();
|
2006-01-27 15:43:23 +00:00
|
|
|
_theme->drawAll();
|
2005-01-06 19:09:34 +00:00
|
|
|
_system->updateScreen();
|
2002-09-22 04:03:45 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
OSystem::Event event;
|
2004-09-28 20:19:37 +00:00
|
|
|
uint32 time = _system->getMillis();
|
2002-09-30 12:56:59 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
while (_system->pollEvent(event)) {
|
2006-06-16 06:26:26 +00:00
|
|
|
if (activeDialog != _dialogStack.top() && event.type != OSystem::EVENT_QUIT && event.type != OSystem::EVENT_SCREEN_CHANGED)
|
|
|
|
continue;
|
|
|
|
|
2005-06-02 12:29:01 +00:00
|
|
|
Common::Point mouse(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y);
|
2006-10-08 18:22:28 +00:00
|
|
|
|
|
|
|
// HACK to change the cursor to the new themes one
|
|
|
|
if (_themeChange) {
|
2006-10-08 20:19:23 +00:00
|
|
|
_theme->enable();
|
2006-10-08 18:22:28 +00:00
|
|
|
|
2006-10-08 20:37:39 +00:00
|
|
|
_useStdCursor = !_theme->ownCursor();
|
|
|
|
if (_useStdCursor)
|
2006-10-08 18:22:28 +00:00
|
|
|
setupCursor();
|
|
|
|
|
|
|
|
_theme->refresh();
|
|
|
|
|
|
|
|
_themeChange = false;
|
|
|
|
redraw();
|
|
|
|
}
|
2005-09-03 16:26:00 +00:00
|
|
|
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2003-09-24 06:33:59 +00:00
|
|
|
case OSystem::EVENT_KEYDOWN:
|
2005-09-03 16:26:00 +00:00
|
|
|
#if !defined(PALMOS_MODE)
|
2003-09-24 06:33:59 +00:00
|
|
|
// init continuous event stream
|
2004-01-26 07:35:31 +00:00
|
|
|
// not done on PalmOS because keyboard is emulated and keyup is not generated
|
2003-09-24 06:33:59 +00:00
|
|
|
_currentKeyDown.ascii = event.kbd.ascii;
|
|
|
|
_currentKeyDown.keycode = event.kbd.keycode;
|
|
|
|
_currentKeyDown.flags = event.kbd.flags;
|
|
|
|
_keyRepeatTime = time + kKeyRepeatInitialDelay;
|
2003-04-30 13:57:57 +00:00
|
|
|
#endif
|
2003-09-24 06:33:59 +00:00
|
|
|
activeDialog->handleKeyDown(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_KEYUP:
|
|
|
|
activeDialog->handleKeyUp(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
|
|
|
|
if (event.kbd.keycode == _currentKeyDown.keycode)
|
|
|
|
// only stop firing events if it's the current key
|
|
|
|
_currentKeyDown.keycode = 0;
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseMoved(mouse.x, mouse.y, 0);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
// We don't distinguish between mousebuttons (for now at least)
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
2004-10-17 19:40:34 +00:00
|
|
|
case OSystem::EVENT_RBUTTONDOWN:
|
2005-01-06 22:51:25 +00:00
|
|
|
button = (event.type == OSystem::EVENT_LBUTTONDOWN ? 1 : 2);
|
2003-09-24 06:33:59 +00:00
|
|
|
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;
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseDown(mouse.x, mouse.y, button, _lastClick.count);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
|
|
|
case OSystem::EVENT_RBUTTONUP:
|
2005-01-06 22:51:25 +00:00
|
|
|
button = (event.type == OSystem::EVENT_LBUTTONUP ? 1 : 2);
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseUp(mouse.x, mouse.y, button, _lastClick.count);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELUP:
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseWheel(mouse.x, mouse.y, -1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELDOWN:
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseWheel(mouse.x, mouse.y, 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
_system->quit();
|
|
|
|
return;
|
|
|
|
case OSystem::EVENT_SCREEN_CHANGED:
|
2006-10-08 18:22:28 +00:00
|
|
|
screenChange();
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2002-07-13 18:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-22 04:03:45 +00:00
|
|
|
// check if event should be sent again (keydown)
|
2006-06-16 06:26:26 +00:00
|
|
|
if (_currentKeyDown.keycode != 0 && activeDialog == _dialogStack.top()) {
|
2003-03-06 19:52:54 +00:00
|
|
|
if (_keyRepeatTime < time) {
|
2002-09-22 04:03:45 +00:00
|
|
|
// fire event
|
2002-11-22 14:02:54 +00:00
|
|
|
activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags);
|
2002-09-30 12:56:59 +00:00
|
|
|
_keyRepeatTime = time + kKeyRepeatSustainDelay;
|
2002-09-22 04:03:45 +00:00
|
|
|
}
|
2002-07-18 14:47:25 +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
|
|
|
|
2006-01-27 15:43:23 +00:00
|
|
|
_theme->closeDialog();
|
|
|
|
|
|
|
|
if (didSaveState) {
|
|
|
|
_theme->disable();
|
2006-06-13 09:57:16 +00:00
|
|
|
restoreState();
|
2006-10-08 20:37:39 +00:00
|
|
|
_useStdCursor = false;
|
2006-01-27 15:43:23 +00:00
|
|
|
}
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::saveState() {
|
2002-07-05 16:56:53 +00:00
|
|
|
// Backup old cursor
|
2002-11-22 14:02:54 +00:00
|
|
|
_currentKeyDown.keycode = 0;
|
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
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::restoreState() {
|
2006-10-08 20:37:39 +00:00
|
|
|
if (_useStdCursor) {
|
|
|
|
CursorMan.popCursor();
|
|
|
|
PaletteMan.popCursorPalette();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::openDialog(Dialog *dialog) {
|
2002-07-07 21:46:53 +00:00
|
|
|
_dialogStack.push(dialog);
|
2002-09-28 16:19:28 +00:00
|
|
|
_needRedraw = true;
|
2006-08-04 15:48:37 +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.
|
|
|
|
int tmpScreenChangeID = _system->getScreenChangeID();
|
|
|
|
if (_lastScreenChangeID != tmpScreenChangeID) {
|
|
|
|
_lastScreenChangeID = tmpScreenChangeID;
|
|
|
|
|
2006-08-04 15:48:37 +00:00
|
|
|
// reinit the whole theme
|
|
|
|
_theme->refresh();
|
|
|
|
// refresh all dialogs
|
|
|
|
for (int i = 0; i < _dialogStack.size(); ++i) {
|
2006-08-12 16:42:19 +00:00
|
|
|
_dialogStack[i]->reflowLayout();
|
2006-08-04 15:48:37 +00:00
|
|
|
}
|
2006-08-04 18:11:00 +00:00
|
|
|
} else {
|
2006-08-12 16:42:19 +00:00
|
|
|
dialog->reflowLayout();
|
|
|
|
}
|
2002-07-07 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::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
|
2002-07-07 21:46:53 +00:00
|
|
|
_dialogStack.pop();
|
2002-09-28 16:19:28 +00:00
|
|
|
_needRedraw = true;
|
2002-07-07 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
void NewGui::setupCursor() {
|
|
|
|
const byte palette[] = {
|
|
|
|
255, 255, 255, 0,
|
|
|
|
255, 255, 255, 0,
|
|
|
|
171, 171, 171, 0,
|
|
|
|
87, 87, 87, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
PaletteMan.pushCursorPalette(palette, 0, 4);
|
|
|
|
CursorMan.pushCursor(NULL, 0, 0, 0, 0);
|
|
|
|
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.
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::animateCursor() {
|
2005-01-06 19:09:34 +00:00
|
|
|
int time = _system->getMillis();
|
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
|
|
|
|
2006-05-25 22:51:42 +00:00
|
|
|
CursorMan.replaceCursor(_cursor, 16, 16, 7, 7);
|
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
|
|
|
|
2006-03-24 14:15:45 +00:00
|
|
|
WidgetSize NewGui::getWidgetSize() {
|
|
|
|
return (WidgetSize)(_theme->_evaluator->getVar("widgetSize"));
|
|
|
|
}
|
|
|
|
|
2006-05-27 05:46:04 +00:00
|
|
|
void NewGui::clearDragWidget() {
|
|
|
|
_dialogStack.top()->_dragWidget = 0;
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
void NewGui::screenChange() {
|
|
|
|
_lastScreenChangeID = _system->getScreenChangeID();
|
|
|
|
|
|
|
|
// reinit the whole theme
|
|
|
|
_theme->refresh();
|
|
|
|
// refresh all dialogs
|
|
|
|
for (int i = 0; i < _dialogStack.size(); ++i) {
|
|
|
|
_dialogStack[i]->reflowLayout();
|
|
|
|
}
|
|
|
|
// We need to redraw immediately. Otherwise
|
|
|
|
// some other event may cause a widget to be
|
|
|
|
// redrawn before redraw() has been called.
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|