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