aboutsummaryrefslogtreecommitdiff
path: root/gui/ThemeParser.h
blob: 9e52f11b51029949b87a4ba3625b2ac30d7f0d2f (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* 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$
 *
 */

#ifndef THEME_PARSER_H
#define THEME_PARSER_H

#include "common/scummsys.h"
#include "graphics/surface.h"
#include "common/system.h"

#include "common/hashmap.h"
#include "common/hash-str.h"
#include "common/stack.h"
#include "common/xmlparser.h"

#include "graphics/VectorRenderer.h"
#include "gui/ThemeEngine.h"

namespace GUI {

using namespace Graphics;
using namespace Common;
class ThemeEngine;	

class ThemeParser : public XMLParser {
	typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const DrawStep &);

public:
	ThemeParser(GUI::ThemeEngine *parent);
	
	virtual ~ThemeParser() {
		delete _defaultStepGlobal;
		delete _defaultStepLocal;
		_palette.clear();
		_drawFunctions.clear();
	}
	
	bool getPaletteColor(const Common::String &name, int &r, int &g, int &b) {
		if (!_palette.contains(name))
			return false;
			
		r = _palette[name].r;
		g = _palette[name].g;
		b = _palette[name].b;
		
		return true;
	}

protected:
	ThemeEngine *_theme;
	
	CUSTOM_XML_PARSER(ThemeParser) {
		XML_KEY(render_info)
			XML_PROP(resolution, false)
			XML_KEY(palette)
				XML_KEY(color)
					XML_PROP(name, true)
					XML_PROP(rgb, true)
				KEY_END()
			KEY_END()

			XML_KEY(fonts)
				XML_KEY(font)
					XML_PROP(id, true)
					XML_PROP(file, true)
					XML_PROP(color, true)
					XML_PROP(resolution, false)
				KEY_END()
			KEY_END()
			
			XML_KEY(bitmaps)
				XML_KEY(bitmap)
					XML_PROP(filename, true)
					XML_PROP(resolution, false)
				KEY_END()
			KEY_END()
			
			XML_KEY(cursor)
				XML_PROP(file, true)
				XML_PROP(hotspot, true)
				XML_PROP(scale, true)
				XML_PROP(resolution, false)
			KEY_END()

			XML_KEY(defaults)
				XML_PROP(stroke, false)
				XML_PROP(shadow, false)
				XML_PROP(bevel, false)
				XML_PROP(factor, false)
				XML_PROP(fg_color, false)
				XML_PROP(bg_color, false)
				XML_PROP(gradient_start, false)
				XML_PROP(gradient_end, false)
				XML_PROP(bevel_color, false)
				XML_PROP(gradient_factor, false)
				XML_PROP(fill, false)
			KEY_END()

			XML_KEY(drawdata)
				XML_PROP(id, true)
				XML_PROP(cache, false)
				XML_PROP(resolution, false)

				XML_KEY(defaults)
					XML_PROP(stroke, false)
					XML_PROP(shadow, false)
					XML_PROP(bevel, false)
					XML_PROP(factor, false)
					XML_PROP(fg_color, false)
					XML_PROP(bg_color, false)
					XML_PROP(gradient_start, false)
					XML_PROP(gradient_end, false)
					XML_PROP(bevel_color, false)
					XML_PROP(gradient_factor, false)
					XML_PROP(fill, false)
				KEY_END()

				XML_KEY(drawstep)
					XML_PROP(func, true)
					XML_PROP(stroke, false)
					XML_PROP(shadow, false)
					XML_PROP(bevel, false)
					XML_PROP(factor, false)
					XML_PROP(fg_color, false)
					XML_PROP(bg_color, false)
					XML_PROP(gradient_start, false)
					XML_PROP(gradient_end, false)
					XML_PROP(gradient_factor, false)
					XML_PROP(bevel_color, false)
					XML_PROP(fill, false)
					XML_PROP(radius, false)
					XML_PROP(width, false)
					XML_PROP(height, false)
					XML_PROP(xpos, false)
					XML_PROP(ypos, false)
					XML_PROP(orientation, false)
					XML_PROP(file, false)
				KEY_END()

				XML_KEY(text)
					XML_PROP(font, true)
					XML_PROP(vertical_align, true)
					XML_PROP(horizontal_align, true)
				KEY_END()
			KEY_END()

		KEY_END() // render_info end

		XML_KEY(layout_info)
			XML_PROP(resolution, false)
			XML_KEY(globals)
				XML_PROP(resolution, false)
				XML_KEY(def)
					XML_PROP(var, true)
					XML_PROP(value, true)
					XML_PROP(resolution, false)
				KEY_END()
				
				XML_KEY(widget)
					XML_PROP(name, true)
					XML_PROP(size, false)
					XML_PROP(pos, false)
					XML_PROP(padding, false)
					XML_PROP(resolution, false)
				KEY_END()
			KEY_END()
			
			XML_KEY(dialog)
				XML_PROP(name, true)
				XML_PROP(overlays, true)
				XML_PROP(shading, false)
				XML_PROP(enabled, false)
				XML_PROP(resolution, false)
				XML_PROP(inset, false)
				XML_KEY(layout)
					XML_PROP(type, true)
					XML_PROP(center, false)
					XML_PROP(padding, false)
					XML_PROP(spacing, false)
					
					XML_KEY(import)
						XML_PROP(layout, true)
					KEY_END()
					
					XML_KEY(widget)
						XML_PROP(name, true)
						XML_PROP(width, false)
						XML_PROP(height, false)
						XML_PROP(type, false)
						XML_PROP(enabled, false)
					KEY_END()
					
					XML_KEY(space)
						XML_PROP(size, false)
					KEY_END()
					
					XML_KEY_RECURSIVE(layout)
				KEY_END()
			KEY_END()
		KEY_END() 
		
	} PARSER_END();
	
	/** Render info callbacks */
	bool parserCallback_render_info(ParserNode *node);
	bool parserCallback_defaults(ParserNode *node);
	bool parserCallback_font(ParserNode *node);
	bool parserCallback_fonts(ParserNode *node);
	bool parserCallback_text(ParserNode *node);
	bool parserCallback_palette(ParserNode *node);
	bool parserCallback_color(ParserNode *node);
	bool parserCallback_drawstep(ParserNode *node);
	bool parserCallback_drawdata(ParserNode *node);
	bool parserCallback_bitmaps(ParserNode *node) { return true; }
	bool parserCallback_bitmap(ParserNode *node);
	bool parserCallback_cursor(ParserNode *node);
	
	
	/** Layout info callbacks */
	bool parserCallback_layout_info(ParserNode *node);
	bool parserCallback_globals(ParserNode *node) { return true; }
	bool parserCallback_def(ParserNode *node);
	bool parserCallback_widget(ParserNode *node);
	bool parserCallback_dialog(ParserNode *node);
	bool parserCallback_layout(ParserNode *node);
	bool parserCallback_space(ParserNode *node);
	bool parserCallback_import(ParserNode *node);
	
	bool closedKeyCallback(ParserNode *node);
	
	bool resolutionCheck(const Common::String &resolution);
	
	void cleanup();

	Graphics::DrawStep *newDrawStep();
	Graphics::DrawStep *defaultDrawStep();
	bool parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific);
	bool parseCommonLayoutProps(ParserNode *node, const Common::String &var);

	Graphics::DrawStep *_defaultStepGlobal;
	Graphics::DrawStep *_defaultStepLocal;

	Common::HashMap<Common::String, DrawingFunctionCallback, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _drawFunctions;

	struct PaletteColor {
		uint8 r, g, b;
	};

	Common::HashMap<Common::String, PaletteColor, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _palette;
};

} // End of namespace GUI

#endif