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 HDB_GFX_H
23 #define HDB_GFX_H
24 
25 #include "graphics/managed_surface.h"
26 
27 namespace Math {
28  class SineTable;
29  class CosineTable;
30 }
31 
32 namespace HDB {
33 
34 #define HDB_FONT "normalprop"
35 
36 struct TileLookup {
37  const char *filename;
38  Tile *tData;
39  uint16 skyIndex;
40  uint16 animIndex;
41 
42  TileLookup() : filename(nullptr), tData(nullptr), skyIndex(0), animIndex(0) {}
43 };
44 
45 struct GfxCache {
46  char name[32];
47  bool status; // false = tileGfx, true = picGfx
48  union {
49  Tile *tileGfx;
50  Picture *picGfx;
51  };
52  uint32 size;
53  int16 loaded;
54 
55  GfxCache() : status(false), tileGfx(nullptr), size(0), loaded(0) { name[0] = 0; }
56 };
57 
58 struct FontInfo {
59  int type; // 0 = mono, 1 = proportional
60  int numChars; // how many characters in font
61  int height; // height of entire font
62  int kerning; // space between chars
63  int leading; // space between lines
64 };
65 
66 struct CharInfo {
67  int16 width; // Character width in pixels
68  int32 offset; // From the start of the font charInfo chunk
69 };
70 
71 class Gfx {
72 public:
73 
74  Gfx();
75  ~Gfx();
76 
77  Graphics::ManagedSurface _globalSurface;
78 
79  void init();
80  void save(Common::OutSaveFile *out);
81  void loadSaveFile(Common::InSaveFile *in);
82  void fillScreen(uint32 color);
83  void updateVideo();
84  void setPointerState(int value);
85  void drawPointer();
86  void showPointer(bool status) {
87  _showCursor = status;
88  }
89  bool getPointer() {
90  return _showCursor;
91  }
92 
93  void setFade(bool fadeIn, bool black, int steps);
94  void updateFade();
95  bool isFadeActive() { return _fadeInfo.active; }
96  bool isFadeStaying() { return _fadeInfo.stayFaded; }
97  void turnOffFade() { _fadeInfo.active = _fadeInfo.stayFaded = false; }
98  void turnOnSnow();
99  void turnOffSnow() { _snowInfo.active = false; }
100 
101  Picture *loadPic(const char *picName);
102  Tile *loadTile(const char *tileName);
103  Tile *loadIcon(const char *tileName);
104  void setPixel(int x, int y, uint16 color);
105 
106  Tile *getTile(int index);
107  void cacheTileSequence(int index, int count);
108  int getTileIndex(const char *name);
109  Picture *getPicture(const char *name);
110 
111  void emptyGfxCaches();
112  void markTileCacheFreeable();
113  void markGfxCacheFreeable();
114 
115  // Returns: true->Tile, false->Pic
116  bool selectGfxType(const char *name);
117  Tile *getTileGfx(const char *name, int32 size);
118  Picture *getPicGfx(const char *name, int32 size);
119 
120  int isSky(int skyIndex);
121  void setSky(int skyIndex);
122  void setup3DStars();
123  void setup3DStarsLeft();
124  void draw3DStars();
125  void draw3DStarsLeft();
126  void drawSky();
127  void drawSnow();
128 
129  int animateTile(int tileIndex);
130 
131  // Font Functions
132 
133  bool loadFont(const char *string);
134  void drawText(const char *string);
135  void getDimensions(const char *string, int *pixelsWide, int *lines);
136  int stringLength(const char *string);
137  void centerPrint(const char *string);
138  void setTextEdges(int left, int right, int top, int bottom);
139  void getTextEdges(int *left, int *right, int *top, int *bottom);
140  void setKernLead(int kern, int lead);
141  void getKernLead(int *kern, int *lead);
142  void setCursor(int x, int y);
143  void getCursor(int *x, int *y);
144 
145  // Trig Functions
146 
147  double getSin(int index);
148  double getCos(int index);
149 
150  // Bonus star functions
151 
152  void turnOnBonusStars(int which);
153  void drawBonusStars();
154 
155  void drawDebugInfo(Tile *_debugLogo, int fps);
156 
157 private:
158  int _numTiles;
159  TileLookup *_tLookupArray;
160  uint16 _skyTiles[kMaxSkies];
161 
162  Graphics::ManagedSurface _fadeBuffer1, _fadeBuffer2;
163 
164  Common::Array<GfxCache *> *_gfxCache;
165 
166  int _currentSky; // 0 if no Sky, 1+ for which Sky to use
167  struct {
168  bool active;
169  bool stayFaded;
170  bool isBlack;
171  int speed;
172  bool isFadeIn;
173 
174  int curStep;
175  } _fadeInfo;
176 
177 #define MAX_SNOW 50 // how many snowflakes onscreen
178 #define MAX_SNOW_XV 12
179  struct {
180  bool active;
181  double x[MAX_SNOW];
182  double y[MAX_SNOW];
183  double yv[MAX_SNOW];
184  int xvindex[MAX_SNOW];
185  } _snowInfo;
186 
187  struct {
188  int x, y, speed;
189  uint16 color;
190  } _stars3D[kNum3DStars];
191 
192  struct {
193  double x, y, speed;
194  uint16 color;
195  } _stars3DSlow[kNum3DStars];
196 
197  int _tileSkyStars; // Index of sky_stars tile
198  int _tileSkyStarsLeft; // Left-scrolling stars, slow
199  int _tileSkyClouds; // Index of sky_stars tile
200  Picture *_starField[4];
201  Picture *_snowflake;
202  Picture *_skyClouds;
203 
204  struct {
205  bool active;
206  int starAngle[10];
207  Picture *gfx[2];
208  uint32 timer;
209  int anim, radius;
210  double angleSpeed;
211  uint32 totalTime;
212  } _starsInfo;
213 
214  // Cursor
215  int _cursorX, _cursorY;
216  Picture *_mousePointer[8]; // Gfx for screen pointer (4 Animations)
217  int _pointerDisplayable;
218  bool _showCursor;
219 
220  // Font Data
221 
222  FontInfo _fontHeader;
223  Common::Array<CharInfo *> _charInfoBlocks;
224  Graphics::Surface _fontSurfaces[256];
225  uint16 _fontGfx;
226  int _eLeft, _eRight, _eTop, _eBottom;
227 
228  bool _systemInit;
229 
230  Math::SineTable *_sines;
231  Math::CosineTable *_cosines;
232 };
233 
234 class Picture {
235 public:
236 
237  Picture();
238  ~Picture();
239 
241  int draw(int x, int y);
242  int drawMasked(int x, int y, int alpha = 0xff);
243 
244  int _width, _height;
245 
246  char *getName() { return _name; }
247 
248  Graphics::ManagedSurface *getSurface() { return &_surface; }
249 
250 private:
251  char _name[64];
252 
253  Graphics::ManagedSurface _surface;
254 };
255 
256 class Tile {
257 public:
258 
259  Tile();
260  ~Tile();
261 
263  int draw(int x, int y);
264  int drawMasked(int x, int y, int alpha = 0xff);
265 
266  uint32 _flags;
267 
268  char *getName() { return _name; }
269 private:
270  char _name[64];
271 
272  Graphics::ManagedSurface _surface;
273 };
274 
275 } // End of Namespace HDB
276 
277 #endif // !HDB_GFX_H
Definition: managed_surface.h:51
Definition: ai-player.h:25
Definition: gfx.h:71
Definition: gfx.h:36
Definition: surface.h:67
Definition: savefile.h:54
Definition: array.h:52
Definition: gfx.h:66
Definition: stream.h:745
Definition: wma.h:38
Definition: gfx.h:256
Definition: gfx.h:45
Definition: gfx.h:58
Definition: gfx.h:234