ScummVM API documentation
ThemeEval.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GUI_THEME_EVAL_H
23 #define GUI_THEME_EVAL_H
24 
25 #include "common/scummsys.h"
26 #include "common/hashmap.h"
27 #include "common/hash-str.h"
28 #include "common/stack.h"
29 #include "common/str.h"
30 #include "common/textconsole.h"
31 #include "graphics/font.h"
32 
33 #include "gui/ThemeLayout.h"
34 
35 namespace GUI {
36 
37 class ThemeEval {
38 
41 
42 public:
43  ThemeEval() : _scaleFactor(1.0f) {
44  buildBuiltinVars();
45  }
46 
47  ~ThemeEval();
48 
49  void buildBuiltinVars();
50 
51  int getVar(const Common::String &s) {
52  if (_vars.contains(s))
53  return _vars[s];
54 
55  if (_builtin.contains(s))
56  return _builtin[s];
57 
58  error("CRITICAL: Missing variable: '%s'", s.c_str());
59  return -13375; //EVAL_UNDEF_VAR
60  }
61 
62  int getVar(const Common::String &s, int def) {
63  if (_vars.contains(s))
64  return _vars[s];
65 
66  if (_builtin.contains(s))
67  return _builtin[s];
68 
69  return def;
70  }
71 
72  void setScaleFactor(float s) { _scaleFactor = s; }
73 
74  void setVar(const Common::String &name, int val) { _vars[name] = val; }
75 
76  bool hasVar(const Common::String &name) { return _vars.contains(name) || _builtin.contains(name); }
77 
78  ThemeEval &addDialog(const Common::String &name, const Common::String &overlays, int16 maxWidth = -1, int16 maxHeight = -1, int inset = 0);
79  ThemeEval &addLayout(ThemeLayout::LayoutType type, int spacing = -1, ThemeLayout::ItemAlign itemAlign = ThemeLayout::kItemAlignStart);
80  ThemeEval &addWidget(const Common::String &name, const Common::String &type, int w = -1, int h = -1, Graphics::TextAlign align = Graphics::kTextAlignStart, bool useRTL = true);
81  ThemeEval &addImportedLayout(const Common::String &name);
82  ThemeEval &addSpace(int size = -1);
83 
84  ThemeEval &addPadding(int16 l, int16 r, int16 t, int16 b);
85 
86  ThemeEval &closeLayout() { _curLayout.pop(); return *this; }
87  ThemeEval &closeDialog() { _curLayout.pop(); _curDialog.clear(); return *this; }
88 
89  bool hasDialog(const Common::String &name);
90 
91  void reflowDialogLayout(const Common::String &name, Widget *widgetChain);
92  bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, int16 &w, int16 &h);
93  bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, int16 &w, int16 &h, bool &useRTL);
94 
95  Graphics::TextAlign getWidgetTextHAlign(const Common::String &widget);
96 
97 #ifdef LAYOUT_DEBUG_DIALOG
98  void debugDraw(Graphics::ManagedSurface *screen, const Graphics::Font *font) {
99  if (_layouts.contains(LAYOUT_DEBUG_DIALOG)) {
100  _layouts[LAYOUT_DEBUG_DIALOG]->debugDraw(screen, font);
101  } else {
102  Common::String list;
103 
104  for (auto l = _layouts.begin(); l != _layouts.end(); ++l)
105  list += " " + l->_key;
106 
107  warning("debugDraw: Unknown layout %s\nList:%s", LAYOUT_DEBUG_DIALOG, list.c_str());
108  }
109  }
110 #endif
111 
112  void reset();
113 
114 private:
115  VariablesMap _vars;
116  VariablesMap _builtin;
117 
118  LayoutsMap _layouts;
119  Common::Stack<ThemeLayout *> _curLayout;
120  Common::String _curDialog;
121 
122  float _scaleFactor;
123 };
124 
125 } // End of namespace GUI
126 
127 #endif
Definition: managed_surface.h:51
Definition: str.h:59
Definition: font.h:83
TextAlign
Definition: font.h:48
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: ThemeEval.h:37
Definition: system.h:46
Items are aligned to the left for vertical layouts or to the top for horizontal layouts.
Definition: ThemeLayout.h:59
Align the text to start of line (virtual).
Definition: font.h:50
bool contains(const Key &key) const
Definition: hashmap.h:594
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: widget.h:101
Definition: stack.h:102
ItemAlign
Cross-direction alignment of layout children.
Definition: ThemeLayout.h:58