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 MM_SHARED_XEEN_SPRITES_H
23 #define MM_SHARED_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 "mm/shared/xeen/file.h"
30 #include "mm/shared/xeen/xsurface.h"
31 
32 namespace MM {
33 namespace Xeen {
34 class XeenEngine;
35 class Window;
36 } // namespace Xeen
37 
38 namespace Shared {
39 namespace Xeen {
40 
41 enum {
42  SCALE_MASK = 0x7FFF, SCALE_ENLARGE = 0x8000
43 };
44 
45 enum SpriteFlags {
46  SPRFLAG_MODE_MASK = 0xF00, SPRFLAG_DRAWER1 = 0x100, SPRFLAG_DRAWER2 = 0x200,
47  SPRFLAG_DRAWER3 = 0x300, SPRFLAG_DRAWER4 = 0x400, SPRFLAG_DRAWER5 = 0x500, SPRFLAG_DRAWER6 = 0x600,
48  SPRFLAG_DRAWER7 = 0x700, SPRFLAG_800 = 0x800, SPRFLAG_SCENE_CLIPPED = 0x2000,
49  SPRFLAG_BOTTOM_CLIPPED = 0x4000, SPRFLAG_HORIZ_FLIPPED = 0x8000, SPRFLAG_RESIZE = 0x10000
50 };
51 
53 protected:
54  struct IndexEntry {
55  uint16 _offset1, _offset2;
56  };
58  size_t _filesize;
59  byte *_data;
60  Common::Path _filename;
61  static int _clippedBottom;
62 
66  void load(Common::SeekableReadStream &f);
67 
71  void draw(XSurface &dest, int frame, const Common::Point &destPos,
72  const Common::Rect &bounds, uint flags = 0, int scale = 0) const;
73 
77  void copy(const SpriteResource &src);
78 public:
80  SpriteResource(const Common::Path &filename);
81  SpriteResource(const SpriteResource &src);
82 
83  virtual ~SpriteResource();
84 
88  SpriteResource &operator=(const SpriteResource &src);
89 
93  void load(const Common::Path &filename);
94 
98  void clear();
99 
109  void draw(XSurface &dest, int frame, const Common::Point &destPos,
110  uint flags = 0, int scale = 0) const;
111 
117  void draw(XSurface &dest, int frame) const;
118 
122  void draw(Graphics::ManagedSurface *dest, int frame, const Common::Point &destPos) const;
123 
127  Common::Point getFrameSize(int frame) const;
128 
132  size_t size() const {
133  return _index.size();
134  }
135 
139  bool empty() const {
140  return _index.size() == 0;
141  }
142 
147  static void setClippedBottom(int y) {
148  _clippedBottom = y;
149  }
150 };
151 
156 private:
157  byte *_data = nullptr;
158  size_t _filesize = 0;
159 protected:
160  byte *_destTop = nullptr, *_destBottom = nullptr;
161  byte *_destLeft = nullptr, *_destRight = nullptr;
162  int _pitch = 0;
163 private:
167  static uint getScaledVal(int xy, uint16 &scaleMask);
168 protected:
172  void rcr(uint16 &val, bool &cf);
173 
177  virtual void drawPixel(byte *dest, byte pixel);
178 public:
182  SpriteDrawer(byte *data, size_t filesize) : _data(data), _filesize(filesize) {
183  }
184 
188  virtual ~SpriteDrawer() {
189  }
190 
194  void draw(XSurface &dest, uint16 offset, const Common::Point &pt,
195  const Common::Rect &clipRect, uint flags, int scale);
196 };
197 
198 class SpriteDrawer1 : public SpriteDrawer {
199 private:
200  byte _offset = 0, _mask = 0;
201 protected:
205  void drawPixel(byte *dest, byte pixel) override;
206 public:
210  SpriteDrawer1(byte *data, size_t filesize, int index);
211 };
212 
217 class SpriteDrawer2 : public SpriteDrawer {
218 private:
219  uint16 _mask1 = 0, _mask2 = 0;
220  uint16 _random1 = 0, _random2 = 0;
221 private:
225  void drawPixel(byte *dest, byte pixel) override;
226 public:
230  SpriteDrawer2(byte *data, size_t filesize, int index);
231 };
232 
236 class SpriteDrawer3 : public SpriteDrawer {
237 private:
238  uint16 _offset = 0, _mask = 0;
239  byte _palette[256 * 3];
240  bool _hasPalette = false;
241 private:
245  void drawPixel(byte *dest, byte pixel) override;
246 public:
250  SpriteDrawer3(byte *data, size_t filesize, int index);
251 };
252 
253 class SpriteDrawer4 : public SpriteDrawer {
254 private:
255  byte _threshold = 0;
256 protected:
260  void drawPixel(byte *dest, byte pixel) override;
261 public:
265  SpriteDrawer4(byte *data, size_t filesize, int index);
266 };
267 
271 class SpriteDrawer5 : public SpriteDrawer {
272 private:
273  uint16 _threshold = 0, _random1 = 0, _random2 = 0;
274 protected:
278  void drawPixel(byte *dest, byte pixel) override;
279 public:
283  SpriteDrawer5(byte *data, size_t filesize, int index);
284 };
285 
286 class SpriteDrawer6 : public SpriteDrawer {
287 private:
288  byte _mask = 0;
289 protected:
293  void drawPixel(byte *dest, byte pixel) override;
294 public:
298  SpriteDrawer6(byte *data, size_t filesize, int index);
299 };
300 
301 } // End of namespace Xeen
302 } // End of namespace Shared
303 } // End of namespace MM
304 
305 #endif
Definition: managed_surface.h:51
bool empty() const
Definition: sprites.h:139
Definition: sprites.h:198
Definition: xsurface.h:45
Definition: array.h:52
Definition: sprites.h:52
Definition: rect.h:144
Definition: sprites.h:286
Definition: path.h:52
Definition: stream.h:745
static void setClippedBottom(int y)
Definition: sprites.h:147
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
size_t size() const
Definition: sprites.h:132
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: sprites.h:271
Definition: detection.h:27
Definition: rect.h:45
Definition: sprites.h:54
size_type size() const
Definition: array.h:315
Definition: sprites.h:253
SpriteDrawer(byte *data, size_t filesize)
Definition: sprites.h:182
virtual ~SpriteDrawer()
Definition: sprites.h:188
Definition: sprites.h:217
Definition: sprites.h:236
Definition: sprites.h:155