File: panel.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (571 lines) | stat: -rw-r--r-- 17,709 bytes parent folder | download | duplicates (3)
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 *
 * Based on the original sources
 *   Faery Tale II -- The Halls of the Dead
 *   (c) 1993-1996 The Wyrmkeep Entertainment Co.
 */

#ifndef SAGA2_PANEL_H
#define SAGA2_PANEL_H

#include "saga2/input.h"
#include "saga2/vdraw.h"

namespace Common {
struct Event;
}

namespace Saga2 {
//  Fix problem with DOS's encroachment on name space that should
//  rightfully belong to the application programmer.

#ifdef enable
#undef enable
#undef disable
#endif

/* ===================================================================== *
                          Cursor Cycling Stuff
 * ===================================================================== */

void cycleCursor();

/* ===================================================================== *
                          Forward declarations
 * ===================================================================== */

class gPanel;
class gPanelList;
class gPanelMessage;
class gWindow;

/* ===================================================================== *
                      Input dispatching functions
 * ===================================================================== */

void HandleTimerTick(long newTick);
void EventLoop(bool &running, bool modal = false);

/* ===================================================================== *
                                Constants
 * ===================================================================== */

enum gEventType {
	kEventNone = 0,                         // no event occurred
	kEventMouseDown,                        // left button pressed
	kEventMouseUp,                          // left button released
	kEventRMouseDown,                       // right button pressed
	kEventRMouseUp,                         // right button released
	kEventMouseMove,                        // mouse moved
	kEventMouseDrag,                        // mouse dragged
	kEventMouseOutside,                     // mouse click outside of window
	kEventKeyDown,                          // keystroke

	kEventNewValue,                         // object had new value
	kEventDoubleClick,                      // double-clicked on object
	kEventAltValue,                         // for multi-function objects

	kEventLast
};

/* ===================================================================== *
   gEvent: returns input events to the user
 * ===================================================================== */

struct gEvent {
	gPanel          *panel;                 // where event came from
	gEventType      eventType;              // type of event that occurred
	Point16         mouse;                  // mouse position
	int32           value;                  // new value of control
	gWindow         *window;                // active window
};

typedef void        AppFunc(gEvent &);

#ifndef __WATCOMC__
#define APPFUNCDECL __cdecl
#else
#define APPFUNCDECL
#endif

#define APPFUNC(a)  void a ( gEvent &ev )
#define APPFUNCV(a) void a ( gEvent & )

//  Note: panels in this system are not, in general, resizeable

/* ===================================================================== *
   gPanel class: The basic user interface element
 * ===================================================================== */

class gPanel {
	friend class    gToolBase;
	friend class    gWindow;

	AppFunc         *_command;               // application function
protected:
	gWindow         &_window;                // window this belongs to
	Rect16          _extent;                 // rectangular bounds of the control
	const char      *_title;                 // title of the panel
	byte            _enabled,            // allows disabling the panel
	                _selected,           // some panels have a selected state
	                _imageLabel,         // button label is image, not text
	                _ghosted,            // button is dimmed
	                _wantMousePoll;      // send mousemoves even if mouse not moving!

	// window constructor
	gPanel(gWindow &, const Rect16 &, AppFunc *cmd);

public:
	uint32          _id;                     // panel id number
	void            *_userData;              // data for this panel

	// constructor
	gPanel(gPanelList &, const Rect16 &, const char *, uint16, AppFunc *cmd = NULL);
	gPanel(gPanelList &, const Rect16 &, gPixelMap &, uint16, AppFunc *cmd = NULL);

	gPanel(gPanelList &, const StaticRect &, const char *, uint16, AppFunc *cmd = NULL);
	virtual ~gPanel();                      // destructor

	virtual gPanel *hitTest(const Point16 &p);
	virtual gPanel *keyTest(int16 key);

protected:
	virtual void pointerMove(gPanelMessage &msg);
	virtual bool pointerHit(gPanelMessage &msg);
	virtual bool pointerRHit(gPanelMessage &msg);
	virtual void pointerDrag(gPanelMessage &msg);
	virtual void pointerRelease(gPanelMessage &msg);
	virtual bool keyStroke(gPanelMessage &msg);
	virtual void timerTick(gPanelMessage &msg);
	virtual void onMouseHintDelay();

	void notify(gEventType, int32 value);
	void notify(gEvent &ev) {
		if (_command) _command(ev);
	}
	void drawTitle(TextPositions placement);


public:
	bool isActive();                     // true if we are active panel
	virtual bool activate(gEventType why);  // activate the control
	virtual void deactivate();       // deactivate the control
	virtual void draw();                 // redraw the panel.
	virtual void enable(bool abled);
	virtual void select(uint16 selected);
	virtual void ghost(bool ghosted);
	virtual void invalidate(Rect16 *area = nullptr);
	virtual void setMousePoll(bool abled) {
		_wantMousePoll = abled ? 1 : 0;
	}

	//  Redraw the panel, but only a small clipped section,
	//  and perhaps drawn onto an off-screen map.
	virtual void drawClipped(
	    gPort         &port,
	    const Point16 &offset,
	    const Rect16  &r);

//	void setCommand( AppFunc *func ) { command = func; }
	gWindow *getWindow() {
		return &_window;
	}
	void makeActive();
	Rect16 getExtent() {
		return _extent;
	}
	bool isSelected() {
		return _selected != 0;
	}
	bool isGhosted() {
		return _ghosted != 0;
	}
	bool    getEnabled() const {
		return (bool)_enabled;
	}
	void    show(bool shown = true, bool inval = true) {
		enable(shown);
		if (inval)
			invalidate();
	}

	void moveToFront(gPanelList &l);
	void moveToBack(gPanelList &l);
};

/* ===================================================================== *
   gPanelMessage class: How user input is distributes to panels
 * ===================================================================== */

class gPanelMessage {
public:
	Point16         _pickPos,            // mouse position relative to panel
	                _pickAbsPos;         // mouse position relative to display
	byte            _leftButton,         // left button state
	                _rightButton,        // right button state
	                _inPanel,            // whether mouse is currently in panel
	                _pointerEnter,       // set when pointer enters panel
	                _pointerLeave,       // set when pointer leaves panel
	                _doubleClick;        // set when double click detected

	//  For keyboard input

	uint16          _key,                // keystroke from keyboard
	                _qualifier;          // qualifier from keyboard

	uint32          _timeStamp;          // time of message

	gPanelMessage() {
		_leftButton = 0;
		_rightButton = 0;
		_inPanel = 0;
		_pointerEnter = 0;
		_pointerLeave = 0;
		_doubleClick = 0;
		_key = 0;
		_qualifier = 0;
		_timeStamp = 0;
	}
};

/* ===================================================================== *
   gPanelList class: A list of panels
 * ===================================================================== */

class gControl;

class gPanelList : public gPanel {

	friend class    gControl;
	friend class    gToolBase;

	friend void gPanel::moveToFront(gPanelList &l);
	friend void gPanel::moveToBack(gPanelList &l);

protected:

	Common::List<gPanel *> _contents;               // list of panels

	gPanelList(gWindow &, const Rect16 &, char *, uint16, AppFunc *cmd = NULL);

public:

	gPanelList(gPanelList &);
	~gPanelList();

	gPanel *hitTest(const Point16 &p);
	gPanel *keyTest(int16 key);
	void removeControls();

public:
	void invalidate(Rect16 *area = nullptr);
	void draw();                         // redraw the controls
	void drawClipped(
	    gPort         &port,
	    const Point16 &offset,
	    const Rect16  &r);

	void enable(bool abled);                 // enable list and all children
//	void setPointer( gPixelMap &map, int x, int y );
};

inline void gPanel::moveToFront(gPanelList &l) {
	l._contents.remove(this);
	l._contents.push_front(this);
}

inline void gPanel::moveToBack(gPanelList &l) {
	l._contents.remove(this);
	l._contents.push_back(this);
}

/* ===================================================================== *
   gWindow class: A context for holding panels.
 * ===================================================================== */

/*
enum windowFeatures {
    windowTitleBar  = (1<<0),               // window has a title bar
    windowCanDrag   = (1<<1),               // window is draggable
//  windowVisible   = (1<<2),               // window is visible
//  windowBackSaved = (1<<3),               // backsave data under window
//  windowCloseBox  = (1<<4),               // create a close box
//  windowNoBorder  = (1<<5),               // window with no border
};
*/

class gWindow : public gPanelList {

	friend class    gControl;
	friend class    gPanel;
	friend class    gToolBase;

public:
	gDisplayPort    _windowPort;

	gWindow(const Rect16 &, uint16, const char saveName[], AppFunc *cmd = NULL);
	~gWindow();

	operator gPort() {
		return _windowPort;
	}
	void postEvent(gEvent &ev) {
		gPanel::notify(ev);
	}

protected:
	bool            _openFlag;               // true if window open.

	//gWindowWinInfoInINIFile saver;

private:
	bool activate(gEventType why);       // activate the control
	void deactivate();

	void pointerMove(gPanelMessage &msg);
	bool pointerHit(gPanelMessage &msg);
	void pointerDrag(gPanelMessage &msg);
	void pointerRelease(gPanelMessage &msg);

	//  Dragging modes for window -- private and static!

	enum drag_modes {
		kDragNone = 0,
		kDragPosition
	};

	static int      _dragMode;               // current dragging mode
	static StaticRect  _dragExtent;          // dragging extent
	static StaticPoint16 _dragOffset;        // offset to window origin

	void shadow();

public:
	void setExtent(const Rect16 &);          // set window position and size
	Rect16 getExtent() {
		return _extent;    // set window position and size
	}
protected:
	void setPos(Point16 pos);                // set window position
	void insert();                      // insert window into window list
	virtual void toFront();              // re-order the windows

public:
	bool isOpen() {
		return _openFlag;    // true if window is visible
	}
	void draw();                         // redraw the panel.
	void drawClipped(
	    gPort         &port,
	    const Point16 &offset,
	    const Rect16  &r);

	//  Redraw the window, but only a small clipped section,
	//  and perhaps drawn onto an off-screen map.
//	void drawClipped(
//		gPort         &port,
//		const Point16 &offset,
//		const Rect16  &r );

	void enable(bool abled);
	void select(uint16 sel);               // activate the window

	virtual bool open();
	virtual void close();
	virtual bool isModal();

	//  Update a region of a window, and all floaters which
	//  might be above that window.
	virtual void update(const Rect16 &updateRect) = 0;

//	void setPointer( gPixelMap &map, int x, int y );
};

/* ===================================================================== *
   gControl class: The basis for buttons and other controls.
 * ===================================================================== */

class gControl : public gPanel {
public:
	uint8       _accelKey;
	gPanelList *_list;

	gControl(gPanelList &, const Rect16 &, const char *, uint16, AppFunc *cmd = NULL);
	gControl(gPanelList &, const Rect16 &, gPixelMap &, uint16, AppFunc *cmd = NULL);

	gControl(gPanelList &, const StaticRect &, const char *, uint16, AppFunc *cmd = NULL);
	~gControl();                            // destructor

	gPanel *keyTest(int16 key);

	void enable(bool abled);                 // enable the control
	void select(uint16 sel);               // selecte the control
	void ghost(bool ghosted);
//	virtual void newValue( void );

	void draw();                         // redraw the control.
};

/* ===================================================================== *
   gGenericControl class: A generic button that notifies everything
 * ===================================================================== */

class gGenericControl : public gControl {
	bool _dblClickFlag;

public:
	gGenericControl(gPanelList &, const Rect16 &, uint16, AppFunc *cmd = NULL);

	//  Disable double click for next mouse click
	void disableDblClick() {
		_dblClickFlag = true;
	}

	enum    controlValue {
		kCVEnter = (1 << 0),
		kCVLeave = (1 << 1)
	};

protected:
	bool activate(gEventType why);       // activate the control
	void deactivate();

	void pointerMove(gPanelMessage &msg);
	bool pointerHit(gPanelMessage &msg);
	void pointerDrag(gPanelMessage &msg);
	void pointerRelease(gPanelMessage &msg);

	void draw();                         // redraw the control.
};


/* ===================================================================== *
   gToolBase class: The primary dispatcher for user interface events
 * ===================================================================== */

void     setMouseTextF(char *format, ...);
void     LockUI(bool state);

class gToolBase {
	friend class    gWindow;
	friend class    gPanel;
	friend void     EventLoop(bool &running);
	friend int16        leftButtonState();
	friend int16        rightButtonState();
	friend void     StageModeCleanup();
	friend void     TileModeCleanup();
	friend void dumpGBASE(char *msg);

	// windows

	Common::List<gWindow *> _windowList;     // list of windows
	gWindow         *_mouseWindow,           // window mouse is in
	                *_activeWindow;          // current active window
	gPanel          *_mousePanel,            // panel that mouse is in
	                *_activePanel;           // panel that has input focus
	Rect16          _dragRect;               // dragging rectangle for windows
	Point16         _pickPos;                // mouse pos relative to panel
	uint8           _leftDrag,               // left-button dragging
	                _rightDrag;              // right button dragging
	gPanelMessage   _msg;                    // message that we send out

	int32           _lastMouseMoveTime;      // time of last mouse move

	gMouseState _curMouseState;

public:
	bool            _mouseHintSet;           // true if mouse hint is up.

	gToolBase() {
		_mouseWindow = nullptr;
		_activeWindow = nullptr;
		_mousePanel = nullptr;
		_activePanel = nullptr;
		_leftDrag = 0;
		_rightDrag = 0;
		_lastMouseMoveTime = 0;
	}

private:
	void setMsgQ(gPanelMessage &msg_, gPanel *panel) {
		if (panel == &panel->_window)
			msg_._pickPos = _pickPos;
		else {
			_msg._pickPos.x = (int16)(_pickPos.x - panel->_extent.x);
			_msg._pickPos.y = (int16)(_pickPos.y - panel->_extent.y);
		}
	}

	void setMsg(gPanelMessage &msg_, gPanel *panel) {
		setMsgQ(msg_, panel);
		_msg._inPanel = (msg_._pickPos.x >= 0
		               && msg_._pickPos.y >= 0
		               && msg_._pickPos.x < panel->_extent.width
		               && msg_._pickPos.y < panel->_extent.height);
		//          panel->extent.ptInside( pickPos );
	}

public:
	void setActive(gPanel *newActive);
	void leavePanel();               // we're changing windows
public:
	void handleMouse(Common::Event &event, uint32 time);
	void handleKeyStroke(Common::Event &event);
	void handleTimerTick(int32 tick);
	Common::List<gWindow *>::iterator topWindowIterator() {
		return _windowList.end();
	}
	Common::List<gWindow *>::iterator bottomWindowIterator() {
		return _windowList.reverse_begin();
	}
	gWindow *topWindow() {
		return _windowList.front();
	}
	gWindow *bottomWindow() {
		return _windowList.back();
	}
	bool isMousePanel(gPanel *p) {
		return (_mousePanel != NULL) ? (p == _mousePanel) : (p == topWindow());
	}
};

/* ===================================================================== *
   Application functions to call for event handling
 * ===================================================================== */

void EventLoop(bool &running);
void initPanels(gDisplayPort &port);
void cleanupPanels();

//void writeHelpLine( char *msg, ... );

int16 leftButtonState();
int16 rightButtonState();

//  Kludge structure to contain both a mouse event and a time stamp
struct MouseExtState {
	gMouseState st;
	int32       time;
};

} // end of namespace Saga2

#endif