ScummVM API documentation
draw.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_DRAW_H
29 #define GOB_DRAW_H
30 
31 #include "common/stack.h"
32 #include "gob/video.h"
33 
34 namespace Common {
35 class WinResources;
36 }
37 
38 namespace Gob {
39 
40 #define RENDERFLAG_NOINVALIDATE 0x0001
41 #define RENDERFLAG_CAPTUREPUSH 0x0002
42 #define RENDERFLAG_COLLISIONS 0x0004
43 #define RENDERFLAG_CAPTUREPOP 0x0008
44 #define RENDERFLAG_USEDELTAS 0x0010
45 #define RENDERFLAG_BORDERHOTSPOTS 0x0040
46 #define RENDERFLAG_HASWINDOWS 0x0080
47 #define RENDERFLAG_NOBLITINVALIDATED 0x0200
48 #define RENDERFLAG_NOSUBTITLES 0x0400
49 #define RENDERFLAG_FROMSPLIT 0x0800
50 #define RENDERFLAG_DOUBLECOORDS 0x1000
51 #define RENDERFLAG_DOUBLEVIDEO 0x2000
52 
53 class Draw {
54 public:
55  static const int kSpriteCount = 100;
56  static const int kFontCount = 16;
57  static const int kFrontSurface = 20;
58  static const int kBackSurface = 21;
59  static const int kAnimSurface = 22;
60  static const int kCursorSurface = 23;
61  static const int kCaptureSurface = 30;
62 
63  struct FontToSprite {
64  int8 sprite;
65  int8 base;
66  int8 width;
67  int8 height;
68  FontToSprite() : sprite(0), base(0), width(0), height(0) {}
69  };
70 
71  struct fascinWin {
72  int16 id;
73  int16 left;
74  int16 top;
75  int16 width;
76  int16 height;
77  SurfacePtr savedSurface;
78  };
79 
80  int16 _renderFlags;
81 
82  uint16 _fontIndex;
83  int16 _spriteLeft;
84  int16 _spriteTop;
85  int16 _spriteRight;
86  int16 _spriteBottom;
87  int16 _destSpriteX;
88  int16 _destSpriteY;
89  int16 _backColor;
90  int16 _frontColor;
91  int16 _colorOffset;
92  int16 _transparency;
93 
94  int16 _sourceSurface;
95  int16 _destSurface;
96 
97  char _letterToPrint;
98  const char *_textToPrint;
99  char *_hotspotText;
100 
101  int16 _backDeltaX;
102  int16 _backDeltaY;
103 
104  int16 _subtitleFont;
105  int16 _subtitleColor;
106 
107  FontToSprite _fontToSprite[4];
108  Font *_fonts[kFontCount];
109 
110  Common::Array<SurfacePtr> _spritesArray;
111 
112  int16 _invalidatedCount;
113  int16 _invalidatedLefts[30];
114  int16 _invalidatedTops[30];
115  int16 _invalidatedRights[30];
116  int16 _invalidatedBottoms[30];
117 
118  bool _noInvalidated;
119  // Don't blit invalidated rects when in video mode 5 or 7
120  bool _noInvalidated57;
121  bool _paletteCleared;
122  bool _applyPal;
123 
124  SurfacePtr _backSurface;
125  SurfacePtr _frontSurface;
126 
127  int16 _unusedPalette1[18];
128  int16 _unusedPalette2[16];
129  Video::Color _vgaPalette[256];
130 
131  Common::Stack<Video::Color *> _paletteStack;
132 
133  // 0 (00b): No cursor
134  // 1 (01b): Cursor would be on _backSurface
135  // 2 (10b): Cursor would be on _frontSurface
136  // 3 (11b): Cursor would be on _backSurface and _frontSurface
137  uint8 _showCursor;
138  int16 _cursorIndex;
139  int16 _transparentCursor;
140  uint32 _cursorTimeKey;
141 
142  int16 _cursorX;
143  int16 _cursorY;
144  int16 _cursorWidth;
145  int16 _cursorHeight;
146 
147  int32 _cursorHotspotXVar;
148  int32 _cursorHotspotYVar;
149 
150  int32 _cursorHotspotX;
151  int32 _cursorHotspotY;
152 
153  SurfacePtr _cursorSprites;
154  SurfacePtr _cursorSpritesBack;
155  SurfacePtr _scummvmCursor;
156 
157  int16 _cursorAnim;
158  int8 _cursorAnimLow[40];
159  int8 _cursorAnimHigh[40];
160  int8 _cursorAnimDelays[40];
161  Common::String _cursorNames[40];
162  Common::String _cursorName;
163  bool _cursorDrawnFromScripts;
164 
165  int32 _cursorCount;
166 
167  int16 _palLoadData1[4];
168  int16 _palLoadData2[4];
169 
170  // Coordinates adjustment mode
171  // Some game were released for a higher resolution than the one they
172  // were originally designed for. adjustCoords() is used to adjust
173  //
174  int16 _needAdjust;
175 
176  int16 _scrollOffsetY;
177  int16 _scrollOffsetX;
178 
179  int16 _pattern;
180 
181  fascinWin _fascinWin[10];
182  int16 _winMaxWidth;
183  int16 _winMaxHeight;
184  int16 _winCount;
185  int16 _winVarArrayLeft;
186  int16 _winVarArrayTop;
187  int16 _winVarArrayWidth;
188  int16 _winVarArrayHeight;
189  int16 _winVarArrayStatus;
190  int16 _winVarArrayLimitsX;
191  int16 _winVarArrayLimitsY;
192 
193 
194  void invalidateRect(int16 left, int16 top, int16 right, int16 bottom);
195  void blitInvalidated();
196  void setPalette();
197  void clearPalette();
198 
199  void dirtiedRect(int16 surface, int16 left, int16 top, int16 right, int16 bottom);
200  void dirtiedRect(SurfacePtr surface, int16 left, int16 top, int16 right, int16 bottom);
201 
202  void initSpriteSurf(int16 index, int16 width, int16 height, int16 flags, byte bpp = 0);
203  void freeSprite(int16 index);
204  void adjustCoords(char adjust, int16 *coord1, int16 *coord2);
205  void adjustCoords(char adjust, uint16 *coord1, uint16 *coord2) {
206  adjustCoords(adjust, (int16 *)coord1, (int16 *)coord2);
207  }
208  void resizeCursors(int16 width, int16 height, int16 count, bool transparency);
209  int stringLength(const char *str, uint16 fontIndex);
210  void printTextCentered(int16 id, int16 left, int16 top, int16 right,
211  int16 bottom, const char *str, int16 fontIndex, int16 color);
212  void drawButton( uint16 id, int16 left, int16 top, int16 right, int16 bottom, char *paramStr, int16 var3, int16 var4, int16 shortId);
213 
214  int32 getSpriteRectSize(int16 index);
215  void forceBlit(bool backwards = false);
216 
217  static const int16 _wobbleTable[360];
218  void wobble(Surface &surfDesc);
219 
220  Font *loadFont(const char *path) const;
221  bool loadFont(uint16 fontIndex, const char *path);
222 
223  virtual void initScreen() = 0;
224  virtual void closeScreen() = 0;
225  virtual void blitCursor() = 0;
226 
227  virtual void animateCursor(int16 cursor) = 0;
228  virtual void printTotText(int16 id) = 0;
229  virtual void spriteOperation(int16 operation, bool ttsAddHotspotText = true) = 0;
230 
231  virtual int16 openWin(int16 id) { return 0; }
232  virtual void closeWin(int16 id) {}
233  virtual int16 handleCurWin() { return 0; }
234  virtual int16 getWinFromCoord(int16 &dx, int16 &dy) { return -1; }
235  virtual void moveWin(int16 id) {}
236  virtual bool overlapWin(int16 idWin1, int16 idWin2) { return false; }
237  virtual void closeAllWin() {}
238  virtual void activeWin(int16 id) {}
239 
240  Draw(GobEngine *vm);
241  virtual ~Draw();
242 
243 protected:
244  GobEngine *_vm;
245 #ifdef USE_TTS
246  Common::String _previousTot;
247 #endif
248 };
249 
250 class Draw_v1 : public Draw {
251 public:
252  void initScreen() override;
253  void closeScreen() override;
254  void blitCursor() override;
255  void animateCursor(int16 cursor) override;
256  void printTotText(int16 id) override;
257  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
258 
259  Draw_v1(GobEngine *vm);
260  ~Draw_v1() override {}
261 };
262 
263 class Draw_v2 : public Draw_v1 {
264 public:
265  void initScreen() override;
266  void closeScreen() override;
267  void blitCursor() override;
268  void animateCursor(int16 cursor) override;
269  void printTotText(int16 id) override;
270  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
271 
272  Draw_v2(GobEngine *vm);
273  ~Draw_v2() override {}
274 
275 private:
276  uint8 _mayorWorkaroundStatus;
277 
278  void fixLittleRedStrings();
279 };
280 
281 class Draw_Bargon: public Draw_v2 {
282 public:
283  void initScreen() override;
284 
285  Draw_Bargon(GobEngine *vm);
286  ~Draw_Bargon() override {}
287 };
288 
289 class Draw_Fascination: public Draw_v2 {
290 public:
292  ~Draw_Fascination() override {}
293  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
294 
295  void decompWin(int16 x, int16 y, SurfacePtr destPtr);
296  void drawWin(int16 fct);
297  void saveWin(int16 id);
298  void restoreWin(int16 id);
299  void handleWinBorder(int16 id);
300  void drawWinTrace(int16 left, int16 top, int16 width, int16 height);
301 
302  int16 openWin(int16 id) override;
303  void closeWin(int16 id) override;
304  int16 getWinFromCoord(int16 &dx, int16 &dy) override;
305  int16 handleCurWin() override;
306  void activeWin(int16 id) override;
307  void moveWin(int16 id) override;
308  bool overlapWin(int16 idWin1, int16 idWin2) override;
309  void closeAllWin() override;
310 
311 };
312 
313 class Draw_Playtoons: public Draw_v2 {
314 private:
315  struct TotTextInfo {
316  Common::String str;
317  int16 rectLeft = 0;
318  int16 rectRight = 0;
319  int16 rectTop = 0;
320  int16 rectBottom = 0;
321  int16 colCmd = 0;
322  int16 fontIndex = 0;
323  int16 color = 0;
324  };
325 
326 public:
328  ~Draw_Playtoons() override {}
329  void printTotText(int16 id) override;
330  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
331 };
332 
333 
334 class Draw_v7 : public Draw_Playtoons {
335 public:
336  Draw_v7(GobEngine *vm);
337  ~Draw_v7() override;
338 
339  void initScreen() override;
340  void animateCursor(int16 cursor) override;
341 
342 
343 private:
344  Common::WinResources *_cursors;
345 
346  bool loadCursorFile();
347  bool loadCursorFromFile(Common::String filename);
348 };
349 
350 // Draw operations
351 
352 #define DRAW_BLITSURF 0
353 #define DRAW_PUTPIXEL 1
354 #define DRAW_FILLRECT 2
355 #define DRAW_DRAWLINE 3
356 #define DRAW_INVALIDATE 4
357 #define DRAW_LOADSPRITE 5
358 #define DRAW_PRINTTEXT 6
359 #define DRAW_DRAWBAR 7
360 #define DRAW_CLEARRECT 8
361 #define DRAW_FILLRECTABS 9
362 #define DRAW_DRAWLETTER 10
363 
364 } // End of namespace Gob
365 
366 #endif // GOB_DRAW_H
Definition: draw.h:281
Definition: gob.h:166
Definition: str.h:59
Definition: draw.h:250
Definition: draw.h:63
Definition: draw.h:71
Definition: array.h:52
Definition: draw.h:263
Definition: video.h:40
Definition: video.h:88
Definition: anifile.h:40
Definition: algorithm.h:29
Definition: draw.h:289
Definition: surface.h:106
Definition: draw.h:53
Definition: winexe.h:110
Definition: draw.h:313
Definition: draw.h:334
Definition: stack.h:102