1 /* ScummVM - Graphic Adventure Engine
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.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "gui/ThemeEval.h"
27 #include "gui/widget.h"
29 #include "graphics/scaler.h"
33 ThemeEval::~ThemeEval() {
37 void ThemeEval::buildBuiltinVars() {
38 _builtin
["kThumbnailWidth"] = kThumbnailWidth
;
39 _builtin
["kThumbnailHeight"] = kThumbnailHeight1
;
40 _builtin
["kThumbnailHeight2"] = kThumbnailHeight2
;
43 void ThemeEval::reset() {
48 for (LayoutsMap::iterator i
= _layouts
.begin(); i
!= _layouts
.end(); ++i
)
54 bool ThemeEval::getWidgetData(const Common::String
&widget
, int16
&x
, int16
&y
, uint16
&w
, uint16
&h
) {
55 Common::StringTokenizer
tokenizer(widget
, ".");
57 if (widget
.hasPrefix("Dialog."))
58 tokenizer
.nextToken();
60 Common::String dialogName
= "Dialog." + tokenizer
.nextToken();
61 Common::String widgetName
= tokenizer
.nextToken();
63 if (!_layouts
.contains(dialogName
))
66 return _layouts
[dialogName
]->getWidgetData(widgetName
, x
, y
, w
, h
);
69 Graphics::TextAlign
ThemeEval::getWidgetTextHAlign(const Common::String
&widget
) {
70 Common::StringTokenizer
tokenizer(widget
, ".");
72 if (widget
.hasPrefix("Dialog."))
73 tokenizer
.nextToken();
75 Common::String dialogName
= "Dialog." + tokenizer
.nextToken();
76 Common::String widgetName
= tokenizer
.nextToken();
78 if (!_layouts
.contains(dialogName
))
79 return Graphics::kTextAlignInvalid
;
81 return _layouts
[dialogName
]->getWidgetTextHAlign(widgetName
);
84 void ThemeEval::addWidget(const Common::String
&name
, int w
, int h
, const Common::String
&type
, bool enabled
, Graphics::TextAlign align
) {
87 Graphics::TextAlign typeAlign
= Graphics::kTextAlignInvalid
;
90 typeW
= getVar("Globals." + type
+ ".Width", -1);
91 typeH
= getVar("Globals." + type
+ ".Height", -1);
92 typeAlign
= (Graphics::TextAlign
)getVar("Globals." + type
+ ".Align", Graphics::kTextAlignInvalid
);
95 ThemeLayoutWidget
*widget
= new ThemeLayoutWidget(_curLayout
.top(), name
,
96 typeW
== -1 ? w
: typeW
,
97 typeH
== -1 ? h
: typeH
,
98 typeAlign
== Graphics::kTextAlignInvalid
? align
: typeAlign
);
100 _curLayout
.top()->addChild(widget
);
101 setVar(_curDialog
+ "." + name
+ ".Enabled", enabled
? 1 : 0);
104 void ThemeEval::addDialog(const Common::String
&name
, const Common::String
&overlays
, bool enabled
, int inset
) {
108 ThemeLayout
*layout
= 0;
110 if (overlays
== "screen") {
111 layout
= new ThemeLayoutMain(inset
, inset
, g_system
->getOverlayWidth() - 2 * inset
, g_system
->getOverlayHeight() - 2 * inset
);
112 } else if (overlays
== "screen_center") {
113 layout
= new ThemeLayoutMain(-1, -1, -1, -1);
114 } else if (getWidgetData(overlays
, x
, y
, w
, h
)) {
115 layout
= new ThemeLayoutMain(x
+ inset
, y
+ inset
, w
- 2 * inset
, h
- 2 * inset
);
119 error("Error when loading dialog position for '%s'", overlays
.c_str());
121 if (_layouts
.contains(name
))
122 delete _layouts
[name
];
124 _layouts
[name
] = layout
;
127 getVar("Globals.Padding.Left", 0),
128 getVar("Globals.Padding.Right", 0),
129 getVar("Globals.Padding.Top", 0),
130 getVar("Globals.Padding.Bottom", 0)
133 _curLayout
.push(layout
);
135 setVar(name
+ ".Enabled", enabled
? 1 : 0);
138 void ThemeEval::addLayout(ThemeLayout::LayoutType type
, int spacing
, bool center
) {
139 ThemeLayout
*layout
= 0;
142 spacing
= getVar("Globals.Layout.Spacing", 4);
144 layout
= new ThemeLayoutStacked(_curLayout
.top(), type
, spacing
, center
);
149 getVar("Globals.Padding.Left", 0),
150 getVar("Globals.Padding.Right", 0),
151 getVar("Globals.Padding.Top", 0),
152 getVar("Globals.Padding.Bottom", 0)
155 _curLayout
.top()->addChild(layout
);
156 _curLayout
.push(layout
);
159 void ThemeEval::addSpace(int size
) {
160 ThemeLayout
*space
= new ThemeLayoutSpacing(_curLayout
.top(), size
);
161 _curLayout
.top()->addChild(space
);
164 bool ThemeEval::addImportedLayout(const Common::String
&name
) {
165 if (!_layouts
.contains(name
))
168 _curLayout
.top()->importLayout(_layouts
[name
]);
172 } // End of namespace GUI