aboutsummaryrefslogtreecommitdiff
path: root/engines/made/screen.h
blob: c91704ef796c4d0f9fd623b938422af48ab3eecb (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
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef MADE_SCREEN_H
#define MADE_SCREEN_H

#include "common/endian.h"
#include "common/util.h"
#include "common/rect.h"

#include "graphics/surface.h"
#include "graphics/cursorman.h"

#include "made/resource.h"
#include "made/screenfx.h"

namespace Made {

struct SpriteChannel {
	int16 type;
	int16 state;
	uint16 index;
	int16 x, y;
	uint16 fontNum;
	int16 textColor, outlineColor;
	int16 frameNum;
	int16 mask;
};

struct ClipInfo {
	Common::Rect clipRect;
	Graphics::Surface *destSurface;
};

struct SpriteListItem {
	int16 index, xofs, yofs;
};

class MadeEngine;

static const byte defaultMouseCursor[256] = {
	0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  0,  0,  0,  0,  0,  0,
	0,  0,  0,  0,  0,  0,  0,  1, 15, 15,  1,  0,  0,  0,  0,  0,
	0,  0,  0,  0,  0,  0,  0,  1, 15, 15,  1,  0,  0,  0,  0,  0,
	0,  0,  0,  0,  0,  0,  0,  1, 15, 15,  1,  0,  0,  0,  0,  0,
	0,  1,  1,  1,  1,  1,  1,  1, 15, 15,  1,  0,  0,  0,  0,  0,
	1,  1, 15,  1, 15,  1, 15,  1, 15, 15,  1,  0,  0,  0,  0,  0,
	1, 15, 15,  1, 15,  1, 15,  1, 15, 15,  1,  0,  0,  0,  0,  0,
	1, 15, 15, 15, 15, 15, 15, 15, 15, 15,  1,  0,  1,  1,  1,  0,
	1, 15, 15, 15, 15, 15, 15, 15, 15, 15,  1,  1, 15, 15, 15,  1,
	1, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,  1,  1,  1,
	1, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,  1,  1,  0,  0,
	1,  1, 15, 15, 15, 15, 15, 15, 15, 15, 15,  1,  1,  0,  0,  0,
	0,  1,  1, 15, 15, 15, 15, 15, 15, 15,  1,  1,  0,  0,  0,  0,
	0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,
	0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
};

class Screen {
public:
	Screen(MadeEngine *vm);
	~Screen();

	void clearScreen();

	void drawSurface(Graphics::Surface *sourceSurface, int x, int y, int16 flipX, int16 flipY, int16 mask, const ClipInfo &clipInfo);

	void setRGBPalette(byte *palRGB, int start = 0, int count = 256);
	bool isPaletteLocked() { return _paletteLock; }
	void setPaletteLock(bool lock) { _paletteLock = lock; }
	bool isScreenLocked() { return _screenLock; }
	void setScreenLock(bool lock) { _screenLock = lock; }
	void setVisualEffectNum(int visualEffectNum) { _visualEffectNum = visualEffectNum; }

	void setClipArea(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
		_clipArea.clipRect = Common::Rect(x1, y1, x2, y2);
	}

	void setExcludeArea(uint16 x1, uint16 y1, uint16 x2, uint16 y2);

	void setClip(int16 clip) { _clip = clip; }
	void setExclude(int16 exclude) { _exclude = exclude; }
	void setGround(int16 ground) { _ground = ground; }
	void setMask(int16 mask) { _mask = mask; }

	void setTextColor(int16 color) { _textColor = color; }

	void setTextRect(const Common::Rect &textRect) {
		_textRect = textRect;
		_textX = _textRect.left;
		_textY = _textRect.top;
	}

	void getTextRect(Common::Rect &textRect) {
		textRect = _textRect;
	}

	void setOutlineColor(int16 color) {
		_outlineColor = color;
		_dropShadowColor = -1;
	}

	void setDropShadowColor(int16 color) {
		_outlineColor = -1;
		_dropShadowColor = color;
	}

	void setTextXY(int16 x, int16 y) {
		_textX = x;
		_textY = y;
	}

	void homeText() {
		_textX = _textRect.left;
		_textY = _textRect.top;
	}

	uint16 updateChannel(uint16 channelIndex);
	void deleteChannel(uint16 channelIndex);
	int16 getChannelType(uint16 channelIndex);
	int16 getChannelState(uint16 channelIndex);
	void setChannelState(uint16 channelIndex, int16 state);
	uint16 setChannelLocation(uint16 channelIndex, int16 x, int16 y);
	uint16 setChannelContent(uint16 channelIndex, uint16 index);
	void setChannelUseMask(uint16 channelIndex);
	void drawSpriteChannels(const ClipInfo &clipInfo, int16 includeStateMask, int16 excludeStateMask);
	void updateSprites();
	void clearChannels();

	uint16 drawFlex(uint16 flexIndex, int16 x, int16 y, int16 flipX, int16 flipY, int16 mask, const ClipInfo &clipInfo);

	void drawAnimFrame(uint16 animIndex, int16 x, int16 y, int16 frameNum, int16 flipX, int16 flipY, const ClipInfo &clipInfo);

	uint16 drawPic(uint16 index, int16 x, int16 y, int16 flipX, int16 flipY);
	uint16 drawMask(uint16 index, int16 x, int16 y);

	uint16 drawAnimPic(uint16 animIndex, int16 x, int16 y, int16 frameNum, int16 flipX, int16 flipY);

	void addSprite(uint16 spriteIndex);

	uint16 drawSprite(uint16 flexIndex, int16 x, int16 y);
	uint16 placeSprite(uint16 channelIndex, uint16 flexIndex, int16 x, int16 y);

	uint16 placeAnim(uint16 channelIndex, uint16 animIndex, int16 x, int16 y, int16 frameNum);
	int16 setAnimFrame(uint16 channelIndex, int16 frameNum);
	int16 getAnimFrame(uint16 channelIndex);

	uint16 placeText(uint16 channelIndex, uint16 textObjectIndex, int16 x, int16 y, uint16 fontNum, int16 textColor, int16 outlineColor);

	void show();
	void flash(int count);

	void setFont(int16 fontNum);
	void printChar(uint c, int16 x, int16 y, byte color);
	void printText(const char *text);
	void printTextEx(const char *text, int16 x, int16 y, int16 fontNum, int16 textColor, int16 outlineColor, const ClipInfo &clipInfo);
	void printObjectText(int16 objectIndex, int16 x, int16 y, int16 fontNum, int16 textColor, int16 outlineColor, const ClipInfo &clipInfo);
	int16 getTextWidth(int16 fontNum, const char *text);

	// Interface functions for the screen effects class
	Graphics::Surface *lockScreen();
	void unlockScreen();
	void showWorkScreen();
	void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
	void updateScreenAndWait(int delay);

	int16 addToSpriteList(int16 index, int16 xofs, int16 yofs);
	SpriteListItem getFromSpriteList(int16 index);
	void clearSpriteList();

	void setDefaultMouseCursor();

protected:
	MadeEngine *_vm;
	ScreenEffects *_fx;

	bool _screenLock;
	bool _paletteLock;

	byte *_screenPalette;
	byte *_palette, *_newPalette;
	int _paletteColorCount, _oldPaletteColorCount;
	bool _paletteInitialized, _needPalette;
	int16 _textColor;
	int16 _outlineColor;
	int16 _dropShadowColor;

	int16 _textX, _textY;
	Common::Rect _textRect;
	int16 _currentFontNum;
	FontResource *_font;
	ClipInfo _fontDrawCtx;

	int16 _clip, _exclude, _ground, _mask;
	int _visualEffectNum;

	Graphics::Surface *_backgroundScreen, *_workScreen, *_screenMask;
	ClipInfo _clipArea, _backgroundScreenDrawCtx, _workScreenDrawCtx, _maskDrawCtx;

	ClipInfo _excludeClipArea[4];
	bool _excludeClipAreaEnabled[4];

	uint16 _channelsUsedCount;
	SpriteChannel _channels[100];

	Common::Array<SpriteListItem> _spriteList;

};

} // End of namespace Made

#endif /* MADE_H */