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 _transparency;
92 
93  int16 _sourceSurface;
94  int16 _destSurface;
95 
96  char _letterToPrint;
97  const char *_textToPrint;
98  char *_hotspotText;
99 
100  int16 _backDeltaX;
101  int16 _backDeltaY;
102 
103  int16 _subtitleFont;
104  int16 _subtitleColor;
105 
106  FontToSprite _fontToSprite[4];
107  Font *_fonts[kFontCount];
108 
109  Common::Array<SurfacePtr> _spritesArray;
110 
111  int16 _invalidatedCount;
112  int16 _invalidatedLefts[30];
113  int16 _invalidatedTops[30];
114  int16 _invalidatedRights[30];
115  int16 _invalidatedBottoms[30];
116 
117  bool _noInvalidated;
118  // Don't blit invalidated rects when in video mode 5 or 7
119  bool _noInvalidated57;
120  bool _paletteCleared;
121  bool _applyPal;
122 
123  SurfacePtr _backSurface;
124  SurfacePtr _frontSurface;
125 
126  int16 _unusedPalette1[18];
127  int16 _unusedPalette2[16];
128  Video::Color _vgaPalette[256];
129 
130  Common::Stack<Video::Color *> _paletteStack;
131 
132  // 0 (00b): No cursor
133  // 1 (01b): Cursor would be on _backSurface
134  // 2 (10b): Cursor would be on _frontSurface
135  // 3 (11b): Cursor would be on _backSurface and _frontSurface
136  uint8 _showCursor;
137  int16 _cursorIndex;
138  int16 _transparentCursor;
139  uint32 _cursorTimeKey;
140 
141  int16 _cursorX;
142  int16 _cursorY;
143  int16 _cursorWidth;
144  int16 _cursorHeight;
145 
146  int32 _cursorHotspotXVar;
147  int32 _cursorHotspotYVar;
148 
149  int32 _cursorHotspotX;
150  int32 _cursorHotspotY;
151 
152  SurfacePtr _cursorSprites;
153  SurfacePtr _cursorSpritesBack;
154  SurfacePtr _scummvmCursor;
155 
156  int16 _cursorAnim;
157  int8 _cursorAnimLow[40];
158  int8 _cursorAnimHigh[40];
159  int8 _cursorAnimDelays[40];
160  Common::String _cursorNames[40];
161  Common::String _cursorName;
162  bool _cursorDrawnFromScripts;
163 
164  int32 _cursorCount;
165 
166  int16 _palLoadData1[4];
167  int16 _palLoadData2[4];
168 
169  // Coordinates adjustment mode
170  // Some game were released for a higher resolution than the one they
171  // were originally designed for. adjustCoords() is used to adjust
172  //
173  int16 _needAdjust;
174 
175  int16 _scrollOffsetY;
176  int16 _scrollOffsetX;
177 
178  int16 _pattern;
179 
180  fascinWin _fascinWin[10];
181  int16 _winMaxWidth;
182  int16 _winMaxHeight;
183  int16 _winCount;
184  int16 _winVarArrayLeft;
185  int16 _winVarArrayTop;
186  int16 _winVarArrayWidth;
187  int16 _winVarArrayHeight;
188  int16 _winVarArrayStatus;
189  int16 _winVarArrayLimitsX;
190  int16 _winVarArrayLimitsY;
191 
192 
193  void invalidateRect(int16 left, int16 top, int16 right, int16 bottom);
194  void blitInvalidated();
195  void setPalette();
196  void clearPalette();
197 
198  void dirtiedRect(int16 surface, int16 left, int16 top, int16 right, int16 bottom);
199  void dirtiedRect(SurfacePtr surface, int16 left, int16 top, int16 right, int16 bottom);
200 
201  void initSpriteSurf(int16 index, int16 width, int16 height, int16 flags, byte bpp = 0);
202  void freeSprite(int16 index);
203  void adjustCoords(char adjust, int16 *coord1, int16 *coord2);
204  void adjustCoords(char adjust, uint16 *coord1, uint16 *coord2) {
205  adjustCoords(adjust, (int16 *)coord1, (int16 *)coord2);
206  }
207  void resizeCursors(int16 width, int16 height, int16 count, bool transparency);
208  int stringLength(const char *str, uint16 fontIndex);
209  void printTextCentered(int16 id, int16 left, int16 top, int16 right,
210  int16 bottom, const char *str, int16 fontIndex, int16 color);
211  void oPlaytoons_sub_F_1B( uint16 id, int16 left, int16 top, int16 right, int16 bottom, char *paramStr, int16 var3, int16 var4, int16 shortId);
212 
213  int32 getSpriteRectSize(int16 index);
214  void forceBlit(bool backwards = false);
215 
216  static const int16 _wobbleTable[360];
217  void wobble(Surface &surfDesc);
218 
219  Font *loadFont(const char *path) const;
220  bool loadFont(uint16 fontIndex, const char *path);
221 
222  virtual void initScreen() = 0;
223  virtual void closeScreen() = 0;
224  virtual void blitCursor() = 0;
225 
226  virtual void animateCursor(int16 cursor) = 0;
227  virtual void printTotText(int16 id) = 0;
228  virtual void spriteOperation(int16 operation, bool ttsAddHotspotText = true) = 0;
229 
230  virtual int16 openWin(int16 id) { return 0; }
231  virtual void closeWin(int16 id) {}
232  virtual int16 handleCurWin() { return 0; }
233  virtual int16 getWinFromCoord(int16 &dx, int16 &dy) { return -1; }
234  virtual void moveWin(int16 id) {}
235  virtual bool overlapWin(int16 idWin1, int16 idWin2) { return false; }
236  virtual void closeAllWin() {}
237  virtual void activeWin(int16 id) {}
238 
239  Draw(GobEngine *vm);
240  virtual ~Draw();
241 
242 protected:
243  GobEngine *_vm;
244 #ifdef USE_TTS
245  Common::String _previousTot;
246 #endif
247 };
248 
249 class Draw_v1 : public Draw {
250 public:
251  void initScreen() override;
252  void closeScreen() override;
253  void blitCursor() override;
254  void animateCursor(int16 cursor) override;
255  void printTotText(int16 id) override;
256  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
257 
258  Draw_v1(GobEngine *vm);
259  ~Draw_v1() override {}
260 };
261 
262 class Draw_v2 : public Draw_v1 {
263 public:
264  void initScreen() override;
265  void closeScreen() override;
266  void blitCursor() override;
267  void animateCursor(int16 cursor) override;
268  void printTotText(int16 id) override;
269  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
270 
271  Draw_v2(GobEngine *vm);
272  ~Draw_v2() override {}
273 
274 private:
275  uint8 _mayorWorkaroundStatus;
276 
277  void fixLittleRedStrings();
278 };
279 
280 class Draw_Bargon: public Draw_v2 {
281 public:
282  void initScreen() override;
283 
284  Draw_Bargon(GobEngine *vm);
285  ~Draw_Bargon() override {}
286 };
287 
288 class Draw_Fascination: public Draw_v2 {
289 public:
291  ~Draw_Fascination() override {}
292  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
293 
294  void decompWin(int16 x, int16 y, SurfacePtr destPtr);
295  void drawWin(int16 fct);
296  void saveWin(int16 id);
297  void restoreWin(int16 id);
298  void handleWinBorder(int16 id);
299  void drawWinTrace(int16 left, int16 top, int16 width, int16 height);
300 
301  int16 openWin(int16 id) override;
302  void closeWin(int16 id) override;
303  int16 getWinFromCoord(int16 &dx, int16 &dy) override;
304  int16 handleCurWin() override;
305  void activeWin(int16 id) override;
306  void moveWin(int16 id) override;
307  bool overlapWin(int16 idWin1, int16 idWin2) override;
308  void closeAllWin() override;
309 
310 };
311 
312 class Draw_Playtoons: public Draw_v2 {
313 public:
315  ~Draw_Playtoons() override {}
316  void spriteOperation(int16 operation, bool ttsAddHotspotText = true) override;
317 };
318 
319 
320 class Draw_v7 : public Draw_Playtoons {
321 public:
322  Draw_v7(GobEngine *vm);
323  ~Draw_v7() override;
324 
325  void initScreen() override;
326  void animateCursor(int16 cursor) override;
327 
328 
329 private:
330  Common::WinResources *_cursors;
331 
332  bool loadCursorFile();
333  bool loadCursorFromFile(Common::String filename);
334 };
335 
336 // Draw operations
337 
338 #define DRAW_BLITSURF 0
339 #define DRAW_PUTPIXEL 1
340 #define DRAW_FILLRECT 2
341 #define DRAW_DRAWLINE 3
342 #define DRAW_INVALIDATE 4
343 #define DRAW_LOADSPRITE 5
344 #define DRAW_PRINTTEXT 6
345 #define DRAW_DRAWBAR 7
346 #define DRAW_CLEARRECT 8
347 #define DRAW_FILLRECTABS 9
348 #define DRAW_DRAWLETTER 10
349 
350 } // End of namespace Gob
351 
352 #endif // GOB_DRAW_H
Definition: draw.h:280
Definition: gob.h:166
Definition: str.h:59
Definition: draw.h:249
Definition: draw.h:63
Definition: draw.h:71
Definition: array.h:52
Definition: draw.h:262
Definition: video.h:40
Definition: video.h:88
Definition: anifile.h:40
Definition: algorithm.h:29
Definition: draw.h:288
Definition: surface.h:106
Definition: draw.h:53
Definition: winexe.h:110
Definition: draw.h:312
Definition: draw.h:320
Definition: stack.h:102