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  kWindowMinWidth = 70,
50  kWindowMinHeight = 70
51 };
52 
53 enum WindowClick {
54  kBorderNone = 0,
55  kBorderScrollUp,
56  kBorderScrollDown,
57  kBorderScrollLeft,
58  kBorderScrollRight,
59  kBorderCloseButton,
60  kBorderInner,
61  kBorderBorder,
62  kBorderResizeButton,
63  kBorderActivate,
64  kBorderDeactivate,
65  kBorderDragged,
66  kBorderResized,
67  kBorderMaximizeButton,
68 };
69 
70 enum {
71  kWindowModeDynamicScrollbar = 1 << 0
72 };
73 }
74 using namespace MacWindowConstants;
75 
80 class BaseMacWindow : public MacWidget {
81 public:
88  BaseMacWindow(int id, bool editable, MacWindowManager *wm);
89  virtual ~BaseMacWindow() {}
90 
95  int getId() { return _id; }
96 
102  WindowType getType() { return _type; }
103 
108  bool isEditable() { return _editable; }
109 
114  virtual void setVisible(bool visible, bool silent = false);
119  bool isVisible();
120 
125  ManagedSurface *getWindowSurface() { return _composeSurface; }
126 
131  virtual ManagedSurface *getBorderSurface() = 0;
132 
140  virtual const Common::Rect &getInnerDimensions() = 0;
141 
147  virtual bool draw(bool forceRedraw = false) = 0;
148 
156  virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
157 
165  virtual bool processEvent(Common::Event &event) = 0;
166 
170  virtual bool isDirty() = 0;
171 
179  void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
180 
185  void setDraggable(bool draggable) { _draggable = draggable; }
186 
187 protected:
188  int _id;
189  WindowType _type;
190 
191  bool _editable;
192 
193  bool (*_callback)(WindowClick, Common::Event &, void *);
194  void *_dataPtr;
195 
196  bool _visible;
197 
198  bool _draggable;
199 };
200 
205 class MacWindow : public BaseMacWindow {
206 public:
217  MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
218 
224  MacWindow(const MacWindow &source);
225  virtual ~MacWindow() {}
226 
232  void move(int x, int y);
233 
234  /*
235  * Change the width and the height of the window (outer dimensions).
236  * @param w New width of the window.
237  * @param h New height of the window.
238  */
239  virtual void resize(int w, int h);
240 
241  /*
242  * Change the width and the height of the inner window.
243  * @param w New width of the window.
244  * @param h New height of the window.
245  */
246  virtual void resizeInner(int w, int h);
247 
254  void setDimensions(const Common::Rect &r) override;
255 
262  void setInnerDimensions(const Common::Rect &r);
263 
268  void setBackgroundPattern(int pattern);
269 
275  bool draw(ManagedSurface *g, bool forceRedraw = false) override;
276 
277  bool draw(bool forceRedraw = false) override;
278  void blit(ManagedSurface *g, Common::Rect &dest) override;
279 
280  const Common::Rect &getInnerDimensions() override { return _innerDims; }
281  ManagedSurface *getBorderSurface() override { return &_borderSurface; }
282 
287  void center(bool toCenter = true);
288 
294  void setActive(bool active) override;
299  bool isActive() const;
300 
305  void setTitle(const Common::String &title);
306 
311  virtual void setTitleVisible(bool visible);
312 
316  bool isTitleVisible();
317 
322  const Common::String &getTitle() const { return _title; };
323 
329  void setHighlight(WindowClick highlightedPart);
335  void setScroll(float scrollPos, float scrollSize);
339  bool processEvent(Common::Event &event) override;
340  bool hasAllFocus() override { return _beingDragged || _beingResized; }
341 
353  void loadBorder(Common::SeekableReadStream &file, uint32 flags, int lo = -1, int ro = -1, int to = -1, int bo = -1);
354  void loadBorder(Common::SeekableReadStream &file, uint32 flags, const BorderOffsets &offsets);
355  void setBorder(Graphics::ManagedSurface *surface, uint32 flags, const BorderOffsets &offsets);
356  void disableBorder();
357  void loadInternalBorder(uint32 flags);
362  void enableScrollbar(bool active) { _hasScrollBar = active; }
363 
368  void setCloseable(bool closeable);
369 
374  void setBorderType(int borderType);
379  int getBorderType() const { return _borderType; };
380 
386  uint32 getBorderFlags() const;
387 
388  void addDirtyRect(const Common::Rect &r);
389  void markAllDirty();
390  void mergeDirtyRects();
391  Common::Rect getDirtyRectBounds();
392  void clearDirtyRects() { _dirtyRects.clear(); }
393  Common::List<Common::Rect> &getDirtyRectList() { return _dirtyRects; }
394 
395  bool isDirty() override { return _borderIsDirty || _contentIsDirty; }
396 
397  void setBorderDirty(bool dirty) { _borderIsDirty = true; }
398  void setContentDirty(bool dirty) { _contentIsDirty = true; }
399  void resizeBorderSurface();
400 
401  void setMode(uint32 mode) { _mode = mode; }
402  void setBorderOffsets(BorderOffsets &offsets) { _macBorder.setOffsets(offsets); }
403  const BorderOffsets &getBorderOffsets() const { return _macBorder.getOffset(); }
404 
405  void updateInnerDims();
406 
407 private:
408  void rebuildSurface(); // Propagate dimensions change and recreate patter/borders, etc.
409  void drawBorderFromSurface(ManagedSurface *g, uint32 flags);
410  void drawPattern();
411  void drawBox(ManagedSurface *g, int x, int y, int w, int h);
412  void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
413  const Font *getTitleFont();
414  void updateOuterDims();
415 
416  bool isInCloseButton(int x, int y) const;
417  bool isInResizeButton(int x, int y) const;
418  WindowClick isInScroll(int x, int y) const;
419 
420 protected:
421  void drawBorder();
422  WindowClick isInBorder(int x, int y) const;
423 
424 protected:
425  ManagedSurface _borderSurface;
426 
427  bool _borderIsDirty;
428  Common::Rect _innerDims;
429 
430  Common::List<Common::Rect> _dirtyRects;
431  bool _hasScrollBar;
432 
433  uint32 _mode;
434 private:
435  MacWindowBorder _macBorder;
436 
437  int _pattern;
438  bool _hasPattern;
439 
440  bool _scrollable;
441  bool _resizable;
442 
443  bool _closeable;
444  bool _isTitleVisible;
445 
446  int _borderWidth;
447 
448  bool _beingDragged, _beingResized;
449  int _draggedX, _draggedY;
450 
451  WindowClick _highlightedPart;
452 
453  Common::String _title;
454  Common::String _shadowedTitle;
455 
456  int _borderType;
457 };
458 
459 } // End of namespace Graphics
460 
461 #endif
Definition: managed_surface.h:51
const Common::String & getTitle() const
Definition: macwindow.h:322
Definition: str.h:59
Definition: font.h:83
Definition: macwindow.h:205
int getBorderType() const
Definition: macwindow.h:379
Definition: rect.h:524
Definition: stream.h:745
ManagedSurface * getWindowSurface()
Definition: macwindow.h:125
void setCallback(bool(*callback)(WindowClick, Common::Event &, void *), void *data)
Definition: macwindow.h:179
Definition: macwindowmanager.h:147
Definition: macwindowborder.h:57
ManagedSurface * getBorderSurface() override
Definition: macwindow.h:281
const Common::Rect & getInnerDimensions() override
Definition: macwindow.h:280
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:108
int getId()
Definition: macwindow.h:95
WindowType getType()
Definition: macwindow.h:102
bool isDirty() override
Definition: macwindow.h:395
void setDraggable(bool draggable)
Definition: macwindow.h:185
void enableScrollbar(bool active)
Definition: macwindow.h:362
Definition: macwindow.h:80
Definition: macwindowborder.h:81