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/events.h"
33 #include "mediastation/mediascript/scriptvalue.h"
34 
35 namespace MediaStation {
36 
37 class MediaStationEngine;
38 struct DissolvePattern;
39 class PixMapImage;
40 
41 enum BlitMode {
42  kUncompressedBlit = 0x00,
43  kRle8Blit = 0x01,
44  kClipEnabled = 0x04,
45  kUncompressedTransparentBlit = 0x08,
46  kPartialDissolve = 0x10,
47  kFullDissolve = 0x20,
48  // These are variants of Color Cell Compression to compress low framerate
49  // "videos" as opposed to just animations. They seem only to be used in
50  // the Lamb Chop cutscenes.
51  kColorCellCompressionBlit = 0x40,
52  kColorCellCompressionTransparentBlit = 0x80
53 };
54 
55 enum TransitionType {
56  kTransitionFadeToBlack = 300,
57  kTransitionFadeToPalette = 301,
58  kTransitionSetToPalette = 302,
59  kTransitionSetToBlack = 303,
60  kTransitionFadeToColor = 304,
61  kTransitionSetToColor = 305,
62  kTransitionSetToPercentOfPalette = 306,
63  kTransitionFadeToPaletteObject = 307,
64  kTransitionSetToPaletteObject = 308,
65  kTransitionSetToPercentOfPaletteObject = 309,
66  kTransitionColorShiftCurrentPalette = 310,
67  kTransitionScrollLeft = 311,
68  kTransitionScrollRight = 312,
69  kTransitionScrollUp = 313,
70  kTransitionScrollDown = 314,
71  kTransitionWipeLeft = 315,
72  kTransitionWipeRight = 316,
73  kTransitionWipeUp = 317,
74  kTransitionWipeDown = 318,
75  kTransitionSlideLeft = 319,
76  kTransitionSlideRight = 320,
77  kTransitionSlideUp = 321,
78  kTransitionSlideDown = 322,
79  kTransitionSlitLROpen = 323,
80  kTransitionSlitLRClose = 324,
81  kTransitionSlitUDOpen = 325,
82  kTransitionSlitUDClose = 326,
83  kTransitionCircleIn = 327,
84  kTransitionCircleOut = 328
85 };
86 const char *transitionTypeToStr(TransitionType type);
87 
88 enum VideoDisplayManagerSectionType {
89  kVideoDisplayManagerUpdateDirty = 0x578,
90  kVideoDisplayManagerUpdateAll = 0x579,
91  kVideoDisplayManagerEffectTransition = 0x57a,
92  kVideoDisplayManagerSetTime = 0x57b,
93  kVideoDisplayManagerLoadPalette = 0x5aa,
94 };
95 
96 class Region {
97 public:
98  void addRect(const Common::Rect &rect);
99  bool intersects(const Common::Rect &rect);
100  void operator&=(const Common::Rect &rect);
101  void operator+=(const Common::Point &point);
102 
104  Common::Rect _bounds;
105 };
106 
107 class Clip {
108 public:
109  Clip() {}
110  Clip(const Common::Rect &rect);
111 
112  void addToRegion(const Region &region);
113  void addToRegion(const Common::Rect &rect);
114  bool clipIntersectsRect(const Common::Rect &rect);
115  void intersectWithRegion(const Common::Rect &rect);
116  void makeEmpty();
117 
118  Region _region;
119  Common::Rect _bounds;
120 };
121 
123 public:
124  bool clipIsEmpty();
125  void intersectClipWith(const Common::Rect &rect);
126  bool rectIsInClip(const Common::Rect &rect);
127  void setClipTo(Region region);
128  void emptyCurrentClip();
129  void deleteClips();
130 
131  void addClip();
132  Clip *currentClip();
133  Clip *previousClip();
134  void verifyClipSize();
135 
136  // These are not named as such in the original, but are helper functions
137  // for things that likely were macros or something similar in the original.
138  void pushOrigin();
139  void popOrigin();
140 
141  Common::Point _origin;
142  Graphics::ManagedSurface *_destImage = nullptr;
143 
144 private:
146  Common::Stack<Clip> _clips;
147 };
148 
149 
151 public:
152  bool printerIsReady();
153  void printScreen();
154  void printSpatialObject(SpatialEntity *entity);
155  void setSourceSize(Common::Point size);
156  void flushToPrinter();
157 
158  bool _isPortrait = false;
159 
160  double _leftMargin = -1;
161  double _rightMargin = -1;
162  double _topMargin = -1;
163  double _bottomMargin = -1;
164 };
165 
167 public:
168  virtual ~DisplayUpdateManager() {}
169  virtual void onEvent(const DisplayEvent &event);
170 
171  void performAutoUpdateAndFlush();
172  void performUpdateAll();
173  void performUpdateDirty();
174 
175  void enableAutoUpdate(uint disabledUpdateDepthCounter);
176  uint disableAutoUpdate();
177  bool needToDisplay();
178 
179 private:
180  bool _autoUpdateEnabled = true;
181  bool _forceFlush = false;
182  uint _disabledScreenAutoUpdateToken = 0;
183 };
184 
186 public:
189 
190  virtual bool attemptToReadFromStream(Chunk &chunk, uint sectionType) override;
191 
192  void flushToDisplay();
193  void updateScreen() { _screen->update(); }
194  Graphics::Palette *getRegisteredPalette() { return _registeredPalette; }
195  void setRegisteredPalette(Graphics::Palette *palette) { _registeredPalette = palette; }
196 
197  void imageBlit(
198  Common::Point destinationPoint,
199  const PixMapImage *image,
200  double dissolveFactor,
201  DisplayContext *displayContext,
202  Graphics::ManagedSurface *destinationImage = nullptr,
203  bool useTransBlit = false);
204 
205  void imageDeltaBlit(
206  Common::Point deltaFramePos,
207  const Common::Point &keyFrameOffset,
208  const PixMapImage *deltaFrame,
209  const PixMapImage *keyFrame,
210  const double dissolveFactor,
211  DisplayContext *displayContext);
212 
213  Graphics::ManagedSurface decompressRle8Bitmap(
214  const PixMapImage *source,
215  const Graphics::ManagedSurface *keyFrame = nullptr,
216  const Common::Point *keyFrameOffset = nullptr);
217 
218  const int16 CCC_BLOCK_DIMENSION = 4;
219  Graphics::ManagedSurface decompressCccBitmap(const PixMapImage *source);
220  Graphics::ManagedSurface decompressCccTransparentBitmap(const PixMapImage *source);
221  void decompressCccBlock(
223  int16_t blockX,
224  int16_t blockY,
225  uint8_t backgroundColor,
226  uint8_t foregroundColor,
227  uint16_t bitMask,
228  int16_t blockWidth,
229  int16_t blockHeight,
230  const uint8_t *transparencyColor = nullptr);
231 
232  void effectTransition(Common::Array<ScriptValue> &args);
233  void setTransitionOnSync(Common::Array<ScriptValue> &args) { _scheduledTransitionOnSync = args; }
234  void doTransitionOnSync();
235 
236  void setGammaValues(double red, double green, double blue);
237  void getDefaultGammaValues(double &red, double &green, double &blue);
238  void getGammaValues(double &red, double &green, double &blue);
239 
240  DisplayContext _displayContext;
241 
242 private:
243  MediaStationEngine *_vm = nullptr;
244  Graphics::Screen *_screen = nullptr;
245  Graphics::Palette *_registeredPalette = nullptr;
246  Common::Array<ScriptValue> _scheduledTransitionOnSync;
247  double _defaultTransitionTime = 0.0;
248 
249  const double DEFAULT_GAMMA_VALUE = 1.0;
250  double _redGamma = 1.0;
251  double _greenGamma = 1.0;
252  double _blueGamma = 1.0;
253 
254  void readAndEffectTransition(Chunk &chunk);
255  void readAndRegisterPalette(Chunk &chunk);
256 
257  // Blitting methods.
258  // blitRectsClip encompasses the functionality of both opaqueBlitRectsClip
259  // and transparentBlitRectsClip in the disasm.
260  void blitRectsClip(
262  const Common::Point &destLocation,
263  const PixMapImage *source,
264  const Common::Array<Common::Rect> &dirtyRegion,
265  bool useTransBlit = false);
266  void rleBlitRectsClip(
268  const Common::Point &destLocation,
269  const PixMapImage *source,
270  const Common::Array<Common::Rect> &dirtyRegion);
271  void cccBlitRectsClip(
273  const Common::Point &destLocation,
274  const PixMapImage *source,
275  const Common::Array<Common::Rect> &dirtyRegion);
276  void cccTransparentBlitRectsClip(
278  const Common::Point &destLocation,
279  const PixMapImage *source,
280  const Common::Array<Common::Rect> &dirtyRegion);
281  void dissolveBlitRectsClip(
283  const Common::Point &destPos,
284  const PixMapImage *source,
285  const Common::Array<Common::Rect> &dirtyRegion,
286  const uint dissolveFactor);
287  void dissolveBlit1Rect(
289  const Common::Rect &areaToRedraw,
290  const Common::Point &originOnScreen,
291  const PixMapImage *source,
292  const Common::Rect &dirtyRegion,
293  const DissolvePattern &pattern);
294  void fullDeltaRleBlitRectsClip(
295  Graphics::ManagedSurface *destinationImage,
296  const Common::Point &deltaFramePos,
297  const Common::Point &keyFrameOffset,
298  const PixMapImage *deltaFrame,
299  const PixMapImage *keyFrame,
300  const Common::Array<Common::Rect> &dirtyRegion);
301  void deltaRleBlitRectsClip(
302  Graphics::ManagedSurface *destinationImage,
303  const Common::Point &deltaFramePos,
304  const PixMapImage *deltaFrame,
305  const PixMapImage *keyFrame,
306  const Common::Array<Common::Rect> &dirtyRegion);
307  void deltaRleBlit1Rect(
308  Graphics::ManagedSurface *destinationImage,
309  const Common::Point &destinationPoint,
310  const PixMapImage *sourceImage,
311  const PixMapImage *deltaImage,
312  const Common::Rect &dirtyRect);
313 
314  // Transition methods.
315  const double DEFAULT_FADE_TRANSITION_TIME_IN_SECONDS = 0.5;
316  const byte DEFAULT_PALETTE_TRANSITION_START_INDEX = 0x01;
317  const byte DEFAULT_PALETTE_TRANSITION_COLOR_COUNT = 0xFE;
318  void fadeToBlack(Common::Array<ScriptValue> &args);
319  void fadeToRegisteredPalette(Common::Array<ScriptValue> &args);
320  void setToRegisteredPalette(Common::Array<ScriptValue> &args);
321  void setToBlack(Common::Array<ScriptValue> &args);
322  void fadeToColor(Common::Array<ScriptValue> &args);
323  void setToColor(Common::Array<ScriptValue> &args);
324  void setToPercentOfPalette(Common::Array<ScriptValue> &args);
325  void fadeToPaletteObject(Common::Array<ScriptValue> &args);
326  void setToPaletteObject(Common::Array<ScriptValue> &args);
327  void setToPercentOfPaletteObject(Common::Array<ScriptValue> &args);
328  void colorShiftCurrentPalette(Common::Array<ScriptValue> &args);
329  void circleOut(Common::Array<ScriptValue> &args);
330 
331  void _setPalette(Graphics::Palette &palette, uint startIndex, uint colorCount);
332  void _setPaletteToColor(Graphics::Palette &targetPalette, byte r, byte g, byte b);
333  uint _limitColorRange(uint &startIndex, uint &colorCount);
334  byte _interpolateColorComponent(byte source, byte target, double progress);
335 
336  void _fadeToColor(byte r, byte g, byte b, double fadeTime, uint startIndex, uint colorCount);
337  void _setToColor(byte r, byte g, byte b, uint startIndex, uint colorCount);
338  void _setPercentToColor(double percent, byte r, byte g, byte b, uint startIndex, uint colorCount);
339 
340  void _fadeToPalette(double fadeTime, Graphics::Palette &targetPalette, uint startIndex, uint colorCount);
341  void _setToPercentPalette(double percent, Graphics::Palette &currentPalette, Graphics::Palette &targetPalette,
342  uint startIndex, uint colorCount);
343  void _fadeToRegisteredPalette(double fadeTime, uint startIndex, uint colorCount);
344  void _setToRegisteredPalette(uint startIndex, uint colorCount);
345  void _colorShiftCurrentPalette(uint startIndex, uint shiftAmount, uint colorCount);
346  void _fadeToPaletteObject(uint paletteId, double fadeTime, uint startIndex, uint colorCount);
347  void _setToPaletteObject(uint paletteId, uint startIndex, uint colorCount);
348  void _setPercentToPaletteObject(double percent, uint paletteId, uint startIndex, uint colorCount);
349 };
350 
351 } // End of namespace MediaStation
352 
353 #endif
Definition: managed_surface.h:51
Definition: actor.h:279
Definition: graphics.h:185
Definition: actor.h:34
Definition: events.h:71
Definition: dissolvepatterns.h:726
Definition: datafile.h:99
Definition: rect.h:536
Definition: graphics.h:150
Definition: screen.h:47
Definition: graphics.h:122
Definition: clients.h:31
Definition: graphics.h:96
Definition: bitmap.h:52
Definition: mediastation.h:77
Definition: rect.h:144
Definition: graphics.h:107
Simple class for handling a palette data.
Definition: palette.h:61
Definition: graphics.h:166