ScummVM API documentation
actor.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 MEDIASTATION_ACTOR_H
23 #define MEDIASTATION_ACTOR_H
24 
25 #include "common/events.h"
26 #include "common/keyboard.h"
27 
28 #include "mediastation/datafile.h"
29 #include "mediastation/mediascript/eventhandler.h"
30 #include "mediastation/mediascript/scriptconstants.h"
31 #include "mediastation/mediascript/scriptvalue.h"
32 
33 namespace MediaStation {
34 
35 enum ActorType {
36  kActorTypeEmpty = 0x0000,
37  kActorTypeScreen = 0x0001, // SCR
38  kActorTypeStage = 0x0002, // STG
39  kActorTypePath = 0x0004, // PTH
40  kActorTypeSound = 0x0005, // SND
41  kActorTypeTimer = 0x0006, // TMR
42  kActorTypeImage = 0x0007, // IMG
43  kActorTypeHotspot = 0x000b, // HSP
44  kActorTypeSprite = 0x000e, // SPR
45  kActorTypeLKZazu = 0x000f,
46  kActorTypeLKConstellations = 0x0010,
47  kActorTypeDocument = 0x0011,
48  kActorTypeImageSet = 0x001d,
49  kActorTypeCursor = 0x000c, // CSR
50  kActorTypePrinter = 0x0019, // PRT
51  kActorTypeMovie = 0x0016, // MOV
52  kActorTypePalette = 0x0017,
53  kActorTypeText = 0x001a, // TXT
54  kActorTypeFont = 0x001b, // FON
55  kActorTypeCamera = 0x001c, // CAM
56  kActorTypeCanvas = 0x001e, // CVS
57  kActorTypeXsnd = 0x001f,
58  kActorTypeXsndMidi = 0x0020,
59  kActorTypeRecorder = 0x0021,
60  kActorTypeFunction = 0x0069 // FUN
61 };
62 
63 enum ActorHeaderSectionType {
64  kActorHeaderEmptySection = 0x0000,
65  kActorHeaderEventHandler = 0x0017,
66  kActorHeaderChildActorId = 0x0019,
67  kActorHeaderActorId = 0x001a,
68  kActorHeaderChunkReference = 0x001b,
69  kActorHeaderMovieAnimationChunkReference = 0x06a4,
70  kActorHeaderMovieAudioChunkReference = 0x06a5,
71  kActorHeaderActorReference = 0x077b,
72  kActorHeaderBoundingBox = 0x001c,
73  kActorHeaderMouseActiveArea = 0x001d,
74  kActorHeaderZIndex = 0x001e,
75  kActorHeaderStartup = 0x001f,
76  kActorHeaderTransparency = 0x0020,
77  kActorHeaderHasOwnSubfile = 0x0021,
78  kActorHeaderCursorResourceId = 0x0022,
79  kActorHeaderFrameRate = 0x0024,
80  kActorHeaderLoadType = 0x0032,
81  kActorHeaderSoundInfo = 0x0033,
82  kActorHeaderMovieLoadType = 0x0037,
83  kActorHeaderSpriteChunkCount = 0x03e8,
84  kActorHeaderPalette = 0x05aa,
85  kActorHeaderDissolveFactor = 0x05dc,
86  kActorHeaderGetOffstageEvents = 0x05dd,
87  kActorHeaderX = 0x05de,
88  kActorHeaderY = 0x05df,
89  kActorHeaderScaleXAndY = 0x77a,
90  kActorHeaderScaleX = 0x77c,
91  kActorHeaderScaleY = 0x77d,
92  kActorHeaderUnk0 = 0x7d0,
93  kActorHeaderActorName = 0x0bb8,
94 
95  // PATH FIELDS.
96  kActorHeaderStartPoint = 0x060e,
97  kActorHeaderEndPoint = 0x060f,
98  kActorHeaderPathTotalSteps = 0x0610,
99  kActorHeaderStepRate = 0x0611,
100  kActorHeaderDuration = 0x0612,
101 
102  // CAMERA FIELDS.
103  kActorHeaderViewportOrigin = 0x076f,
104  kActorHeaderLensOpen = 0x0770,
105 
106  // STAGE FIELDS.
107  kActorHeaderStageSize = 0x0771,
108  kActorHeaderCylindricalX = 0x0772,
109  kActorHeaderCylindricalY = 0x0773,
110 
111  // TEXT FIELDS.
112  kActorHeaderEditable = 0x03eb,
113  kActorHeaderFontId = 0x0258,
114  kActorHeaderInitialText = 0x0259,
115  kActorHeaderTextMaxLength = 0x25a,
116  kActorHeaderTextJustification = 0x025b,
117  kActorHeaderTextPosition = 0x25f,
118  kActorHeaderTextUnk1 = 0x262,
119  kActorHeaderTextUnk2 = 0x263,
120  kActorHeaderTextCharacterClass = 0x0266,
121 
122  // SPRITE FIELDS.
123  kActorHeaderSpriteClip = 0x03e9,
124  kActorHeaderCurrentSpriteClip = 0x03ea
125 };
126 
127 class SpatialEntity;
128 
130  SpatialEntity *keyDown = nullptr;
131  // There is no key up event.
132  SpatialEntity *mouseDown = nullptr;
133  SpatialEntity *mouseUp = nullptr;
134  SpatialEntity *mouseMoved = nullptr;
135  SpatialEntity *mouseExit = nullptr;
136  SpatialEntity *mouseEnter = nullptr;
137  SpatialEntity *mouseOutOfFocus = nullptr;
138 };
139 
140 enum MouseEventFlag {
141  kNoFlag = 0x00,
142  kMouseDownFlag = 0x01,
143  kMouseUpFlag = 0x02,
144  kMouseMovedFlag = 0x04,
145  kMouseExitFlag = 0x10,
146  kMouseEnterFlag = 0x08,
147  kMouseUnk1Flag = 0x20,
148  kMouseOutOfFocusFlag = 0x40,
149  kKeyDownFlag = 0x80,
150  // There is no key up event.
151 };
152 
153 class StageActor;
154 
155 class Actor {
156 public:
157  Actor(ActorType type) : _type(type) {};
158  virtual ~Actor();
159 
160  // Does any needed frame drawing, audio playing, event handlers, etc.
161  virtual void process() { return; }
162 
163  // Runs built-in bytecode methods.
164  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args);
165 
166  virtual bool isSpatialActor() const { return false; }
167 
168  virtual void initFromParameterStream(Chunk &chunk);
169  virtual void readParameter(Chunk &chunk, ActorHeaderSectionType paramType);
170  virtual void loadIsComplete();
171 
172  // These are not pure virtual so if an actor doesn't read any chunks or
173  // subfiles it doesn't need to just implement these with an error message.
174  virtual void readChunk(Chunk &chunk);
175  virtual void readSubfile(Subfile &subfile, Chunk &chunk);
176 
177  void processTimeEventHandlers();
178  void runEventHandlerIfExists(EventType eventType, const ScriptValue &arg);
179  void runEventHandlerIfExists(EventType eventType);
180 
181  ActorType type() const { return _type; }
182  uint id() const { return _id; }
183  uint contextId() const { return _contextId; }
184  void setId(uint id) { _id = id; }
185  void setContextId(uint id) { _contextId = id; }
186 
187  uint32 _chunkReference = 0;
188  uint _actorReference = 0;
189 
190 protected:
191  ActorType _type = kActorTypeEmpty;
192  bool _loadIsComplete = false;
193  uint _id = 0;
194  uint _contextId = 0;
195 
196  uint _startTime = 0;
197  uint _lastProcessedTime = 0;
198  uint _duration = 0;
200 };
201 
202 class SpatialEntity : public Actor {
203 public:
204  SpatialEntity(ActorType type) : Actor(type) {};
205 
206  virtual void draw(const Common::Array<Common::Rect> &dirtyRegion) { return; }
207  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args) override;
208  virtual void readParameter(Chunk &chunk, ActorHeaderSectionType paramType) override;
209  virtual void loadIsComplete() override;
210 
211  virtual bool isSpatialActor() const override { return true; }
212  virtual bool isVisible() const { return _isVisible; }
213  virtual Common::Rect getBbox() const { return _boundingBox; }
214  int zIndex() const { return _zIndex; }
215 
216  virtual void invalidateMouse();
217  virtual bool interactsWithMouse() const { return false; }
218 
219  virtual uint16 findActorToAcceptMouseEvents(
220  const Common::Point &point,
221  uint16 eventMask,
222  MouseActorState &state,
223  bool inBounds) { return kNoFlag; }
224  virtual uint16 findActorToAcceptKeyboardEvents(
225  uint16 asciiCode,
226  uint16 eventMask,
227  MouseActorState &state) { return kNoFlag; }
228 
229  virtual void mouseDownEvent(const Common::Event &event) { return; }
230  virtual void mouseUpEvent(const Common::Event &event) { return; }
231  virtual void mouseEnteredEvent(const Common::Event &event) { return; }
232  virtual void mouseExitedEvent(const Common::Event &event) { return; }
233  virtual void mouseMovedEvent(const Common::Event &event) { return; }
234  virtual void mouseOutOfFocusEvent(const Common::Event &event) { return; }
235  virtual void keyboardEvent(const Common::Event &event) { return; }
236 
237  void setParentStage(StageActor *parentStage) { _parentStage = parentStage; }
238  void setToNoParentStage() { _parentStage = nullptr; }
239  StageActor *getParentStage() const { return _parentStage; }
240 
241  virtual void invalidateLocalBounds();
242 
243 protected:
244  uint _stageId = 0;
245  int _zIndex = 0;
246  double _dissolveFactor = 0.0;
247  double _scaleX = 0.0;
248  double _scaleY = 0.0;
249  Common::Rect _boundingBox;
250  bool _isVisible = false;
251  bool _hasTransparency = false;
252  bool _getOffstageEvents = false;
253  StageActor *_parentStage = nullptr;
254 
255  void moveTo(int16 x, int16 y);
256  void moveToCentered(int16 x, int16 y);
257  void setBounds(const Common::Rect &bounds);
258  void setZIndex(int zIndex);
259  virtual void setMousePosition(int16 x, int16 y);
260 
261  virtual void setDissolveFactor(double dissolveFactor);
262  virtual void invalidateLocalZIndex();
263 };
264 
265 } // End of namespace MediaStation
266 
267 #endif
Definition: actor.h:129
Definition: actor.h:202
Definition: actor.h:33
Definition: datafile.h:102
Definition: stage.h:33
Definition: rect.h:524
Definition: hashmap.h:85
Definition: events.h:210
Definition: rect.h:144
Definition: datafile.h:128
Definition: actor.h:155
Definition: scriptvalue.h:36