aboutsummaryrefslogtreecommitdiff
path: root/engines/m4/gui.h
blob: 731824518d94f7a503c6ca8e43f82fd665eb07e8 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/* 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 M4_GUI_H
#define M4_GUI_H

#include "common/list.h"
#include "common/rect.h"

#include "m4/viewmgr.h"
#include "m4/events.h"
#include "m4/globals.h"
#include "m4/graphics.h"
#include "m4/saveload.h"
#include "m4/sprite.h"
#include "m4/assets.h"

namespace M4 {

class GUIObject;
class MenuObject;
class GUIObjectButton;
class SpriteAsset;
class View;

enum MenuType {GAME_MENU, OPTIONS_MENU, SAVE_MENU, LOAD_MENU, MAIN_MENU};

enum {
	BTNID_QUIT = 1,
	BTNID_OPTIONS = 2,
	BTNID_RESUME = 3,
	BTNID_SAVE = 4,
	BTNID_LOAD = 5,
	BTNID_MAIN = 6,

	OPTIONID_DONE = 1,
	OPTIONID_CANCEL = 2,
	OPTIONID_HSLIDER_DIGI = 3,
	OPTIONID_HSLIDER_MIDI = 4,

	SAVELOADID_SAVE = 1,
	SAVELOADID_CANCELSAVE = 2,
	SAVELOADID_LOAD = 3,
	SAVELOADID_CANCELLOAD = 4,

	SLTAG_SAVELOAD = 100,
	SLTAG_SAVELOAD_LABEL = 101,
	SLTAG_CANCEL = 102,
	SLTAG_VSLIDER = 103,
	SLTAG_THUMBNAIL = 104,

	SLTAG_SLOTS_START = 1001,
	SLTAG_TEXTFIELD = 2000
};

enum ObjectType {
	OBJTYPE_BUTTON,

	OBJTYPE_SLIDER,
	OBJTYPE_OM_SWITCH_ON,
	OBJTYPE_OM_SWITCH_OFF,
	OBJTYPE_OM_DONE,
	OBJTYPE_OM_CANCEL,

	OBJTYPE_SL_SAVE,
	OBJTYPE_SL_LOAD,
	OBJTYPE_SL_CANCEL,
	OBJTYPE_SL_TEXT
};

enum GameMenuSpriteType {
	GM_DIALOG_BOX,

	GM_BUTTON_GREYED,
	GM_BUTTON_NORMAL,
	GM_BUTTON_MOUSEOVER,
	GM_BUTTON_PRESSED
};

enum OptionMenuSpriteType {
	OM_DIALOG_BOX,

	OM_SLIDER_BTN_NORMAL,
	OM_SLIDER_BTN_MOUSEOVER,
	OM_SLIDER_BTN_PRESSED,
	OM_SLIDER_BAR,
	OM_DONE_BTN_GREYED,
	OM_DONE_BTN_NORMAL,
	OM_DONE_BTN_MOUSEOVER,
	OM_DONE_BTN_PRESSED,
	OM_CANCEL_BTN_NORMAL,
	OM_CANCEL_BTN_MOUSEOVER,
	OM_CANCEL_BTN_PRESSED
};


enum SaveLoadSpriteType {
	SL_DIALOG_BOX,
	SL_EMPTY_THUMBNAIL,

	SL_SAVE_BTN_GREYED,
	SL_SAVE_BTN_NORMAL,
	SL_SAVE_BTN_MOUSEOVER,
	SL_SAVE_BTN_PRESSED,

	SL_LOAD_BTN_GREYED,
	SL_LOAD_BTN_NORMAL,
	SL_LOAD_BTN_MOUSEOVER,
	SL_LOAD_BTN_PRESSED,

	SL_CANCEL_BTN_NORMAL,
	SL_CANCEL_BTN_MOUSEOVER,
	SL_CANCEL_BTN_PRESSED,

	SL_UP_BTN_GREYED,
	SL_UP_BTN_NORMAL,
	SL_UP_BTN_MOUSEOVER,
	SL_UP_BTN_PRESSED,

	SL_DOWN_BTN_GREYED,
	SL_DOWN_BTN_NORMAL,
	SL_DOWN_BTN_MOUSEOVER,
	SL_DOWN_BTN_PRESSED,

	SL_SAVE_LABEL,
	SL_LOAD_LABEL,

	SL_SLIDER_BTN_NORMAL,
	SL_SLIDER_BTN_MOUSEOVER,
	SL_SLIDER_BTN_PRESSED,

	SL_LINE_NORMAL,
	SL_LINE_MOUSEOVER,
	SL_LINE_PRESSED,

	SL_SCROLLBAR
};

enum TextColors {
	TEXT_COLOR_NORMAL = 1,
	TEXT_COLOR_GREYED = 1,
	TEXT_COLOR_MOUSEOVER = 2,
	TEXT_COLOR_PRESSED = 2,

	TEXT_COLOR_GREYED_HILIGHT    = 236,
	TEXT_COLOR_GREYED_FOREGROUND = 131,
	TEXT_COLOR_GREYED_SHADOW     = 186,

	TEXT_COLOR_NORMAL_HILIGHT    = 129,
	TEXT_COLOR_NORMAL_FOREGROUND = 130,
	TEXT_COLOR_NORMAL_SHADOW     = 236,

	TEXT_COLOR_MOUSEOVER_HILIGHT    = 129,
	TEXT_COLOR_MOUSEOVER_FOREGROUND = 130,
	TEXT_COLOR_MOUSEOVER_SHADOW     = 236,

	TEXT_COLOR_PRESSED_HILIGHT    = 236,
	TEXT_COLOR_PRESSED_FOREGROUND = 130,
	TEXT_COLOR_PRESSED_SHADOW     = 129
};

#define MENU_SS_FIELD_NORMAL 5
#define MENU_SS_FIELD_MOUSEOVER 6

#define MENU_SS_H_SLIDER_NORMAL 5
#define MENU_SS_H_SLIDER_MOUSE_OVER 6
#define MENU_SS_H_SLIDER_PRESSED 7

#define MENU_SS_SWITCH_ON_NORMAL 8
#define MENU_SS_SWITCH_ON_MOUSEOVER 9
#define MENU_SS_SWITCH_ON_PRESSED 13

#define MENU_SS_SWITCH_OFF_PRESSED 10
#define MENU_SS_SWITCH_OFF_NORMAL 11
#define MENU_SS_SWITCH_OFF_MOUSEOVER 12

#define MENU_GUI "gui menu"
#define MENU_GAME "gamemenu"
#define MENU_OPTIONS "opmenu"
#define MENU_ERROR "errmenu"
#define MENU_SAVELOAD "slmenu"
#define MENU_BURGMAIN "903menu"
#define MENU_BURGDEMOMAIN "901menu"

#define SL_NUM_VISIBLE_SLOTS 8
#define SL_THUMBNAIL_WIDTH  215
#define SL_THUMBNAIL_HEIGHT 162

enum MenuObjectState {OS_GREYED = 0, OS_NORMAL = 1, OS_MOUSEOVER = 2, OS_PRESSED = 3};

class DialogView: public View {
public:
	DialogView(M4Engine *Vm, const Common::Rect &viewBounds, bool transparent = false):
		View(Vm, viewBounds, transparent) {};
	DialogView(M4Engine *Vm, int x = 0, int y = 0, bool transparent = false):
		View(Vm, x, y, transparent) {};

	M4Engine *vm() { return _vm; }
	virtual SpriteAsset *sprites() = 0;
	virtual MenuType getMenuType() = 0;
	virtual MenuObject *getItem(int objectId) { return NULL; }
	virtual void refresh(const Common::Rect &areaRect) {}
	virtual void close();

	int _topSaveSlotIndex, _selectedSlot;
	int _highlightedSlot;
	bool _deleteSaveDesc;
	M4Surface *_savegameThumbnail;
};

class GUIObject {
protected:
	View *_parent;
	Common::Rect _bounds;
	M4Surface *_background;
public:
	GUIObject(View *owner, const Common::Rect &bounds);
	virtual ~GUIObject() {}

	bool isInside(int x, int y) { return _bounds.contains(x, y); }
	Common::Rect getBounds() const { return _bounds; }

	virtual void onRefresh() {}
};

class MenuObject: public GUIObject {
public:
	typedef void (*Callback)(DialogView *view, MenuObject *item);
protected:
	MenuObject::Callback _callback;
	ObjectType _objectType;
	MenuObjectState	_objectState;
	bool _transparent;
	int _objectId;
public:
	MenuObject(DialogView *owner, int objectId, int xs, int ys, int width, int height,
			   bool greyed = false, bool transparent = false);
	~MenuObject();

	DialogView *parent() { return (DialogView *)_parent; }
	MenuObjectState getState() { return _objectState; }
	virtual void setState(MenuObjectState state) {
		_objectState = state;
		onRefresh();
	}
	int getObjectId() { return _objectId; }

	void onExecute();
	virtual bool onEvent(M4EventType event, int32 param, int x, int y, MenuObject *&currentItem) { return false; }
};

class MenuButton: public MenuObject {
public:
	MenuButton(DialogView *owner, int buttonId, int xs, int ys, int width, int height,
		Callback callbackFn = NULL, bool greyed = false, bool transparent = false,
		ObjectType buttonType = OBJTYPE_BUTTON);

	void onRefresh();
	bool onEvent(M4EventType event, int32 param, int x, int y, MenuObject *&currentItem);
	bool getToggled() { return _objectType == OBJTYPE_OM_SWITCH_ON; }
};

enum MenuHorizSliderState {HSLIDER_THUMB_NORMAL = 0, HSLIDER_THUMB_MOUSEOVER = 1, HSLIDER_THUMB_PRESSED = 2};
#define SLIDER_BAR_COLOR 129

class MenuHorizSlider: public MenuObject {
protected:
	MenuHorizSliderState _sliderState;
	Common::Point _thumbSize;
	int _maxThumbX;
	int _percent;
	int _thumbX;
public:
	MenuHorizSlider(DialogView *owner, int sliderId, int xs, int ys, int width, int height,
		int initialPercentage, Callback callbackFn = NULL, bool transparent = false);

	void onRefresh();
	bool onEvent(M4EventType event, int32 param, int x, int y, MenuObject *&currentItem);
	int percent() { return _percent; }
};

enum MenuVertSliderState {
	VSLIDER_NONE	  = 0x0000,
	VSLIDER_UP        = 0x0010,
	VSLIDER_PAGE_UP   = 0x0020,
	VSLIDER_THUMBNAIL = 0x0030,
	VSLIDER_PAGE_DOWN = 0x0040,
	VSLIDER_DOWN      = 0x0050
};

class MenuVertSlider: public MenuObject {
protected:
	MenuVertSliderState _sliderState;
	Common::Point _thumbSize;
	int _percent;
	int _thumbY;
	int _minThumbY;
	int _maxThumbY;

	MenuVertSliderState getSliderArea(int y);
	void updateThumbnails() {}
public:
	MenuVertSlider(DialogView *owner, int sliderId, int xs, int ys, int width, int height,
		int initialPercentage, Callback callbackFn = NULL, bool transparent = false);

	void onRefresh();
	bool onEvent(M4EventType event, int32 param, int x, int y, MenuObject *&currentItem);
	MenuVertSliderState sliderState() { return _sliderState; }
	int percent() { return _percent; }
	void setPercentage(int value);
};

class MenuMessage: public MenuObject {
public:
	MenuMessage(DialogView *owner, int objectId, int x, int y, int w, int h, bool transparent = false);

	void onRefresh();
};

class MenuImage: public MenuObject {
private:
	M4Surface *_sprite;
public:
	MenuImage(DialogView *owner, int objectId, int xs, int ys, int width, int height,
		M4Surface *image, bool transparent = false);

	void onRefresh();
	const M4Surface *sprite() { return _sprite; }
	void setSprite(M4Surface *v) {
		_sprite = v;
		onRefresh();
	}
};

class MenuSaveLoadText: public MenuButton {
private:
	bool _loadFlag;
	const char *_displayText;
	int _displayValue;
	int _index;
	bool _visible;
public:
	MenuSaveLoadText(DialogView *owner, int textId, int xs, int ys, int width, int height,
		Callback callbackFn = NULL, bool greyed = false, bool transparent = false,
		bool loadFlag = false, const char *displayText = NULL, int displayValue = 0);

	void onRefresh();
	bool onEvent(M4EventType event, int32 param, int x, int y, MenuObject *&currentItem);
	void setDisplay(int value, const char *text) { _displayValue = value; _displayText = text; }
	int getIndex() { return _index; }
	const char *getText() { return _displayText; }
	bool getVisible() const { return _visible; }
	void setVisible(bool value);
};

class MenuTextField: public MenuObject {
private:
	int _displayValue;
	char _displayText[MAX_SAVEGAME_NAME];
	int _pixelWidth;
	char *_promptEnd;
	char *_cursor;
public:
	MenuTextField(DialogView *owner, int fieldId, int xs, int ys, int width, int height,
		bool greyed, Callback callbackFn = NULL, const char *displayText = NULL,
		int displayValue = 0, bool transparent = true);

	void onRefresh();
	bool onEvent(M4EventType event, int32 param, int x, int y, MenuObject *&currentItem);

	const char *getText() { return _displayText; }
	int getDisplayValue() { return _displayValue; }

};

class GUIRect: public GUIObject {
private:
	int _tag;
public:
	GUIRect(View *owner, const Common::Rect &bounds, int tag): GUIObject(owner, bounds) { _tag = tag; };

	virtual bool onEvent(M4EventType eventType, int32 param, int x, int y, GUIObject *&currentItem) { return false; }
	int getTag() const { return _tag; }
};

enum GUIButtonState {BUTTON_NORMAL, BUTTON_MOUSEOVER, BUTTON_PRESSED};

class GUIButton: public GUIRect {
protected:
	M4Surface *_normalSprite, *_mouseOverSprite, *_pressedSprite;
	GUIButtonState _buttonState;
	bool _visible;
	bool _tracking;
public:
	GUIButton(View *owner, const Common::Rect &bounds, int tag,
		M4Surface *normalSprite, M4Surface *mouseOverSprite, M4Surface *pressedSprite);

	void onRefresh();
	bool onEvent(M4EventType eventType, int32 param, int x, int y, GUIObject *&currentItem);
	GUIButtonState getState() const { return _buttonState; }
};

class GUITextField: public GUIRect {
private:
	Common::String _text;
public:
	GUITextField(View *owner, const Common::Rect &bounds);
	void setText(const char *value) {
		_text = value;
		onRefresh();
	}

	void onRefresh();
};


class Dialogs {
public:
	void keyMouseCollision() {}
};

}

#endif