ScummVM API documentation
sprites.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 XEEN_SPRITES_H
23 #define XEEN_SPRITES_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "common/file.h"
28 #include "graphics/surface.h"
29 #include "xeen/files.h"
30 #include "xeen/xsurface.h"
31 
32 namespace Xeen {
33 
34 class XeenEngine;
35 class Window;
36 
37 enum {
38  SCALE_MASK = 0x7FFF, SCALE_ENLARGE = 0x8000
39 };
40 
41 enum SpriteFlags {
42  SPRFLAG_MODE_MASK = 0xF00, SPRFLAG_DRAWER1 = 0x100, SPRFLAG_DRAWER2 = 0x200,
43  SPRFLAG_DRAWER3 = 0x300, SPRFLAG_DRAWER4 = 0x400, SPRFLAG_DRAWER5 = 0x500, SPRFLAG_DRAWER6 = 0x600,
44  SPRFLAG_DRAWER7 = 0x700, SPRFLAG_800 = 0x800, SPRFLAG_SCENE_CLIPPED = 0x2000,
45  SPRFLAG_BOTTOM_CLIPPED = 0x4000, SPRFLAG_HORIZ_FLIPPED = 0x8000, SPRFLAG_RESIZE = 0x10000
46 };
47 
49 private:
50  struct IndexEntry {
51  uint16 _offset1, _offset2;
52  };
54  size_t _filesize;
55  byte *_data;
56  Common::String _filename;
57  static int _clippedBottom;
58 
62  void load(Common::SeekableReadStream &f);
63 
67  void draw(XSurface &dest, int frame, const Common::Point &destPos,
68  const Common::Rect &bounds, uint flags = 0, int scale = 0);
69 
73  void draw(int windowNum, int frame, const Common::Point &destPos,
74  const Common::Rect &bounds, uint flags = 0, int scale = 0);
75 
79  void copy(const SpriteResource &src);
80 public:
82  SpriteResource(const Common::String &filename);
83  SpriteResource(const Common::String &filename, int ccMode);
84  SpriteResource(const SpriteResource &src);
85 
86  virtual ~SpriteResource();
87 
92 
96  void load(const Common::String &filename);
97 
101  void load(const Common::String &filename, int ccMode);
102 
106  void clear();
107 
117  void draw(XSurface &dest, int frame, const Common::Point &destPos,
118  uint flags = 0, int scale = 0);
119 
129  void draw(Window &dest, int frame, const Common::Point &destPos,
130  uint flags = 0, int scale = 0);
131 
141  void draw(int windowIndex, int frame, const Common::Point &destPos,
142  uint flags = 0, int scale = 0);
143 
149  void draw(XSurface &dest, int frame);
150 
156  void draw(int windowIndex, int frame);
157 
161  Common::Point getFrameSize(int frame) const;
162 
166  size_t size() const { return _index.size(); }
167 
171  bool empty() const { return _index.size() == 0; }
172 
177  static void setClippedBottom(int y) { _clippedBottom = y; }
178 };
179 
184 private:
185  byte *_data;
186  size_t _filesize;
187 protected:
188  byte *_destTop, *_destBottom;
189  byte *_destLeft, *_destRight;
190  int _pitch;
191 private:
195  static uint getScaledVal(int xy, uint16 &scaleMask);
196 protected:
200  void rcr(uint16 &val, bool &cf);
201 
205  virtual void drawPixel(byte *dest, byte pixel);
206 public:
210  SpriteDrawer(byte *data, size_t filesize) : _data(data), _filesize(filesize) {}
211 
215  virtual ~SpriteDrawer() {}
216 
220  void draw(XSurface &dest, uint16 offset, const Common::Point &pt,
221  const Common::Rect &clipRect, uint flags, int scale);
222 };
223 
224 class SpriteDrawer1 : public SpriteDrawer {
225 private:
226  byte _offset, _mask;
227 protected:
231  void drawPixel(byte *dest, byte pixel) override;
232 public:
236  SpriteDrawer1(byte *data, size_t filesize, int index);
237 };
238 
243 class SpriteDrawer2 : public SpriteDrawer {
244 private:
245  uint16 _mask1, _mask2;
246  uint16 _random1, _random2;
247 private:
251  void drawPixel(byte *dest, byte pixel) override;
252 public:
256  SpriteDrawer2(byte *data, size_t filesize, int index);
257 };
258 
262 class SpriteDrawer3 : public SpriteDrawer {
263 private:
264  uint16 _offset, _mask;
265  byte _palette[256 * 3];
266  bool _hasPalette;
267 private:
271  void drawPixel(byte *dest, byte pixel) override;
272 public:
276  SpriteDrawer3(byte *data, size_t filesize, int index);
277 };
278 
279 class SpriteDrawer4 : public SpriteDrawer {
280 private:
281  byte _threshold;
282 protected:
286  void drawPixel(byte *dest, byte pixel) override;
287 public:
291  SpriteDrawer4(byte *data, size_t filesize, int index);
292 };
293 
297 class SpriteDrawer5 : public SpriteDrawer {
298 private:
299  uint16 _threshold, _random1, _random2;
300 protected:
304  void drawPixel(byte *dest, byte pixel) override;
305 public:
309  SpriteDrawer5(byte *data, size_t filesize, int index);
310 };
311 
312 class SpriteDrawer6 : public SpriteDrawer {
313 private:
314  byte _mask;
315 protected:
319  void drawPixel(byte *dest, byte pixel) override;
320 public:
324  SpriteDrawer6(byte *data, size_t filesize, int index);
325 };
326 
327 } // End of namespace Xeen
328 
329 #endif /* MADS_SPRITES_H */
Definition: sprites.h:279
Definition: str.h:59
Definition: sprites.h:243
Definition: xsurface.h:43
Definition: sprites.h:48
virtual ~SpriteDrawer()
Definition: sprites.h:215
Definition: sprites.h:262
Definition: rect.h:144
Definition: sprites.h:224
bool empty() const
Definition: sprites.h:171
Definition: stream.h:652
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: sprites.h:312
Definition: window.h:79
static void setClippedBottom(int y)
Definition: sprites.h:177
Common::Point getFrameSize(int frame) const
Definition: rect.h:45
size_type size() const
Definition: array.h:272
Definition: sprites.h:297
Definition: sprites.h:183
size_t size() const
Definition: sprites.h:166
SpriteResource & operator=(const SpriteResource &src)
Definition: character.h:33
SpriteDrawer(byte *data, size_t filesize)
Definition: sprites.h:210