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 
29 namespace GUI {
30 
31 class CommandSender;
32 
34  friend class CommandSender;
35 protected:
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.
43 protected:
44  CommandReceiver *_target;
45 public:
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 
58 class Widget;
59 
60 class GuiObject : public CommandReceiver {
61  friend class Widget;
62 protected:
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 
72 public:
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 
106  virtual void handleMouseWheel(int x, int y, int direction) {};
107  virtual void handleTooltipUpdate(int x, int y) {};
108 protected:
109  virtual void releaseFocus() = 0;
110 };
111 
112 } // End of namespace GUI
113 
114 #endif
Definition: str.h:59
Definition: rect.h:144
Definition: system.h:46
Definition: object.h:60
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: object.h:33
Definition: widget.h:101
Definition: object.h:40