ScummVM API documentation
object.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef BAGEL_BAGLIB_OBJECT_H
24 #define BAGEL_BAGLIB_OBJECT_H
25 
26 #include "bagel/spacebar/baglib/expression.h"
27 #include "bagel/spacebar/baglib/res.h"
28 #include "bagel/spacebar/boflib/gfx/bitmap.h"
29 #include "bagel/boflib/string.h"
30 #include "bagel/spacebar/baglib/parse_object.h"
31 
32 namespace Bagel {
33 namespace SpaceBar {
34 
35 class CBagObject;
36 typedef void *(*BagFuncPtr)(int, void *);
37 
38 enum BagObjectType {
39  BASE_OBJ = 0x0000,
40  BMP_OBJ = BOF_BMP_OBJ,
41  SPRITE_OBJ = BOF_SPRITE_OBJ,
42  BUTTON_OBJ = BOF_BUTTON_OBJ,
43  SOUND_OBJ = BOF_SOUND_OBJ,
44  LINK_OBJ = BOF_LINK_OBJ,
45  TEXT_OBJ = BOF_TEXT_OBJ,
46  CHAR_OBJ = BOF_CHAR_OBJ,
47  VAR_OBJ = BOF_VAR_OBJ,
48  AREA_OBJ = BOF_AREA_OBJ,
49  EXPRESS_OBJ = BOF_EXPRESS_OBJ,
50  COMMAND_OBJ = BOF_COMM_OBJ,
51  MOVIE_OBJ = BOF_MOVIE_OBJ,
52  THING_OBJ = BOF_THING_OBJ,
53  RESPRNT_OBJ = BOF_RESPRNT_OBJ,
54  DOSSIER_OBJ = BOF_DOSSIER_OBJ,
55  USER_OBJ = 0x1000
56 };
57 
58 enum BAG_OBJECT_PROPERTIES {
59  NONE = 0x0000,
60  MOVABLE = 0x0001,
61  MODAL = 0x0002,
62  VISIBLE = 0x0004,
63  HIGHLIGHT = 0x0008,
64  ACTIVE = 0x0010,
65  TRANSPAR = 0x0020,
66  HIDEONCLK = 0x0040,
67  IMRUN = 0x0080,
68  LOCAL = 0x0100,
69  NEGATIVE = 0x0200,
70  CONUPDATE = 0x0400,
71  STRETCH = 0x0800,
72  TIMELESS = 0x1000,
73  FLOATING = 0x2000,
74  PRELOAD = 0x4000,
75  FOREGROUND = 0x8000
76 };
77 
78 class CBagMenu;
79 class CBagStorageDev;
80 
81 CBofString getStringTypeOfObject(BagObjectType n);
82 
86 class CBagObject : public CBagParseObject, public CBofObject, public CBofError {
87 private:
88  CBofString _sFileName; // File name contain object look/feel data
89  CBofString *_psName = nullptr; // Name of this object, needed by movable objects only, it equals file name unless specified.
90  CBagMenu *_pMenu = nullptr; // Menu for the object
91  CBagExpression *_pEvalExpr = nullptr; // Pointer to expression to be evaluated by
92  CBofString _emptyString;
93 
94  int16 _nState = 0; // Current state of the object
95  uint16 _nId = 0; // Ref Id for an object
96 
97 protected:
98  uint16 _xObjType = AREA_OBJ;
99 
100 private:
101  uint16 _nProperties = 0; // Properties of object
102 
103  int16 _nX = 0; // Replaces _xPosition
104  int16 _nY = 0;
105 
106  byte _nOverCursor = 0; // Ref Id for the objects over cursor
107  byte _bDirty : 1; // Object needs redrawing or not?
108  byte _bMsgWaiting : 1; // Event needing to be played?
109  byte _bAlwaysUpdate : 1; // For message light
110  byte _bNoMenu : 1; // Used by AS NOMENU
111 
112 protected:
113  byte _bInteractive = 0;
114 
115  // Object property functionality
116  bool isProperty(BAG_OBJECT_PROPERTIES xProp) {
117  return _nProperties & xProp;
118  }
119 
120  void setProperty(BAG_OBJECT_PROPERTIES xProp, bool bVal);
121 
122 public:
123  CBagObject();
124  virtual ~CBagObject();
125 
126  bool isInteractive() {
127  return _bInteractive;
128  }
129  void setInteractive(bool b) {
130  _bInteractive = (byte)b;
131  }
132 
133  // Callback function functionality - probably can be phased out
134  virtual bool runCallBack() {
135  return false;
136  }
137 
138  virtual BagFuncPtr getCallBack() {
139  return nullptr;
140  }
141 
142  // Run Object is called when there is no callback and the item was selected
143  virtual bool runObject();
144 
145  void setExpression(CBagExpression *pExpr) {
146  _pEvalExpr = pExpr;
147  }
148  CBagExpression *getExpression() const {
149  return _pEvalExpr;
150  }
151 
152  // Return true if the Object had members that are properly initialized/de-initialized
153  ErrorCode attach() override;
154  ErrorCode detach() override;
155 
156  BagObjectType getType() {
157  return (BagObjectType)_xObjType;
158  }
159  void setType(BagObjectType nType) {
160  _xObjType = (uint16)nType;
161  }
162 
163  // Object can be moved within a screen
164  virtual bool isInside(const CBofPoint &xPoint) {
165  return getRect().ptInRect(xPoint);
166  }
167 
168  // Object can be moved within a screen
169  bool isMovable() {
170  return isProperty(MOVABLE);
171  }
172  void setMovable(bool b = true) {
173  setProperty(MOVABLE, b);
174  }
175  // Object can be stretched within a screen
176  bool isStretchable() {
177  return isProperty(STRETCH);
178  }
179  void setStretchable(bool b = true) {
180  setProperty(STRETCH, b);
181  }
182  // Object has exclusive updates to a screen
183  bool isModal() {
184  return isProperty(MODAL);
185  }
186  void setModal(bool b = true) {
187  setProperty(MODAL, b);
188  }
189  virtual bool isModalDone() {
190  return true;
191  }
192  // Is object visible within scene
193  bool isVisible() {
194  return isProperty(VISIBLE);
195  }
196  void setVisible(bool b = true) {
197  setProperty(VISIBLE, b);
198  }
199  // Should object be highlighted when the mouse is over
200  bool isHighlight() {
201  return isProperty(HIGHLIGHT);
202  }
203  void setHighlight(bool b = true) {
204  setProperty(HIGHLIGHT, b);
205  }
206  // Is the object active in this world
207  bool isActive() {
208  return isProperty(ACTIVE);
209  }
210  void setActive(bool b = true) {
211  setProperty(ACTIVE, b);
212  }
213  // Is the object has a transparent background
214  bool isTransparent() {
215  return isProperty(TRANSPAR);
216  }
217 
218  virtual void setTransparent(bool b = true) {
219  setProperty(TRANSPAR, b);
220  }
221  // Should the object be hidden when clicked on
222  bool isHideOnClick() {
223  return isProperty(HIDEONCLK);
224  }
225  void setHideOnClick(bool b = true) {
226  setProperty(HIDEONCLK, b);
227  }
228  // Should the object run and then be destroyed after the attach
229  bool isImmediateRun() {
230  return isProperty(IMRUN);
231  }
232  void setImmediateRun(bool b = true) {
233  setProperty(IMRUN, b);
234  }
235  // Is the object currently local to the object
236  bool isLocal() {
237  return isProperty(LOCAL);
238  }
239  void setLocal(bool b = true) {
240  setProperty(LOCAL, b);
241  }
242  // Is the object expression negative
243  bool isNegative() {
244  return isProperty(NEGATIVE);
245  }
246  void setNegative(bool b = true) {
247  setProperty(NEGATIVE, b);
248  }
249  // Should the object be constantly updated, even when not on screen
250  bool isConstantUpdate() {
251  return isProperty(CONUPDATE);
252  }
253  void setConstantUpdate(bool b = true) {
254  setProperty(CONUPDATE, b);
255  }
256  // Does this objects action take up time
257  bool isTimeless() {
258  return isProperty(TIMELESS);
259  }
260 
261  void setTimeless(bool b = true);
262  // Does this objects have a set position/or should the sdev provide one when it is attached
263  bool isFloating() {
264  return isProperty(FLOATING);
265  }
266  void setFloating(bool b = true) {
267  setProperty(FLOATING, b);
268  }
269  // Does this objects have a set position/or should the sdev provide one when it is attached
270  bool isPreload() {
271  return isProperty(PRELOAD);
272  }
273  void setPreload(bool b = true) {
274  setProperty(PRELOAD, b);
275  }
276  // Does this objects have a set position/or should the sdev provide one when it is attached
277  bool isForeGround();
278  void setForeGround(bool b = true);
279  int getProperties();
280  void setProperties(int nProperties);
281 
282  // Init variables
283  virtual const CBofString *getInitInfo() const;
284  virtual void setInitInfo(const CBofString &) {
285  }
286  virtual int getProperty(const CBofString &sProp);
287  virtual void setProperty(const CBofString &, int nVal);
288 
289  bool isDirty() {
290  return _bDirty != 0;
291  }
292 
293  void setDirty(bool b = true) {
294  _bDirty = (byte)b;
295  }
296 
297  // If this thing is getting purged but is awaiting playback, then mark it as such.
298  bool isMsgWaiting() {
299  return _bMsgWaiting != 0;
300  }
301 
302  void setMsgWaiting(bool b = true) {
303  _bMsgWaiting = (byte)b;
304  }
305 
306  bool isAlwaysUpdate() {
307  return _bAlwaysUpdate != 0;
308  }
309 
310  void setAlwaysUpdate(bool b = true) {
311  _bAlwaysUpdate = (byte)b;
312  }
313 
314  bool isNoMenu() {
315  return _bNoMenu;
316  }
317 
318  void setNoMenu(bool b = true) {
319  _bNoMenu = (byte)b;
320  }
321 
322  virtual CBofPoint getPosition();
323  virtual int getRefId();
324  virtual int getOverCursor();
325  virtual int getState();
326  virtual CBofRect getRect();
327  virtual const CBofString &getFileName();
328  CBagMenu *getMenuPtr();
329  virtual const CBofString &getRefName();
330  virtual void setRefName(const CBofString &s);
331  virtual void setFileName(const CBofString &s);
332  virtual void setSize(const CBofSize &) {
333  }
334  virtual void setRefId(int id);
335  virtual void setOverCursor(int curs);
336  virtual void setState(int state);
337  virtual void setMenuPtr(CBagMenu *pm);
338  virtual void setPosition(const CBofPoint &pos);
339 
346  ParseCodes setInfo(CBagIfstream &istr) override;
347 
348  virtual ErrorCode update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcRect = nullptr, int /*nMaskColor*/ = -1);
349  virtual bool onObjInteraction(CBagObject * /*pObj*/, CBagStorageDev * /*pSDev*/);
350  virtual void onLButtonDown(uint32 /*nFlags*/, CBofPoint */*xPoint*/, void * = nullptr) {
351  }
352  virtual void onLButtonUp(uint32 /*nFlags*/, CBofPoint */*xPoint*/, void * = nullptr); // run menu if available
353  virtual bool onMouseMove(uint32 /*nFlags*/, CBofPoint /*xPoint*/, void * = nullptr);
354  virtual bool onMouseOver(uint32 /*nFlags*/, CBofPoint /*xPoint*/, void * = nullptr);
355 };
356 
357 inline void CBagObject::setFileName(const CBofString &s) {
358  _sFileName = s;
359 }
360 
361 inline void CBagObject::setMenuPtr(CBagMenu *pm) {
362  _pMenu = pm;
363 }
364 
365 } // namespace SpaceBar
366 } // namespace Bagel
367 
368 #endif
Definition: ifstream.h:32
Definition: object.h:28
Definition: size.h:32
Definition: parse_object.h:48
Definition: object.h:86
Definition: rect.h:35
Definition: menu_dlg.h:32
Definition: error.h:52
Definition: string.h:38
Definition: afxwin.h:27
Definition: expression.h:33
Definition: point.h:32
ParseCodes setInfo(CBagIfstream &istr) override
Definition: storage_dev_win.h:79
Definition: bitmap.h:57