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