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
34namespace Graphics {
35
36class MacWindowManager;
37class MacWindowBorder;
38class MacWidget;
39
40namespace MacWindowConstants {
41enum WindowType {
42 kWindowUnknown,
43 kWindowWindow,
44 kWindowMenu
45};
46
47enum {
48 kBorderWidth = 17,
49 kWindowMinWidth = 70,
50 kWindowMinHeight = 70
51};
52
53enum 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
70enum {
71 kWindowModeDynamicScrollbar = 1 << 0
72};
73}
74using namespace MacWindowConstants;
75
80class BaseMacWindow : public MacWidget {
81public:
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() override { return _editable; }
109
114 virtual void setVisible(bool visible, bool silent = false);
119 bool isVisible();
120
125 ManagedSurface *getWindowSurface() { return _composeSurface; }
126
132
140 virtual const Common::Rect &getInnerDimensions() = 0;
141
147 bool draw(bool forceRedraw = false) override = 0;
148
156 bool draw(ManagedSurface *g, bool forceRedraw = false) override = 0;
157
165 bool processEvent(Common::Event &event) override = 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
187protected:
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
205class MacWindow : public BaseMacWindow {
206public:
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
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
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 = dirty; }
398 void setContentDirty(bool dirty) { _contentIsDirty = dirty; }
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
407private:
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
420protected:
421 void drawBorder();
422 WindowClick isInBorder(int x, int y) const;
423
424protected:
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;
434private:
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
void clear()
Definition: list.h:245
Definition: stream.h:745
Definition: str.h:59
Definition: macwindow.h:80
virtual ManagedSurface * getBorderSurface()=0
bool draw(bool forceRedraw=false) override=0
virtual const Common::Rect & getInnerDimensions()=0
BaseMacWindow(int id, bool editable, MacWindowManager *wm)
int getId()
Definition: macwindow.h:95
ManagedSurface * getWindowSurface()
Definition: macwindow.h:125
void setCallback(bool(*callback)(WindowClick, Common::Event &, void *), void *data)
Definition: macwindow.h:179
bool isEditable() override
Definition: macwindow.h:108
WindowType getType()
Definition: macwindow.h:102
bool draw(ManagedSurface *g, bool forceRedraw=false) override=0
bool processEvent(Common::Event &event) override=0
virtual void setVisible(bool visible, bool silent=false)
virtual bool isDirty()=0
void setDraggable(bool draggable)
Definition: macwindow.h:185
Definition: macwidget.h:39
void setOffsets(int left, int right, int top, int bottom)
BorderOffsets & getOffset()
Definition: macwindow.h:205
void setActive(bool active) override
void setInnerDimensions(const Common::Rect &r)
const Common::String & getTitle() const
Definition: macwindow.h:322
bool draw(bool forceRedraw=false) override
MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm)
const Common::Rect & getInnerDimensions() override
Definition: macwindow.h:280
void loadBorder(Common::SeekableReadStream &file, uint32 flags, int lo=-1, int ro=-1, int to=-1, int bo=-1)
void center(bool toCenter=true)
void setCloseable(bool closeable)
MacWindow(const MacWindow &source)
void setDimensions(const Common::Rect &r) override
void setHighlight(WindowClick highlightedPart)
int getBorderType() const
Definition: macwindow.h:379
ManagedSurface * getBorderSurface() override
Definition: macwindow.h:281
void enableScrollbar(bool active)
Definition: macwindow.h:362
bool isActive() const
void setScroll(float scrollPos, float scrollSize)
void setBorderType(int borderType)
bool draw(ManagedSurface *g, bool forceRedraw=false) override
bool isDirty() override
Definition: macwindow.h:395
void move(int x, int y)
void setBackgroundPattern(int pattern)
bool processEvent(Common::Event &event) override
virtual void setTitleVisible(bool visible)
uint32 getBorderFlags() const
void setTitle(const Common::String &title)
Definition: macwindowmanager.h:149
Definition: managed_surface.h:51
Definition: formatinfo.h:28
Definition: events.h:218
Definition: rect.h:536
Definition: macwindowborder.h:57