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