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 MEDIASTATION_GRAPHICS_H
23 #define MEDIASTATION_GRAPHICS_H
24 
25 #include "common/rect.h"
26 #include "common/array.h"
27 #include "common/stack.h"
28 #include "graphics/managed_surface.h"
29 #include "graphics/screen.h"
30 
31 #include "mediastation/clients.h"
32 #include "mediastation/mediascript/scriptvalue.h"
33 
34 namespace MediaStation {
35 
36 class MediaStationEngine;
37 struct DissolvePattern;
38 class PixMapImage;
39 
40 enum BlitMode {
41  kUncompressedBlit = 0x00,
42  kRle8Blit = 0x01,
43  kClipEnabled = 0x04,
44  kUncompressedTransparentBlit = 0x08,
45  kPartialDissolve = 0x10,
46  kFullDissolve = 0x20,
47  kCccBlit = 0x40,
48  kCccTransparentBlit = 0x80
49 };
50 
51 enum TransitionType {
52  kTransitionFadeToBlack = 300,
53  kTransitionFadeToPalette = 301,
54  kTransitionSetToPalette = 302,
55  kTransitionSetToBlack = 303,
56  kTransitionFadeToColor = 304,
57  kTransitionSetToColor = 305,
58  kTransitionSetToPercentOfPalette = 306,
59  kTransitionFadeToPaletteObject = 307,
60  kTransitionSetToPaletteObject = 308,
61  kTransitionSetToPercentOfPaletteObject = 309,
62  kTransitionColorShiftCurrentPalette = 310,
63  kTransitionCircleOut = 328
64 };
65 
66 enum VideoDisplayManagerSectionType {
67  kVideoDisplayManagerUpdateDirty = 0x578,
68  kVideoDisplayManagerUpdateAll = 0x579,
69  kVideoDisplayManagerEffectTransition = 0x57a,
70  kVideoDisplayManagerSetTime = 0x57b,
71  kVideoDisplayManagerLoadPalette = 0x5aa,
72 };
73 
74 class Region {
75 public:
76  void addRect(const Common::Rect &rect);
77  bool intersects(const Common::Rect &rect);
78  void operator&=(const Common::Rect &rect);
79  void operator+=(const Common::Point &point);
80 
82  Common::Rect _bounds;
83 };
84 
85 class Clip {
86 public:
87  Clip() {}
88  Clip(const Common::Rect &rect);
89 
90  void addToRegion(const Region &region);
91  void addToRegion(const Common::Rect &rect);
92  bool clipIntersectsRect(const Common::Rect &rect);
93  void intersectWithRegion(const Common::Rect &rect);
94  void makeEmpty();
95 
96  Region _region;
97  Common::Rect _bounds;
98 };
99 
101 public:
102  bool clipIsEmpty();
103  void intersectClipWith(const Common::Rect &rect);
104  bool rectIsInClip(const Common::Rect &rect);
105  void setClipTo(Region region);
106  void emptyCurrentClip();
107  void deleteClips();
108 
109  void addClip();
110  Clip *currentClip();
111  Clip *previousClip();
112  void verifyClipSize();
113 
114  // These are not named as such in the original, but are helper functions
115  // for things that likely were macros or something similar in the original.
116  void pushOrigin();
117  void popOrigin();
118 
119  Common::Point _origin;
120  Graphics::ManagedSurface *_destImage = nullptr;
121 
122 private:
124  Common::Stack<Clip> _clips;
125 };
126 
128 public:
131 
132  virtual bool attemptToReadFromStream(Chunk &chunk, uint sectionType) override;
133 
134  void updateScreen() { _screen->update(); }
135  Graphics::Palette *getRegisteredPalette() { return _registeredPalette; }
136  void setRegisteredPalette(Graphics::Palette *palette) { _registeredPalette = palette; }
137 
138  void imageBlit(
139  Common::Point destinationPoint,
140  const PixMapImage *image,
141  double dissolveFactor,
142  DisplayContext *displayContext,
143  Graphics::ManagedSurface *destinationImage = nullptr,
144  bool useTransBlit = false);
145 
146  void imageDeltaBlit(
147  Common::Point deltaFramePos,
148  const Common::Point &keyFrameOffset,
149  const PixMapImage *deltaFrame,
150  const PixMapImage *keyFrame,
151  const double dissolveFactor,
152  DisplayContext *displayContext);
153 
154  void effectTransition(Common::Array<ScriptValue> &args);
155  void setTransitionOnSync(Common::Array<ScriptValue> &args) { _scheduledTransitionOnSync = args; }
156  void doTransitionOnSync();
157 
158  void performUpdateDirty();
159  void performUpdateAll();
160 
161  void setGammaValues(double red, double green, double blue);
162  void getDefaultGammaValues(double &red, double &green, double &blue);
163  void getGammaValues(double &red, double &green, double &blue);
164 
165  DisplayContext _displayContext;
166 
167 private:
168  MediaStationEngine *_vm = nullptr;
169  Graphics::Screen *_screen = nullptr;
170  Graphics::Palette *_registeredPalette = nullptr;
171  Common::Array<ScriptValue> _scheduledTransitionOnSync;
172  double _defaultTransitionTime = 0.0;
173 
174  const double DEFAULT_GAMMA_VALUE = 1.0;
175  double _redGamma = 1.0;
176  double _greenGamma = 1.0;
177  double _blueGamma = 1.0;
178 
179  void readAndEffectTransition(Chunk &chunk);
180  void readAndRegisterPalette(Chunk &chunk);
181 
182  // Blitting methods.
183  // blitRectsClip encompasses the functionality of both opaqueBlitRectsClip
184  // and transparentBlitRectsClip in the disasm.
185  void blitRectsClip(
187  const Common::Point &destLocation,
188  const Graphics::ManagedSurface &source,
189  const Common::Array<Common::Rect> &dirtyRegion,
190  bool useTransBlit = false);
191  void rleBlitRectsClip(
193  const Common::Point &destLocation,
194  const PixMapImage *source,
195  const Common::Array<Common::Rect> &dirtyRegion);
196  Graphics::ManagedSurface decompressRle8Bitmap(
197  const PixMapImage *source,
198  const Graphics::ManagedSurface *keyFrame = nullptr,
199  const Common::Point *keyFrameOffset = nullptr);
200  void dissolveBlitRectsClip(
202  const Common::Point &destPos,
203  const PixMapImage *source,
204  const Common::Array<Common::Rect> &dirtyRegion,
205  const uint dissolveFactor);
206  void dissolveBlit1Rect(
208  const Common::Rect &areaToRedraw,
209  const Common::Point &originOnScreen,
210  const PixMapImage *source,
211  const Common::Rect &dirtyRegion,
212  const DissolvePattern &pattern);
213  void fullDeltaRleBlitRectsClip(
214  Graphics::ManagedSurface *destinationImage,
215  const Common::Point &deltaFramePos,
216  const Common::Point &keyFrameOffset,
217  const PixMapImage *deltaFrame,
218  const PixMapImage *keyFrame,
219  const Common::Array<Common::Rect> &dirtyRegion);
220  void deltaRleBlitRectsClip(
221  Graphics::ManagedSurface *destinationImage,
222  const Common::Point &deltaFramePos,
223  const PixMapImage *deltaFrame,
224  const PixMapImage *keyFrame,
225  const Common::Array<Common::Rect> &dirtyRegion);
226  void deltaRleBlit1Rect(
227  Graphics::ManagedSurface *destinationImage,
228  const Common::Point &destinationPoint,
229  const PixMapImage *sourceImage,
230  const PixMapImage *deltaImage,
231  const Common::Rect &dirtyRect);
232 
233  // Transition methods.
234  const double DEFAULT_FADE_TRANSITION_TIME_IN_SECONDS = 0.5;
235  const byte DEFAULT_PALETTE_TRANSITION_START_INDEX = 0x01;
236  const byte DEFAULT_PALETTE_TRANSITION_COLOR_COUNT = 0xFE;
237  void fadeToBlack(Common::Array<ScriptValue> &args);
238  void fadeToRegisteredPalette(Common::Array<ScriptValue> &args);
239  void setToRegisteredPalette(Common::Array<ScriptValue> &args);
240  void setToBlack(Common::Array<ScriptValue> &args);
241  void fadeToColor(Common::Array<ScriptValue> &args);
242  void setToColor(Common::Array<ScriptValue> &args);
243  void setToPercentOfPalette(Common::Array<ScriptValue> &args);
244  void fadeToPaletteObject(Common::Array<ScriptValue> &args);
245  void setToPaletteObject(Common::Array<ScriptValue> &args);
246  void setToPercentOfPaletteObject(Common::Array<ScriptValue> &args);
247  void colorShiftCurrentPalette(Common::Array<ScriptValue> &args);
248  void circleOut(Common::Array<ScriptValue> &args);
249 
250  void _setPalette(Graphics::Palette &palette, uint startIndex, uint colorCount);
251  void _setPaletteToColor(Graphics::Palette &targetPalette, byte r, byte g, byte b);
252  uint _limitColorRange(uint &startIndex, uint &colorCount);
253  byte _interpolateColorComponent(byte source, byte target, double progress);
254 
255  void _fadeToColor(byte r, byte g, byte b, double fadeTime, uint startIndex, uint colorCount);
256  void _setToColor(byte r, byte g, byte b, uint startIndex, uint colorCount);
257  void _setPercentToColor(double percent, byte r, byte g, byte b, uint startIndex, uint colorCount);
258 
259  void _fadeToPalette(double fadeTime, Graphics::Palette &targetPalette, uint startIndex, uint colorCount);
260  void _setToPercentPalette(double percent, Graphics::Palette &currentPalette, Graphics::Palette &targetPalette,
261  uint startIndex, uint colorCount);
262  void _fadeToRegisteredPalette(double fadeTime, uint startIndex, uint colorCount);
263  void _setToRegisteredPalette(uint startIndex, uint colorCount);
264  void _colorShiftCurrentPalette(uint startIndex, uint shiftAmount, uint colorCount);
265  void _fadeToPaletteObject(uint paletteId, double fadeTime, uint startIndex, uint colorCount);
266  void _setToPaletteObject(uint paletteId, uint startIndex, uint colorCount);
267  void _setPercentToPaletteObject(double percent, uint paletteId, uint startIndex, uint colorCount);
268 };
269 
270 } // End of namespace MediaStation
271 
272 #endif
Definition: managed_surface.h:51
Definition: graphics.h:127
Definition: actor.h:33
Definition: dissolvepatterns.h:726
Definition: datafile.h:102
Definition: rect.h:524
Definition: screen.h:48
Definition: graphics.h:100
Definition: clients.h:29
Definition: graphics.h:74
Definition: bitmap.h:52
Definition: mediastation.h:74
Definition: rect.h:144
Definition: graphics.h:85
Simple class for handling a palette data.
Definition: palette.h:61