ScummVM API documentation
anim.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, MojoTouch has
23  * exclusively licensed this code on March 23th, 2024, to be used in
24  * closed-source products.
25  * Therefore, any contributions (commits) to it will also be dual-licensed.
26  *
27  */
28 
29 #ifndef TOON_ANIM_H
30 #define TOON_ANIM_H
31 
32 #include "common/stream.h"
33 #include "common/array.h"
34 #include "common/func.h"
35 #include "graphics/surface.h"
36 
37 #include "toon/script.h"
38 
39 namespace Toon {
40 
41 class Picture;
42 class ToonEngine;
43 
45  int16 _x1;
46  int16 _y1;
47  int16 _x2;
48  int16 _y2;
49  int32 _ref;
50  uint8 *_data;
51  uint32 _dataSize;
52 };
53 
54 class Animation {
55 public:
56  Animation(ToonEngine *vm);
57  ~Animation();
58 
59  int16 _x1;
60  int16 _y1;
61  int16 _x2;
62  int16 _y2;
63  int32 _numFrames;
64  int32 _fps;
65  AnimationFrame *_frames;
66  uint8 *_palette;
67  int32 _paletteEntries;
68  char _name[32];
69  bool _shadowFlag;
70 
71  bool loadAnimation(const Common::String &file);
72  void drawFrame(Graphics::Surface &surface, int32 frame, int16 x, int16 y);
73  void drawFontFrame(Graphics::Surface &surface, int32 frame, int16 x, int16 y, byte *colorMap);
74  void drawFrameOnPicture(int32 frame, int16 x, int16 y);
75  void drawFrameWithMask(Graphics::Surface &surface, int32 frame, int16 xx, int16 yy, int32 zz, Picture *mask);
76  void drawFrameWithMaskAndScale(Graphics::Surface &surface, int32 frame, int16 xx, int16 yy, int32 zz, Picture *mask, int32 scale);
77 // void drawStrip(int32 offset = 0);
78  void applyPalette(int32 offset, int32 srcOffset, int32 numEntries);
79  Common::Rect getFrameRect(int32 frame);
80  int16 getFrameWidth(int32 frame);
81  int16 getFrameHeight(int32 frame);
82  int16 getWidth() const;
83  int16 getHeight() const;
84  Common::Rect getRect();
85 protected:
86  ToonEngine *_vm;
87 };
88 
89 enum AnimationInstanceType {
90  kAnimationCharacter = 1,
91  kAnimationScene = 2,
92  kAnimationCursor = 4
93 };
94 
96 public:
97  AnimationInstance(ToonEngine *vm, AnimationInstanceType type);
98  void update(int32 timeIncrement);
99  void render();
100  void renderOnPicture();
101  void setAnimation(Animation *animation, bool setRange = true);
102  void playAnimation();
103  void setAnimationRange(int32 rangeStart, int32 rangeEnd);
104  void setFps(int32 fps);
105  void setLooping(bool enable);
106  void stopAnimation();
107  void setFrame(int32 position);
108  void forceFrame(int32 position);
109  void setPosition(int16 x, int16 y, int32 z, bool relative = false);
110  Animation *getAnimation() const { return _animation; }
111  void setScale(int32 scale, bool align = false);
112  void setVisible(bool visible);
113  bool getVisible() const { return _visible; }
114  void setUseMask(bool useMask);
115  void moveRelative(int16 dx, int16 dy, int32 dz);
116  void getRect(int16 *x1, int16 *y1, int16 *x2, int16 *y2) const;
117  int16 getX() const { return _x; }
118  int16 getY() const { return _y; }
119  int32 getZ() const { return _z; }
120  int16 getX2() const;
121  int16 getY2() const;
122  int32 getZ2() const;
123  int32 getFrame() const { return _currentFrame; }
124  void reset();
125  void save(Common::WriteStream *stream);
126  void load(Common::ReadStream *stream);
127 
128  void setId(int32 id) { _id = id; }
129  int32 getId() const { return _id; }
130 
131  void setX(int16 x, bool relative = false);
132  void setY(int16 y, bool relative = false);
133  void setZ(int32 z, bool relative = false);
134  void setLayerZ(int32 layer);
135  int32 getLayerZ() const;
136 
137  AnimationInstanceType getType() const { return _type; }
138 
139 protected:
140  int32 _currentFrame;
141  int32 _currentTime;
142  int32 _fps;
143  Animation *_animation;
144  int16 _x;
145  int16 _y;
146  int32 _z;
147  int32 _layerZ;
148  int32 _rangeStart;
149  int32 _rangeEnd;
150  int32 _scale;
151  int32 _id;
152 
153  AnimationInstanceType _type;
154 
155  bool _useMask;
156  bool _playing;
157  bool _looping;
158  bool _visible;
159  bool _alignBottom;
160 
161  ToonEngine *_vm;
162 };
163 
165 public:
167  AnimationInstance *createNewInstance(AnimationInstanceType type);
168  void addInstance(AnimationInstance *instance);
169  void removeInstance(AnimationInstance *instance);
170  void updateInstance(AnimationInstance* instance);
171  void removeAllInstances(AnimationInstanceType type);
172  void render();
173  void update(int32 timeIncrement);
174  bool hasInstance(AnimationInstance* instance);
175 
176 protected:
177  ToonEngine *_vm;
179 };
180 
182 public:
183  AnimationInstance *_originalAnimInstance;
184  AnimationInstance *_animInstance;
185  Animation *_animation;
186  int32 _id;
187  bool _active;
188 
189  void load(ToonEngine *vm, Common::ReadStream *stream);
190  void save(ToonEngine *vm, Common::WriteStream *stream);
191 };
192 
194 public:
195  EMCData *_data;
196  EMCState _state;
197  uint32 _lastTimer;
198  bool _frozen;
199  bool _frozenForConversation;
200  bool _active;
201 };
202 
203 } // End of namespace Toon
204 
205 #endif
Definition: anim.h:193
Definition: str.h:59
Definition: surface.h:67
Definition: stream.h:77
Definition: array.h:52
Definition: script.h:44
Definition: rect.h:144
Definition: anim.h:181
Definition: toon.h:118
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: anim.h:164
Definition: stream.h:385
Definition: anim.h:39
Definition: script.h:55
Definition: anim.h:95
Definition: anim.h:44
Definition: picture.h:43
Definition: anim.h:54