ScummVM API documentation
qd_animation.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 QDENGINE_QDCORE_QD_ANIMATION_H
23#define QDENGINE_QDCORE_QD_ANIMATION_H
24
25#include "qdengine/parser/xml_fwd.h"
26#include "qdengine/system/graphics/gr_screen_region.h"
27#include "qdengine/system/graphics/gr_tile_animation.h"
28
29#include "qdengine/qdcore/qd_resource.h"
30#include "qdengine/qdcore/qd_animation_frame.h"
31#include "qdengine/qdcore/qd_named_object.h"
32
33
34namespace QDEngine {
35
36
37class qdAnimationInfo;
38
39const int QD_ANIMATION_FLAG_REFERENCE = 0x01;
40const int QD_ANIMATION_FLAG_LOOP = 0x04;
41const int QD_ANIMATION_FLAG_FLIP_HORIZONTAL = 0x08;
42const int QD_ANIMATION_FLAG_FLIP_VERTICAL = 0x10;
43const int QD_ANIMATION_FLAG_BLACK_FON = 0x20;
44const int QD_ANIMATION_FLAG_SUPPRESS_ALPHA = 0x40;
45const int QD_ANIMATION_FLAG_CROP = 0x80;
46const int QD_ANIMATION_FLAG_COMPRESS = 0x100;
47const int QD_ANIMATION_FLAG_TILE_COMPRESS = 0x200;
48
49enum qdAnimationStatus {
50 QD_ANIMATION_STOPPED = 0,
51 QD_ANIMATION_PLAYING,
52 QD_ANIMATION_PAUSED,
53 QD_ANIMATION_END_PLAYING
54};
55
57class qdAnimation : public qdNamedObject, public qdResource {
58public:
60 qdAnimation(const qdAnimation &anm);
62
63 qdAnimation &operator = (const qdAnimation &anm);
64
65 int named_object_type() const {
66 return QD_NAMED_OBJECT_ANIMATION;
67 }
68
69 const qdAnimationFrame *get_cur_frame() const;
70 const qdAnimationFrame *get_cur_frame(float &scale) const;
71 qdAnimationFrame *get_cur_frame();
72
73 void set_cur_frame(int number);
74 int get_cur_frame_number() const;
75
76 qdAnimationFrame *get_frame(int number);
77 const qdAnimationFrame *get_scaled_frame(int number, int scale_index) const;
78
79 int num_frames() const {
80 return _num_frames;
81 }
82
83 float length() const {
84 return _length;
85 }
86 float cur_time() const {
87 return _cur_time;
88 }
89
90 void set_time(float tm) {
91 _cur_time = tm;
92 }
93
94 float cur_time_rel() const {
95 if (_length > 0.01f)
96 return _cur_time / _length;
97 return 0.0f;
98 }
99 void set_time_rel(float tm) {
100 if (tm < 0.0f) tm = 0.0f;
101 if (tm > 0.99f) tm = 0.99f;
102 _cur_time = _length * tm;
103 }
104 void advance_time(float tm);
105
106 void init_size();
107 int size_x() const {
108 return _sx;
109 }
110 int size_y() const {
111 return _sy;
112 }
113
114 int picture_size_x() const;
115 int picture_size_y() const;
116
117 bool is_playing() const {
118 return (_status == QD_ANIMATION_PLAYING ||
119 _status == QD_ANIMATION_END_PLAYING);
120 }
121
122 int status() const {
123 return _status;
124 }
125 bool is_finished() const {
126 return _is_finished;
127 }
128 bool need_stop() const {
129 return _status == QD_ANIMATION_END_PLAYING;
130 }
131
132 void start() {
133 _status = QD_ANIMATION_PLAYING;
134 _is_finished = false;
135 _cur_time = 0.0f;
136 }
137 void stop() {
138 _status = QD_ANIMATION_STOPPED;
139 _is_finished = true;
140 }
141 void pause() {
142 _status = QD_ANIMATION_PAUSED;
143 }
144 void resume() {
145 _status = QD_ANIMATION_PLAYING;
146 }
147
148 void quant(float dt);
149
150 void redraw(int x, int y, int z, int mode = 0) const;
151 void redraw(int x, int y, int z, float scale, int mode = 0) const;
152
153 void redraw_rot(int x, int y, int z, float angle, int mode = 0) const;
154 void redraw_rot(int x, int y, int z, float angle, const Vect2f &scale, int mode = 0) const;
155
156 void draw_mask(int x, int y, int z, uint32 mask_color, int mask_alpha, int mode = 0) const;
157 void draw_mask(int x, int y, int z, uint32 mask_color, int mask_alpha, float scale, int mode = 0) const;
158
159 void draw_mask_rot(int x, int y, int z, float angle, uint32 mask_color, int mask_alpha, int mode = 0) const;
160 void draw_mask_rot(int x, int y, int z, float angle, uint32 mask_color, int mask_alpha, const Vect2f &scale, int mode = 0) const;
161
162 void draw_contour(int x, int y, uint32 color) const;
163 void draw_contour(int x, int y, uint32 color, float scale) const;
164
165 bool hit(int x, int y) const;
166 bool hit(int x, int y, float scale) const;
167
168 bool add_frame(qdAnimationFrame *p, qdAnimationFrame *insert_pos = 0, bool insert_after = true);
169 bool remove_frame(int number);
170 bool remove_frame_range(int number0, int number1);
171 bool reverse_frame_range(int number0, int number1);
172
173 void load_script(const xml::tag *p);
174 bool save_script(Common::WriteStream &fh, int indent = 0) const;
175
176 const Common::Path qda_file() const {
177 return _qda_file;
178 }
179 void qda_set_file(const Common::Path &fname);
180
181 bool qda_load(const Common::Path &fname);
182
183 bool load_resources();
184 void free_resources();
185
186 bool scale(float coeff_x, float coeff_y);
187
188 bool crop();
189 bool undo_crop();
190
191 Vect2i remove_edges();
192
193 bool compress();
194 bool uncompress();
195 bool tileCompress(grTileCompressionMethod method = TILE_UNCOMPRESSED, int tolerance = 0);
196
197 qdAnimationFrameList &frames_list() {
198 return _frames;
199 };
200
201 void create_reference(qdAnimation *p, const qdAnimationInfo *inf = NULL) const;
202 bool is_reference(const qdAnimation *p) const {
203 if (p->check_flag(QD_ANIMATION_FLAG_REFERENCE) && p->_parent == this) return true;
204 return false;
205 }
206
207 void clear() {
208 stop();
209 _frames_ptr = &_frames;
210 _parent = NULL;
211 }
212
213 bool is_empty() const {
214 return (_frames_ptr->empty());
215 }
216
218
223 grScreenRegion screen_region(int mode = 0, float scale = 1.0f) const;
224
225 const qdAnimation *parent() const {
226 return _parent;
227 }
228
229 // qdResource
233 void set_resource_file(const Common::Path &file_name) {
234 qda_set_file(file_name);
235 }
238 if (qda_file().empty()) {
239 if (!check_flag(QD_ANIMATION_FLAG_REFERENCE) && !_frames.empty()) {
240 if (_frames.front()->has_file())
241 return _frames.front()->file();
242 else
243 return NULL;
244 } else
245 return NULL;
246 } else
247 return qda_file();
248 }
249#ifdef __QD_DEBUG_ENABLE__
250 uint32 resource_data_size() const;
251#endif
252
254 bool load_data(Common::SeekableReadStream &fh, int save_version);
257
258 bool add_scale(float value);
259 bool create_scaled_frames();
260
261 const Std::vector<float> &scales() const {
262 if (check_flag(QD_ANIMATION_FLAG_REFERENCE) && _parent) return _parent->_scales;
263 else return _scales;
264 }
265 void clear_scales() {
266 _scales.clear();
267 }
268
269 const grTileAnimation *tileAnimation() const {
270 if (check_flag(QD_ANIMATION_FLAG_REFERENCE) && _parent)
271 return _parent->_tileAnimation;
272 else
273 return _tileAnimation;
274 }
275
276 static Common::String flag2str(int fl, bool truncate = false, bool icon = false);
277 static Common::String status2str(int fl, bool truncate = false);
278
279private:
280 int _sx;
281 int _sy;
282
283 enum {
284 qda_version = 104
285 };
286
287 float _length;
288 float _cur_time;
289
290 float _playback_speed;
291
292 int _num_frames;
293
294 const qdAnimationFrameList *_frames_ptr;
295 qdAnimationFrameList _frames;
296
297 const qdAnimationFrameList *_scaled_frames_ptr;
298 qdAnimationFrameList _scaled_frames;
299 Std::vector<float> _scales;
300
301 grTileAnimation *_tileAnimation;
302
303 int _status;
304 bool _is_finished;
305
306 Common::Path _qda_file;
307
308 const qdAnimation *_parent;
309
310 int get_scale_index(float &scale_value) const;
311
312 bool copy_frames(const qdAnimation &anm);
313 void clear_frames();
314};
315
316} // namespace QDEngine
317
318#endif // QDENGINE_QDCORE_QD_ANIMATION_H
void clear()
Definition: array.h:321
t_T & front()
Definition: list.h:196
bool empty() const
Definition: list.h:258
Definition: path.h:52
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Прямоугольная область на экране.
Definition: gr_screen_region.h:31
Кадр анимации.
Definition: qd_animation_frame.h:31
Анимация.
Definition: qd_animation.h:57
bool save_data(Common::WriteStream &fh) const
Запись данных в сэйв.
const Common::Path resource_file() const
Возвращает имя файла, в котором хранится анимация.
Definition: qd_animation.h:237
int named_object_type() const
Возвращает тип объекта.
Definition: qd_animation.h:65
bool free_resource()
Выгружает из памяти данные ресурса.
bool load_resource()
Загружает в память данные ресурса.
void set_resource_file(const Common::Path &file_name)
Устанавливает имя файла, в котором хранятся данные ресурса.
Definition: qd_animation.h:233
bool load_data(Common::SeekableReadStream &fh, int save_version)
Загрузка данных из сэйва.
grScreenRegion screen_region(int mode=0, float scale=1.0f) const
Возвращает область экрана, занимаемую анимацией.
Поименованный объект.
Definition: qd_named_object.h:70
bool check_flag(int fl) const
Возвращает true, если установлен флаг fl.
Definition: qd_named_object.h:99
Definition: qd_resource.h:34
Базовый класс для игровых ресурсов.
Definition: console.h:28