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