ScummVM API documentation
object.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 GUI_OBJECT_H
23#define GUI_OBJECT_H
24
25#include "common/scummsys.h"
26#include "common/str.h"
27#include "common/rect.h"
28
29namespace GUI {
30
31class CommandSender;
32
34 friend class CommandSender;
35protected:
36 virtual ~CommandReceiver() {}
37 virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {}
38};
39
41 // TODO - allow for multiple targets, i.e. store targets in a list
42 // and add methods addTarget/removeTarget.
43protected:
44 CommandReceiver *_target;
45public:
46 CommandSender(CommandReceiver *target) : _target(target) {}
47 virtual ~CommandSender() {}
48
49 void setTarget(CommandReceiver *target) { _target = target; }
50 CommandReceiver *getTarget() const { return _target; }
51
52 virtual void sendCommand(uint32 cmd, uint32 data) {
53 if (_target && cmd)
54 _target->handleCommand(this, cmd, data);
55 }
56};
57
58class Widget;
59
60class GuiObject : public CommandReceiver {
61 friend class Widget;
62protected:
63 Common::Rect _textDrawableArea;
64
65 int16 _x, _y;
66 uint16 _w, _h;
67 bool _useRTL;
68 const Common::String _name;
69
70 Widget *_firstWidget;
71
72public:
73 GuiObject(int x, int y, int w, int h, bool scale = false);
74 GuiObject(const Common::String &name);
75 ~GuiObject() override;
76
77 virtual void setTextDrawableArea(const Common::Rect &r) { _textDrawableArea = r; }
78
79 virtual void resize(int x, int y, int w, int h, bool scale = true);
80 virtual Widget *addChild(Widget *newChild);
81
82 virtual int16 getRelX() const { return _x; }
83 virtual int16 getRelY() const { return _y; }
84 virtual int16 getAbsX() const { return _x; }
85 virtual int16 getAbsY() const { return _y; }
86 virtual int16 getChildX() const { return getAbsX(); }
87 virtual int16 getChildY() const { return getAbsY(); }
88 virtual uint16 getWidth() const { return _w; }
89 virtual uint16 getHeight() const { return _h; }
90
91 virtual bool isVisible() const = 0;
92
93 virtual void reflowLayout();
94
95 virtual void removeWidget(Widget *widget);
96
97 virtual bool isPointIn(int x, int y) {
98 return (x >= _x && x < (_x + _w) && (y >= _y) && (y < _y + _h));
99 }
100
104 virtual Common::Rect getClipRect() const;
105
106protected:
107 virtual void handleMouseWheel(int x, int y, int direction) = 0;
108 virtual void releaseFocus() = 0;
109 virtual void registerTickleWidget(Widget *widget) = 0;
110 // As this function can be called from a widget destructor, don't make it pure virtual to avoid it
111 // being called when GuiObject destroys its widgets chain
112 virtual void unregisterTickleWidget(Widget *widget) {}
113};
114
115} // End of namespace GUI
116
117#endif
Definition: str.h:59
Definition: object.h:33
Definition: object.h:40
Definition: object.h:60
virtual Common::Rect getClipRect() const
Definition: widget.h:99
Definition: rect.h:536