aboutsummaryrefslogtreecommitdiff
path: root/engines/lab/dispman.h
blob: d83d4fb73e8208507f8cf1a7c798c170fdf470ae (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
/* 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.
 *
 */

/*
 * This code is based on Labyrinth of Time code with assistance of
 *
 * Copyright (c) 1993 Terra Nova Development
 * Copyright (c) 2004 The Wyrmkeep Entertainment Co.
 *
 */

#ifndef LAB_DISPMAN_H
#define LAB_DISPMAN_H

namespace Lab {

class LabEngine;
class Image;

struct TextFont {
	uint32 _dataLength;
	uint16 _height;
	byte _widths[256];
	uint16 _offsets[256];
	byte *_data;
};

enum TransitionType {
	kTransitionNone,
	kTransitionWipe,
	kTransitionScrollWipe,
	kTransitionScrollBlack,
	kTransitionScrollBounce,
	kTransitionTransporter,
	kTransitionReadFirstFrame,
	kTransitionReadNextFrame
};

class DisplayMan {
private:
	LabEngine *_vm;

	/**
	 * Does the fading of the Palette on the screen.
	 */
	uint16 fadeNumIn(uint16 num, uint16 res, uint16 counter);
	uint16 fadeNumOut(uint16 num, uint16 res, uint16 counter);

	/**
	 * Extracts the first word from a string.
	 */
	Common::String getWord(const char *mainBuffer);

	void createBox(uint16 y2);

	/**
	 * Sets up either a low-res or a high-res 256 color screen.
	 */
	void createScreen(bool hiRes);

	/**
	 * Scrolls the display to black.
	 */
	void doScrollBlack();
	void copyPage(uint16 width, uint16 height, uint16 nheight, uint16 startline, byte *mem);

	/**
	 * Scrolls the display to a new picture from a black screen.
	 */
	void doScrollWipe(const Common::String filename);

	/**
	 * Does the scroll bounce.  Assumes bitmap already in memory.
	 */
	void doScrollBounce();

	/**
	 * Does the transporter wipe.
	 */
	void doTransWipe(const Common::String filename);

	/**
	 * Draws a vertical line.
	 */
	void drawHLine(uint16 x, uint16 y1, uint16 y2, byte color);

	/**
	 * Draws a horizontal line.
	 */
	void drawVLine(uint16 x1, uint16 y, uint16 x2, byte color);

	/**
	 * Draws the text to the screen.
	 */
	void drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const Common::String text);

	/**
	 * Gets a line of text for flowText; makes sure that its length is less than
	 * or equal to the maximum width.
	 */
	Common::String getLine(TextFont *tf, const char **mainBuffer, uint16 lineWidth);

	/**
	 * Returns the length of a text in the specified font.
	 */
	uint16 textLength(TextFont *font, const Common::String text);

	bool _actionMessageShown;
	Common::File *_curBitmap;
	byte _curVgaPal[256 * 3];
	byte *_currentDisplayBuffer;

public:
	DisplayMan(LabEngine *lab);
	virtual ~DisplayMan();

	void loadPict(const Common::String filename);
	void loadBackPict(const Common::String fileName, uint16 *highPal);

	/**
	 * Reads in a picture into the display bitmap.
	 */
	void readPict(const Common::String filename, bool playOnce = true, bool onlyDiffData = false, byte *memoryBuffer = nullptr);
	void freePict();

	/**
	 * Does a certain number of pre-programmed wipes.
	 */
	void doTransition(TransitionType transitionType, const Common::String filename);

	/**
	 * Changes the front screen to black.
	 */
	void blackScreen();

	/**
	 * Changes the front screen to white.
	 */
	void whiteScreen();

	/**
	 * Changes the entire screen to black.
	*/
	void blackAllScreen();

	/**
	 * Draws the control panel display.
	 */
	void drawPanel();

	/**
	 * Sets up the Labyrinth screens, and opens up the initial windows.
	 */
	void setUpScreens();

	int longDrawMessage(Common::String str, bool isActionMessage);

	/**
	 * Draws a message to the message box.
	 */
	void drawMessage(Common::String str, bool isActionMessage);

	void setActionMessage(bool val) { _actionMessageShown = val; }

	/**
	 * Fills in a rectangle.
	 */
	void rectFill(uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte color);
	void rectFill(Common::Rect fillRect, byte color);
	void rectFillScaled(uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte color);
	/**
	 * Dumps a chunk of text to an arbitrary box; flows it within that box and
	 * optionally centers it. Returns the number of characters that were processed.
	 * @note Every individual word MUST be int16 enough to fit on a line, and
	 * each line less than 255 characters.
	 * @param font Pointer on the font used
	 * @param spacing How much vertical spacing between the lines
	 * @param penColor Pen number to use for text
	 * @param backPen Background color
	 * @param fillBack Whether to fill the background
	 * @param centerh Whether to center the text horizontally
	 * @param centerv Whether to center the text vertically
	 * @param output Whether to output any text
	 * @param textRect Coords
	 * @param text The text itself
	 */
	int flowText(TextFont *font, int16 spacing, byte penColor, byte backPen, bool fillBack,
				bool centerh, bool centerv, bool output, Common::Rect textRect, const char *text, Image *targetImage = nullptr);

	void screenUpdate();

	/**
	 * Converts a 16-color Amiga palette to a VGA palette, then sets
	 * the VGA palette.
	 */
	void setAmigaPal(uint16 *pal);

	/**
	 * Writes any number of the 256 color registers.
	 * @param buf A char pointer which contains the selected color registers.
	 * Each value representing a color register occupies 3 bytes in the array.  The
	 * order is red, green then blue. The first byte in the array is the red component
	 * of the first element selected. The length of the buffer is 3 times the number
	 * of registers selected.
	 * @param first The number of the first color register to write.
	 * @param numReg The number of registers to write.
	 */
	void writeColorRegs(byte *buf, uint16 first, uint16 numReg);
	void setPalette(void *newPal, uint16 numColors);

	/**
	 * Overlays a region on the screen using the desired pen color.
	 */
	void checkerBoardEffect(uint16 penColor, uint16 x1, uint16 y1, uint16 x2, uint16 y2);

	/**
	 * Returns the base address of the current VGA display.
	 */
	byte *getCurrentDrawingBuffer();

	/**
	 * Scrolls the display in the x direction by blitting.
	 * The _tempScrollData variable must be initialized to some memory, or this
	 * function will fail.
	 */
	void scrollDisplayX(int16 dx, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer);

	/**
	 * Scrolls the display in the y direction by blitting.
	 */
	void scrollDisplayY(int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer);
	void fade(bool fadein);

	/**
	 * Closes a font and frees all memory associated with it.
	 */
	void freeFont(TextFont **font);

	/**
	 * Returns the height of a specified font.
	 */
	uint16 textHeight(TextFont *tf);

	bool _longWinInFront;
	bool _lastMessageLong;
	uint32 _screenBytesPerPage;
	int _screenWidth;
	int _screenHeight;
	byte *_displayBuffer;
	uint16 *_fadePalette;
};

} // End of namespace Lab

#endif // LAB_DISPMAN_H