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 "graphics/managed_surface.h"
28 #include "graphics/screen.h"
29 
30 #include "mediastation/clients.h"
31 #include "mediastation/mediascript/scriptvalue.h"
32 
33 namespace MediaStation {
34 
35 class MediaStationEngine;
36 struct DissolvePattern;
37 class Bitmap;
38 
39 enum BlitMode {
40  kUncompressedBlit = 0x00,
41  kRle8Blit = 0x01,
42  kClipEnabled = 0x04,
43  kUncompressedTransparentBlit = 0x08,
44  kPartialDissolve = 0x10,
45  kFullDissolve = 0x20,
46  kCccBlit = 0x40,
47  kCccTransparentBlit = 0x80
48 };
49 
50 enum TransitionType {
51  kTransitionFadeToBlack = 300,
52  kTransitionFadeToPalette = 301,
53  kTransitionSetToPalette = 302,
54  kTransitionSetToBlack = 303,
55  kTransitionFadeToColor = 304,
56  kTransitionSetToColor = 305,
57  kTransitionSetToPercentOfPalette = 306,
58  kTransitionFadeToPaletteObject = 307,
59  kTransitionSetToPaletteObject = 308,
60  kTransitionSetToPercentOfPaletteObject = 309,
61  kTransitionColorShiftCurrentPalette = 310,
62  kTransitionCircleOut = 328
63 };
64 
65 enum VideoDisplayManagerSectionType {
66  kVideoDisplayManagerUpdateDirty = 0x578,
67  kVideoDisplayManagerUpdateAll = 0x579,
68  kVideoDisplayManagerEffectTransition = 0x57a,
69  kVideoDisplayManagerSetTime = 0x57b,
70  kVideoDisplayManagerLoadPalette = 0x5aa,
71 };
72 
74 public:
77 
78  virtual bool attemptToReadFromStream(Chunk &chunk, uint sectionType) override;
79 
80  void updateScreen() { _screen->update(); }
81  Graphics::Palette *getRegisteredPalette() { return _registeredPalette; }
82  void setRegisteredPalette(Graphics::Palette *palette) { _registeredPalette = palette; }
83 
84  void imageBlit(
85  const Common::Point &destinationPoint,
86  const Bitmap *image,
87  double dissolveFactor,
88  const Common::Array<Common::Rect> &dirtyRegion,
89  Graphics::ManagedSurface *destinationImage = nullptr);
90 
91  void imageDeltaBlit(
92  const Common::Point &deltaFramePos,
93  const Common::Point &keyFrameOffset,
94  const Bitmap *deltaFrame,
95  const Bitmap *keyFrame,
96  const double dissolveFactor,
97  const Common::Array<Common::Rect> &dirtyRegion);
98 
99  void effectTransition(Common::Array<ScriptValue> &args);
100  void setTransitionOnSync(Common::Array<ScriptValue> &args) { _scheduledTransitionOnSync = args; }
101  void doTransitionOnSync();
102 
103  void performUpdateDirty();
104  void performUpdateAll();
105 
106 private:
107  MediaStationEngine *_vm = nullptr;
108  Graphics::Screen *_screen = nullptr;
109  Graphics::Palette *_registeredPalette = nullptr;
110  Common::Array<ScriptValue> _scheduledTransitionOnSync;
111  double _defaultTransitionTime = 0.0;
112 
113  void readAndEffectTransition(Chunk &chunk);
114  void readAndRegisterPalette(Chunk &chunk);
115 
116  // Blitting methods.
117  // blitRectsClip encompasses the functionality of both opaqueBlitRectsClip
118  // and transparentBlitRectsClip in the disasm.
119  void blitRectsClip(
121  const Common::Point &destLocation,
122  const Graphics::ManagedSurface &source,
123  const Common::Array<Common::Rect> &dirtyRegion);
124  void rleBlitRectsClip(
126  const Common::Point &destLocation,
127  const Bitmap *source,
128  const Common::Array<Common::Rect> &dirtyRegion);
129  Graphics::ManagedSurface decompressRle8Bitmap(
130  const Bitmap *source,
131  const Graphics::ManagedSurface *keyFrame = nullptr,
132  const Common::Point *keyFrameOffset = nullptr);
133  void dissolveBlitRectsClip(
135  const Common::Point &destPos,
136  const Bitmap *source,
137  const Common::Array<Common::Rect> &dirtyRegion,
138  const uint dissolveFactor);
139  void dissolveBlit1Rect(
141  const Common::Rect &areaToRedraw,
142  const Common::Point &originOnScreen,
143  const Bitmap *source,
144  const Common::Rect &dirtyRegion,
145  const DissolvePattern &pattern);
146  void fullDeltaRleBlitRectsClip(
147  Graphics::ManagedSurface *destinationImage,
148  const Common::Point &deltaFramePos,
149  const Common::Point &keyFrameOffset,
150  const Bitmap *deltaFrame,
151  const Bitmap *keyFrame,
152  const Common::Array<Common::Rect> &dirtyRegion);
153  void deltaRleBlitRectsClip(
154  Graphics::ManagedSurface *destinationImage,
155  const Common::Point &deltaFramePos,
156  const Bitmap *deltaFrame,
157  const Bitmap *keyFrame,
158  const Common::Array<Common::Rect> &dirtyRegion);
159  void deltaRleBlit1Rect(
160  Graphics::ManagedSurface *destinationImage,
161  const Common::Point &destinationPoint,
162  const Bitmap *sourceImage,
163  const Bitmap *deltaImage,
164  const Common::Rect &dirtyRect);
165 
166  // Transition methods.
167  const double DEFAULT_FADE_TRANSITION_TIME_IN_SECONDS = 0.5;
168  const byte DEFAULT_PALETTE_TRANSITION_START_INDEX = 0x01;
169  const byte DEFAULT_PALETTE_TRANSITION_COLOR_COUNT = 0xFE;
170  void fadeToBlack(Common::Array<ScriptValue> &args);
171  void fadeToRegisteredPalette(Common::Array<ScriptValue> &args);
172  void setToRegisteredPalette(Common::Array<ScriptValue> &args);
173  void setToBlack(Common::Array<ScriptValue> &args);
174  void fadeToColor(Common::Array<ScriptValue> &args);
175  void setToColor(Common::Array<ScriptValue> &args);
176  void setToPercentOfPalette(Common::Array<ScriptValue> &args);
177  void fadeToPaletteObject(Common::Array<ScriptValue> &args);
178  void setToPaletteObject(Common::Array<ScriptValue> &args);
179  void setToPercentOfPaletteObject(Common::Array<ScriptValue> &args);
180  void colorShiftCurrentPalette(Common::Array<ScriptValue> &args);
181  void circleOut(Common::Array<ScriptValue> &args);
182 
183  void _setPalette(Graphics::Palette &palette, uint startIndex, uint colorCount);
184  void _setPaletteToColor(Graphics::Palette &targetPalette, byte r, byte g, byte b);
185  uint _limitColorRange(uint &startIndex, uint &colorCount);
186  byte _interpolateColorComponent(byte source, byte target, double progress);
187 
188  void _fadeToColor(byte r, byte g, byte b, double fadeTime, uint startIndex, uint colorCount);
189  void _setToColor(byte r, byte g, byte b, uint startIndex, uint colorCount);
190  void _setPercentToColor(double percent, byte r, byte g, byte b, uint startIndex, uint colorCount);
191 
192  void _fadeToPalette(double fadeTime, Graphics::Palette &targetPalette, uint startIndex, uint colorCount);
193  void _setToPercentPalette(double percent, Graphics::Palette &currentPalette, Graphics::Palette &targetPalette,
194  uint startIndex, uint colorCount);
195  void _fadeToRegisteredPalette(double fadeTime, uint startIndex, uint colorCount);
196  void _setToRegisteredPalette(uint startIndex, uint colorCount);
197  void _colorShiftCurrentPalette(uint startIndex, uint shiftAmount, uint colorCount);
198  void _fadeToPaletteObject(uint paletteId, double fadeTime, uint startIndex, uint colorCount);
199  void _setToPaletteObject(uint paletteId, uint startIndex, uint colorCount);
200  void _setPercentToPaletteObject(double percent, uint paletteId, uint startIndex, uint colorCount);
201 };
202 
203 } // End of namespace MediaStation
204 
205 #endif
Definition: managed_surface.h:51
Definition: graphics.h:73
Definition: actor.h:33
Definition: dissolvepatterns.h:726
Definition: datafile.h:102
Definition: rect.h:524
Definition: screen.h:48
Definition: bitmap.h:50
Definition: clients.h:29
Definition: mediastation.h:69
Definition: rect.h:144
virtual void update()
Simple class for handling a palette data.
Definition: palette.h:55