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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gui/ThemeEval.h"
|
2008-11-08 01:30:32 +00:00
|
|
|
|
2008-11-09 15:14:01 +00:00
|
|
|
#include "graphics/scaler.h"
|
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/system.h"
|
2010-03-20 12:56:56 +00:00
|
|
|
#include "common/tokenizer.h"
|
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-02 17:51:08 +00:00
|
|
|
void ThemeEval::reset() {
|
|
|
|
_vars.clear();
|
|
|
|
_curDialog.clear();
|
|
|
|
_curLayout.clear();
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-09-02 17:51:08 +00:00
|
|
|
for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
|
|
|
|
delete i->_value;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-09-02 17:51:08 +00:00
|
|
|
_layouts.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) {
|
|
|
|
Common::StringTokenizer tokenizer(widget, ".");
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-09-02 17:51:08 +00:00
|
|
|
if (widget.hasPrefix("Dialog."))
|
|
|
|
tokenizer.nextToken();
|
|
|
|
|
|
|
|
Common::String dialogName = "Dialog." + tokenizer.nextToken();
|
|
|
|
Common::String widgetName = tokenizer.nextToken();
|
2008-12-22 11:22:15 +00:00
|
|
|
|
|
|
|
if (!_layouts.contains(dialogName))
|
2008-09-02 17:51:08 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return _layouts[dialogName]->getWidgetData(widgetName, x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2009-06-06 17:52:44 +00:00
|
|
|
Graphics::TextAlign ThemeEval::getWidgetTextHAlign(const Common::String &widget) {
|
|
|
|
Common::StringTokenizer tokenizer(widget, ".");
|
|
|
|
|
|
|
|
if (widget.hasPrefix("Dialog."))
|
|
|
|
tokenizer.nextToken();
|
|
|
|
|
|
|
|
Common::String dialogName = "Dialog." + tokenizer.nextToken();
|
|
|
|
Common::String widgetName = tokenizer.nextToken();
|
|
|
|
|
|
|
|
if (!_layouts.contains(dialogName))
|
|
|
|
return Graphics::kTextAlignInvalid;
|
|
|
|
|
|
|
|
return _layouts[dialogName]->getWidgetTextHAlign(widgetName);
|
|
|
|
}
|
2008-08-05 10:03:53 +00:00
|
|
|
|
2009-06-06 17:51:41 +00:00
|
|
|
void ThemeEval::addWidget(const Common::String &name, int w, int h, const Common::String &type, bool enabled, Graphics::TextAlign align) {
|
2008-08-06 14:28:37 +00:00
|
|
|
int typeW = -1;
|
|
|
|
int typeH = -1;
|
2009-06-06 17:52:44 +00:00
|
|
|
Graphics::TextAlign typeAlign = Graphics::kTextAlignInvalid;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-06 14:28:37 +00:00
|
|
|
if (!type.empty()) {
|
|
|
|
typeW = getVar("Globals." + type + ".Width", -1);
|
|
|
|
typeH = getVar("Globals." + type + ".Height", -1);
|
2009-06-06 17:52:44 +00:00
|
|
|
typeAlign = (Graphics::TextAlign)getVar("Globals." + type + ".Align", Graphics::kTextAlignInvalid);
|
2016-06-24 17:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ThemeLayoutWidget *widget;
|
|
|
|
if (type == "TabWidget")
|
|
|
|
widget = new ThemeLayoutTabWidget(_curLayout.top(), name,
|
|
|
|
typeW == -1 ? w : typeW,
|
|
|
|
typeH == -1 ? h : typeH,
|
|
|
|
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign,
|
|
|
|
getVar("Globals.TabWidget.Tab.Height", 0));
|
|
|
|
else
|
|
|
|
widget = new ThemeLayoutWidget(_curLayout.top(), name,
|
|
|
|
typeW == -1 ? w : typeW,
|
|
|
|
typeH == -1 ? h : typeH,
|
|
|
|
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign);
|
2008-12-22 11:22:15 +00:00
|
|
|
|
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-13 10:42:01 +00:00
|
|
|
void ThemeEval::addDialog(const Common::String &name, const Common::String &overlays, bool enabled, int inset) {
|
2008-08-05 23:58:45 +00:00
|
|
|
int16 x, y;
|
2008-08-08 15:06:28 +00:00
|
|
|
uint16 w, h;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-08 15:06:28 +00:00
|
|
|
ThemeLayout *layout = 0;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-07 23:23:21 +00:00
|
|
|
if (overlays == "screen") {
|
2008-08-13 10:42:01 +00:00
|
|
|
layout = new ThemeLayoutMain(inset, inset, g_system->getOverlayWidth() - 2 * inset, g_system->getOverlayHeight() - 2 * inset);
|
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)) {
|
2008-08-13 10:42:01 +00:00
|
|
|
layout = new ThemeLayoutMain(x + inset, y + inset, w - 2 * inset, h - 2 * inset);
|
2008-08-05 23:58:45 +00:00
|
|
|
}
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-08 15:06:28 +00:00
|
|
|
if (!layout)
|
|
|
|
error("Error when loading dialog position for '%s'", overlays.c_str());
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-09 14:15:34 +00:00
|
|
|
if (_layouts.contains(name))
|
|
|
|
delete _layouts[name];
|
2008-12-22 11:22:15 +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)
|
|
|
|
);
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
_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-15 16:44:44 +00:00
|
|
|
void ThemeEval::addLayout(ThemeLayout::LayoutType type, int spacing, bool center) {
|
2008-08-05 10:03:53 +00:00
|
|
|
ThemeLayout *layout = 0;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-06 10:50:28 +00:00
|
|
|
if (spacing == -1)
|
|
|
|
spacing = getVar("Globals.Layout.Spacing", 4);
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-12-26 01:08:49 +00:00
|
|
|
layout = new ThemeLayoutStacked(_curLayout.top(), type, spacing, center);
|
2008-10-14 17:29:48 +00:00
|
|
|
|
|
|
|
assert(layout);
|
2008-12-22 11:22:15 +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)
|
|
|
|
);
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-05 10:03:53 +00:00
|
|
|
_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;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
_curLayout.top()->importLayout(_layouts[name]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-12 22:25:35 +00:00
|
|
|
} // End of namespace GUI
|