ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

ThemeEval.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "gui/ThemeEval.h"
00024 
00025 #include "graphics/scaler.h"
00026 
00027 #include "common/system.h"
00028 #include "common/tokenizer.h"
00029 
00030 namespace GUI {
00031 
00032 ThemeEval::~ThemeEval() {
00033     reset();
00034 }
00035 
00036 void ThemeEval::buildBuiltinVars() {
00037     _builtin["kThumbnailWidth"] = kThumbnailWidth;
00038     _builtin["kThumbnailHeight"] = kThumbnailHeight1;
00039     _builtin["kThumbnailHeight2"] = kThumbnailHeight2;
00040 }
00041 
00042 void ThemeEval::reset() {
00043     _vars.clear();
00044     _curDialog.clear();
00045     _curLayout.clear();
00046 
00047     for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
00048         delete i->_value;
00049 
00050     _layouts.clear();
00051 }
00052 
00053 bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) {
00054     Common::StringTokenizer tokenizer(widget, ".");
00055 
00056     if (widget.hasPrefix("Dialog."))
00057         tokenizer.nextToken();
00058 
00059     Common::String dialogName = "Dialog." + tokenizer.nextToken();
00060     Common::String widgetName = tokenizer.nextToken();
00061 
00062     if (!_layouts.contains(dialogName))
00063         return false;
00064 
00065     return _layouts[dialogName]->getWidgetData(widgetName, x, y, w, h);
00066 }
00067 
00068 Graphics::TextAlign ThemeEval::getWidgetTextHAlign(const Common::String &widget) {
00069     Common::StringTokenizer tokenizer(widget, ".");
00070 
00071     if (widget.hasPrefix("Dialog."))
00072         tokenizer.nextToken();
00073 
00074     Common::String dialogName = "Dialog." + tokenizer.nextToken();
00075     Common::String widgetName = tokenizer.nextToken();
00076 
00077     if (!_layouts.contains(dialogName))
00078         return Graphics::kTextAlignInvalid;
00079 
00080     return _layouts[dialogName]->getWidgetTextHAlign(widgetName);
00081 }
00082 
00083 void ThemeEval::addWidget(const Common::String &name, int w, int h, const Common::String &type, bool enabled, Graphics::TextAlign align) {
00084     int typeW = -1;
00085     int typeH = -1;
00086     Graphics::TextAlign typeAlign = Graphics::kTextAlignInvalid;
00087 
00088     if (!type.empty()) {
00089         typeW = getVar("Globals." + type + ".Width", -1);
00090         typeH = getVar("Globals." + type + ".Height", -1);
00091         typeAlign = (Graphics::TextAlign)getVar("Globals." + type + ".Align", Graphics::kTextAlignInvalid);
00092     }
00093 
00094     ThemeLayoutWidget *widget;
00095     if (type == "TabWidget")
00096         widget = new ThemeLayoutTabWidget(_curLayout.top(), name,
00097                                     typeW == -1 ? w : typeW,
00098                                     typeH == -1 ? h : typeH,
00099                                     typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign,
00100                                     getVar("Globals.TabWidget.Tab.Height", 0));
00101     else
00102         widget = new ThemeLayoutWidget(_curLayout.top(), name,
00103                                     typeW == -1 ? w : typeW,
00104                                     typeH == -1 ? h : typeH,
00105                                     typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign);
00106 
00107     _curLayout.top()->addChild(widget);
00108     setVar(_curDialog + "." + name + ".Enabled", enabled ? 1 : 0);
00109 }
00110 
00111 void ThemeEval::addDialog(const Common::String &name, const Common::String &overlays, bool enabled, int inset) {
00112     int16 x, y;
00113     uint16 w, h;
00114 
00115     ThemeLayout *layout = 0;
00116 
00117     if (overlays == "screen") {
00118         layout = new ThemeLayoutMain(inset, inset, g_system->getOverlayWidth() - 2 * inset, g_system->getOverlayHeight() - 2 * inset);
00119     } else if (overlays == "screen_center") {
00120         layout = new ThemeLayoutMain(-1, -1, -1, -1);
00121     } else if (getWidgetData(overlays, x, y, w, h)) {
00122         layout = new ThemeLayoutMain(x + inset, y + inset, w - 2 * inset, h - 2 * inset);
00123     }
00124 
00125     if (!layout)
00126         error("Error when loading dialog position for '%s'", overlays.c_str());
00127 
00128     if (_layouts.contains(name))
00129         delete _layouts[name];
00130 
00131     _layouts[name] = layout;
00132 
00133     layout->setPadding(
00134         getVar("Globals.Padding.Left", 0),
00135         getVar("Globals.Padding.Right", 0),
00136         getVar("Globals.Padding.Top", 0),
00137         getVar("Globals.Padding.Bottom", 0)
00138         );
00139 
00140     _curLayout.push(layout);
00141     _curDialog = name;
00142     setVar(name + ".Enabled", enabled ? 1 : 0);
00143 }
00144 
00145 void ThemeEval::addLayout(ThemeLayout::LayoutType type, int spacing, bool center) {
00146     ThemeLayout *layout = 0;
00147 
00148     if (spacing == -1)
00149         spacing = getVar("Globals.Layout.Spacing", 4);
00150 
00151     layout = new ThemeLayoutStacked(_curLayout.top(), type, spacing, center);
00152 
00153     assert(layout);
00154 
00155     layout->setPadding(
00156         getVar("Globals.Padding.Left", 0),
00157         getVar("Globals.Padding.Right", 0),
00158         getVar("Globals.Padding.Top", 0),
00159         getVar("Globals.Padding.Bottom", 0)
00160         );
00161 
00162     _curLayout.top()->addChild(layout);
00163     _curLayout.push(layout);
00164 }
00165 
00166 void ThemeEval::addSpace(int size) {
00167     ThemeLayout *space = new ThemeLayoutSpacing(_curLayout.top(), size);
00168     _curLayout.top()->addChild(space);
00169 }
00170 
00171 bool ThemeEval::addImportedLayout(const Common::String &name) {
00172     if (!_layouts.contains(name))
00173         return false;
00174 
00175     _curLayout.top()->importLayout(_layouts[name]);
00176     return true;
00177 }
00178 
00179 } // End of namespace GUI


Generated on Sat Feb 16 2019 05:01:09 for ResidualVM by doxygen 1.7.1
curved edge   curved edge