aboutsummaryrefslogtreecommitdiff
path: root/engines/toon/anim.h
blob: 7bf633220c125dd7a307b8911ec5c3643ba5daf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef TOON_ANIM_H
#define TOON_ANIM_H

#include "common/stream.h"
#include "common/array.h"
#include "common/func.h"
#include "graphics/surface.h"

#include "toon/script.h"

namespace Toon {

class Picture;
class ToonEngine;

struct AnimationFrame {
	int32 _x1;
	int32 _y1;
	int32 _x2;
	int32 _y2;
	int32 _ref;
	uint8 *_data;
};

class Animation {
public:
	Animation(ToonEngine *vm);
	~Animation();

	int32 _x1;
	int32 _y1;
	int32 _x2;
	int32 _y2;
	int32 _numFrames;
	int32 _fps;
	AnimationFrame *_frames;
	uint8 *_palette;
	int32 _paletteEntries;
	char _name[32];

	bool loadAnimation(Common::String file);
	void drawFrame(Graphics::Surface &surface, int32 frame, int32 x, int32 y);
	void drawFontFrame(Graphics::Surface &surface, int32 frame, int32 x, int32 y, byte *colorMap);
	void drawFrameOnPicture(int32 frame, int32 x, int32 y);
	void drawFrameWithMask(Graphics::Surface &surface, int32 frame, int32 xx, int32 yy, int32 zz, Picture *mask);
	void drawFrameWithMaskAndScale(Graphics::Surface &surface, int32 frame, int32 xx, int32 yy, int32 zz, Picture *mask, int32 scale);
	void drawStrip(int32 offset = 0);
	void applyPalette(int32 offset, int32 srcOffset, int32 numEntries);
	int32 getFrameWidth(int32 frame);
	int32 getFrameHeight(int32 frame);
	int32 getWidth() const;
	int32 getHeight() const;
	Common::Rect getRect();
protected:
	ToonEngine *_vm;
};

enum AnimationInstanceType {
	kAnimationCharacter = 1,
	kAnimationScene = 2,
	kAnimationCursor = 4
};

class AnimationInstance {
public:
	AnimationInstance(ToonEngine *vm, AnimationInstanceType type);
	void update(int32 timeIncrement);
	void render();
	void renderOnPicture();
	void setAnimation(Animation *animation, bool setRange = true);
	void playAnimation();
	void setAnimationRange(int32 rangeStart, int rangeEnd);
	void setFps(int32 fps);
	void setLooping(bool enable);
	void stopAnimation();
	void setFrame(int32 position);
	void forceFrame(int32 position);
	void setPosition(int32 x, int32 y, int32 z, bool relative = false);
	Animation *getAnimation() const { return _animation; }
	void setScale(int32 scale);
	void setVisible(bool visible);
	bool getVisible() const { return _visible; }
	void setUseMask(bool useMask);
	void moveRelative(int32 dx, int32 dy, int32 dz);
	void getRect(int32 *x1, int32 *y1, int32 *x2, int32 *y2) const;
	int32 getX() const { return _x; }
	int32 getY() const { return _y; }
	int32 getZ() const { return _z; }
	int32 getX2() const;
	int32 getY2() const;
	int32 getZ2() const;
	int32 getFrame() const { return _currentFrame; }
	void reset();
	void save(Common::WriteStream *stream);
	void load(Common::ReadStream *stream);

	void setId(int32 id) { _id = id; }
	int32 getId() const { return _id; }

	void setX(int32 x, bool relative = false);
	void setY(int32 y, bool relative = false);
	void setZ(int32 z, bool relative = false);
	void setLayerZ(int32 layer);
	int32 getLayerZ() const;

	AnimationInstanceType getType() const { return _type; }

protected:
	int32 _currentFrame;
	int32 _currentTime;
	int32 _fps;
	Animation *_animation;
	int32 _x;
	int32 _y;
	int32 _z;
	int32 _layerZ;
	int32 _rangeStart;
	int32 _rangeEnd;
	int32 _scale;
	int32 _id;

	AnimationInstanceType _type;

	bool _useMask;
	bool _playing;
	bool _looping;
	bool _visible;

	ToonEngine *_vm;
};

class AnimationManager {
public:
	AnimationManager(ToonEngine *vm);
	AnimationInstance *createNewInstance(AnimationInstanceType type);
	void addInstance(AnimationInstance *instance);
	void removeInstance(AnimationInstance *instance);
	void removeAllInstances(AnimationInstanceType type);
	void render();
	void update(int32 timeIncrement);

protected:
	ToonEngine *_vm;
	Common::Array<AnimationInstance *> _instances;
};

class SceneAnimation {
public:
	AnimationInstance *_animInstance;
	Animation *_animation;
	int32 _id;
	bool _active;

	void load(ToonEngine *vm, Common::ReadStream *stream);
	void save(ToonEngine *vm, Common::WriteStream *stream);
};

class SceneAnimationScript {
public:
	EMCData *_data;
	EMCState _state;
	uint32 _lastTimer;
	bool _frozen;
	bool _active;
};

} // End of namespace Toon

#endif