ScummVM API documentation
window.h
1
2/* ScummVM - Graphic Adventure Engine
3 *
4 * ScummVM is the legal property of its developers, whose names
5 * are too numerous to list here. Please refer to the COPYRIGHT
6 * file distributed with this source distribution.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef BAGEL_BOFLIB_GUI_WINDOW_H
24#define BAGEL_BOFLIB_GUI_WINDOW_H
25
26#include "common/list.h"
27#include "common/events.h"
28#include "bagel/spacebar/boflib/array.h"
29#include "bagel/boflib/stdinc.h"
30#include "bagel/boflib/error.h"
31#include "bagel/boflib/object.h"
32#include "bagel/boflib/point.h"
33#include "bagel/boflib/rect.h"
34#include "bagel/boflib/size.h"
35#include "bagel/spacebar/boflib/timer.h"
36#include "bagel/boflib/llist.h"
37#include "bagel/spacebar/boflib/gfx/bitmap.h"
38#include "bagel/boflib/palette.h"
39#include "bagel/spacebar/boflib/gfx/text.h"
40
41namespace Bagel {
42
43class CBofString;
44
45namespace SpaceBar {
46
47#define MAX_TITLE 64
48#define USE_DEFAULT (-1)
49
50class CBofBitmap;
51class CBofTimerPacket;
52
53class CBofWindow : public CLList, public CBofObject, public CBofError {
54private:
55 bool _visible = true;
56 bool _enabled = true;
58 uint32 _lastLButtonTime = 0, _lastRButtonTime = 0;
59
64 uint32 translateKey(const Common::Event &event) const;
65
66protected:
71
72public:
77
87 CBofWindow(const char *pszName, int x, int y, int nWidth, int nHeight, CBofWindow *pParent);
88
92 virtual ~CBofWindow();
93
94 static ErrorCode initialize();
95 static ErrorCode shutdown();
96 static Common::Point getMousePos();
97
109 virtual ErrorCode create(const char *pszName, int x, int y, int nWidth, int nHeight, CBofWindow *pParent, uint32 nControlID = 0);
110
119 virtual ErrorCode create(const char *pszName, CBofRect *pRect, CBofWindow *pParent, uint32 nControlID = 0);
120
124 virtual void destroy();
125 virtual void destroyWindow() {
126 destroy();
127 }
128
132 void show();
133
134 void select();
135
139 void hide();
140
144 void center();
145
152 void move(int x, int y, bool bRepaint = false);
153
159 void reSize(CBofRect *pRect, bool bRepaint = false);
160
161 virtual ErrorCode close() {
162 onClose();
163
164 return ERR_NONE;
165 }
166
173 void postMessage(uint32 nMessage, uint32 lParam1, uint32 lParam2);
174
178 void postUserMessage(uint32 lMessage, uint32 lExtraInfo);
179
186 void setTimer(uint32 nID, uint32 nInterval, BofCallback pCallBack = nullptr);
187
192 void killTimer(uint32 nID);
193
198
203 return _parent;
204 }
205
210 void validateAnscestors(CBofRect *pRect = nullptr);
211
212 static CBofWindow *getActiveWindow() {
213 return _pActiveWindow;
214 }
215
216 void setActive() {
217 _pActiveWindow = this;
218 }
219
220 static CBofWindow *getWindowList() {
221 return _pWindowList;
222 }
223
224 CBofRect getWindowRect() const {
225 return _cWindowRect;
226 }
227 CBofRect getClientRect();
228
229 CBofRect getRect() const {
230 return _cRect;
231 }
232
233 int width() const {
234 return _cRect.width();
235 }
236 int height() const {
237 return _cRect.height();
238 }
239
240 void screenToClient(CBofPoint *pPoint);
241
247
254 ErrorCode setBackdrop(CBofBitmap *pNewBitmap, bool bRefresh = false);
255
262 ErrorCode setBackdrop(const char *pszFileName, bool bRefresh = false);
263
264 void clearBackdrop() {
265 _pBackdrop = nullptr;
266 }
267
268 CBofBitmap *getBackdrop() const {
269 return _pBackdrop;
270 }
271
272 bool hasBackdrop() const {
273 return _pBackdrop != nullptr;
274 }
275
280
287 ErrorCode paintBackdrop(CBofRect *pRect = nullptr, int nTransparentColor = -1);
288
289 void setControlID(uint32 nID) {
290 _nID = nID;
291 }
292 uint32 getControlID() const {
293 return _nID;
294 }
295
296 void setBkColor(COLORREF cColor) {
297 _cBkColor = cColor;
298 }
299 COLORREF getBkColor() const {
300 return _cBkColor;
301 }
302
303 void setFgColor(COLORREF cColor) {
304 _cFgColor = cColor;
305 }
306 COLORREF getFgColor() const {
307 return _cFgColor;
308 }
309
310 void setPrevMouseDown(CBofPoint p) {
311 _cPrevMouseDown = p;
312 }
313 CBofPoint getPrevMouseDown() const {
314 return _cPrevMouseDown;
315 }
316
321
326
330 bool hasCapture() const;
331
335 void setFocus();
336
341
345 bool hasFocus() const;
346
347 void flushAllMessages();
348
353 void validateRect(const CBofRect *pRect);
354
359 void invalidateRect(const CBofRect *pRect);
360
361 virtual void onBofButton(CBofObject *pButton, int nExtraInfo);
362 virtual void onBofScrollBar(CBofObject *pButton, int nNewPos);
363 virtual void onBofListBox(CBofObject *pListBox, int nItemIndex);
364 virtual void onMainLoop();
365
366 virtual void onSoundNotify(CBofObject *pObject, uint32 lParam2);
367 virtual void onMovieNotify(uint32 lParam1, uint32 lParam2);
368
369 virtual void onMCINotify(uint32 wParam, uint32 lParam);
370
371 virtual void onTimer(uint32 nTimerId);
372
377 virtual void handleEvent(const Common::Event &event);
378
379 Graphics::ManagedSurface *getSurface();
380
381 bool isCreated() const {
382 return _surface != nullptr;
383 }
384
385 virtual void enable() {
386 _enabled = true;
387 updateWindow();
388 }
389 virtual void disable() {
390 _enabled = false;
391 updateWindow();
392 }
393 bool isVisible() const {
394 return _visible;
395 }
396 bool isEnabled() const {
397 return _enabled;
398 }
399
400 void updateWindow();
401
402 void setParent(CBofWindow *parent);
403
408
409 virtual void onKeyHit(uint32 lKey, uint32 lRepCount);
410 void fillWindow(byte iColor);
411 void fillRect(CBofRect *pRect, byte iColor);
412
413 ErrorCode paintBeveledText(CBofRect *rect, const CBofString &string, int size, int weight, COLORREF color, int justify, uint32 format);
414
415
416protected:
417 CBofWindow *_parent = nullptr; // Pointer to parent window
418 Array<CBofWindow *> _children; // Child element pointers
419
420 virtual void onMouseMove(uint32 nFlags, CBofPoint *pPoint, void * = nullptr);
421 virtual void onLButtonDown(uint32 nFlags, CBofPoint *pPoint, void * = nullptr);
422 virtual void onLButtonUp(uint32 nFlags, CBofPoint *pPoint, void * = nullptr);
423 virtual void onLButtonDblClk(uint32 nFlags, CBofPoint *pPoint);
424
425 virtual void onRButtonDown(uint32 nFlags, CBofPoint *pPoint);
426 virtual void onRButtonUp(uint32 nFlags, CBofPoint *pPoint);
427 virtual void onRButtonDblClk(uint32 nFlags, CBofPoint *pPoint);
428
429 virtual void onReSize(CBofSize *pSize);
430 virtual void onPaint(CBofRect *pRect);
431 virtual void onClose();
432
433 virtual void onUserMessage(uint32 nMessage, uint32 lParam);
434
435 virtual void onActivate();
436 virtual void onDeActivate();
437
438 // Window Data
439 char _szTitle[MAX_TITLE] = { 0 }; // Title of window
440 CBofRect _cWindowRect; // Screen based area of this window
441 CBofRect _cRect; // Window-based area of this window
442 CBofBitmap *_pBackdrop = nullptr; // Backdrop bitmap
443 uint32 _nID = 0; // ID of this window
444
445 COLORREF _cBkColor = RGB(255, 255, 255);
446 COLORREF _cFgColor = RGB(0, 0, 0);
447
448 bool _bCaptured = false;
449 Graphics::ManagedSurface *_surface = nullptr;
450
451 static CBofWindow *_pWindowList;
452 static CBofWindow *_pActiveWindow;
453 static CBofTimerPacket *_pTimerList;
454 CBofPoint _cPrevMouseDown;
455 static int _mouseX;
456 static int _mouseY;
457};
458
459class CBofMessage : public CBofObject {
460public:
461 CBofWindow *_pWindow; // destination window for message
462 uint32 _nMessage; // message to send (usually WM_USER)
463 uint32 _lParam1; // user defined info
464 uint32 _lParam2; // more user defined info
465};
466
467class CBofTimerPacket : public CBofObject, public CLList {
468public:
469 CBofWindow *_pOwnerWindow;
470 BofCallback _pCallBack;
471 uint32 _nID;
472 uint32 _nInterval;
473};
474
475extern CBofWindow *g_hackWindow;
476
477} // namespace SpaceBar
478} // namespace Bagel
479
480#endif
Definition: error.h:52
Definition: object.h:28
Definition: point.h:32
Definition: rect.h:35
Definition: size.h:32
Definition: string.h:38
Definition: llist.h:31
Definition: array.h:32
Definition: bitmap.h:57
Definition: window.h:459
Definition: palette.h:64
Definition: window.h:467
Definition: window.h:53
CBofWindow(const char *pszName, int x, int y, int nWidth, int nHeight, CBofWindow *pParent)
void reSize(CBofRect *pRect, bool bRepaint=false)
virtual ErrorCode create(const char *pszName, CBofRect *pRect, CBofWindow *pParent, uint32 nControlID=0)
void postUserMessage(uint32 lMessage, uint32 lExtraInfo)
void killTimer(uint32 nID)
void postMessage(uint32 nMessage, uint32 lParam1, uint32 lParam2)
ErrorCode setBackdrop(CBofBitmap *pNewBitmap, bool bRefresh=false)
void move(int x, int y, bool bRepaint=false)
ErrorCode setBackdrop(const char *pszFileName, bool bRefresh=false)
void setTimer(uint32 nID, uint32 nInterval, BofCallback pCallBack=nullptr)
virtual ErrorCode create(const char *pszName, int x, int y, int nWidth, int nHeight, CBofWindow *pParent, uint32 nControlID=0)
void validateRect(const CBofRect *pRect)
void validateAnscestors(CBofRect *pRect=nullptr)
virtual void handleEvent(const Common::Event &event)
void selectPalette(CBofPalette *pPal)
void invalidateRect(const CBofRect *pRect)
CBofWindow * getParent() const
Definition: window.h:202
ErrorCode paintBackdrop(CBofRect *pRect=nullptr, int nTransparentColor=-1)
Definition: list.h:44
Definition: managed_surface.h:51
Definition: events.h:218
Definition: rect.h:144