ScummVM API documentation
macwindow.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GRAPHICS_MACGUI_MACWINDOW_H
23 #define GRAPHICS_MACGUI_MACWINDOW_H
24 
25 #include "common/stream.h"
26 
27 #include "graphics/managed_surface.h"
28 #include "graphics/nine_patch.h"
29 #include "graphics/font.h"
30 
31 #include "graphics/macgui/macwidget.h"
32 #include "graphics/macgui/macwindowborder.h"
33 
34 namespace Graphics {
35 
36 class MacWindowManager;
37 class MacWindowBorder;
38 class MacWidget;
39 
40 namespace MacWindowConstants {
41 enum WindowType {
42  kWindowUnknown,
43  kWindowWindow,
44  kWindowMenu
45 };
46 
47 enum {
48  kBorderWidth = 17
49 };
50 
51 enum WindowClick {
52  kBorderNone = 0,
53  kBorderScrollUp,
54  kBorderScrollDown,
55  kBorderScrollLeft,
56  kBorderScrollRight,
57  kBorderCloseButton,
58  kBorderInner,
59  kBorderBorder,
60  kBorderResizeButton
61 };
62 
63 enum {
64  kWindowModeDynamicScrollbar = 1 << 0
65 };
66 }
67 using namespace MacWindowConstants;
68 
73 class BaseMacWindow : public MacWidget {
74 public:
81  BaseMacWindow(int id, bool editable, MacWindowManager *wm);
82  virtual ~BaseMacWindow() {}
83 
88  int getId() { return _id; }
89 
95  WindowType getType() { return _type; }
96 
101  bool isEditable() { return _editable; }
102 
107  virtual void setVisible(bool visible, bool silent = false);
112  bool isVisible();
113 
118  ManagedSurface *getWindowSurface() { return _composeSurface; }
119 
124  virtual ManagedSurface *getBorderSurface() = 0;
125 
133  virtual const Common::Rect &getInnerDimensions() = 0;
134 
140  virtual bool draw(bool forceRedraw = false) = 0;
141 
149  virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
150 
158  virtual bool processEvent(Common::Event &event) = 0;
159 
163  virtual bool isDirty() = 0;
164 
172  void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
173 
174 protected:
175  int _id;
176  WindowType _type;
177 
178  bool _editable;
179 
180  bool (*_callback)(WindowClick, Common::Event &, void *);
181  void *_dataPtr;
182 
183  bool _visible;
184 
185  bool _draggable;
186 };
187 
192 class MacWindow : public BaseMacWindow {
193 public:
204  MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
205 
211  MacWindow(const MacWindow &source);
212  virtual ~MacWindow() {}
213 
219  void move(int x, int y);
220 
221  /*
222  * Change the width and the height of the window (outer dimensions).
223  * @param w New width of the window.
224  * @param h New height of the window.
225  */
226  virtual void resize(int w, int h);
227 
228  /*
229  * Change the width and the height of the inner window.
230  * @param w New width of the window.
231  * @param h New height of the window.
232  */
233  virtual void resizeInner(int w, int h);
234 
241  void setDimensions(const Common::Rect &r) override;
242 
249  void setInnerDimensions(const Common::Rect &r);
250 
255  void setBackgroundPattern(int pattern);
256 
262  bool draw(ManagedSurface *g, bool forceRedraw = false) override;
263 
264  bool draw(bool forceRedraw = false) override;
265  void blit(ManagedSurface *g, Common::Rect &dest) override;
266 
267  const Common::Rect &getInnerDimensions() override { return _innerDims; }
268  ManagedSurface *getBorderSurface() override { return &_borderSurface; }
269 
274  void center(bool toCenter = true);
275 
281  void setActive(bool active) override;
286  bool isActive() const;
287 
292  void setTitle(const Common::String &title);
293 
298  virtual void setTitleVisible(bool visible);
299 
303  bool isTitleVisible();
304 
309  const Common::String &getTitle() const { return _title; };
310 
316  void setHighlight(WindowClick highlightedPart);
322  void setScroll(float scrollPos, float scrollSize);
326  bool processEvent(Common::Event &event) override;
327  bool hasAllFocus() override { return _beingDragged || _beingResized; }
328 
340  void loadBorder(Common::SeekableReadStream &file, uint32 flags, int lo = -1, int ro = -1, int to = -1, int bo = -1);
341  void loadBorder(Common::SeekableReadStream &file, uint32 flags, const BorderOffsets &offsets);
342  void setBorder(Graphics::ManagedSurface *surface, uint32 flags, const BorderOffsets &offsets);
343  void disableBorder();
344  void loadInternalBorder(uint32 flags);
349  void enableScrollbar(bool active) { _hasScrollBar = active; }
350 
355  void setCloseable(bool closeable);
356 
361  void setBorderType(int borderType);
366  int getBorderType() const { return _borderType; };
367 
373  uint32 getBorderFlags() const;
374 
375  void addDirtyRect(const Common::Rect &r);
376  void markAllDirty();
377  void mergeDirtyRects();
378 
379  bool isDirty() override { return _borderIsDirty || _contentIsDirty; }
380 
381  void setBorderDirty(bool dirty) { _borderIsDirty = true; }
382  void resizeBorderSurface();
383 
384  void setMode(uint32 mode) { _mode = mode; }
385  void setBorderOffsets(BorderOffsets &offsets) { _macBorder.setOffsets(offsets); }
386 
387  void updateInnerDims();
388 
389 private:
390  void rebuildSurface(); // Propagate dimensions change and recreate patter/borders, etc.
391  void drawBorderFromSurface(ManagedSurface *g, uint32 flags);
392  void drawPattern();
393  void drawBox(ManagedSurface *g, int x, int y, int w, int h);
394  void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
395  const Font *getTitleFont();
396  void updateOuterDims();
397 
398  bool isInCloseButton(int x, int y) const;
399  bool isInResizeButton(int x, int y) const;
400  WindowClick isInScroll(int x, int y) const;
401 
402 protected:
403  void drawBorder();
404  WindowClick isInBorder(int x, int y) const;
405  const BorderOffsets &getBorderOffsets() const { return _macBorder.getOffset(); }
406 
407 protected:
408  ManagedSurface _borderSurface;
409 
410  bool _borderIsDirty;
411  Common::Rect _innerDims;
412 
413  Common::List<Common::Rect> _dirtyRects;
414  bool _hasScrollBar;
415 
416  uint32 _mode;
417 private:
418  MacWindowBorder _macBorder;
419 
420  int _pattern;
421  bool _hasPattern;
422 
423  bool _scrollable;
424  bool _resizable;
425 
426  bool _closeable;
427  bool _isTitleVisible;
428 
429  int _borderWidth;
430 
431  bool _beingDragged, _beingResized;
432  int _draggedX, _draggedY;
433 
434  WindowClick _highlightedPart;
435 
436  Common::String _title;
437  Common::String _shadowedTitle;
438 
439  int _borderType;
440 };
441 
442 } // End of namespace Graphics
443 
444 #endif
Definition: managed_surface.h:51
const Common::String & getTitle() const
Definition: macwindow.h:309
Definition: str.h:59
Definition: font.h:83
Definition: macwindow.h:192
int getBorderType() const
Definition: macwindow.h:366
Definition: rect.h:524
Definition: stream.h:745
ManagedSurface * getWindowSurface()
Definition: macwindow.h:118
void setCallback(bool(*callback)(WindowClick, Common::Event &, void *), void *data)
Definition: macwindow.h:172
Definition: macwindowmanager.h:147
Definition: macwindowborder.h:57
ManagedSurface * getBorderSurface() override
Definition: macwindow.h:268
const Common::Rect & getInnerDimensions() override
Definition: macwindow.h:267
Definition: events.h:210
Definition: formatinfo.h:28
Definition: macwidget.h:39
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
bool isEditable()
Definition: macwindow.h:101
int getId()
Definition: macwindow.h:88
WindowType getType()
Definition: macwindow.h:95
bool isDirty() override
Definition: macwindow.h:379
void enableScrollbar(bool active)
Definition: macwindow.h:349
Definition: macwindow.h:73
Definition: macwindowborder.h:80