aboutsummaryrefslogtreecommitdiff
path: root/gui/ThemeEval.cpp
blob: a448048d605429324ecb0974579f1ba9ec898ea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#include "gui/ThemeEval.h"
#include "gui/widget.h"

#include "graphics/scaler.h"

namespace GUI {

ThemeEval::~ThemeEval() {
	reset();
}

void ThemeEval::buildBuiltinVars() {
	_builtin["kThumbnailWidth"] = kThumbnailWidth;
	_builtin["kThumbnailHeight"] = kThumbnailHeight1;
	_builtin["kThumbnailHeight2"] = kThumbnailHeight2;
	
	_builtin["kNormalWidgetSize"] = GUI::kNormalWidgetSize;
	_builtin["kBigWidgetSize"] = GUI::kBigWidgetSize;
}

void ThemeEval::reset() {
	_vars.clear();
	_curDialog.clear();
	_curLayout.clear();
	
	for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
		delete i->_value;
		
	_layouts.clear();
}

bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) {
	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 false;

	if (widgetName.empty())
		return _layouts[dialogName]->getDialogData(x, y, w, h);
		
	return _layouts[dialogName]->getWidgetData(widgetName, x, y, w, h);
}


void ThemeEval::addWidget(const Common::String &name, int w, int h, const Common::String &type, bool enabled) {	
	int typeW = -1;
	int typeH = -1;
	
	if (!type.empty()) {
		typeW = getVar("Globals." + type + ".Width", -1);
		typeH = getVar("Globals." + type + ".Height", -1);
	}
	
	ThemeLayoutWidget *widget = new ThemeLayoutWidget(_curLayout.top(), name, 
								typeW == -1 ? w : typeW, 
								typeH == -1 ? h : typeH);
	
	_curLayout.top()->addChild(widget);
	setVar(_curDialog + "." + name + ".Enabled", enabled ? 1 : 0);
}

void ThemeEval::addDialog(const Common::String &name, const Common::String &overlays, bool enabled, int inset) {
	int16 x, y;
	uint16 w, h;
	
	ThemeLayout *layout = 0;
	
	if (overlays == "screen") {
		layout = new ThemeLayoutMain(inset, inset, g_system->getOverlayWidth() - 2 * inset, g_system->getOverlayHeight() - 2 * inset);
	} else if (overlays == "screen_center") {
		layout = new ThemeLayoutMain(-1, -1, -1, -1);
	} else if (getWidgetData(overlays, x, y, w, h)) {
		layout = new ThemeLayoutMain(x + inset, y + inset, w - 2 * inset, h - 2 * inset);
	}
	
	if (!layout)
		error("Error when loading dialog position for '%s'", overlays.c_str());
		
	if (_layouts.contains(name))
		delete _layouts[name];
	
	_layouts[name] = layout;

	layout->setPadding(
		getVar("Globals.Padding.Left", 0),
		getVar("Globals.Padding.Right", 0),
		getVar("Globals.Padding.Top", 0),
		getVar("Globals.Padding.Bottom", 0)
		);
	
	_curLayout.push(layout);
	_curDialog = name;
	setVar(name + ".Enabled", enabled ? 1 : 0);
}

void ThemeEval::addLayout(ThemeLayout::LayoutType type, int spacing, bool center) {
	ThemeLayout *layout = 0;
	
	if (spacing == -1)
		spacing = getVar("Globals.Layout.Spacing", 4);
	
	if (type == ThemeLayout::kLayoutVertical)
		layout = new ThemeLayoutVertical(_curLayout.top(), spacing, center);
	else if (type == ThemeLayout::kLayoutHorizontal)
		layout = new ThemeLayoutHorizontal(_curLayout.top(), spacing, center);

	assert(layout);
	
	layout->setPadding(
		getVar("Globals.Padding.Left", 0),
		getVar("Globals.Padding.Right", 0),
		getVar("Globals.Padding.Top", 0),
		getVar("Globals.Padding.Bottom", 0)
		);
	
	_curLayout.top()->addChild(layout);
	_curLayout.push(layout);
}

void ThemeEval::addSpace(int size) {
	ThemeLayout *space = new ThemeLayoutSpacing(_curLayout.top(), size);
	_curLayout.top()->addChild(space);
}

bool ThemeEval::addImportedLayout(const Common::String &name) {
	if (!_layouts.contains(name))
		return false;
		
	_curLayout.top()->importLayout(_layouts[name]);
	return true;
}

} // End of namespace GUI