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/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/boflib/timer.h"
36 #include "bagel/boflib/llist.h"
37 #include "bagel/boflib/gfx/bitmap.h"
38 #include "bagel/boflib/gfx/palette.h"
39 #include "bagel/boflib/gfx/text.h"
40 
41 namespace Bagel {
42 class CBofString;
43 
44 #define MAX_TITLE 64
45 #define USE_DEFAULT (-1)
46 
47 class CBofBitmap;
48 class CBofTimerPacket;
49 
50 class CBofWindow : public CLList, public CBofObject, public CBofError {
51 private:
52  bool _visible = true;
53  bool _enabled = true;
55  uint32 _lastLButtonTime = 0, _lastRButtonTime = 0;
56 
61  uint32 translateKey(const Common::Event &event) const;
62 
63 protected:
67  void checkTimers();
68 
69 public:
73  CBofWindow();
74 
84  CBofWindow(const char *pszName, int x, int y, int nWidth, int nHeight, CBofWindow *pParent);
85 
89  virtual ~CBofWindow();
90 
91  static ErrorCode initialize();
92  static ErrorCode shutdown();
93  static Common::Point getMousePos();
94 
106  virtual ErrorCode create(const char *pszName, int x, int y, int nWidth, int nHeight, CBofWindow *pParent, uint32 nControlID = 0);
107 
116  virtual ErrorCode create(const char *pszName, CBofRect *pRect, CBofWindow *pParent, uint32 nControlID = 0);
117 
121  virtual void destroy();
122  virtual void destroyWindow() {
123  destroy();
124  }
125 
129  void show();
130 
131  void select();
132 
136  void hide();
137 
141  void center();
142 
149  void move(int x, int y, bool bRepaint = false);
150 
156  void reSize(CBofRect *pRect, bool bRepaint = false);
157 
158  virtual ErrorCode close() {
159  onClose();
160 
161  return ERR_NONE;
162  }
163 
170  void postMessage(uint32 nMessage, uint32 lParam1, uint32 lParam2);
171 
175  void postUserMessage(uint32 lMessage, uint32 lExtraInfo);
176 
183  void setTimer(uint32 nID, uint32 nInterval, BofCallback pCallBack = nullptr);
184 
189  void killTimer(uint32 nID);
190 
194  void killMyTimers();
195 
200  return _parent;
201  }
202 
207  void validateAnscestors(CBofRect *pRect = nullptr);
208 
209  static CBofWindow *getActiveWindow() {
210  return _pActiveWindow;
211  }
212 
213  void setActive() {
214  _pActiveWindow = this;
215  }
216 
217  static CBofWindow *getWindowList() {
218  return _pWindowList;
219  }
220 
221  CBofRect getWindowRect() const {
222  return _cWindowRect;
223  }
224  CBofRect getClientRect();
225 
226  CBofRect getRect() const {
227  return _cRect;
228  }
229 
230  int width() const {
231  return _cRect.width();
232  }
233  int height() const {
234  return _cRect.height();
235  }
236 
237  void screenToClient(CBofPoint *pPoint);
238 
243  void selectPalette(CBofPalette *pPal);
244 
251  ErrorCode setBackdrop(CBofBitmap *pNewBitmap, bool bRefresh = false);
252 
259  ErrorCode setBackdrop(const char *pszFileName, bool bRefresh = false);
260 
261  void clearBackdrop() {
262  _pBackdrop = nullptr;
263  }
264 
265  CBofBitmap *getBackdrop() const {
266  return _pBackdrop;
267  }
268 
269  bool hasBackdrop() const {
270  return _pBackdrop != nullptr;
271  }
272 
276  void killBackdrop();
277 
284  ErrorCode paintBackdrop(CBofRect *pRect = nullptr, int nTransparentColor = -1);
285 
286  void setControlID(uint32 nID) {
287  _nID = nID;
288  }
289  uint32 getControlID() const {
290  return _nID;
291  }
292 
293  void setBkColor(RGBCOLOR cColor) {
294  _cBkColor = cColor;
295  }
296  RGBCOLOR getBkColor() const {
297  return _cBkColor;
298  }
299 
300  void setFgColor(RGBCOLOR cColor) {
301  _cFgColor = cColor;
302  }
303  RGBCOLOR getFgColor() const {
304  return _cFgColor;
305  }
306 
307  void setPrevMouseDown(CBofPoint p) {
308  _cPrevMouseDown = p;
309  }
310  CBofPoint getPrevMouseDown() const {
311  return _cPrevMouseDown;
312  }
313 
317  void setCapture();
318 
322  void releaseCapture();
323 
327  bool hasCapture() const;
328 
332  void setFocus();
333 
337  void releaseFocus();
338 
342  bool hasFocus() const;
343 
344  void flushAllMessages();
345 
350  void validateRect(const CBofRect *pRect);
351 
356  void invalidateRect(const CBofRect *pRect);
357 
358  virtual void onBofButton(CBofObject *pButton, int nExtraInfo);
359  virtual void onBofScrollBar(CBofObject *pButton, int nNewPos);
360  virtual void onBofListBox(CBofObject *pListBox, int nItemIndex);
361  virtual void onMainLoop();
362 
363  virtual void onSoundNotify(CBofObject *pObject, uint32 lParam2);
364  virtual void onMovieNotify(uint32 lParam1, uint32 lParam2);
365 
366  virtual void onMCINotify(uint32 wParam, uint32 lParam);
367 
368  virtual void onTimer(uint32 nTimerId);
369 
374  virtual void handleEvent(const Common::Event &event);
375 
376  Graphics::ManagedSurface *getSurface();
377 
378  bool isCreated() const {
379  return _surface != nullptr;
380  }
381 
382  virtual void enable() {
383  _enabled = true;
384  updateWindow();
385  }
386  virtual void disable() {
387  _enabled = false;
388  updateWindow();
389  }
390  bool isVisible() const {
391  return _visible;
392  }
393  bool isEnabled() const {
394  return _enabled;
395  }
396 
397  void updateWindow();
398 
399  void setParent(CBofWindow *parent);
400 
404  void handleEvents();
405 
406  virtual void onKeyHit(uint32 lKey, uint32 lRepCount);
407  void fillWindow(byte iColor);
408  void fillRect(CBofRect *pRect, byte iColor);
409 
410  ErrorCode paintBeveledText(CBofRect *rect, const CBofString &string, int size, int weight, RGBCOLOR color, int justify, uint32 format);
411 
412 
413 protected:
414  CBofWindow *_parent = nullptr; // Pointer to parent window
415  Array<CBofWindow *> _children; // Child element pointers
416 
417  virtual void onMouseMove(uint32 nFlags, CBofPoint *pPoint, void * = nullptr);
418  virtual void onLButtonDown(uint32 nFlags, CBofPoint *pPoint, void * = nullptr);
419  virtual void onLButtonUp(uint32 nFlags, CBofPoint *pPoint, void * = nullptr);
420  virtual void onLButtonDblClk(uint32 nFlags, CBofPoint *pPoint);
421 
422  virtual void onRButtonDown(uint32 nFlags, CBofPoint *pPoint);
423  virtual void onRButtonUp(uint32 nFlags, CBofPoint *pPoint);
424  virtual void onRButtonDblClk(uint32 nFlags, CBofPoint *pPoint);
425 
426  virtual void onReSize(CBofSize *pSize);
427  virtual void onPaint(CBofRect *pRect);
428  virtual void onClose();
429 
430  virtual void onUserMessage(uint32 nMessage, uint32 lParam);
431 
432  virtual void onActivate();
433  virtual void onDeActivate();
434 
435  // Window Data
436  char _szTitle[MAX_TITLE] = { 0 }; // Title of window
437  CBofRect _cWindowRect; // Screen based area of this window
438  CBofRect _cRect; // Window-based area of this window
439  CBofBitmap *_pBackdrop = nullptr; // Backdrop bitmap
440  uint32 _nID = 0; // ID of this window
441 
442  RGBCOLOR _cBkColor = RGB(255, 255, 255);
443  RGBCOLOR _cFgColor = RGB(0, 0, 0);
444 
445  bool _bCaptured = false;
446  Graphics::ManagedSurface *_surface = nullptr;
447 
448  static CBofWindow *_pWindowList;
449  static CBofWindow *_pActiveWindow;
450  static CBofTimerPacket *_pTimerList;
451  CBofPoint _cPrevMouseDown;
452  static int _mouseX;
453  static int _mouseY;
454 };
455 
456 class CBofMessage : public CBofObject {
457 public:
458  CBofWindow *_pWindow; // destination window for message
459  uint32 _nMessage; // message to send (usually WM_USER)
460  uint32 _lParam1; // user defined info
461  uint32 _lParam2; // more user defined info
462 };
463 
464 class CBofTimerPacket : public CBofObject, public CLList {
465 public:
466  CBofWindow *_pOwnerWindow;
467  BofCallback _pCallBack;
468  uint32 _nID;
469  uint32 _nInterval;
470 };
471 
472 extern CBofWindow *g_hackWindow;
473 
474 } // namespace Bagel
475 
476 #endif
Definition: managed_surface.h:51
Definition: window.h:50
Definition: window.h:464
void invalidateRect(const CBofRect *pRect)
Definition: object.h:28
Definition: size.h:31
bool hasCapture() const
Definition: list.h:44
Definition: bitmap.h:55
ErrorCode setBackdrop(CBofBitmap *pNewBitmap, bool bRefresh=false)
Definition: rect.h:36
void setTimer(uint32 nID, uint32 nInterval, BofCallback pCallBack=nullptr)
Definition: error.h:50
virtual ~CBofWindow()
virtual ErrorCode create(const char *pszName, int x, int y, int nWidth, int nHeight, CBofWindow *pParent, uint32 nControlID=0)
void killTimer(uint32 nID)
void postUserMessage(uint32 lMessage, uint32 lExtraInfo)
bool hasFocus() const
virtual void destroy()
Definition: events.h:199
Definition: rect.h:45
void postMessage(uint32 nMessage, uint32 lParam1, uint32 lParam2)
void validateRect(const CBofRect *pRect)
Definition: string.h:38
Definition: bagel.h:31
ErrorCode paintBackdrop(CBofRect *pRect=nullptr, int nTransparentColor=-1)
Definition: point.h:34
Definition: palette.h:69
Definition: window.h:456
Definition: array.h:31
CBofWindow * getParent() const
Definition: window.h:199
Definition: llist.h:31
virtual void handleEvent(const Common::Event &event)
void move(int x, int y, bool bRepaint=false)
void reSize(CBofRect *pRect, bool bRepaint=false)
void validateAnscestors(CBofRect *pRect=nullptr)
void selectPalette(CBofPalette *pPal)