ScummVM API documentation
render_manager.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 ZVISION_RENDER_MANAGER_H
23 #define ZVISION_RENDER_MANAGER_H
24 
25 #include "zvision/graphics/render_table.h"
26 #include "zvision/text/truetype_font.h"
27 
28 #include "common/rect.h"
29 #include "common/hashmap.h"
30 
31 #include "graphics/surface.h"
32 
33 #include "zvision/graphics/graphics_effect.h"
34 
35 class OSystem;
36 
37 namespace Common {
38 class String;
39 class SeekableReadStream;
40 }
41 
42 namespace Video {
43 class VideoDecoder;
44 }
45 
46 namespace ZVision {
47 
49 public:
50  RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat, bool doubleFPS);
51  ~RenderManager();
52 
53 private:
54  struct OneSubtitle {
55  Common::Rect r;
56  Common::String txt;
57  int16 timer;
58  bool todelete;
59  bool redraw;
60  };
61 
64 
65 private:
66  ZVision *_engine;
67  OSystem *_system;
68  const Graphics::PixelFormat _pixelFormat;
69 
75  Common::Rect _workingWindow;
76 
77  // Center of the screen in the x direction
78  const int _screenCenterX;
79  // Center of the screen in the y direction
80  const int _screenCenterY;
81 
83  Graphics::Surface _currentBackgroundImage;
84  Common::Rect _backgroundDirtyRect;
85 
90  int16 _backgroundOffset;
92  uint16 _backgroundWidth;
94  uint16 _backgroundHeight;
95 
96  // A buffer that holds the portion of the background that is used to render the final image
97  // If it's a normal scene, the pixels will be blitted directly to the screen
98  // If it's a panorma / tilt scene, the pixels will be first warped to _warpedSceneSurface
99  Graphics::Surface _backgroundSurface;
100  Common::Rect _backgroundSurfaceDirtyRect;
101 
102  // A buffer for subtitles
103  Graphics::Surface _subtitleSurface;
104 
105  // Rectangle for subtitles area
106  Common::Rect _subtitleArea;
107 
108  // A buffer for menu drawing
109  Graphics::Surface _menuSurface;
110  Common::Rect _menuSurfaceDirtyRect;
111 
112  // Rectangle for menu area
113  Common::Rect _menuArea;
114 
115  // A buffer used for apply graphics effects
116  Graphics::Surface _effectSurface;
117 
118  // A buffer to store the result of the panorama / tilt warps
119  Graphics::Surface _warpedSceneSurface;
120 
121 
123  RenderTable _renderTable;
124 
125  // Internal subtitles counter
126  uint16 _subid;
127 
128  // Subtitle list
129  SubtitleMap _subsList;
130 
131  // Visual effects list
132  EffectsList _effects;
133 
134  bool _doubleFPS;
135 
136 public:
137  void initialize();
138 
142  void renderSceneToScreen();
143 
144  void copyToScreen(const Graphics::Surface &surface, Common::Rect &rect, int16 srcLeft, int16 srcTop);
145 
153  void renderImageToBackground(const Common::Path &fileName, int16 destinationX, int16 destinationY);
154 
163  void renderImageToBackground(const Common::Path &fileName, int16 destX, int16 destY, uint32 colorkey);
164 
174  void renderImageToBackground(const Common::Path &fileName, int16 destX, int16 destY, int16 keyX, int16 keyY);
175 
182  void setBackgroundImage(const Common::Path &fileName);
183 
194  void setBackgroundPosition(int offset);
195 
202  const Common::Point screenSpaceToImageSpace(const Common::Point &point);
203 
204  // Return pointer of RenderTable object
205  RenderTable *getRenderTable();
206 
207  // Return current background offset
208  uint32 getCurrentBackgroundOffset();
209 
219  static Graphics::Surface *tranposeSurface(const Graphics::Surface *surface);
220 
221  // Scale buffer (nearest)
222  void scaleBuffer(const void *src, void *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel, uint32 dstWidth, uint32 dstHeight);
223 
224  // Blitting surface-to-surface methods
225  void blitSurfaceToSurface(const Graphics::Surface &src, const Common::Rect &_srcRect , Graphics::Surface &dst, int x, int y);
226  void blitSurfaceToSurface(const Graphics::Surface &src, const Common::Rect &_srcRect , Graphics::Surface &dst, int _x, int _y, uint32 colorkey);
227 
228  // Blitting surface-to-background methods
229  void blitSurfaceToBkg(const Graphics::Surface &src, int x, int y, int32 colorkey = -1);
230 
231  // Blitting surface-to-background methods with scale
232  void blitSurfaceToBkgScaled(const Graphics::Surface &src, const Common::Rect &_dstRect, int32 colorkey = -1);
233 
234  // Blitting surface-to-menu methods
235  void blitSurfaceToMenu(const Graphics::Surface &src, int x, int y, int32 colorkey = -1);
236 
237  // Subtitles methods
238 
239  void initSubArea(uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow);
240 
241  // Create subtitle area and return ID
242  uint16 createSubArea(const Common::Rect &area);
243  uint16 createSubArea();
244 
245  // Delete subtitle by ID
246  void deleteSubArea(uint16 id);
247  void deleteSubArea(uint16 id, int16 delay);
248 
249  // Update subtitle area
250  void updateSubArea(uint16 id, const Common::String &txt);
251 
252  // Processing subtitles
253  void processSubs(uint16 deltatime);
254 
255  // Return background size
256  Common::Point getBkgSize();
257 
258  // Return portion of background as new surface
259  Graphics::Surface *getBkgRect(Common::Rect &rect);
260 
261  // Load image into new surface
262  Graphics::Surface *loadImage(const Common::Path &file);
263  Graphics::Surface *loadImage(const Common::Path &file, bool transposed);
264 
265  // Clear whole/area of menu surface
266  void clearMenuSurface();
267  void clearMenuSurface(const Common::Rect &r);
268 
269  // Copy menu buffer to screen
270  void renderMenuToScreen();
271 
272  // Copy needed portion of background surface to workingWindow surface
273  void prepareBackground();
274 
284  void readImageToSurface(const Common::Path &fileName, Graphics::Surface &destination);
285 
296  void readImageToSurface(const Common::Path &fileName, Graphics::Surface &destination, bool transposed);
297 
298  // Add visual effect to effects list
299  void addEffect(GraphicsEffect *_effect);
300 
301  // Delete effect(s) by ID (ID equal to slot of action:region that create this effect)
302  void deleteEffect(uint32 ID);
303 
304  // Create "mask" for effects - (color +/- depth) will be selected as not transparent. Like color selection
305  // xy - base color
306  // depth - +/- of base color
307  // rect - rectangle where select pixels
308  // minD - if not NULL will receive real bottom border of depth
309  // maxD - if not NULL will receive real top border of depth
310  EffectMap *makeEffectMap(const Common::Point &xy, int16 depth, const Common::Rect &rect, int8 *minD, int8 *maxD);
311 
312  // Create "mask" for effects by simple transparent color
313  EffectMap *makeEffectMap(const Graphics::Surface &surf, uint16 transp);
314 
315  // Return background rectangle in screen coordinates
316  Common::Rect transformBackgroundSpaceRectToScreenSpace(const Common::Rect &src);
317 
318  // Mark whole background surface as dirty
319  void markDirty();
320 
321 #if 0
322  // Fill background surface by color
323  void bkgFill(uint8 r, uint8 g, uint8 b);
324 #endif
325 
326  bool askQuestion(const Common::String &str);
327  void delayedMessage(const Common::String &str, uint16 milsecs);
328  void timedMessage(const Common::String &str, uint16 milsecs);
329  void showDebugMsg(const Common::String &msg, int16 delay = 3000);
330 
331  void checkBorders();
332  void rotateTo(int16 to, int16 time);
333  void updateRotation();
334 
335  void upscaleRect(Common::Rect &rect);
336 };
337 
338 } // End of namespace ZVision
339 
340 #endif
Definition: str.h:59
Definition: surface.h:67
Definition: render_table.h:30
Definition: pixelformat.h:138
Definition: rect.h:144
Definition: path.h:52
Definition: graphics_effect.h:35
Definition: clock.h:29
Definition: algorithm.h:29
Definition: rect.h:45
Definition: render_manager.h:48
Definition: system.h:161
Definition: avi_frames.h:36