aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/msurface.h
blob: 2e4ca7e728149b64e0ae8b2367001f3bb8717418 (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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/* 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/surface.h"
#include "mads/palette.h"

namespace MADS {

class MADSEngine;
class MSprite;

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

/*
 * MADS graphics surface
 */
class MSurface : public Graphics::Surface {
public:
	static MADSEngine *_vm;

	/**
	 * Sets the engine reference
	 */
	static void setVm(MADSEngine *vm) { _vm = vm; }

	/**
	 * Create a new surface.
	 */
	static MSurface *init();

	/**
	 * Create a surface
	 */
	static MSurface *init(int width, int height);
private:
	byte _color;
protected:
	/**
	 * Basic constructor
	 */
	MSurface();

	/**
	 * Constructor for a surface with fixed dimensions
	 */
	MSurface(int width, int height);
public:
	/**
	 * Helper method for calculating new dimensions when scaling a sprite
	 */
	static int scaleValue(int value, int scale, int err);	
public:
	/**
	 * Destructor
	 */
	virtual ~MSurface();

	/**
	 * Reinitialises a surface to have a given set of dimensions
	 */
	void setSize(int width, int height);

	/**
	 * Sets the color used for drawing on the surface
	 */
	void setColor(byte value) { _color = value; }

	/**
	 * Returns the currently active color
	 */
	byte getColor() const { return _color; }
	
	/**
	 * Draws a vertical line using the currently set color
	 */
	void vLine(int x, int y1, int y2);

	/**
	 * Draws a horizontal line using the currently set color
	 */
	void hLine(int x1, int x2, int y);

	/**
	 * Draws a vertical line using an Xor on each pixel
	 */
	void vLineXor(int x, int y1, int y2);

	/**
	 * Draws a horizontal line using an Xor on each pixel
	 */
	void hLineXor(int x1, int x2, int y);

	/**
	 * Draws an arbitrary line on the screen using a specified color
	 * @param startPos		Starting position
	 * @param endPos		Ending position
	 * @param color			Color to use
	 */
	void line(const Common::Point &startPos, const Common::Point &endPos, byte color);

	/**
	 * Draws a rectangular frame using the currently set color
	 * @param r		Bounds for rectangle
	 */
	void frameRect(const Common::Rect &r);

	/**
	 * Draws a rectangular frame using the currently set color
	 * @param r		Bounds for rectangle
	 * @param color	Color to use
	 */
	void frameRect(const Common::Rect &r, byte color);

	/**
	 * Draws a filled in box using the currently set color
	 * @param r		Bounds for rectangle
	 */
	void fillRect(const Common::Rect &r);

	/**
	 * Draws a filled in box using the currently set color
	 * @param r		Bounds for rectangle
	 * @param color	Color to use
	 */
	void fillRect(const Common::Rect &r, byte color);

	/**
	 * 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);

	/**
	 * Returns the width of the surface
	 */
	int getWidth() const { return w; }

	/**
	 * Returns the height of the surface
	 */
	int getHeight() const { return h; }

	/**
	 * Returns the size of the surface as a Rect
	 */
	Common::Rect getBounds() const {
		return Common::Rect(0, 0, w, h);
	}

	/**
	 * Returns a pointer to the surface data
	 */
	byte *getData() { return (byte *)Graphics::Surface::getPixels(); }
	
	/**
	 * Returns a pointer to a given position within the surface
	 */
	byte *getBasePtr(int x, int y) { return (byte *)Graphics::Surface::getBasePtr(x, y); }

	/**
	 * Clears the surface
	 */
	void empty();

	/**
	 * Updates the screen with the contents of the surface
	 */
	void updateScreen();

	/**
	 * Copys a sub-section of another surface into the current one.
	 * @param src			Source surface
	 * @param srcBounds		Area of source surface to copy
	 * @param destPos		Destination position to draw in current surface
	 * @param transparentColor	Transparency palette index
	 */
	void copyFrom(MSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos,
		int transparentColor = -1);

	/**
	 * Copies the surface to a given destination surface
	 */
	void copyTo(MSurface *dest, int transparentColor = -1) { 
		dest->copyFrom(this, Common::Rect(w, h), Common::Point(), transparentColor);		
	}

	/**
	 * Copies the surface to a given destination surface
	 */
	void copyTo(MSurface *dest, const Common::Point &pt, int transparentColor = -1) {
		dest->copyFrom(this, Common::Rect(w, h), pt, transparentColor);
	}

	/**
	 * Copies the surface to a given destination surface
	 */
	void copyTo(MSurface *dest, const Common::Rect &srcBounds, const Common::Point &destPos,
				int transparentColor = -1) {
		dest->copyFrom(this, srcBounds, destPos, transparentColor);
	}

	/**
	 * Translates the data of a surface using a specified RGBList translation matrix.
	 */
	void translate(RGBList *list, bool isTransparent = false);

	// Base virtual methods
	/**
	 * Loads a background by scene name
	 */
	virtual void loadBackground(const Common::String &sceneName) {}

	/**
	 * Load background by room number
	 */
	virtual void loadBackground(int roomNumber, RGBList **palData) = 0;

	/**
	 * Load background from a passed stream
	 */
	virtual void loadBackground(Common::SeekableReadStream *source, RGBList **palData) {}

	/**
	 * Load scene codes from a passed stream
	 */
	virtual void loadCodes(Common::SeekableReadStream *source) = 0;

	/**
	 * Load a given user interface by index
	 */
	virtual void loadInterface(int index, RGBList **palData) {}
};

class MSurfaceMADS: public MSurface {
	friend class MSurface;
protected:
	MSurfaceMADS(): MSurface() {}
	MSurfaceMADS(int width, int height): MSurface(width, height) {}
public:
	virtual void loadCodes(Common::SeekableReadStream *source);
	virtual void loadBackground(const Common::String &sceneName) {}
	virtual void loadBackground(int roomNumber, RGBList **palData);
	virtual void loadInterface(int index, RGBList **palData);
};

class MSurfaceNebular: public MSurfaceMADS {
	friend class MSurface;
protected:
	MSurfaceNebular(): MSurfaceMADS() {}
	MSurfaceNebular(int width, int height): MSurfaceMADS(width, height) {}
private:
	void loadBackgroundStream(Common::SeekableReadStream *source, RGBList **palData);
public:
	virtual void loadBackground(int roomNumber, RGBList **palData);
};

} // End of namespace MADS

#endif /* MADS_MSURFACE_H */