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, int16 &w, int16 &h) {
00054     bool useRTL;
00055 
00056     return getWidgetData(widget, x, y, w, h, useRTL);
00057 }
00058 
00059 bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, int16 &w, int16 &h, bool &useRTL) {
00060     Common::StringTokenizer tokenizer(widget, ".");
00061 
00062     if (widget.hasPrefix("Dialog."))
00063         tokenizer.nextToken();
00064 
00065     Common::String dialogName = "Dialog." + tokenizer.nextToken();
00066     Common::String widgetName = tokenizer.nextToken();
00067 
00068     if (!_layouts.contains(dialogName))
00069         return false;
00070 
00071     return _layouts[dialogName]->getWidgetData(widgetName, x, y, w, h, useRTL);
00072 }
00073 
00074 Graphics::TextAlign ThemeEval::getWidgetTextHAlign(const Common::String &widget) {
00075     Common::StringTokenizer tokenizer(widget, ".");
00076 
00077     if (widget.hasPrefix("Dialog."))
00078         tokenizer.nextToken();
00079 
00080     Common::String dialogName = "Dialog." + tokenizer.nextToken();
00081     Common::String widgetName = tokenizer.nextToken();
00082 
00083     if (!_layouts.contains(dialogName))
00084         return Graphics::kTextAlignInvalid;
00085 
00086     return _layouts[dialogName]->getWidgetTextHAlign(widgetName);
00087 }
00088 
00089 ThemeEval &ThemeEval::addWidget(const Common::String &name, const Common::String &type, int w, int h, Graphics::TextAlign align, bool useRTL) {
00090     int typeW = -1;
00091     int typeH = -1;
00092     Graphics::TextAlign typeAlign = Graphics::kTextAlignInvalid;
00093 
00094     if (!type.empty()) {
00095         typeW = getVar("Globals." + type + ".Width", -1);
00096         typeH = getVar("Globals." + type + ".Height", -1);
00097         typeAlign = (Graphics::TextAlign)getVar("Globals." + type + ".Align", Graphics::kTextAlignInvalid);
00098     }
00099 
00100     ThemeLayoutWidget *widget;
00101     if (type == "TabWidget")
00102         widget = new ThemeLayoutTabWidget(_curLayout.top(), name,
00103                                     typeW == -1 ? w : typeW,
00104                                     typeH == -1 ? h : typeH,
00105                                     typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign,
00106                                     getVar("Globals.TabWidget.Tab.Height", 0));
00107     else
00108         widget = new ThemeLayoutWidget(_curLayout.top(), name,
00109                                     typeW == -1 ? w : typeW,
00110                                     typeH == -1 ? h : typeH,
00111                                     typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign,
00112                                     useRTL);
00113 
00114     _curLayout.top()->addChild(widget);
00115 
00116     return *this;
00117 }
00118 
00119 ThemeEval &ThemeEval::addDialog(const Common::String &name, const Common::String &overlays, int16 width, int16 height, int inset) {
00120     Common::String var = "Dialog." + name;
00121 
00122     ThemeLayout *layout = new ThemeLayoutMain(name, overlays, width, height, inset);
00123 
00124     if (_layouts.contains(var))
00125         delete _layouts[var];
00126 
00127     _layouts[var] = layout;
00128 
00129     layout->setPadding(
00130         getVar("Globals.Padding.Left", 0),
00131         getVar("Globals.Padding.Right", 0),
00132         getVar("Globals.Padding.Top", 0),
00133         getVar("Globals.Padding.Bottom", 0)
00134         );
00135 
00136     _curLayout.push(layout);
00137     _curDialog = name;
00138 
00139     return *this;
00140 }
00141 
00142 ThemeEval &ThemeEval::addLayout(ThemeLayout::LayoutType type, int spacing, ThemeLayout::ItemAlign itemAlign) {
00143     ThemeLayout *layout = nullptr;
00144 
00145     if (spacing == -1)
00146         spacing = getVar("Globals.Layout.Spacing", 4);
00147 
00148     layout = new ThemeLayoutStacked(_curLayout.top(), type, spacing, itemAlign);
00149 
00150     assert(layout);
00151 
00152     layout->setPadding(
00153         getVar("Globals.Padding.Left", 0),
00154         getVar("Globals.Padding.Right", 0),
00155         getVar("Globals.Padding.Top", 0),
00156         getVar("Globals.Padding.Bottom", 0)
00157         );
00158 
00159     _curLayout.top()->addChild(layout);
00160     _curLayout.push(layout);
00161 
00162     return *this;
00163 }
00164 
00165 ThemeEval &ThemeEval::addSpace(int size) {
00166     ThemeLayout *space = new ThemeLayoutSpacing(_curLayout.top(), size);
00167     _curLayout.top()->addChild(space);
00168 
00169     return *this;
00170 }
00171 
00172 bool ThemeEval::hasDialog(const Common::String &name) {
00173     Common::StringTokenizer tokenizer(name, ".");
00174 
00175     if (name.hasPrefix("Dialog."))
00176         tokenizer.nextToken();
00177 
00178     Common::String dialogName = "Dialog." + tokenizer.nextToken();
00179     return _layouts.contains(dialogName);
00180 }
00181 
00182 void ThemeEval::reflowDialogLayout(const Common::String &name, Widget *widgetChain) {
00183     if (!_layouts.contains("Dialog." + name)) {
00184         warning("No layout found for dialog '%s'", name.c_str());
00185         return;
00186     }
00187 
00188     _layouts["Dialog." + name]->reflowLayout(widgetChain);
00189 }
00190 
00191 ThemeEval &ThemeEval::addImportedLayout(const Common::String &name) {
00192     ThemeLayout *importedLayout = _layouts[name];
00193     assert(importedLayout);
00194 
00195     _curLayout.top()->importLayout(importedLayout);
00196 
00197     return *this;
00198 }
00199 
00200 } // End of namespace GUI


Generated on Sat Aug 8 2020 05:01:26 for ResidualVM by doxygen 1.7.1
curved edge   curved edge