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