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  kBorderActivate,
62  kBorderDeactivate,
63  kBorderDragged,
64  kBorderResized,
65  kBorderMaximizeButton,
66 };
67 
68 enum {
69  kWindowModeDynamicScrollbar = 1 << 0
70 };
71 }
72 using namespace MacWindowConstants;
73 
78 class BaseMacWindow : public MacWidget {
79 public:
86  BaseMacWindow(int id, bool editable, MacWindowManager *wm);
87  virtual ~BaseMacWindow() {}
88 
93  int getId() { return _id; }
94 
100  WindowType getType() { return _type; }
101 
106  bool isEditable() { return _editable; }
107 
112  virtual void setVisible(bool visible, bool silent = false);
117  bool isVisible();
118 
123  ManagedSurface *getWindowSurface() { return _composeSurface; }
124 
129  virtual ManagedSurface *getBorderSurface() = 0;
130 
138  virtual const Common::Rect &getInnerDimensions() = 0;
139 
145  virtual bool draw(bool forceRedraw = false) = 0;
146 
154  virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
155 
163  virtual bool processEvent(Common::Event &event) = 0;
164 
168  virtual bool isDirty() = 0;
169 
177  void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
178 
183  void setDraggable(bool draggable) { _draggable = draggable; }
184 
185 protected:
186  int _id;
187  WindowType _type;
188 
189  bool _editable;
190 
191  bool (*_callback)(WindowClick, Common::Event &, void *);
192  void *_dataPtr;
193 
194  bool _visible;
195 
196  bool _draggable;
197 };
198 
203 class MacWindow : public BaseMacWindow {
204 public:
215  MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
216 
222  MacWindow(const MacWindow &source);
223  virtual ~MacWindow() {}
224 
230  void move(int x, int y);
231 
232  /*
233  * Change the width and the height of the window (outer dimensions).
234  * @param w New width of the window.
235  * @param h New height of the window.
236  */
237  virtual void resize(int w, int h);
238 
239  /*
240  * Change the width and the height of the inner window.
241  * @param w New width of the window.
242  * @param h New height of the window.
243  */
244  virtual void resizeInner(int w, int h);
245 
252  void setDimensions(const Common::Rect &r) override;
253 
260  void setInnerDimensions(const Common::Rect &r);
261 
266  void setBackgroundPattern(int pattern);
267 
273  bool draw(ManagedSurface *g, bool forceRedraw = false) override;
274 
275  bool draw(bool forceRedraw = false) override;
276  void blit(ManagedSurface *g, Common::Rect &dest) override;
277 
278  const Common::Rect &getInnerDimensions() override { return _innerDims; }
279  ManagedSurface *getBorderSurface() override { return &_borderSurface; }
280 
285  void center(bool toCenter = true);
286 
292  void setActive(bool active) override;
297  bool isActive() const;
298 
303  void setTitle(const Common::String &title);
304 
309  virtual void setTitleVisible(bool visible);
310 
314  bool isTitleVisible();
315 
320  const Common::String &getTitle() const { return _title; };
321 
327  void setHighlight(WindowClick highlightedPart);
333  void setScroll(float scrollPos, float scrollSize);
337  bool processEvent(Common::Event &event) override;
338  bool hasAllFocus() override { return _beingDragged || _beingResized; }
339 
351  void loadBorder(Common::SeekableReadStream &file, uint32 flags, int lo = -1, int ro = -1, int to = -1, int bo = -1);
352  void loadBorder(Common::SeekableReadStream &file, uint32 flags, const BorderOffsets &offsets);
353  void setBorder(Graphics::ManagedSurface *surface, uint32 flags, const BorderOffsets &offsets);
354  void disableBorder();
355  void loadInternalBorder(uint32 flags);
360  void enableScrollbar(bool active) { _hasScrollBar = active; }
361 
366  void setCloseable(bool closeable);
367 
372  void setBorderType(int borderType);
377  int getBorderType() const { return _borderType; };
378 
384  uint32 getBorderFlags() const;
385 
386  void addDirtyRect(const Common::Rect &r);
387  void markAllDirty();
388  void mergeDirtyRects();
389  Common::Rect getDirtyRectBounds();
390  void clearDirtyRects() { _dirtyRects.clear(); }
391  Common::List<Common::Rect> &getDirtyRectList() { return _dirtyRects; }
392 
393  bool isDirty() override { return _borderIsDirty || _contentIsDirty; }
394 
395  void setBorderDirty(bool dirty) { _borderIsDirty = true; }
396  void setContentDirty(bool dirty) { _contentIsDirty = true; }
397  void resizeBorderSurface();
398 
399  void setMode(uint32 mode) { _mode = mode; }
400  void setBorderOffsets(BorderOffsets &offsets) { _macBorder.setOffsets(offsets); }
401 
402  void updateInnerDims();
403 
404 private:
405  void rebuildSurface(); // Propagate dimensions change and recreate patter/borders, etc.
406  void drawBorderFromSurface(ManagedSurface *g, uint32 flags);
407  void drawPattern();
408  void drawBox(ManagedSurface *g, int x, int y, int w, int h);
409  void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
410  const Font *getTitleFont();
411  void updateOuterDims();
412 
413  bool isInCloseButton(int x, int y) const;
414  bool isInResizeButton(int x, int y) const;
415  WindowClick isInScroll(int x, int y) const;
416 
417 protected:
418  void drawBorder();
419  WindowClick isInBorder(int x, int y) const;
420  const BorderOffsets &getBorderOffsets() const { return _macBorder.getOffset(); }
421 
422 protected:
423  ManagedSurface _borderSurface;
424 
425  bool _borderIsDirty;
426  Common::Rect _innerDims;
427 
428  Common::List<Common::Rect> _dirtyRects;
429  bool _hasScrollBar;
430 
431  uint32 _mode;
432 private:
433  MacWindowBorder _macBorder;
434 
435  int _pattern;
436  bool _hasPattern;
437 
438  bool _scrollable;
439  bool _resizable;
440 
441  bool _closeable;
442  bool _isTitleVisible;
443 
444  int _borderWidth;
445 
446  bool _beingDragged, _beingResized;
447  int _draggedX, _draggedY;
448 
449  WindowClick _highlightedPart;
450 
451  Common::String _title;
452  Common::String _shadowedTitle;
453 
454  int _borderType;
455 };
456 
457 } // End of namespace Graphics
458 
459 #endif
Definition: managed_surface.h:51
const Common::String & getTitle() const
Definition: macwindow.h:320
Definition: str.h:59
Definition: font.h:83
Definition: macwindow.h:203
int getBorderType() const
Definition: macwindow.h:377
Definition: rect.h:524
Definition: stream.h:745
ManagedSurface * getWindowSurface()
Definition: macwindow.h:123
void setCallback(bool(*callback)(WindowClick, Common::Event &, void *), void *data)
Definition: macwindow.h:177
Definition: macwindowmanager.h:147
Definition: macwindowborder.h:57
ManagedSurface * getBorderSurface() override
Definition: macwindow.h:279
const Common::Rect & getInnerDimensions() override
Definition: macwindow.h:278
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:106
int getId()
Definition: macwindow.h:93
WindowType getType()
Definition: macwindow.h:100
bool isDirty() override
Definition: macwindow.h:393
void setDraggable(bool draggable)
Definition: macwindow.h:183
void enableScrollbar(bool active)
Definition: macwindow.h:360
Definition: macwindow.h:78
Definition: macwindowborder.h:80