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