aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/msurface.h
blob: 5b5a1d62c1b8c9ec2c4f48cd0670e1496c0498bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef MADS_MSURFACE_H
#define MADS_MSURFACE_H

#include "common/scummsys.h"
#include "common/rect.h"
#include "graphics/screen.h"
#include "mads/palette.h"

namespace MADS {

class MADSEngine;
class MSprite;
class DepthSurface;

/**
 * Basic sprite information
 */
struct SpriteInfo {
	MSprite *sprite;
	int hotX, hotY;
	int width, height;
	int scaleX, scaleY;
	uint8 encoding;
	byte *inverseColorTable;
	byte *palette;
};

/*
 * Base MADS surface class. This derivces from Graphics::Screen
 * because it has logic we'll need for our own Screen class that
 * derives from this one
 */
class BaseSurface : public Graphics::Screen {
private:
	/**
	 * Helper method for calculating new dimensions when scaling a sprite
	 */
	int scaleValue(int value, int scale, int err);
protected:
	static MADSEngine *_vm;
public:
	/**
	 * Sets the engine reference used all surfaces
	 */
	static void setVm(MADSEngine *vm) { _vm = vm; }

	/**
	* Base method for descendents to load their contents
	*/
	virtual void load(const Common::String &resName) {}
public:
	/**
	 * Basic constructor
	 */
	BaseSurface() : Graphics::Screen(0, 0) {
		free();		// Free the 0x0 surface allocated by Graphics::Screen
	}

	/**
	 * Constructor for a surface with fixed dimensions
	 */
	BaseSurface(int width, int height) : Graphics::Screen(width, height) {}

	/**
	 * Destructor
	 */
	virtual ~BaseSurface() {}

	/**
	 * Return a rect containing the bounds of the surface
	 */
	Common::Rect getBounds() { return Common::Rect(0, 0, this->w, this->h); }

	/**
	 * Return the pixels for the surface
	 */
	inline byte *getPixels() { return (byte *)Graphics::ManagedSurface::getPixels(); }

	/**
	 * Return the pixels for the surface
	 */
	inline const void *getPixels() const { return (const byte *)Graphics::ManagedSurface::getPixels(); }

	/**
	 * Return a pointer to a given position on the surface
	 */
	byte *getBasePtr(int x, int y) { return (byte *)Graphics::ManagedSurface::getBasePtr(x, y); }

	/**
	 * Return a pointer to a given position on the surface
	 */
	inline const byte *getBasePtr(int x, int y) const { return (const byte *)Graphics::ManagedSurface::getBasePtr(x, y); }

	/**
	 * Draws a sprite
	 * @param pt		Position to draw sprite at
	 * @param info		General sprite details
	 * @param clipRect	Clipping rectangle to constrain sprite drawing within
	 */
	void drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect);

	/**
	 * Scroll the screen horizontally by a given amount
	 * @param xAmount	Horizontal amount
	 */
	void scrollX(int xAmount);

	/**
	 * Scroll the screen vertically by a given amount
	 * @param yAmount	Vertical amount
	 */
	void scrollY(int yAmount);

	/**
	 * Translates the pixels of an image used the passed palette with RGB mapping
	 */
	void translate(Common::Array<RGB6> &palette);

	/**
	* Translates the pixels of an image used the passed palette with RGB mapping
	*/
	void translate(byte map[PALETTE_COUNT]);

	/**
	 * Create a new surface which is a flipped horizontal copy of the current one
	 */
	BaseSurface *flipHorizontal() const;

	/**
	 * Copy an area from one surface to another, translating it using a palette
	 * map as it's done
	 */
	void copyRectTranslate(BaseSurface &srcSurface, const byte *paletteMap,
		const Common::Point &destPos, const Common::Rect &srcRect);

	/**
	 * Copys a sub-section of another surface into the current one.
	 * @param src			Source surface
	 * @param destPos		Destination position to draw in current surface
	 * @param depth			Depth of sprite
	 * @param depthSurface	Depth surface to use with sprite depth
	 * @param scale			Scale for image
	 * @param flipped		Flag for whether image is to be flipped
	 * @param transparentColor	Transparency palette index
	 */
	void copyFrom(BaseSurface &src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
		int scale, bool flipped, int transparentColor = -1);
};

class MSurface : public BaseSurface {
protected:
	/**
	 * Override the addDirtyRect from Graphics::Screen, since for standard
	 * surfaces we don't need dirty rects to be tracked
	 */
	virtual void addDirtyRect(const Common::Rect &r) {}
public:
	MSurface() : BaseSurface() {}
	MSurface(int width, int height) : BaseSurface(width, height) {}
};

class DepthSurface : public MSurface {
public:
	/**
	 * Depth style
	 */
	int _depthStyle;

	/**
	 * Constructor
	 */
	DepthSurface() : MSurface(), _depthStyle(0) {}

	/**
	 * Returns the depth at a given position
	 */
	int getDepth(const Common::Point &pt);

	/**
	 */
	int getDepthHighBit(const Common::Point &pt);
};

} // End of namespace MADS

#endif /* MADS_MSURFACE_H */