ScummVM API documentation
castmember.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 DIRECTOR_CASTMEMBER_CASTMEMBER_H
23 #define DIRECTOR_CASTMEMBER_CASTMEMBER_H
24 
25 #include "common/rect.h"
26 
27 #include "director/archive.h"
28 #include "director/stxt.h"
29 
30 #include "director/lingo/lingo-object.h"
31 
32 namespace Graphics {
33 class MacWidget;
34 }
35 
36 namespace Common {
37 class SeekableReadStream;
38 class SeekableReadStreamEndian;
39 class MemoryWriteStream;
40 }
41 
42 namespace Director {
43 
44 struct CastMemberInfo;
45 class Channel;
46 struct Resource;
47 
48 class CastMember : public Object<CastMember> {
49 public:
50  CastMember(Cast *cast, uint16 castId, Common::SeekableReadStreamEndian &stream);
51  CastMember(Cast *cast, uint16 castId);
52  virtual ~CastMember() {}
53 
54  virtual CastMember *duplicate(Cast *cast, uint16 castId);
55 
56  Cast *getCast() { return _cast; }
57  uint16 getID() { return _castId; }
58  CastMemberInfo *getInfo();
59 
60  virtual void load();
61  virtual void unload();
62  bool isLoaded() { return _loaded; }
63 
64  virtual bool isEditable() { return false; }
65  virtual void setEditable(bool editable) {}
66  virtual bool isModified() { return _modified; }
67  virtual bool needsReload() { return _needsReload; }
68  void setModified(bool modified);
69  virtual Graphics::MacWidget *createWidget(Common::Rect &bbox, Channel *channel, SpriteType spriteType) { return nullptr; }
70  virtual void updateWidget(Graphics::MacWidget *widget, Channel *channel) {}
71  virtual void updateFromWidget(Graphics::MacWidget *widget, bool spriteEditable) {}
72  virtual Common::Rect getInitialRect() { return _initialRect; }
73 
74  virtual void setColors(uint32 *fgcolor, uint32 *bgcolor) { return; }
75  virtual uint32 getForeColor() { return 0; }
76  virtual void setForeColor(uint32 fgCol) { return; }
77  virtual uint32 getBackColor() { return 0; }
78  virtual void setBackColor(uint32 bgCol) { return; }
79 
80  bool hasProp(const Common::String &propName) override;
81  Datum getProp(const Common::String &propName) override;
82  void setProp(const Common::String &propName, const Datum &value, bool force = false) override;
83  bool hasField(int field) override;
84  Datum getField(int field) override;
85  void setField(int field, const Datum &value) override;
86 
87  // release the control to widget, this happens when we are changing sprites. Because we are having the new cast member and the old one shall leave
88  void releaseWidget() { _widget = nullptr; }
89 
90  virtual Common::String formatInfo() { return Common::String(); };
91 
92  // Return the default bounding box of the cast member. The origin is at the registration offset.
93  virtual Common::Rect getBbox();
94  // Return the bounding box of the cast member, assuming a stretched width and height value.
95  // The origin is at the registration offset.
96  virtual Common::Rect getBbox(int16 currentWidth, int16 currentHeight);
97  // Return the default registration offset. Offset is relative to the top-left corner of the widget.
98  virtual Common::Point getRegistrationOffset() { return Common::Point(0, 0); }
99  // Return the registration offset, assuming a stretched width and height value.
100  // Offset is relative to the top-left corner of the widget.
101  virtual Common::Point getRegistrationOffset(int16 currentWidth, int16 currentHeight) { return Common::Point(0, 0); }
102 
103  virtual CollisionTest isWithin(const Common::Rect &bbox, const Common::Point &pos, InkType ink) { return bbox.contains(pos) ? kCollisionYes : kCollisionNo; }
104 
105  // When writing the 'CASt' resource, the general structure is the same for all the CastMembers
106  // Three parts to a 'CASt' resource (header + _info_, _data_)
107  // The headers, are common, the _info_ writing is handled by the Cast class, so no worries there
108  // So, the only thing that differs is the _data_, for which we'll have separate implementations for each CastMember
109  uint32 writeCAStResource(Common::SeekableWriteStream *writeStream);
110  uint32 getCastInfoSize();
111  uint32 getCastResourceSize();
112  virtual void writeCastData(Common::SeekableWriteStream *writeStream);
113  virtual uint32 getCastDataSize();
114 
115  CastType _type;
116  Common::Rect _initialRect;
117  Common::Rect _boundingRect;
118  Common::Array<Resource> _children;
119 
120  bool _hilite;
121  bool _erase;
122  int _purgePriority;
123  uint32 _size;
124 
125  /* Data fields used when saving the Cast Member */
126  uint32 _castDataSize;
127  uint8 _flags1;
128  // This index is the index that it appears in the original movie archive
129  int16 _index;
130 
131 protected:
132  Cast *_cast;
133  // This is the id of the cast member, this id is unique to only cast members
134  // Basically the cast members are given ids starting from _castArrayStart to _castArrayEnd
135  // e.g. 0, 1, 2, 3, 4
136  uint16 _castId;
137  // a link to the widget we created, we may use it later
138  Graphics::MacWidget *_widget;
139  bool _loaded;
140  bool _modified;
141  bool _isChanged;
142  bool _needsReload;
143 };
144 
145 struct EditInfo {
146  Common::Rect rect;
147  int32 selStart;
148  int32 selEnd;
149  byte version;
150  byte rulerFlag;
151  bool valid;
152 
153  EditInfo(): valid(false) {}
154  void read(Common::ReadStreamEndian *stream);
155  void write(Common::WriteStream *stream);
156 
157  Common::String toString() {
158  return Common::String::format("rect: [%s] selStart: %d selEnd: %d version: %d rulerFlag: %d valid: %d",
159  rect.toString().c_str(), selStart, selEnd, version, rulerFlag, valid);
160  }
161 };
162 
164  // Header
165  uint32 unk1;
166  uint32 unk2;
167  uint32 flags;
168  uint16 count;
169  bool autoHilite;
170  uint32 scriptId;
171 
172  // List items
173  Common::String script; // 0 (removed on protecting)
174  Common::String name;
175  Common::String directory;
176  Common::String fileName;
177  Common::String fileType; // 4 pre-D5
178  Common::String propInit; // 4 post-D5
179  EditInfo scriptEditInfo; // 5 (removed on protecting)
180  FontStyle scriptStyle; // (removed on protecting)
181  EditInfo textEditInfo; // (removed on protecting)
182  EditInfo rteEditInfo; // (removed on protecting)
183  byte xtraGuid[16]; // 9
184  Common::String xtraDisplayName;
185  Common::Array<byte> bpTable; // (removed on protecting)
186  Common::Rect32 xtraRect; // Rect32
187  Common::Rect scriptRect; // (removed on protecting)
188  Common::Array<byte> dvWindowInfo; // (removed on protecting)
189  byte guid[16]; // 15 Seems to be a GUID
190  Common::String mediaFormatName; // 16 Used by DV cast members to store the media format name
191  uint32 creationTime; // (removed on protecting)
192  uint32 modifiedTime; // (removed on protecting)
193  Common::String modifiedBy; // (removed on protecting)
194  Common::String comments; // 20 (removed on protecting, but could be retained)
195  uint32 imageQuality; // 21
196 
197  CastMemberInfo() : autoHilite(false), scriptId(0) {
198  memset(xtraGuid, 0, 16);
199  memset(guid, 0, 16);
200  creationTime = 0;
201  modifiedTime = 0;
202  imageQuality = 0;
203  }
204 };
205 
206 } // End of namespace Director
207 
208 #endif
Definition: cast.h:87
Definition: rect.h:526
Definition: stream.h:854
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: channel.h:40
Definition: stream.h:77
String toString() const
Definition: rect.h:459
Definition: rect.h:524
Definition: archive.h:36
Definition: lingo-object.h:71
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: macwidget.h:39
Definition: lingo.h:130
bool contains(T x, T y) const
Definition: rect.h:246
Definition: stream.h:351
Definition: stream.h:944
Definition: stxt.h:34
Definition: castmember.h:145
Definition: castmember.h:48
Definition: castmember.h:163