ScummVM API documentation
graphics.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 SLUDGE_GRAPHICS_H
23 #define SLUDGE_GRAPHICS_H
24 
25 #include "sludge/sprbanks.h"
26 
27 namespace Common {
28 class SeekableReadStream;
29 class WriteStream;
30 }
31 
32 namespace Sludge {
33 
34 class Parallax;
35 class SludgeEngine;
36 class SpritePalette;
37 
38 struct StackHandler;
39 struct FrozenStuffStruct;
40 struct LoadedSpriteBank;
41 struct OnScreenPerson;
42 struct SpriteBank;
43 struct Sprite;
44 struct VariableStack;
45 struct ZBufferData;
46 
47 enum ELightMapMode {
48  LIGHTMAPMODE_NONE = -1,
49  LIGHTMAPMODE_HOTSPOT,
50  LIGHTMAPMODE_PIXEL,
51  LIGHTMAPMODE_NUM
52 };
53 
54 // Parallax
55 struct ParallaxLayer {
56  Graphics::Surface surface;
57  int speedX, speedY;
58  bool wrapS, wrapT;
59  uint16 fileNum, fractionX, fractionY;
60  int cameraX, cameraY;
61 };
63 
65 public:
67  virtual ~GraphicsManager();
68 
69  void init();
70  void kill();
71 
72  // graphics
73  void setWindowSize(uint winWidth, uint winHeight) { _winWidth = winWidth; _winHeight = winHeight; }
74  bool initGfx();
75  void display();
76  void clear();
77 
78  // Parallax
79  bool loadParallax(uint16 v, uint16 fracX, uint16 fracY);
80  void killParallax();
81  void saveParallax(Common::WriteStream *fp);
82  void drawParallax();
83 
84  // Backdrop
85  void killAllBackDrop();
86  bool resizeBackdrop(int x, int y);
87  bool killResizeBackdrop(int x, int y);
88  void killBackDrop();
89  void loadBackDrop(int fileNum, int x, int y);
90  void mixBackDrop(int fileNum, int x, int y);
91  void drawBackDrop();
92  void blankScreen(int x1, int y1, int x2, int y2);
93  void blankAllScreen();
94  void darkScreen();
95  void saveHSI(Common::WriteStream *stream);
96  bool loadHSI(int num, Common::SeekableReadStream *stream, int, int, bool);
97  bool mixHSI(int num, Common::SeekableReadStream *stream, int x = 0, int y = 0);
98  void drawLine(uint, uint, uint, uint);
99  void drawHorizontalLine(uint, uint, uint);
100  void drawVerticalLine(uint, uint, uint);
101  void hardScroll(int distance);
102  bool getRGBIntoStack(uint x, uint y, StackHandler *sH);
103  void saveBackdrop(Common::WriteStream *stream); // To game save
104  void loadBackdrop(int ssgVersion, Common::SeekableReadStream *streamn); // From game save
105 
106  // Lightmap
107  int _lightMapMode;
108  void killLightMap();
109  bool loadLightMap(int v);
110  void saveLightMap(Common::WriteStream *stream);
111  bool loadLightMap(int ssgVersion, Common::SeekableReadStream *stream);
112 
113  // Snapshot
114  void nosnapshot();
115  bool snapshot();
116  void saveSnapshot(Common::WriteStream *stream);
117  bool restoreSnapshot(Common::SeekableReadStream *stream);
118 
119  // Camera
120  int getCamX() { return _cameraX; }
121  int getCamY() { return _cameraY; }
122  float getCamZoom() { return _cameraZoom; }
123  void aimCamera(int cameraX, int cameraY);
124  void zoomCamera(int z);
125 
126  // Screen
127  int getCenterX(int width) { return (_winWidth - width) >> 1; }
128  int checkSizeValide(int width, int height) { return ((width >= 0) && (height >= 0) && (width < (int)_winWidth) && (height < (int)_winHeight)); }
129 
130  // Freeze
131  bool freeze();
132  void unfreeze(bool killImage = true);
133  int howFrozen();
134  bool isFrozen() { return (_frozenStuff != nullptr); }
135 
136  // Sprites
137  static void forgetSpriteBank(SpriteBank &forgetme);
138  bool loadSpriteBank(char *filename, SpriteBank &loadhere);
139  bool loadSpriteBank(int fileNum, SpriteBank &loadhere, bool isFont);
140 
141  void fontSprite(int x1, int y1, Sprite &single, const SpritePalette &fontPal);
142  void flipFontSprite(int x1, int y1, Sprite &single, const SpritePalette &fontPal);
143 
144  bool scaleSprite(Sprite &single, const SpritePalette &fontPal, OnScreenPerson *thisPerson, bool mirror);
145  void fixScaleSprite(int x1, int y1, Sprite &single, const SpritePalette &fontPal, OnScreenPerson *thisPerson, const int camX, const int camY, bool);
146 
147  void pasteSpriteToBackDrop(int x1, int y1, Sprite &single, const SpritePalette &fontPal);
148  bool reserveSpritePal(SpritePalette &sP, int n);
149  void burnSpriteToBackDrop(int x1, int y1, Sprite &single, const SpritePalette &fontPal);
150 
151  // Sprite Bank
152  LoadedSpriteBank *loadBankForAnim(int ID);
153 
154  // ZBuffer
155  bool setZBuffer(int y);
156  void killZBuffer();
157  void drawZBuffer(int x, int y, bool upsidedown);
158  void saveZBuffer(Common::WriteStream *stream);
159  bool loadZBuffer(Common::SeekableReadStream *stream);
160 
161  void drawSpriteToZBuffer(int x, int y, uint8 depth, const Graphics::Surface &surface);
162  void fillZBuffer(uint8 d);
163 
164  // Colors
165  void setBlankColor(int r, int g, int b) { _currentBlankColour = _renderSurface.format.RGBToColor(r & 255, g & 255, b & 255);};
166  void setBurnColor(int r, int g, int b) {
167  _currentBurnR = r;
168  _currentBurnG = g;
169  _currentBurnB = b;
170  }
171  void saveColors(Common::WriteStream *stream);
172  void loadColors(Common::SeekableReadStream *stream);
173 
174  // Thumbnail
175  bool setThumbnailSize(int thumbWidth, int thumbHeight);
176  bool saveThumbnail(Common::WriteStream *stream);
178  void showThumbnail(const Common::String &filename, int x, int y);
179 
180  // Transition
181  void setBrightnessLevel(int brightnessLevel);
182  void setFadeMode(int fadeMode) { _fadeMode = fadeMode; };
183  void fixBrightness();
184  void resetRandW();
185  void reserveTransitionTexture();
186 
187  void transitionFader();
188  void transitionDisolve();
189  void transitionTV();
190  void transitionBlinds();
191  void transitionSnapshotBox();
192  void transitionCrossFader();
193 
194  // BG effects
195  bool blurScreen();
196  void blur_saveSettings(Common::WriteStream *stream);
197  void blur_loadSettings(Common::SeekableReadStream *stream);
198  bool blur_createSettings(int numParams, VariableStack *&stack);
199 
200  uint getWinWidth() { return _winWidth; }
201  uint getWinHeight() { return _winHeight; }
202 
203 private:
204  SludgeEngine *_vm;
205 
206  uint _winWidth, _winHeight, _sceneWidth, _sceneHeight;
207 
208  // renderSurface
209  Graphics::Surface _renderSurface;
210 
211  // Z Buffer Surface
212  uint8 *_zBufferSurface = nullptr;
213 
214  // Snapshot
215  Graphics::Surface _snapshotSurface;
216 
217  // LightMap
218  int _lightMapNumber;
219  Graphics::Surface _lightMap;
220 
221  // Camera
222  float _cameraZoom;
223  int _cameraX, _cameraY;
224 
225  // Freeze
226  FrozenStuffStruct *_frozenStuff;
227  Graphics::Surface _freezeSurface;
228  void freezeGraphics();
229 
230  // Back drop
231  Graphics::Surface _backdropSurface;
232  Graphics::Surface _origBackdropSurface;
233  bool _backdropExists;
234  bool reserveBackdrop();
235 
236  // Sprites
237  void fontSprite(bool flip, int x, int y, Sprite &single, const SpritePalette &fontPal);
238  Graphics::Surface *duplicateSurface(Graphics::Surface *surface);
239  void blendColor(Graphics::Surface * surface, uint32 color, Graphics::TSpriteBlendMode mode);
240  Graphics::Surface *applyLightmapToSprite(Graphics::Surface *&blitted, OnScreenPerson *thisPerson, bool mirror, int x, int y, int x1, int y1, int diffX, int diffY);
241 
242  // Sprite banks
243  LoadedSpriteBanks _allLoadedBanks;
244 
245  // ZBuffer
246  ZBufferData *_zBuffer;
247  void sortZPal(int *oldpal, int *newpal, int size);
248 
249  // Colors
250  uint _currentBlankColour;
251  byte _currentBurnR, _currentBurnG, _currentBurnB;
252 
253  // Thumbnail
254  int _thumbWidth;
255  int _thumbHeight;
256 
257  // Transition
258  byte _brightnessLevel;
259  byte _fadeMode;
260 
261 #define RANDKK 17
262 
263  uint32 _randbuffer[RANDKK][2];
264  int _randp1, _randp2;
265  Graphics::ManagedSurface *_transitionTexture;
266 
267  // Parallax
268  ParallaxLayers *_parallaxLayers;
269 
270  inline int sortOutPCamera(int cX, int fX, int sceneMax, int boxMax) {
271  return (fX == 65535) ? (sceneMax ? ((cX * boxMax) / sceneMax) : 0) : ((cX * fX) / 100);
272  }
273 };
274 
275 } // End of namespace Sludge
276 
277 
278 #endif // SLUDGE_GRAPHICS_H
Definition: managed_surface.h:51
Definition: str.h:59
Definition: variable.h:132
Definition: surface.h:66
bool saveThumbnail(Common::WriteStream &out)
Definition: people.h:76
Definition: stream.h:77
Definition: variable.h:60
Definition: graphics.h:64
Definition: list.h:44
Definition: sprites.h:28
Definition: sprites.h:78
Definition: stream.h:745
Definition: sprites.h:34
Definition: sludge.h:68
Definition: builtin.h:27
Definition: algorithm.h:29
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: freeze.h:41
Definition: sprbanks.h:28
Definition: zbuffer.h:26
Definition: graphics.h:55