2008-08-05 10:03:53 +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.
|
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/util.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/hashmap.h"
|
|
|
|
#include "common/hash-str.h"
|
|
|
|
#include "common/xmlparser.h"
|
2008-08-08 10:37:58 +00:00
|
|
|
#include "graphics/scaler.h"
|
2008-08-05 10:03:53 +00:00
|
|
|
|
|
|
|
#include "gui/ThemeRenderer.h"
|
|
|
|
#include "gui/ThemeParser.h"
|
|
|
|
#include "gui/ThemeEval.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
2008-08-05 16:23:17 +00:00
|
|
|
bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
|
2008-08-05 10:03:53 +00:00
|
|
|
if (name == _name) {
|
|
|
|
x = _x; y = _y;
|
|
|
|
w = _w; h = _h;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-08-05 16:23:17 +00:00
|
|
|
bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
|
2008-08-05 10:03:53 +00:00
|
|
|
for (uint i = 0; i < _children.size(); ++i) {
|
|
|
|
if (_children[i]->getWidgetData(name, x, y, w, h))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeLayoutMain::reflowLayout() {
|
|
|
|
assert(_children.size() <= 1);
|
|
|
|
|
|
|
|
if (_children.size()) {
|
2008-08-07 10:53:33 +00:00
|
|
|
_children[0]->resetLayout();
|
2008-08-05 10:03:53 +00:00
|
|
|
_children[0]->setWidth(_w);
|
|
|
|
_children[0]->setHeight(_h);
|
|
|
|
_children[0]->reflowLayout();
|
2008-08-07 10:53:33 +00:00
|
|
|
|
2008-08-08 15:06:28 +00:00
|
|
|
// _children[0]->setX(_x);
|
|
|
|
// _children[0]->setY(_y);
|
|
|
|
|
2008-08-07 23:23:21 +00:00
|
|
|
if (_w == -1)
|
|
|
|
_w = _children[0]->getWidth();
|
|
|
|
|
|
|
|
if (_h == -1)
|
|
|
|
_h = _children[0]->getHeight();
|
|
|
|
|
|
|
|
if (_y == -1)
|
|
|
|
_y = (g_system->getOverlayHeight() >> 1) - (_h >> 1);
|
|
|
|
|
|
|
|
if (_x == -1)
|
|
|
|
_x = (g_system->getOverlayWidth() >> 1) - (_w >> 1);
|
2008-08-05 10:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeLayoutVertical::reflowLayout() {
|
|
|
|
int curX, curY;
|
2008-08-08 15:06:28 +00:00
|
|
|
int autoWidget = -1;
|
2008-08-05 10:03:53 +00:00
|
|
|
|
|
|
|
curX = _paddingLeft;
|
|
|
|
curY = _paddingTop;
|
|
|
|
_h = _paddingTop + _paddingBottom;
|
|
|
|
|
|
|
|
for (uint i = 0; i < _children.size(); ++i) {
|
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
_children[i]->resetLayout();
|
2008-08-05 10:03:53 +00:00
|
|
|
_children[i]->reflowLayout();
|
2008-08-06 10:50:28 +00:00
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
if (_children[i]->getWidth() == -1)
|
2008-08-06 10:50:28 +00:00
|
|
|
_children[i]->setWidth((_w == -1 ? getParentW() : _w) - _paddingLeft - _paddingRight);
|
2008-08-05 10:03:53 +00:00
|
|
|
|
2008-08-08 15:06:28 +00:00
|
|
|
if (_children[i]->getHeight() == -1) {
|
|
|
|
if (autoWidget != -1)
|
|
|
|
error("Cannot expand automatically two different widgets.");
|
|
|
|
|
|
|
|
autoWidget = i;
|
2008-08-05 10:03:53 +00:00
|
|
|
_children[i]->setHeight(getParentH() - _h - _spacing);
|
2008-08-08 15:06:28 +00:00
|
|
|
}
|
2008-08-05 16:23:17 +00:00
|
|
|
|
|
|
|
_children[i]->setY(curY);
|
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
if (_centered && _children[i]->getWidth() < _w)
|
2008-08-05 16:23:17 +00:00
|
|
|
_children[i]->setX((_w >> 1) - (_children[i]->getWidth() >> 1));
|
|
|
|
else
|
|
|
|
_children[i]->setX(curX);
|
2008-08-05 10:03:53 +00:00
|
|
|
|
|
|
|
if (_reverse) {
|
|
|
|
for (int j = i - 1; j >= 0; --j)
|
|
|
|
_children[j]->setY(_children[i]->getHeight() + _spacing);
|
|
|
|
} else {
|
|
|
|
curY += _children[i]->getHeight() + _spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
_w = MAX(_w, (int16)(_children[i]->getWidth() + _paddingLeft + _paddingRight));
|
2008-08-08 15:06:28 +00:00
|
|
|
|
|
|
|
if (autoWidget != -1 && autoWidget != (int)i) {
|
|
|
|
_children[autoWidget]->setHeight(_children[autoWidget]->getHeight() - (_children[i]->getHeight() + _spacing));
|
2008-08-10 18:26:14 +00:00
|
|
|
|
|
|
|
if (_reverse) for (int j = autoWidget - 1; j >= 0; --j)
|
2008-08-08 15:06:28 +00:00
|
|
|
_children[j]->setY(-(_children[i]->getHeight() + _spacing));
|
2008-08-10 18:26:14 +00:00
|
|
|
else
|
|
|
|
_children[i]->setY(-2 * (_children[i]->getHeight() + _spacing));
|
2008-08-08 15:06:28 +00:00
|
|
|
} else {
|
|
|
|
_h += _children[i]->getHeight() + _spacing;
|
|
|
|
}
|
2008-08-05 10:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeLayoutHorizontal::reflowLayout() {
|
|
|
|
int curX, curY;
|
2008-08-08 15:06:28 +00:00
|
|
|
int autoWidget = -1;
|
2008-08-05 10:03:53 +00:00
|
|
|
|
|
|
|
curX = _paddingLeft;
|
|
|
|
curY = _paddingTop;
|
|
|
|
_w = _paddingLeft + _paddingRight;
|
|
|
|
|
|
|
|
for (uint i = 0; i < _children.size(); ++i) {
|
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
_children[i]->resetLayout();
|
2008-08-05 10:03:53 +00:00
|
|
|
_children[i]->reflowLayout();
|
|
|
|
|
|
|
|
if (_children[i]->getHeight() == -1)
|
2008-08-07 10:53:33 +00:00
|
|
|
_children[i]->setHeight((_h == -1 ? getParentH() : _h) - _paddingTop - _paddingBottom);
|
2008-08-05 10:03:53 +00:00
|
|
|
|
2008-08-08 15:06:28 +00:00
|
|
|
if (_children[i]->getWidth() == -1) {
|
|
|
|
if (autoWidget != -1)
|
|
|
|
error("Cannot expand automatically two different widgets.");
|
|
|
|
|
|
|
|
autoWidget = i;
|
2008-08-05 10:03:53 +00:00
|
|
|
_children[i]->setWidth(getParentW() - _w - _spacing);
|
2008-08-08 15:06:28 +00:00
|
|
|
}
|
2008-08-05 10:03:53 +00:00
|
|
|
|
2008-08-05 16:23:17 +00:00
|
|
|
_children[i]->setX(curX);
|
2008-08-07 10:53:33 +00:00
|
|
|
|
|
|
|
if (_centered && _children[i]->getHeight() < _h)
|
|
|
|
_children[i]->setY((_h >> 1) - (_children[i]->getHeight() >> 1));
|
|
|
|
else
|
|
|
|
_children[i]->setY(curY);
|
2008-08-05 16:23:17 +00:00
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
if (_reverse) {
|
|
|
|
for (int j = i - 1; j >= 0; --j)
|
|
|
|
_children[j]->setX(_children[i]->getWidth() + _spacing);
|
|
|
|
} else {
|
|
|
|
curX += (_children[i]->getWidth() + _spacing);
|
|
|
|
}
|
|
|
|
|
2008-08-08 15:06:28 +00:00
|
|
|
if (autoWidget != -1 && autoWidget != (int)i) {
|
|
|
|
_children[autoWidget]->setWidth(_children[autoWidget]->getWidth() - (_children[i]->getWidth() + _spacing));
|
2008-08-10 18:26:14 +00:00
|
|
|
|
|
|
|
if (_reverse) for (int j = autoWidget - 1; j >= 0; --j)
|
2008-08-08 15:06:28 +00:00
|
|
|
_children[j]->setX(-(_children[i]->getWidth() + _spacing));
|
2008-08-10 18:26:14 +00:00
|
|
|
else
|
|
|
|
_children[i]->setX(-2 * (_children[i]->getWidth() + _spacing));
|
2008-08-08 15:06:28 +00:00
|
|
|
} else {
|
|
|
|
_w += _children[i]->getWidth() + _spacing;
|
|
|
|
}
|
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
_h = MAX(_h, (int16)(_children[i]->getHeight() + _paddingTop + _paddingBottom));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-09 14:15:34 +00:00
|
|
|
ThemeEval::~ThemeEval() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
2008-08-08 10:37:58 +00:00
|
|
|
void ThemeEval::buildBuiltinVars() {
|
|
|
|
_builtin["kThumbnailWidth"] = kThumbnailWidth;
|
|
|
|
_builtin["kThumbnailHeight"] = kThumbnailHeight1;
|
|
|
|
_builtin["kThumbnailHeight2"] = kThumbnailHeight2;
|
|
|
|
|
|
|
|
_builtin["kButtonWidth"] = GUI::kButtonWidth;
|
|
|
|
_builtin["kButtonHeight"] = GUI::kButtonHeight;
|
|
|
|
_builtin["kSliderWidth"] = GUI::kSliderWidth;
|
|
|
|
_builtin["kSliderHeight"] = GUI::kSliderHeight;
|
|
|
|
_builtin["kBigButtonWidth"] = GUI::kBigButtonWidth;
|
|
|
|
_builtin["kBigButtonHeight"] = GUI::kBigButtonHeight;
|
|
|
|
_builtin["kBigSliderWidth"] = GUI::kBigSliderWidth;
|
|
|
|
_builtin["kBigSliderWidth"] = GUI::kBigSliderWidth;
|
2008-08-08 18:30:16 +00:00
|
|
|
_builtin["kBigSliderHeight"] = GUI::kBigSliderHeight;
|
|
|
|
|
|
|
|
_builtin["kNormalWidgetSize"] = GUI::kNormalWidgetSize;
|
|
|
|
_builtin["kBigWidgetSize"] = GUI::kBigWidgetSize;
|
2008-08-08 10:37:58 +00:00
|
|
|
}
|
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
void ThemeEval::addWidget(const Common::String &name, int w, int h, const Common::String &type, bool enabled) {
|
2008-08-06 14:28:37 +00:00
|
|
|
int typeW = -1;
|
|
|
|
int typeH = -1;
|
|
|
|
|
|
|
|
if (!type.empty()) {
|
|
|
|
typeW = getVar("Globals." + type + ".Width", -1);
|
|
|
|
typeH = getVar("Globals." + type + ".Height", -1);
|
2008-08-07 10:53:33 +00:00
|
|
|
}
|
2008-08-06 14:28:37 +00:00
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
ThemeLayoutWidget *widget = new ThemeLayoutWidget(_curLayout.top(), name,
|
|
|
|
typeW == -1 ? w : typeW,
|
|
|
|
typeH == -1 ? h : typeH);
|
2008-08-05 10:03:53 +00:00
|
|
|
|
|
|
|
_curLayout.top()->addChild(widget);
|
2008-08-07 10:53:33 +00:00
|
|
|
setVar(_curDialog + "." + name + ".Enabled", enabled ? 1 : 0);
|
2008-08-05 10:03:53 +00:00
|
|
|
}
|
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
void ThemeEval::addDialog(const Common::String &name, const Common::String &overlays, bool enabled) {
|
2008-08-05 23:58:45 +00:00
|
|
|
int16 x, y;
|
2008-08-08 15:06:28 +00:00
|
|
|
uint16 w, h;
|
|
|
|
|
|
|
|
ThemeLayout *layout = 0;
|
2008-08-05 23:58:45 +00:00
|
|
|
|
2008-08-07 23:23:21 +00:00
|
|
|
if (overlays == "screen") {
|
2008-08-08 15:06:28 +00:00
|
|
|
layout = new ThemeLayoutMain(0, 0, g_system->getOverlayWidth(), g_system->getOverlayHeight());
|
2008-08-07 23:23:21 +00:00
|
|
|
} else if (overlays == "screen_center") {
|
2008-08-08 15:06:28 +00:00
|
|
|
layout = new ThemeLayoutMain(-1, -1, -1, -1);
|
|
|
|
} else if (getWidgetData(overlays, x, y, w, h)) {
|
|
|
|
layout = new ThemeLayoutMain(x, y, w, h);
|
2008-08-05 23:58:45 +00:00
|
|
|
}
|
2008-08-05 10:03:53 +00:00
|
|
|
|
2008-08-08 15:06:28 +00:00
|
|
|
if (!layout)
|
|
|
|
error("Error when loading dialog position for '%s'", overlays.c_str());
|
2008-08-09 14:15:34 +00:00
|
|
|
|
|
|
|
if (_layouts.contains(name))
|
|
|
|
delete _layouts[name];
|
2008-08-08 15:06:28 +00:00
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
_layouts[name] = layout;
|
2008-08-05 23:58:45 +00:00
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
layout->setPadding(
|
|
|
|
getVar("Globals.Padding.Left", 0),
|
|
|
|
getVar("Globals.Padding.Right", 0),
|
|
|
|
getVar("Globals.Padding.Top", 0),
|
|
|
|
getVar("Globals.Padding.Bottom", 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
_curLayout.push(layout);
|
2008-08-07 10:53:33 +00:00
|
|
|
_curDialog = name;
|
|
|
|
setVar(name + ".Enabled", enabled ? 1 : 0);
|
2008-08-05 10:03:53 +00:00
|
|
|
}
|
|
|
|
|
2008-08-06 10:50:28 +00:00
|
|
|
void ThemeEval::addLayout(ThemeLayout::LayoutType type, int spacing, bool reverse, bool center) {
|
2008-08-05 10:03:53 +00:00
|
|
|
ThemeLayout *layout = 0;
|
|
|
|
|
2008-08-06 10:50:28 +00:00
|
|
|
if (spacing == -1)
|
|
|
|
spacing = getVar("Globals.Layout.Spacing", 4);
|
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
if (type == ThemeLayout::kLayoutVertical)
|
2008-08-06 10:50:28 +00:00
|
|
|
layout = new ThemeLayoutVertical(_curLayout.top(), spacing, reverse, center);
|
2008-08-05 10:03:53 +00:00
|
|
|
else if (type == ThemeLayout::kLayoutHorizontal)
|
2008-08-06 10:50:28 +00:00
|
|
|
layout = new ThemeLayoutHorizontal(_curLayout.top(), spacing, reverse, center);
|
2008-08-05 10:03:53 +00:00
|
|
|
|
|
|
|
layout->setPadding(
|
|
|
|
getVar("Globals.Padding.Left", 0),
|
|
|
|
getVar("Globals.Padding.Right", 0),
|
|
|
|
getVar("Globals.Padding.Top", 0),
|
|
|
|
getVar("Globals.Padding.Bottom", 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
_curLayout.top()->addChild(layout);
|
|
|
|
_curLayout.push(layout);
|
|
|
|
}
|
|
|
|
|
2008-08-06 10:50:28 +00:00
|
|
|
void ThemeEval::addSpace(int size) {
|
2008-08-05 10:03:53 +00:00
|
|
|
ThemeLayout *space = new ThemeLayoutSpacing(_curLayout.top(), size);
|
|
|
|
_curLayout.top()->addChild(space);
|
|
|
|
}
|
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
bool ThemeEval::addImportedLayout(const Common::String &name) {
|
|
|
|
if (!_layouts.contains(name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_curLayout.top()->importLayout(_layouts[name]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
}
|