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 OBJECT_H
23 #define OBJECT_H
24 
25 #include "common/array.h"
26 #include "common/hash-str.h"
27 #include "common/hashmap.h"
28 #include "common/ptr.h"
29 #include "common/rect.h"
30 #include "common/scummsys.h"
31 #include "common/stream.h"
32 
33 namespace Graphics {
34 struct Surface;
35 class ManagedSurface;
36 } // namespace Graphics
37 
38 namespace AGDS {
39 
40 class AGDSEngine;
41 struct Region;
42 using RegionPtr = Common::SharedPtr<Region>;
43 class Animation;
44 using AnimationPtr = Common::SharedPtr<Animation>;
45 
46 class Object {
47 public:
49 
50  struct StringEntry {
51  Common::String string;
52  uint16 flags;
53 
54  StringEntry() : string(), flags() {}
55  StringEntry(const Common::String &s, uint16 f) : string(s), flags(f) {}
56  };
57 
58 private:
63 
64  Common::String _name;
65  CodeType _code;
66  StringTableType _stringTable;
67  bool _stringTableLoaded;
68  KeyHandlersType _keyHandlers;
69  UseHandlersType _useHandlers;
70  ManagedSurfacePtr _picture;
71  ManagedSurfacePtr _rotatedPicture;
72  RegionPtr _region;
73  RegionPtr _trapRegion;
74  AnimationPtr _animation;
75  AnimationPtr _mouseCursor;
76  Common::Point _pos, _animationPos, _offset;
77  Common::Point _regionOffset;
78  Common::Rect _srcRect;
79  int _z;
80  int _rotation;
81  Common::String _text;
82  Common::String _title;
83  uint _clickHandler;
84  uint _examineHandler;
85  uint _userUseHandler;
86  uint _throwHandler;
87  uint _useOnHandler;
88  uint _trapHandler;
89  uint _handlerBD;
90  uint _handlerC1;
91  int _alpha;
92  int _scale;
93  uint _locked;
94  bool _alive;
95  bool _persistent;
96  bool _allowInitialise;
97  bool _ignoreRegion;
98  bool _v2;
99 
100 private:
101  void freeRotated();
102  void freePicture();
103  void createRotated();
104 
105 public:
106  Object(const Common::String &name, Common::SeekableReadStream &stream, bool v2);
107  ~Object();
108 
109  bool allowInitialise() const {
110  return _allowInitialise;
111  }
112  void allowInitialise(bool allow) {
113  _allowInitialise = allow;
114  }
115 
116  void persistent(bool persistent) {
117  _persistent = persistent;
118  }
119  bool persistent() const {
120  return _persistent;
121  }
122 
123  void ignoreRegion(bool ignoreRegion) {
124  _ignoreRegion = ignoreRegion;
125  }
126  bool ignoreRegion() const {
127  return _ignoreRegion;
128  }
129 
130  void readStringTable(unsigned resOffset, uint16 resCount);
131  const StringEntry &getString(uint16 index) const;
132  uint getStringTableSize() const { return _stringTable.size(); }
133 
134  const Common::String &getName() const { return _name; }
135 
136  const CodeType &getCode() const {
137  return _code;
138  }
139 
140  void setAnimation(const AnimationPtr &animation) {
141  _animation = animation;
142  }
143 
144  const AnimationPtr &getAnimation() const {
145  return _animation;
146  }
147 
148  void setAnimationPosition(Common::Point animationPos) {
149  _animationPos = animationPos;
150  }
151 
152  void setMouseCursor(const AnimationPtr &mouseCursor) {
153  _mouseCursor = mouseCursor;
154  freeRotated();
155  }
156 
157  const AnimationPtr &getMouseCursor() const {
158  return _mouseCursor;
159  }
160 
161  void setPicture(Graphics::ManagedSurface *);
162 
163  Graphics::ManagedSurface *getPicture() const {
164  return _rotatedPicture ? _rotatedPicture.get() : _picture.get();
165  }
166 
167  void rotate(int rot);
168  int rotation() const {
169  return _rotation;
170  }
171 
172  void generateRegion();
173  void generateRegion(Common::Rect rect);
174 
175  void regionOffset(Common::Point offset) {
176  _regionOffset = offset;
177  }
178 
179  void setAlpha(int alpha) {
180  if (alpha < 0)
181  alpha = 0;
182  if (alpha > 100)
183  alpha = 100;
184  _alpha = (100 - alpha) * 255 / 100;
185  }
186 
187  int alpha() const {
188  return _alpha;
189  }
190 
191  void scale(int scale) {
192  _scale = scale;
193  }
194 
195  int scale() const {
196  return _scale;
197  }
198 
199  void region(RegionPtr region);
200 
201  const RegionPtr &region() const {
202  return _region;
203  }
204 
205  void setClickHandler(uint ip) {
206  _clickHandler = ip;
207  }
208 
209  uint getClickHandler() const {
210  return _clickHandler;
211  }
212 
213  void setExamineHandler(uint ip) {
214  _examineHandler = ip;
215  }
216 
217  uint getExamineHandler() const {
218  return _examineHandler;
219  }
220 
221  void setUseHandler(const Common::String &name, uint ip) {
222  _useHandlers[name] = ip;
223  }
224 
225  uint getUseHandler(const Common::String &name) const {
226  return _useHandlers.getValOrDefault(name, 0); // use handler can never be 0
227  }
228 
229  void setUserUseHandler(uint ip) {
230  _userUseHandler = ip;
231  }
232 
233  void setThrowHandler(uint ip) {
234  _throwHandler = ip;
235  }
236 
237  void setUseOnHandler(uint ip) {
238  _useOnHandler = ip;
239  }
240 
241  uint getUserUseHandler() const {
242  return _userUseHandler;
243  }
244 
245  void setHandlerBD(uint ip) {
246  _handlerBD = ip;
247  }
248 
249  uint getHandlerBD() const {
250  return _handlerBD;
251  }
252 
253  void setHandlerC1(uint ip) {
254  _handlerC1 = ip;
255  }
256 
257  uint getHandlerC1() const {
258  return _handlerC1;
259  }
260 
261  void setTrapHandler(uint ip, RegionPtr region) {
262  _trapHandler = ip;
263  _trapRegion = region;
264  }
265 
266  RegionPtr getTrapRegion() const { return _trapRegion; }
267 
268  uint getTrapHandler() const { return _trapHandler; }
269 
270  void paint(AGDSEngine &engine, Graphics::Surface &backbuffer, Common::Point pos) const;
271 
272  void moveTo(Common::Point pos);
273 
274  void z(int z) {
275  _z = z;
276  }
277 
278  int z() const {
279  return _z;
280  }
281 
282  const Common::String &getText() const {
283  return _text;
284  }
285 
286  void setText(const Common::String &text) {
287  _text = text;
288  }
289 
290  void title(const Common::String &title) {
291  _title = title;
292  }
293 
294  const Common::String &title() const {
295  return _title;
296  }
297 
298  Common::Point getPosition() const {
299  return _pos - _offset;
300  }
301 
302  Common::Point getOffset() const {
303  return _offset;
304  }
305 
306  Common::Rect getRect() const;
307 
308  void setKeyHandler(const Common::String &name, uint ip) {
309  _keyHandlers[name] = ip;
310  }
311 
312  uint getKeyHandler(const Common::String &name) const {
313  KeyHandlersType::const_iterator i = _keyHandlers.find(name);
314  return i != _keyHandlers.end() ? i->_value : 0;
315  }
316 
317  uint throwHandler() const {
318  return _throwHandler;
319  }
320 
321  uint useOnHandler() const {
322  return _useOnHandler;
323  }
324 
325  bool locked() const {
326  return _locked != 0;
327  }
328  void lock();
329  void unlock();
330 
331  bool alive() const { return _alive; }
332 
333  void alive(bool value);
334 
335  void srcRect(Common::Rect srcRect) { _srcRect = srcRect; }
336 
337  bool pointIn(Common::Point pos);
338 };
340 
341 } // End of namespace AGDS
342 
343 #endif /* AGDS_OBJECT_H */
Definition: managed_surface.h:51
Definition: str.h:59
Definition: surface.h:67
Definition: object.h:46
Definition: rect.h:524
Definition: stream.h:745
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: agds.h:58
Definition: formatinfo.h:28
Definition: rect.h:144
size_type size() const
Definition: array.h:316
Definition: object.h:50
PointerType get() const
Definition: ptr.h:636
Definition: agds.h:81