aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/gfx/base_renderer.h
blob: 6b1a4f97f411a627704bdc50fc8259e04efbda3e (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
/* 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 file is based on WME Lite.
 * http://dead-code.org/redir.php?target=wmelite
 * Copyright (c) 2011 Jan Nedoma
 */

#ifndef WINTERMUTE_BASE_RENDERER_H
#define WINTERMUTE_BASE_RENDERER_H

#include "engines/wintermute/math/rect32.h"
#include "engines/wintermute/base/base.h"
#include "common/rect.h"
#include "common/array.h"

namespace Wintermute {

class BaseImage;
class BaseActiveRect;
class BaseObject;
class BaseSurface;
class BasePersistenceManager;

/**
 * @class BaseRenderer a common interface for the rendering portion of WME
 * this interface is mainly intended to wrap away any differencies between
 * software-rendering/hardware-rendering.
 */
class BaseRenderer: public BaseClass {
public:
	int _realWidth;
	int _realHeight;
	int _drawOffsetX;
	int _drawOffsetY;

	virtual void dumpData(const char *filename) {}
	/**
	 * Take a screenshot of the current screenstate
	 *
	 * @return a BaseImage containing the current screen-buffer.
	 */
	virtual BaseImage *takeScreenshot() = 0;
	virtual bool saveScreenShot(const Common::String &filename, int sizeX = 0, int sizeY = 0);
	virtual bool setViewport(int left, int top, int right, int bottom);
	virtual bool setViewport(Rect32 *rect);
	virtual Rect32 getViewPort() = 0;
	virtual bool setScreenViewport();

	virtual Graphics::PixelFormat getPixelFormat() const = 0;
	/**
	 * Fade the screen to black
	 *
	 * @param alpha amount to fade by (alpha value of black)
	 */
	virtual void fade(uint16 alpha) = 0;
	/**
	 * Fade a portion of the screen to a specific color
	 *
	 * @param r the red component to fade too.
	 * @param g the green component to fade too.
	 * @param b the blue component to fade too.
	 * @param a the alpha component to fade too.
	 * @param rect the portion of the screen to fade (if nullptr, the entire screen will be faded).
	 */
	virtual void fadeToColor(byte r, byte g, byte b, byte a) = 0;

	virtual bool drawLine(int x1, int y1, int x2, int y2, uint32 color); 	// Unused outside indicator-display
	virtual bool drawRect(int x1, int y1, int x2, int y2, uint32 color, int width = 1); 	// Unused outside indicator-display
	BaseRenderer(BaseGame *inGame = nullptr);
	virtual ~BaseRenderer();
	virtual bool setProjection() {
		return STATUS_OK;
	};

	virtual bool windowedBlt();
	/**
	 * Fill a portion of the screen with a specified color
	 *
	 * @param r the red component to fill with.
	 * @param g the green component to fill with.
	 * @param b the blue component to fill with.
	 */
	virtual bool fill(byte r, byte g, byte b, Common::Rect *rect = nullptr) = 0;
	virtual void onWindowChange();
	virtual bool initRenderer(int width, int height, bool windowed);
	/**
	 * Flip the backbuffer onto the screen-buffer
	 * The screen will NOT be updated before calling this function.
	 *
	 * @return true if successfull, false on error.
	 */
	virtual bool flip() = 0;
	/**
	 * Special flip for the indicator drawn during save/load
	 * essentially, just copies the region defined by the _indicator-variables.
	 */
	virtual bool indicatorFlip() = 0;
	virtual void initLoop();
	virtual bool setup2D(bool force = false);
	virtual bool setupLines();

	/**
	 * Get the name of the current renderer
	 *
	 * @return the name of the renderer.
	 */
	virtual Common::String getName() const = 0;
	virtual bool displayDebugInfo() {
		return STATUS_FAILED;
	};
	virtual bool drawShaderQuad() {
		return STATUS_FAILED;
	}

	virtual float getScaleRatioX() const {
		return 1.0f;
	}
	virtual float getScaleRatioY() const {
		return 1.0f;
	}

	/**
	 * Create a Surface fit for use with the renderer.
	 * As diverse implementations of BaseRenderer might have different solutions for storing surfaces
	 * this allows for a common interface for creating surface-handles. (Mostly usefull to ease future
	 * implementation of hw-accelerated rendering, or readding 3D-support at some point).
	 *
	 * @return a surface that can be used with this renderer
	 */
	virtual BaseSurface *createSurface() = 0;

	bool clipCursor();
	bool unclipCursor();

	BaseObject *getObjectAt(int x, int y);
	void deleteRectList();

	virtual bool startSpriteBatch() {
		return STATUS_OK;
	};
	virtual bool endSpriteBatch() {
		return STATUS_OK;
	};
	bool pointInViewport(Point32 *P);
	bool _active;
	bool _ready;

	bool isReady() const { return _ready; }
	bool isWindowed() const { return _windowed; }
	int32 getBPP() const { return _bPP; }

	uint32 _window;
	uint32 _forceAlphaColor;

	void addRectToList(BaseActiveRect *rect);

	// Indicator & Save/Load-related functions
	void initIndicator();
	void setIndicatorVal(int value);
	void setIndicator(int width, int height, int x, int y, uint32 color);
	void persistSaveLoadImages(BasePersistenceManager *persistMgr);
	void initSaveLoad(bool isSaving, bool quickSave = false);
	virtual void endSaveLoad();
	void setLoadingScreen(const char *filename, int x, int y);
	void setSaveImage(const char *filename, int x, int y);

	bool displayIndicator();

	int32 getWidth() const { return _width; }
	int32 getHeight() const { return _height; }
protected:
	int32 _height;
	int32 _width;

	bool _windowed;
	int32 _bPP;

	Common::String _loadImageName;
	Common::String _saveImageName;
	int32 _saveImageX;
	int32 _saveImageY;
	int32 _loadImageX;
	int32 _loadImageY;
	BaseSurface *_saveLoadImage;
	bool _hasDrawnSaveLoadImage;

	int32 _indicatorWidthDrawn;
	uint32 _indicatorColor;
	int32 _indicatorX;
	int32 _indicatorY;
	int32 _indicatorWidth;
	int32 _indicatorHeight;
	bool _loadInProgress;
	bool _indicatorDisplay;
	int32 _indicatorProgress;

	uint32 _clipperWindow;

	Rect32 _windowRect;
	Rect32 _viewportRect;
	Rect32 _screenRect;
	Rect32 _monitorRect;
private:
	Common::Array<BaseActiveRect *> _rectList;
};

BaseRenderer *makeOSystemRenderer(BaseGame *inGame); // Implemented in BRenderSDL.cpp

} // End of namespace Wintermute

#endif