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  virtual ~MacWindow() {}
206 
212  void move(int x, int y);
213 
214  /*
215  * Change the width and the height of the window (outer dimensions).
216  * @param w New width of the window.
217  * @param h New height of the window.
218  */
219  virtual void resize(int w, int h);
220 
221  /*
222  * Change the width and the height of the inner window.
223  * @param w New width of the window.
224  * @param h New height of the window.
225  */
226  virtual void resizeInner(int w, int h);
227 
234  void setDimensions(const Common::Rect &r) override;
235 
242  void setInnerDimensions(const Common::Rect &r);
243 
248  void setBackgroundPattern(int pattern);
249 
255  bool draw(ManagedSurface *g, bool forceRedraw = false) override;
256 
257  bool draw(bool forceRedraw = false) override;
258  void blit(ManagedSurface *g, Common::Rect &dest) override;
259 
260  const Common::Rect &getInnerDimensions() override { return _innerDims; }
261  ManagedSurface *getBorderSurface() override { return &_borderSurface; }
262 
267  void center(bool toCenter = true);
268 
274  void setActive(bool active) override;
279  bool isActive() const;
280 
285  void setTitle(const Common::String &title);
286 
291  virtual void setTitleVisible(bool visible);
292 
296  bool isTitleVisible();
297 
302  const Common::String &getTitle() const { return _title; };
303 
309  void setHighlight(WindowClick highlightedPart);
315  void setScroll(float scrollPos, float scrollSize);
319  bool processEvent(Common::Event &event) override;
320  bool hasAllFocus() override { return _beingDragged || _beingResized; }
321 
333  void loadBorder(Common::SeekableReadStream &file, uint32 flags, int lo = -1, int ro = -1, int to = -1, int bo = -1);
334  void loadBorder(Common::SeekableReadStream &file, uint32 flags, BorderOffsets offsets);
335  void setBorder(Graphics::ManagedSurface *surface, uint32 flags, BorderOffsets offsets);
336  void disableBorder();
337  void loadInternalBorder(uint32 flags);
342  void enableScrollbar(bool active) { _hasScrollBar = active; }
343 
348  void setCloseable(bool closeable);
349 
354  void setBorderType(int borderType);
359  int getBorderType() const { return _borderType; };
360 
366  uint32 getBorderFlags() const;
367 
368  void addDirtyRect(const Common::Rect &r);
369  void markAllDirty();
370  void mergeDirtyRects();
371 
372  bool isDirty() override { return _borderIsDirty || _contentIsDirty; }
373 
374  void setBorderDirty(bool dirty) { _borderIsDirty = true; }
375  void resizeBorderSurface();
376 
377  void setMode(uint32 mode) { _mode = mode; }
378  void setBorderOffsets(BorderOffsets &offsets) { _macBorder.setOffsets(offsets); }
379 
380  void updateInnerDims();
381 
382 private:
383  void rebuildSurface(); // Propagate dimensions change and recreate patter/borders, etc.
384  void drawBorderFromSurface(ManagedSurface *g, uint32 flags);
385  void drawPattern();
386  void drawBox(ManagedSurface *g, int x, int y, int w, int h);
387  void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
388  const Font *getTitleFont();
389  void updateOuterDims();
390 
391  bool isInCloseButton(int x, int y) const;
392  bool isInResizeButton(int x, int y) const;
393  WindowClick isInScroll(int x, int y) const;
394 
395 protected:
396  void drawBorder();
397  WindowClick isInBorder(int x, int y) const;
398  BorderOffsets getBorderOffsets() const { return _macBorder.getOffset(); }
399 
400 protected:
401  ManagedSurface _borderSurface;
402 
403  bool _borderIsDirty;
404  Common::Rect _innerDims;
405 
406  Common::List<Common::Rect> _dirtyRects;
407  bool _hasScrollBar;
408 
409  uint32 _mode;
410 private:
411  MacWindowBorder _macBorder;
412 
413  int _pattern;
414  bool _hasPattern;
415 
416  bool _scrollable;
417  bool _resizable;
418 
419  bool _closeable;
420  bool _isTitleVisible;
421 
422  int _borderWidth;
423 
424  bool _beingDragged, _beingResized;
425  int _draggedX, _draggedY;
426 
427  WindowClick _highlightedPart;
428 
429  Common::String _title;
430  Common::String _shadowedTitle;
431 
432  int _borderType;
433 };
434 
435 } // End of namespace Graphics
436 
437 #endif
Definition: managed_surface.h:51
const Common::String & getTitle() const
Definition: macwindow.h:302
Definition: str.h:59
Definition: font.h:83
Definition: macwindow.h:192
int getBorderType() const
Definition: macwindow.h:359
Definition: rect.h:144
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:149
Definition: macwindowborder.h:57
ManagedSurface * getBorderSurface() override
Definition: macwindow.h:261
const Common::Rect & getInnerDimensions() override
Definition: macwindow.h:260
Definition: events.h:199
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:372
void enableScrollbar(bool active)
Definition: macwindow.h:342
Definition: macwindow.h:73
Definition: macwindowborder.h:75