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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef TWINE_PARSER_SPRITE_H
24 #define TWINE_PARSER_SPRITE_H
25 
26 #include "common/array.h"
27 #include "common/memstream.h"
28 #include "common/stream.h"
29 #include "graphics/managed_surface.h"
30 #include "twine/parser/parser.h"
31 #include "twine/shared.h"
32 
33 namespace TwinE {
34 
35 struct SpriteDim {
36 	int16 x = 0;
37 	int16 y = 0;
38 	int16 w = 0;
39 	int16 h = 0;
40 };
41 
42 class SpriteBoundingBoxData : public Parser {
43 private:
44 	Common::Array<BoundingBox> _boundingBoxes;
45 	Common::Array<SpriteDim> _dimensions;
46 
47 public:
48 	bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
49 
50 	const BoundingBox *bbox(int index) const;
51 	const SpriteDim *dim(int index) const;
52 };
53 
bbox(int index)54 inline const BoundingBox *SpriteBoundingBoxData::bbox(int index) const {
55 	if (index < 0) {
56 		return nullptr;
57 	}
58 	return &_boundingBoxes[index];
59 }
60 
dim(int index)61 inline const SpriteDim *SpriteBoundingBoxData::dim(int index) const {
62 	if (index < 0) {
63 		return nullptr;
64 	}
65 	return &_dimensions[index];
66 }
67 
68 class SpriteData : public Parser {
69 protected:
70 	Graphics::ManagedSurface _surfaces[2];
71 	int _offsetX[2] {0};
72 	int _offsetY[2] {0};
73 	int _sprites = 0;
74 	bool _bricks = false;
75 
76 	bool loadSprite(Common::SeekableReadStream &stream, uint32 offset);
77 	void reset() override;
78 public:
79 	bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
80 
81 	inline const Graphics::ManagedSurface &surface(int index = 0) const {
82 		if (index < 0 || index >= _sprites) {
83 			error("Sprite surface index out of range: %i (max: %i)", index, _sprites);
84 		}
85 		return _surfaces[index];
86 	}
87 
sprites()88 	inline int sprites() const {
89 		return _sprites;
90 	}
91 
92 	inline int offsetX(int index = 0) const {
93 		if (index < 0 || index >= _sprites) {
94 			error("Sprite offset index out of range: %i (max: %i)", index, _sprites);
95 		}
96 		return _offsetX[index];
97 	}
98 
99 	inline int offsetY(int index = 0) const {
100 		if (index < 0 || index >= _sprites) {
101 			error("Sprite offset index out of range: %i (max: %i)", index, _sprites);
102 		}
103 		return _offsetY[index];
104 	}
105 };
106 
107 class BrickData : public SpriteData {
108 public:
BrickData()109 	BrickData() {
110 		_bricks = true;
111 	}
112 };
113 
114 } // End of namespace TwinE
115 
116 #endif
117