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