aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/support/screen_manager.h
blob: 0736f1393cecefb3dd6c2b6de4a4b3b62529b4bb (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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/* 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 TITANIC_SCREEN_MANAGER_H
#define TITANIC_SCREEN_MANAGER_H

#include "common/scummsys.h"
#include "common/array.h"
#include "titanic/support/direct_draw.h"
#include "titanic/support/font.h"
#include "titanic/input_handler.h"
#include "titanic/support/mouse_cursor.h"
#include "titanic/support/text_cursor.h"
#include "titanic/support/video_surface.h"
#include "titanic/core/resource_key.h"

namespace Titanic {

/**
 * The original used page flipping with one primary and one back buffer.
 * Since we don't need that in ScummVM, the back buffer number below is
 * remapped to the primary surface
 */
enum SurfaceNum {
	SURFACE_PRIMARY = -1,		// Surface 0
	SURFACE_BACKBUFFER = -1		// Surface -1
};

class TitanicEngine;

class CScreenManager {
	struct VideoSurfaceEntry {
		CVideoSurface *_surface;
		Rect _bounds;
	};
protected:
	TitanicEngine *_vm;
public:
	static CScreenManager *_screenManagerPtr;
	static CScreenManager *_currentScreenManagerPtr;

	/**
	 * Set the current screen manager
	 */
	static CScreenManager *setCurrent();
public:
	Common::Array<VideoSurfaceEntry> _backSurfaces;
	CVideoSurface *_frontRenderSurface;
	CMouseCursor *_mouseCursor;
	CTextCursor *_textCursor;
	CInputHandler *_inputHandler;
	int _fontNumber;
public:
	CScreenManager(TitanicEngine *vm);
	virtual ~CScreenManager();

	void fn1() {}
	void fn2() {}

	virtual void setWindowHandle(int v);
	virtual bool resetWindowHandle(int v);
	
	/**
	 * Sets the video mode
	 */
	virtual void setMode(int width, int height, int bpp, uint numBackSurfaces, bool flag2) = 0;

	/**
	 * Handles drawing the cursors
	 */
	virtual void drawCursors() = 0;
	
	/**
	 * Locks a specified surface number for access and returns a pointer to it
	 */
	virtual CVideoSurface *lockSurface(SurfaceNum surfaceNum) = 0;
	
	/**
	 * Unlocks a previously locked surface
	 */
	virtual void unlockSurface(CVideoSurface *surface) = 0;
	
	/**
	 * Gets a specified surface number
	 */
	virtual CVideoSurface *getSurface(SurfaceNum surfaceNum) const = 0;

	/**
	 * Return the front render surface
	 */
	virtual CVideoSurface *getFrontRenderSurface() const = 0;
	
	/**
	 * Fill an area with a specific color
	 */
	virtual void fillRect(SurfaceNum surfaceNum, Rect *rect, byte r, byte g, byte b) = 0;

	/**
	 * Blits a surface onto one of the screen surfaces
	 */
	virtual void blitFrom(SurfaceNum surfaceNum, CVideoSurface *src, const Point *destPos = nullptr,
		const Rect *srcRect = nullptr) = 0;

	/**
	 * Blits a surface onto one of the screen surfaces
	 */
	virtual void blitFrom(SurfaceNum surfaceNum, const Rect *rect, CVideoSurface *src, int v = 0) = 0;

	/**
	 * Write a string
	 * @param surfaceNum	Destination surface
	 * @param destRect		Bounds within dest surface
	 * @param yOffset		Y offset for drawing, to allow for parts of
	 *						the text to be scrolled off-screen
	 * @param str			Line or lines to write
	 * @param textCursor	Optional text cursor pointer
	 */
	virtual int writeString(int surfaceNum, const Rect &destRect,
		int yOffset, const CString &str, CTextCursor *textCursor) = 0;

	/**
	 * Write a string
	 * @param surfaceNum	Destination surface
	 * @param srcRect		Drawing area
	 * @param destRect		Bounds of dest surface
	 * @param str			Line or lines to write
	 * @param textCursor	Optional text cursor pointer
	 */
	virtual int writeString(int surfaceNum, const Rect &srcRect,
		const Rect &destRect, const CString &str, CTextCursor *textCursor) = 0;

	/**
	 * Set the font color
	 */
	virtual void setFontColor(byte r, byte g, byte b) = 0;

	/**
	 * Get the text area a string will fit into
	 * @param str		String
	 * @param maxWidth	Maximum width in pixels
	 * @param sizeOut	Optional pointer to output size
	 * @returns			Required height
	 */
	virtual int getTextBounds(const CString &str, int maxWidth, Point *sizeOut = nullptr) const = 0;

	/**
	 * Get the current font height
	 */
	virtual int getFontHeight() const = 0;

	/**
	 * Returns the width of a given string in pixels
	 */
	virtual int stringWidth(const CString &str) = 0;

	/**
	 * Draws a frame enclosing the specified area
	 */
	virtual void frameRect(SurfaceNum surfaceNum, const Rect &rect, byte r, byte g, byte b) = 0;

	/**
	 * Clear a portion of a specified surface
	 */
	virtual void clearSurface(SurfaceNum surfaceNum, Rect *_bounds) = 0;

	/**
	 * Resize the passed surface
	 */
	virtual void resizeSurface(CVideoSurface *surface, int width, int height) = 0;

	/**
	 * Creates a surface of a given size
	 */
	virtual CVideoSurface *createSurface(int w, int h) = 0;
	
	/**
	 * Creates a surface from a specified resource
	 */
	virtual CVideoSurface *createSurface(const CResourceKey &key) = 0;

	/**
	* Get the top-left corner of the screen in global screen co-ordinates
	* For ScummVM, this is always (0, 0), even in Windowed mode
	*/
	virtual Point getScreenTopLeft() { return Point(0, 0); }

	/**
	 * Waits for a vertical screen sync
	 * For ScummVM, this can be safely ignored
	 */
	virtual void waitForVSync() {}

	/**
	 * Show the mouse cursor
	 */
	virtual void showCursor() = 0;
	
	/**
	 * Hide the mouse cursor
	 */
	virtual void hideCursor() = 0;

	/**
	 * Set drawing bounds for a specified surface
	 */
	void setSurfaceBounds(SurfaceNum surfaceNum, const Rect &r);

	/**
	 * Set the current font number
	 */
	int setFontNumber(int fontNumber);
};

class OSScreenManager: CScreenManager {
private:
	DirectDrawManager _directDrawManager;

	/**
	 * Frees any surface buffers
	 */
	void destroyFrontAndBackBuffers();

	/**
	 * Load game cursors
	 */
	void loadCursors();

	/**
	 * Gets an underlying surface
	 */
	DirectDrawSurface *getDDSurface(SurfaceNum surfaceNum);
public:
	int _field48;
	int _field4C;
	int _field50;
	int _field54;
	STFont _fonts[4];
public:
	OSScreenManager(TitanicEngine *vm);
	virtual ~OSScreenManager();

	/**
	 * Sets the video mode
	 */
	virtual void setMode(int width, int height, int bpp, uint numBackSurfaces, bool flag2);

	/**
	 * Handles drawing the cursors
	 */
	virtual void drawCursors();

	/**
	 * Locks a specified surface number for access and returns a pointer to it
	 */
	virtual CVideoSurface *lockSurface(SurfaceNum surfaceNum);
	
	/**
	 * Unlocks a previously locked surface
	 */
	virtual void unlockSurface(CVideoSurface *surface);
	
	/**
	 * Gets a specified surface number
	 */
	virtual CVideoSurface *getSurface(SurfaceNum surfaceNum) const;

	/**
	 * Return the front render surface
	 */
	virtual CVideoSurface *getFrontRenderSurface() const {
		return _frontRenderSurface;
	}


	/**
	 * Fill an area with a specific color
	 */
	virtual void fillRect(SurfaceNum surfaceNum, Rect *rect, byte r, byte g, byte b);

	/**
	 * Blits a surface onto one of the screen surfaces
	 */
	virtual void blitFrom(SurfaceNum surfaceNum, CVideoSurface *src, const Point *destPos,
		const Rect *srcRect = nullptr);

	/**
	 * Blits a surface onto one of the screen surfaces
	 */
	virtual void blitFrom(SurfaceNum surfaceNum, const Rect *rect, CVideoSurface *src, int v = 0);

	/**
	 * Write a string
	 * @param surfaceNum	Destination surface
	 * @param destRect		Bounds within dest surface
	 * @param yOffset		Y offset for drawing, to allow for parts of
	 *						the text to be scrolled off-screen
	 * @param str			Line or lines to write
	 * @param textCursor	Optional text cursor pointer
	 */
	virtual int writeString(int surfaceNum, const Rect &destRect,
		int yOffset, const CString &str, CTextCursor *textCursor);

	/**
	 * Write a string
	 * @param surfaceNum	Destination surface
	 * @param srcRect		Drawing area
	 * @param destRect		Bounds of dest surface
	 * @param str			Line or lines to write
	 * @param textCursor	Optional text cursor pointer
	 */
	virtual int writeString(int surfaceNum, const Rect &srcRect,
		const Rect &destRect, const CString &str, CTextCursor *textCursor);

	/**
	 * Set the font color
	 */
	virtual void setFontColor(byte r, byte g, byte b);

	/**
	 * Get the text area a string will fit into
	 * @param str		String
	 * @param maxWidth	Maximum width in pixels
	 * @param sizeOut	Optional pointer to output size
	 * @returns			Required height
	 */
	virtual int getTextBounds(const CString &str, int maxWidth, Point *sizeOut = nullptr) const;

	/**
	 * Get the current font height
	 */
	virtual int getFontHeight() const;

	/**
	 * Returns the width of a given string in pixels
	 */
	virtual int stringWidth(const CString &str);

	/**
	 * Draws a frame enclosing the specified area
	 */
	virtual void frameRect(SurfaceNum surfaceNum, const Rect &rect, byte r, byte g, byte b);

	/**
	 * Clear a portion of the screen surface
	 */
	virtual void clearSurface(SurfaceNum surfaceNum, Rect *bounds);

	/**
	 * Resize the passed surface
	 */
	virtual void resizeSurface(CVideoSurface *surface, int width, int height);

	/**
	 * Creates a surface of a given size
	 */
	virtual CVideoSurface *createSurface(int w, int h);
	
	/**
	 * Creates a surface from a specified resource
	 */
	virtual CVideoSurface *createSurface(const CResourceKey &key);

	/**
	 * Show the mouse cursor
	 */
	virtual void showCursor();
	
	/**
	 * Hide the mouse cursor
	 */
	virtual void hideCursor();
};

} // End of namespace Titanic

#endif /* TITANIC_SCREEN_MANAGER_H */