ScummVM API documentation
gfx.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef CINE_GFX_H
23#define CINE_GFX_H
24
25#include "common/noncopyable.h"
26#include "common/rect.h"
27#include "common/stack.h"
28#include "cine/object.h"
29#include "cine/bg_list.h"
30
31namespace Cine {
32
33extern byte *collisionPage;
34static const int kCollisionPageBgIdxAlias = 8;
35
36enum BackBufferSource {
37 BEFORE_OPENING_MENU = 0,
38 BEFORE_TAKING_THUMBNAIL,
39 MAX_BACK_BUFFER_SOURCES
40};
41
45struct palBg {
46 byte *bg;
48 char name[15];
49
51 palBg() : bg(NULL), pal(), name() {
52 // Make sure the name is empty (Maybe this is not needed?)
53 memset(this->name, 0, sizeof(this->name));
54 }
55
57 void clear() {
58 // In Operation Stealth the 9th background is sometimes aliased to
59 // the collision page so we should take care not to double delete it
60 // (The collision page is deleted elsewhere).
61 if (this->bg != collisionPage) {
62 delete[] this->bg;
63 }
64 this->bg = NULL;
65 this->pal.clear();
66 memset(this->name, 0, sizeof(this->name));
67 }
68};
69
70class FWRenderer;
71
72class Menu {
73public:
74 enum Type {
75 kSelectionMenu,
76 kTextInputMenu
77 };
78
79 Menu(Type t) : _type(t) {}
80 virtual ~Menu() {}
81
82 Type getType() const { return _type; }
83
84 virtual void drawMenu(FWRenderer &r, bool top) = 0;
85private:
86 const Type _type;
87};
88
89class SelectionMenu : public Menu {
90public:
91 SelectionMenu(Common::Point p, int width, Common::StringArray elements);
92
93 int getElementCount() const { return _elements.size(); }
94
95 void setSelection(int selection);
96
97 void drawMenu(FWRenderer &r, bool top) override;
98private:
99 const Common::Point _pos;
100 const int _width;
101 const Common::StringArray _elements;
102
103 int _selection;
104};
105
106class TextInputMenu : public Menu {
107public:
108 TextInputMenu(Common::Point p, int width, const char *info);
109
110 void setInput(const char *input, int cursor);
111
112 void drawMenu(FWRenderer &r, bool top) override;
113private:
114 const Common::Point _pos;
115 const int _width;
116 const Common::String _info;
117
118 Common::String _input;
119 int _cursor;
120};
121
128 // TODO: Consider getting rid of this
129 friend class SelectionMenu;
130 friend class TextInputMenu;
131private:
132 byte * _savedBackBuffers[MAX_BACK_BUFFER_SOURCES];
133 byte *_background;
134 char _bgName[13];
135
136 Common::String _cmd;
137
138protected:
139 static const int _screenSize = 320 * 200;
140 static const int _screenWidth = 320;
141 static const int _screenHeight = 200;
142
149 uint32 _fadeToBlackLastCalledMs;
150
151 virtual const Cine::Palette& getFadeInSourcePalette();
152 void fillSprite(const ObjectStruct &obj, uint8 color = 0);
153 void drawMaskedSprite(const ObjectStruct &obj, const byte *mask);
154 virtual void drawSprite(const ObjectStruct &obj);
155
156 int drawMessage(const char *str, int x, int y, int width, int color, bool draw = true);
157 void drawPlainBox(int x, int y, int width, int height, byte color);
158 byte transparentDialogBoxStartColor();
159 void drawTransparentBox(int x, int y, int width, int height);
160 void drawBorder(int x, int y, int width, int height, byte color);
161 void drawDoubleBorder(int x, int y, int width, int height, byte color);
162 virtual int drawChar(char character, int x, int y, bool draw = true);
163 virtual int undrawChar(char character, int x, int y);
164 void drawLine(int x, int y, int width, int height, byte color);
165 void remaskSprite(byte *mask, Common::List<overlay>::iterator it);
166 virtual void drawBackground();
167 virtual void clearBackBuffer();
168 virtual void removeSavedBackBuffers();
169
170 virtual void renderOverlay(const Common::List<overlay>::iterator &it);
171 void drawOverlays();
172 virtual void blit(bool useCollisionPage);
173
174public:
175 uint16 _messageBg;
176 uint16 _cmdY;
177
178 FWRenderer();
179 virtual ~FWRenderer();
180
181 virtual bool initialize();
182
184 virtual bool ready() { return _background != NULL; }
185 virtual unsigned int currentBg() { return 0; };
186 virtual unsigned int scrollBg() { return 0; }
187 virtual bool useTransparentDialogBoxes();
188
189 virtual void clear();
190
191 void drawFrame(bool wait = false);
192 void drawCommand();
193 void setCommand(Common::String cmd);
194 Common::String getCommand();
195 virtual void blit();
196 virtual void blitBackBuffer();
197
198 virtual void incrustMask(const BGIncrust &incrust, uint8 color = 0);
199 virtual void incrustSprite(const BGIncrust &incrust);
200
201 virtual bool hasSavedBackBuffer(BackBufferSource source);
202
204 virtual void saveBackBuffer(BackBufferSource source);
205
206 virtual void popSavedBackBuffer(BackBufferSource source);
207
209 virtual void restoreSavedBackBuffer(BackBufferSource source);
210
211 virtual void removeSavedBackBuffer(BackBufferSource source);
212
213 virtual int16 addBackground(const char *bgName, uint16 bgIdx);
214 virtual void loadBg16(const byte *bg, const char *name, unsigned int idx = 0);
215 virtual void loadCt16(const byte *ct, const char *name);
216 virtual void loadBg256(const byte *bg, const char *name, unsigned int idx = 0);
217 virtual void loadCt256(const byte *ct, const char *name);
218 virtual void selectBg(unsigned int idx);
219 virtual void selectScrollBg(unsigned int idx);
220 virtual void setScroll(unsigned int shift);
221 virtual uint getScroll() const;
222 virtual void removeBg(unsigned int idx);
223 virtual void saveBgNames(Common::OutSaveFile &fHandle);
224 virtual const char *getBgName(uint idx = 0) const;
225
226 virtual void setBlackPalette(bool updateChangePal);
227 virtual void setPalette();
228 virtual void restorePalette(Common::SeekableReadStream &fHandle, int version);
229 virtual void savePalette(Common::OutSaveFile &fHandle);
230 virtual void rotatePalette(int firstIndex, int lastIndex, int mode);
231 virtual void transformPalette(int first, int last, int r, int g, int b);
232
233 void pushMenu(Menu *menu);
234 Menu *popMenu();
235 void clearMenuStack();
236
237 virtual uint fadeDelayMs();
238 virtual uint fadeToBlackMinMs();
239 virtual void fadeToBlack();
240 virtual void fadeFromBlack();
241 void showCollisionPage(bool state);
242
243 void drawString(const char *string, byte param);
244 int getStringWidth(const char *str);
245};
246
250class OSRenderer : public FWRenderer {
251private:
252 Common::Array<palBg> _bgTable;
253 unsigned int _currentBg;
254 unsigned int _scrollBg;
255 unsigned int _bgShift;
256
257protected:
258 void setBackground8ToCollisionPage();
259 const Cine::Palette& getFadeInSourcePalette() override;
260 void drawSprite(const ObjectStruct &obj) override;
261 void drawSprite(overlay *overlayPtr, const byte *spritePtr, int16 width, int16 height, byte *page, int16 x, int16 y, byte transparentColor, byte bpp);
262 int drawChar(char character, int x, int y, bool draw = true) override;
263 void drawBackground() override;
264 void renderOverlay(const Common::List<overlay>::iterator &it) override;
265
266public:
267 OSRenderer();
268 ~OSRenderer() override;
269
270 bool initialize() override;
271
273 bool ready() override { return _bgTable[_currentBg].bg != NULL; }
274 unsigned int currentBg() override { return _currentBg; };
275 unsigned int scrollBg() override { return _scrollBg; }
276
277 void clear() override;
278
279 void incrustMask(const BGIncrust &incrust, uint8 color = 0) override;
280 void incrustSprite(const BGIncrust &incrust) override;
281
282 int16 addBackground(const char *bgName, uint16 bgIdx) override;
283 void loadBg16(const byte *bg, const char *name, unsigned int idx = 0) override;
284 void loadCt16(const byte *ct, const char *name) override;
285 void loadBg256(const byte *bg, const char *name, unsigned int idx = 0) override;
286 void loadCt256(const byte *ct, const char *name) override;
287 void selectBg(unsigned int idx) override;
288 void selectScrollBg(unsigned int idx) override;
289 void setScroll(unsigned int shift) override;
290 uint getScroll() const override;
291 void removeBg(unsigned int idx) override;
292 void saveBgNames(Common::OutSaveFile &fHandle) override;
293 const char *getBgName(uint idx = 0) const override;
294
295 void restorePalette(Common::SeekableReadStream &fHandle, int version) override;
296 void savePalette(Common::OutSaveFile &fHandle) override;
297 void rotatePalette(int firstIndex, int lastIndex, int mode) override;
298 void transformPalette(int first, int last, int r, int g, int b) override;
299};
300
301void gfxDrawSprite(byte *src4, uint16 sw, uint16 sh, byte *dst4, int16 sx, int16 sy);
302
303extern FWRenderer *renderer;
304
305void setMouseCursor(int cursor);
306void gfxCopyPage(byte *source, byte *dest);
307
308void transformPaletteRange(byte startColor, byte numColor, int8 r, int8 g, int8 b);
309void gfxFlipPage();
310
311void gfxDrawMaskedSprite(const byte *ptr, const byte *msk, uint16 width, uint16 height, byte *page, int16 x, int16 y);
312void gfxFillSprite(const byte *src4, uint16 sw, uint16 sh, byte *dst4, int16 sx, int16 sy, uint8 fillColor = 0);
313
314void gfxUpdateSpriteMask(byte *destMask, int16 x, int16 y, int16 width, int16 height, const byte *maskPtr, int16 xm, int16 ym, int16 maskWidth, int16 maskHeight);
315
316void gfxDrawLine(int16 x1, int16 y1, int16 x2, int16 y2, byte color, byte *page);
317void gfxDrawPlainBox(int16 x1, int16 y1, int16 x2, int16 y2, byte color);
318
319void gfxResetPage(byte *pagePtr);
320
321int16 gfxGetBit(int16 x, int16 y, const byte *ptr, int16 width);
322byte gfxGetColor(int16 x, int16 y, const byte *ptr, int16 width);
323
324void gfxResetRawPage(byte *pageRaw);
325void gfxConvertSpriteToRaw(byte *dst, const byte *src, uint16 w, uint16 h);
326void gfxCopyRawPage(byte *source, byte *dest);
327void gfxFlipRawPage(byte *frontBuffer);
328void drawSpriteRaw(const byte *spritePtr, const byte *maskPtr, int16 width, int16 height, byte *page, int16 x, int16 y);
329void gfxDrawPlainBoxRaw(int16 x1, int16 y1, int16 x2, int16 y2, byte color, byte *page);
330void drawSpriteRaw2(const byte *spritePtr, byte transColor, int16 width, int16 height, byte *page, int16 x, int16 y);
331void maskBgOverlay(int targetBgIdx, const byte *spritePtr, const byte *maskPtr, int16 width, int16 height, byte *page, int16 x, int16 y);
332
333void fadeFromBlack();
334void fadeToBlack();
335
336//void gfxDrawMaskedSprite(byte *param1, byte *param2, byte *param3, byte *param4, int16 param5);
337void gfxWaitVBL();
338void gfxRedrawMouseCursor();
339
340void blitScreen(byte *frontBuffer, byte *backbuffer);
341void blitRawScreen(byte *frontBuffer);
342void flip();
343
344} // End of namespace Cine
345
346#endif
Definition: gfx.h:127
virtual void restoreSavedBackBuffer(BackBufferSource source)
Cine::Palette _activePal
The active color palette.
Definition: gfx.h:145
Common::Stack< Menu * > _menuStack
All displayed menus.
Definition: gfx.h:146
virtual bool ready()
Definition: gfx.h:184
int _changePal
Load active palette to video backend on next frame.
Definition: gfx.h:147
static const int _screenHeight
Screen height.
Definition: gfx.h:141
uint16 _cmdY
Player command string position on screen.
Definition: gfx.h:176
static const int _screenSize
Screen size.
Definition: gfx.h:139
Cine::Palette _backupPal
The backup color palette.
Definition: gfx.h:144
bool _showCollisionPage
Should we show the collision page instead of the back buffer? Used for debugging.
Definition: gfx.h:148
virtual void saveBackBuffer(BackBufferSource source)
static const int _screenWidth
Screen width.
Definition: gfx.h:140
uint16 _messageBg
Message box background color.
Definition: gfx.h:175
byte * _backBuffer
Screen backbuffer.
Definition: gfx.h:143
Definition: gfx.h:72
Definition: gfx.h:250
bool ready() override
Definition: gfx.h:273
Definition: pal.h:56
Palette & clear()
Definition: gfx.h:89
Definition: gfx.h:106
size_type size() const
Definition: array.h:316
Definition: noncopyable.h:39
Definition: savefile.h:54
Definition: stream.h:745
Definition: stack.h:102
Definition: str.h:59
Definition: anim.h:29
Definition: object.h:29
Definition: object.h:50
Definition: gfx.h:45
Cine::Palette pal
Background color palette.
Definition: gfx.h:47
byte * bg
Background data.
Definition: gfx.h:46
char name[15]
Background filename.
Definition: gfx.h:48
void clear()
Clears the struct (Releases allocated memory etc).
Definition: gfx.h:57
palBg()
Default constructor.
Definition: gfx.h:51
Definition: list_intern.h:54
Definition: rect.h:144