ScummVM API documentation
qd_sprite.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_SPRITE_H
23#define QDENGINE_QDCORE_QD_SPRITE_H
24
25#include "common/str.h"
26
27namespace Common {
28class SeekableReadStream;
29}
30
31#include "qdengine/system/graphics/gr_screen_region.h"
32#include "qdengine/qdcore/qd_resource.h"
33#include "qdengine/xmath.h"
34
35
36namespace QDEngine {
37
39class qdSprite : public qdResource {
40public:
41 enum { // flags
42 ALPHA_FLAG = 0x01
43 };
44
45 qdSprite();
46 qdSprite(int wid, int hei, int format);
47 qdSprite(const qdSprite &spr);
48
49 ~qdSprite();
50
51 qdSprite &operator = (const qdSprite &spr);
52
53 const Vect2i &size() const {
54 return _size;
55 }
56 void set_size(const Vect2i &size) {
57 _size = size;
58 }
59
60 int size_x() const {
61 return _size.x;
62 }
63 int size_y() const {
64 return _size.y;
65 }
66
67 int picture_x() const {
68 return _picture_offset.x;
69 }
70 int picture_y() const {
71 return _picture_offset.y;
72 }
73 void set_picture_offset(const Vect2i &offs) {
74 _picture_offset = offs;
75 }
76
77 int picture_size_x() const {
78 return _picture_size.x;
79 }
80 int picture_size_y() const {
81 return _picture_size.y;
82 }
83 void set_picture_size(const Vect2i &size) {
84 _picture_size = size;
85 }
86
87 int format() const {
88 return _format;
89 }
90 const byte *data() const {
91 return _data;
92 }
93 uint32 data_size() const;
94
95 void set_file(const Common::Path &fname) {
96 _file = fname;
97 }
98 const Common::Path file() const {
99 return _file;
100 }
101 bool has_file() const {
102 return !_file.empty();
103 }
104
105 bool load(const Common::Path &fname);
106 bool load();
107 void save(const Common::Path &fname);
108 void free();
109
110 virtual void qda_load(Common::SeekableReadStream *fh, int version = 100);
111
112 void redraw(int x, int y, int z, int mode = 0) const;
113 void redraw_rot(int x, int y, int z, float angle, int mode = 0) const;
114 void redraw_rot(int x, int y, int z, float angle, const Vect2f &scale, int mode = 0) const;
115
116 void redraw(int x, int y, int z, float scale, int mode = 0) const;
117 void draw_mask(int x, int y, int z, uint32 mask_color, int mask_alpha, int mode = 0) const;
118 void draw_mask(int x, int y, int z, uint32 mask_color, int mask_alpha, float scale, int mode = 0) const;
119
120 void draw_mask_rot(int x, int y, int z, float angle, uint32 mask_color, int mask_alpha, int mode = 0) const;
121 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;
122
123 void draw_contour(int x, int y, uint32 color, int mode = 0) const;
124 void draw_contour(int x, int y, uint32 color, float scale, int mode = 0) const;
125
126 bool hit(int x, int y) const;
127 bool hit(int x, int y, float scale) const;
128
129 bool put_pixel(int x, int y, byte r, byte g, byte b);
130
131 bool crop();
132 bool crop(int left, int top, int right, int bottom, bool store_offsets = true);
133 bool undo_crop();
134
135 bool get_edges_width(int &left, int &top, int &right, int &bottom);
136 Vect2i remove_edges();
137
138 bool compress();
139 bool uncompress();
140 bool is_compressed() const {
141 if (_rle_data) return true;
142 else return false;
143 }
144
145 bool scale(float coeff_x, float coeff_y);
146
147 void set_flag(int fl) {
148 _flags |= fl;
149 }
150 void drop_flag(int fl) {
151 _flags &= ~fl;
152 }
153 bool check_flag(int fl) const {
154 if (_flags & fl) {
155 return true;
156 }
157 return false;
158 }
159 void clear_flags() {
160 _flags = 0;
161 }
162 int flags() const {
163 return _flags;
164 }
165
168 return load();
169 }
172 free();
173 return true;
174 }
175
177 void set_resource_file(const Common::Path &filename) {
178 set_file(filename);
179 }
181
185 if (has_file()) return file();
186 return NULL;
187 }
188#ifdef __QD_DEBUG_ENABLE__
189 uint32 resource_data_size() const {
190 return data_size();
191 }
192#endif
193
195
200 grScreenRegion screen_region(int mode = 0, float scale = 1.0f) const;
201
202private:
203 int _format;
204 int _flags;
205
206 Vect2i _size;
207
208 Vect2i _picture_size;
209 Vect2i _picture_offset;
210
211 byte *_data;
212 class RLEBuffer *_rle_data;
213
214 Common::Path _file;
215
216 friend bool operator == (const qdSprite &sp1, const qdSprite &sp2);
217};
218
219} // namespace QDEngine
220
221#endif // QDENGINE_QDCORE_QD_SPRITE_H
Definition: path.h:52
bool empty() const
Definition: path.h:353
Definition: stream.h:745
Массив, сжатый методом RLE.
Definition: rle_compress.h:29
Definition: xmath.h:117
Definition: xmath.h:268
Прямоугольная область на экране.
Definition: gr_screen_region.h:31
Definition: qd_resource.h:34
Спрайт.
Definition: qd_sprite.h:39
bool free_resource()
Выгружает из памяти данные ресурса.
Definition: qd_sprite.h:171
grScreenRegion screen_region(int mode=0, float scale=1.0f) const
Возвращает область экрана, занимаемую спрайтом.
const Common::Path resource_file() const
Возвращает имя файла, в котором хранятся данные ресурса.
Definition: qd_sprite.h:184
void set_resource_file(const Common::Path &filename)
Устанавливает имя файла, в котором хранятся данные ресурса.
Definition: qd_sprite.h:177
bool load_resource()
Загружает в память данные ресурса.
Definition: qd_sprite.h:167
Definition: algorithm.h:29
Базовый класс для игровых ресурсов.
Definition: console.h:28