ScummVM API documentation
storage_dev_win.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_STORAGE_DEV_WIN_H
24 #define BAGEL_BAGLIB_STORAGE_DEV_WIN_H
25 
26 #include "bagel/spacebar/boflib/gui/dialog.h"
27 #include "bagel/spacebar/boflib/list.h"
28 #include "bagel/spacebar/baglib/object.h"
29 #include "bagel/spacebar/baglib/save_game_file.h"
30 
31 namespace Bagel {
32 namespace SpaceBar {
33 
34 #define SDEV_UNDEF 00
35 #define SDEV_WND 11
36 #define SDEV_DLG 22
37 #define SDEV_BMP 33
38 #define SDEV_PDA 44
39 #define SDEV_WIELD 55
40 #define SDEV_CLOSEP 66
41 #define SDEV_GAMEWIN 77
42 #define SDEV_ZOOMPDA 88
43 
47 class CResource {
48 private:
49  const char *_lpszResourceName;
50  uint32 _nResId;
51 
52 public:
53  CResource() {
54  _lpszResourceName = nullptr;
55  _nResId = 0;
56  }
57 
58  void setResource(const char *lpszResourceName) {
59  _lpszResourceName = lpszResourceName;
60  }
61  void setResource(uint32 nResId) {
62  _nResId = nResId;
63  }
64  const char *getResourceName() const {
65  return _lpszResourceName;
66  }
67  uint32 getResourceId() const {
68  return _nResId;
69  }
70 };
71 
72 // Filter function function prototype.
73 typedef bool (*FilterFunction)(uint16 nFilterId, CBofBitmap *, CBofRect *);
74 
80 public:
81  enum MouseActivity {
82  kMouseNONE = 0x0000, kMouseDRAGGING = 0x0001
83  };
84 
85 private:
86  CBofString _sName; // Name of this storage device
87  CBofString _sBackgroundName; // Name of this storage devices background
88  CBofString _sPrevSDev; // Name of the previous storage device
89 
90  CBofRect _cDestRect; // Position of storage device
91  CBofPoint _xPrevLocation; // Previous view location in bmp.
92 
93  CBagObject *_pLActiveObject; // The last object selected on mouse down
94  // CBagObject *_pRActiveObject; // The last object selected on mouse down
95 
96  CBofList<CBagObject *> *_pObjectList; // Objects to be painted to the pan
97  CBofList<CBagExpression *> *_pExpressionList; // Condition for painting to the pan
98 
99  CBofWindow *_pAssociateWnd; // Sounds need a window
100 
101  MouseActivity _nCurrMouseActivity; // What is up with the mouse currently
102 
103  uint16 _nExitOnEdge; // Non zero if SDev should be closed when an outside edge is clicked on, and and prev sdev is set, _nExitOnEdge is the thickness of the edge
104 
105  uint16 _nFilterId; // Filter id number 0 for normal view
106  uint16 _nFadeId; // Fade id number 0 for no fade in
107  uint16 _nDiskID;
108 
109 protected:
110  uint16 _xSDevType; // Type of storage device
111  static CBofPoint *_xCursorLocation; // Current cursor location in bmp.
112  static CBofRect *gRepaintRect;
113  static bool _bHandledUpEvent; // Hack to stop
114  static bool _hidePdaFl;
115  FilterFunction _pBitmapFilter; // Pointer to the bitmap filter.
116 
117  bool _bForeignList : true; // True if setObjectList has been called
118  bool _bCloseOnOpen : true; // True if other SDev should be closed when this is opened
119  bool _bCloseup : true; // true if is a closeup (includes CIC, or CHAT)
120  bool _bCIC : true; // true if is a CIC
121  bool _bCustom : true; // true if is a hand coded closeup
122  bool _bFirstPaint : true; // run object stuff
123 
124  static bool _bPanPreFiltered; // Let pda know if screens been prefiltered
125  static bool _bDirtyAllObjects; // Dirty all objects in prefilter?
126  static bool _bPreFilter;
127 
128  int _nFloatPages; // The number of pages required to display all floating objects
129 
130 public:
131  CBagStorageDev();
132  virtual ~CBagStorageDev();
133 
134  virtual ErrorCode preFilter(CBofBitmap *pBmp, CBofRect *pRect, CBofList<CBagObject *> *pList = nullptr);
135 
136  static void initialize();
137  static void shutdown();
138 
142  void makeListDirty(CBofList<CBagObject *> *pList);
143 
144  void setDiskID(uint16 nDiskID) {
145  _nDiskID = nDiskID;
146  }
147  uint16 getDiskID() const {
148  return _nDiskID;
149  }
150 
151  virtual ErrorCode setloadFilePos(const CBofPoint) {
152  return ERR_NONE;
153  }
154 
155  bool isCloseup() const {
156  return _bCloseup;
157  }
158  void setCloseup(bool b = true) {
159  _bCloseup = b;
160  }
161 
162  // Set true if sdef is "AS CIC"
163  bool isCIC();
164  void setCIC(bool b = true) {
165  _bCIC = b;
166  }
167 
168  // Set to true if this is a hand coded closeup
169  bool isCustom() const {
170  return _bCustom;
171  }
172  void setCustom(bool b = true) {
173  _bCustom = b;
174  }
175 
176  int getDeviceType() const {
177  return _xSDevType;
178  }
179 
180  int getObjectCount();
181  CBagObject *getObjectByPos(int nIndex);
182  CBagObject *getObject(int nRefId, bool bActiveOnly = false);
183  CBagObject *getObject(const CBofPoint &xPoint, bool bActiveOnly = false);
184  CBagObject *getObject(const CBofString &sName, bool bActiveOnly = false);
185  CBagObject *getObjectByType(const CBofString &sType, bool bActiveOnly = false);
186 
187  static CBofPoint &getLastCursorLocation() {
188  return *_xCursorLocation;
189  }
190  CBofList<CBagObject *> *getObjectList() const {
191  return _pObjectList;
192  }
193  void setObjectList(CBofList<CBagObject *> *pOList, CBofList<CBagExpression *> *pEList = nullptr);
194 
195  bool contains(CBagObject *pObj, bool bActive = true);
196 
197  // virtual CBofRect getLocation() { return CBofRect(); }
198  virtual CBofRect getRect() {
199  return _cDestRect;
200  }
201 
202  virtual void setRect(const CBofRect &xRect) {
203  _cDestRect = xRect;
204  }
205 
206  virtual CBofPoint getPosition() {
207  return _cDestRect.topLeft();
208  }
209 
210  virtual void setPosition(const CBofPoint &pos);
211 
212  virtual ErrorCode addObject(CBagObject *pObj, int nPos = 0); // Add a new object
213  virtual ErrorCode activateLocalObject(CBagObject *pObj);
214  virtual ErrorCode activateLocalObject(const CBofString &sName);
215  virtual ErrorCode attachActiveObjects();
216 
217  virtual ErrorCode removeObject(CBagObject *pRObj);
218  virtual ErrorCode deactivateLocalObject(CBagObject *pObj);
219  virtual ErrorCode deactivateLocalObject(const CBofString &sName);
220  virtual ErrorCode detachActiveObjects();
221 
222  virtual void setHelpFilename(const CBofString &) {
223  }
224 
225  const CBofString &getName() const {
226  return _sName;
227  }
228  void setName(const CBofString &str) {
229  _sName = str;
230  }
231 
232  void setFilterId(uint16 nId) {
233  _nFilterId = nId;
234  }
235  uint16 getFilterId() const {
236  return _nFilterId;
237  }
238 
239  void setFadeId(uint16 nId) {
240  _nFadeId = nId;
241  }
242  uint16 getFadeId() const {
243  return _nFadeId;
244  }
245 
246  const CBofString &getPrevSDev() const {
247  return _sPrevSDev;
248  }
249  const CBofPoint getPrevLoc() const {
250  return _xPrevLocation;
251  }
252  void setPrevSDev(const CBofString &str) {
253  _sPrevSDev = str;
254  }
255 
256  bool getCloseOnOpen() const {
257  return _bCloseOnOpen;
258  }
259  void setCloseOnOpen(bool bVal) {
260  _bCloseOnOpen = bVal;
261  }
262 
263  uint16 getExitOnEdge() const {
264  return _nExitOnEdge;
265  }
266  void setExitOnEdge(uint16 nVal) {
267  _nExitOnEdge = nVal;
268  }
269 
270  CBagObject *getLActiveObject() const {
271  return _pLActiveObject;
272  }
273  // CBagObject* GetRActiveObject() { return _pRActiveObject; }
274  ErrorCode setLActiveObject(CBagObject *pObj) {
275  _pLActiveObject = pObj;
276  return ERR_NONE;
277  }
278 
279  virtual ErrorCode onLActiveObject(uint32 /*nFlags*/, CBofPoint */*xPoint*/, void * = nullptr);
280 
281  MouseActivity getLActivity() const {
282  return _nCurrMouseActivity;
283  }
284  void setLActivity(MouseActivity ma) {
285  _nCurrMouseActivity = ma;
286  }
287 
288  ErrorCode paintStorageDevice(CBofWindow *pWnd, CBofBitmap *pBmp = nullptr, CBofRect * = nullptr);
289 
290  // The associated window describes which window to get screen information from and
291  // where to paint objects and most importantly what info to send to the callbacks
292  virtual void setAssociateWnd(CBofWindow *pWnd) {
293  _pAssociateWnd = pWnd;
294  }
295  virtual CBofWindow *getAssociateWnd() {
296  return _pAssociateWnd;
297  }
298 
299  ParseCodes setInfo(CBagIfstream &fpInput) override; // This function call the pure virt set background
300 
301  virtual ErrorCode setBackground(CBofBitmap *pBmp) = 0; // This could be eliminated but is kept in to insure good class usage
302  virtual CBofBitmap *getBackground() = 0; // Think about it, you can figure this out
303  const CBofString &getBackgroundName() const {
304  return _sBackgroundName;
305  }
306 
307  ErrorCode attach() override; // This function attaches the background and necessary bitmaps
308  ErrorCode detach() override; // This function attaches the background and necessary bitmaps
309 
310  virtual ErrorCode close();
311 
312  virtual ErrorCode loadObjects();
313  virtual ErrorCode releaseObjects();
314  virtual ErrorCode noObjectsUnderMouse();
315 
316  virtual const CBofPoint devPtToViewPort(const CBofPoint &xPoint) {
317  return xPoint;
318  }
319  virtual const CBofPoint viewPortToDevPt(const CBofPoint &xPoint) {
320  return xPoint;
321  }
322 
323  virtual ErrorCode loadFile(const CBofString &sWldName);
324  virtual ErrorCode loadFileFromStream(CBagIfstream &fpInput, const CBofString &sWldName, bool bAttach = true);
325 
326  virtual void onMouseMove(uint32 /*nFlags*/, CBofPoint */*xPoint*/, void * = nullptr);
327  virtual ErrorCode onMouseOver(uint32 /*nFlags*/, CBofPoint */*xPoint*/, void * = nullptr);
328  virtual void onLButtonDown(uint32 /*nFlags*/, CBofPoint */*xPoint*/, void * = nullptr);
329  virtual void onLButtonUp(uint32 /*nFlags*/, CBofPoint */*xPoint*/, void * = nullptr);
330 
331  virtual ErrorCode onCursorUpdate(int /*nCurrObj*/) {
332  return ERR_NONE;
333  }
334  virtual CBagObject *onNewSpriteObject(const CBofString &sInit);
335  virtual CBagObject *onNewBitmapObject(const CBofString &sInit);
336  virtual CBagObject *onNewTextObject(const CBofString &sInit);
337  virtual CBagObject *onNewLinkObject(const CBofString &sInit);
338  virtual CBagObject *onNewRPObject(const CBofString &sInit);
339  virtual CBagObject *onNewEDObject(const CBofString &sInit);
340  virtual CBagObject *onNewDosObject(const CBofString &sInit);
341  virtual CBagObject *onNewSoundObject(const CBofString &sInit);
342  virtual CBagObject *onNewButtonObject(const CBofString &sInit);
343  virtual CBagObject *onNewCharacterObject(const CBofString &sInit);
344  virtual CBagObject *onNewMovieObject(const CBofString &);
345  virtual CBagObject *onNewCommandObject(const CBofString &sInit);
346  virtual CBagObject *onNewAreaObject(const CBofString &sInit);
347  virtual CBagObject *onNewExpressionObject(const CBofString &sInit);
348  virtual CBagObject *onNewVariableObject(const CBofString &sInit);
349  virtual CBagObject *onNewUserObject(const CBofString &sInit);
350  virtual CBagObject *onNewThingObject(const CBofString &sInit);
351 
352  // Call to arrange floating object, override to customize layout
353  virtual CBofPoint arrangeFloater(CBofPoint &nPos, CBagObject *pObj);
354 
355  // Set and Get the number of pages required to display all floating objects
356  int getNumFloatPages() const {
357  return _nFloatPages;
358  }
359  void setNumFloatPages(int nFloatPages) {
360  _nFloatPages = nFloatPages;
361  }
362 
363  // Correctly set the filter function for the storage device.
364  //
365  void onSetFilter(bool (*filterFunction)(uint16 nFilterId, CBofBitmap *, CBofRect *));
366 
367  // Get a pointer to the filter function
368  //
369  FilterFunction getFilter();
370 
371  // Predicate to test if this storage device is filtered.
372  //
373  bool isFiltered() const {
374  return _nFilterId != 0;
375  }
376 
377  // Provide a method to get at the above vars
378  static void setDirtyAllObjects(bool b) {
379  _bDirtyAllObjects = b;
380  }
381  static bool getDirtyAllObjects() {
382  return _bDirtyAllObjects;
383  }
384 
385  // Provide a method to let PDA know that it should update everything
386  static void setPreFiltered(bool b = true) {
387  _bPanPreFiltered = b;
388  }
389  static bool getPreFiltered() {
390  return _bPanPreFiltered;
391  }
392 
393  // We won't always call the prefilter, just when explicitly instructed to.
394  static bool preFilterPan() {
395  return _bPreFilter;
396  }
397  static void setPreFilterPan(bool b = true) {
398  _bPreFilter = b;
399  _bDirtyAllObjects = b;
400  }
401 };
402 
403 class CBagEventSDev;
404 
405 //
406 // CBagStorageDevWnd -
407 // CBagPanWindow is a window that contains a slide bitmap object. It has specialize
408 // functions for handling slide bitmaps and slide objects.
409 //
411 private:
412  //bool _bMadeSelection;
413  bool _bOnUpdate;
414  CBofBitmap *_pWorkBmp;
415  CBofString _sHelpFileName; // Name of the help file for this device
416 
417 public:
418  static CBagEventSDev *_pEvtSDev; // Pointer to the Event Storage Device
419 
421  virtual ~CBagStorageDevWnd();
422  static void initialize() {
423  _pEvtSDev = nullptr;
424  }
425 
426  ErrorCode attach() override; // This function attaches the background and necessary bitmaps
427  ErrorCode detach() override; // This function attaches the background and necessary bitmaps
428 
429  ErrorCode close() override;
430  virtual ErrorCode runModal(CBagObject *pObj);
431  void onTimer(uint32 nEventID) override;
432 
433  void setOnUpdate(bool bVal = true) {
434  _bOnUpdate = bVal;
435  }
436  bool getOnUpdate() const {
437  return _bOnUpdate;
438  }
439 
440  virtual ErrorCode paintScreen(CBofRect *pRect = nullptr);
441  virtual ErrorCode paintObjects(CBofList<CBagObject *> *list, CBofBitmap *pBmp,
442  CBofRect &viewOffsetRect, CBofList<CBofRect> * = nullptr, bool tempVar = true);
443 
444  virtual CBofRect getLocation() {
445  return getWindowRect();
446  }
447 
448  ErrorCode setBackground(CBofBitmap *pBmp) override;
449 
450  CBofBitmap *getBackground() override {
451  return getBackdrop();
452  }
453  virtual CBofBitmap *getWorkBmp() {
454  return _pWorkBmp;
455  }
456 
457  ErrorCode loadFile(const CBofString &sFile) override;
458 
459  virtual const CBofString &getHelpFilename() {
460  return _sHelpFileName;
461  }
462 
463  void setHelpFilename(const CBofString &s) override {
464  _sHelpFileName = s;
465  }
466 
467  virtual ErrorCode onRender(CBofBitmap *pBmp, CBofRect *pRect = nullptr);
468  void onPaint(CBofRect *) override;
469  void onMainLoop() override;
470  void onClose() override;
471  void onMouseMove(uint32 nFlags, CBofPoint *, void * = nullptr) override;
472  void onLButtonDown(uint32 nFlags, CBofPoint *point, void * = nullptr) override;
473  void onLButtonUp(uint32 nFlags, CBofPoint *point, void * = nullptr) override;
474 
475  void onKeyHit(uint32 lKey, uint32 nRepCount) override;
476 
477 protected:
478  virtual ErrorCode setWorkBmp();
479  virtual ErrorCode killWorkBmp();
480 };
481 
487 private:
488  //bool _bMadeSelection;
489  CBofString _sHelpFileName; // Name of the help file for this device
490 
491 public:
493 
494  virtual ErrorCode paintScreen(CBofRect *pRect = nullptr);
495  ErrorCode paintObjects(CBofList<CBagObject *> *list, CBofBitmap *pBmp,
496  CBofRect &viewOffsetRect, CBofList<CBofRect> * = nullptr, bool tempVar = true);
497  ErrorCode paintObjects(CBofList<CBagObject *> *list, CBofBitmap *pBmp) {
498  CBofRect emptyRect;
499  return paintObjects(list, pBmp, emptyRect);
500  }
501 
502  virtual CBofRect getLocation() {
503  return getWindowRect();
504  }
505 
506  ErrorCode setBackground(CBofBitmap *pBmp) override {
507  if (pBmp)
508  return setBackdrop(pBmp);
509 
510  killBackdrop();
511  return ERR_NONE;
512  }
513 
514  CBofBitmap *getBackground() override {
515  return getBackdrop();
516  }
517 
518  ErrorCode loadFile(const CBofString &sFile) override;
519 
520  ErrorCode create(const char *pszName, CBofRect *pRect, CBofWindow *pParent, uint32 nControlID = 0) override;
521 
522  ErrorCode attach() override; // This function attaches the background and necessary bitmaps
523 
524  ErrorCode close() override;
525 
526  virtual const CBofString &getHelpFilename() {
527  return _sHelpFileName;
528  }
529 
530  void setHelpFilename(const CBofString &s) override {
531  _sHelpFileName = s;
532  }
533 
534  void onMainLoop() override;
535  virtual ErrorCode onRender(CBofBitmap *pBmp, CBofRect *pRect = nullptr);
536 
537  void onPaint(CBofRect *) override;
538  void onClose() override;
539  void onMouseMove(uint32 nFlags, CBofPoint *, void * = nullptr) override;
540  void onLButtonDown(uint32 nFlags, CBofPoint *point, void * = nullptr) override;
541  void onLButtonUp(uint32 nFlags, CBofPoint *point, void * = nullptr) override;
542 };
543 
548 private:
549  static int nSDevMngrs;
550  CBofList<CBagStorageDev *> _xStorageDeviceList;
551 
552 public:
555 
556  ErrorCode registerStorageDev(CBagStorageDev *pSDev);
557  ErrorCode unregisterStorageDev(CBagStorageDev *pSDev);
558  ErrorCode releaseStorageDevices();
559 
560  int getObjectValue(const CBofString &sObject, const CBofString &sProperty);
561  void setObjectValue(const CBofString &sObject, const CBofString &sProperty, int nValue);
562 
563  int getNumStorageDevices() const {
564  return _xStorageDeviceList.getCount();
565  }
566 
567  CBagStorageDev *getStorageDevice(int nIndex) {
568  return _xStorageDeviceList[nIndex];
569  }
570  CBagStorageDev *getStorageDeviceContaining(const CBofString &sName);
571  CBagStorageDev *getStorageDeviceContaining(CBagObject *pObj);
572  CBagStorageDev *getStorageDevice(const CBofString &sName);
573  bool moveObject(const CBofString &sDstName, const CBofString &sSrcName, const CBofString &sObjName);
574  bool addObject(const CBofString &sDstName, const CBofString &sObjName);
575  bool removeObject(const CBofString &sSrcName, const CBofString &sObjName);
576 
577  void saveObjList(StObj *pObjList, int nNumEntries);
578  void restoreObjList(StObj *pObjList, int nNumEntries);
579 };
580 
581 extern bool g_allowPaintFl;
582 extern CBagStorageDevWnd *g_lastWindow;
583 
584 } // namespace SpaceBar
585 } // namespace Bagel
586 
587 #endif
Definition: event_sdev.h:31
Definition: ifstream.h:32
Definition: object.h:28
Definition: parse_object.h:48
Definition: window.h:53
Definition: object.h:86
Definition: rect.h:35
Definition: storage_dev_win.h:47
Definition: save_game_file.h:77
Definition: storage_dev_win.h:547
Definition: string.h:38
Definition: afxwin.h:27
Definition: storage_dev_win.h:486
Definition: point.h:32
Definition: storage_dev_win.h:410
Definition: storage_dev_win.h:79
Definition: list.h:60
Definition: dialog.h:39
Definition: bitmap.h:57