ScummVM API documentation
screen.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 ASYLUM_SYSTEM_SCREEN_H
23 #define ASYLUM_SYSTEM_SCREEN_H
24 
25 #include "common/array.h"
26 #include "common/queue.h"
27 #include "common/rect.h"
28 
29 #include "graphics/surface.h"
30 
31 #include "asylum/shared.h"
32 
33 namespace Asylum {
34 
35 #define PALETTE_SIZE (256 * 3)
36 
37 class AsylumEngine;
38 class GraphicResource;
39 class ResourcePack;
40 
41 struct GraphicFrame;
42 
43 enum GraphicItemType {
44  kGraphicItemNormal = 1,
45  kGraphicItemMasked = 5
46 };
47 
48 typedef struct GraphicQueueItem {
49  int32 priority;
50 
51  GraphicItemType type;
52  ResourceId resourceId;
53  uint32 frameIndex;
54  Common::Point source;
55  ResourceId resourceIdDestination;
56  Common::Point destination;
57  DrawFlags flags;
58  int32 transTableNum;
59 
61  priority = 0;
62 
63  type = kGraphicItemNormal;
64  resourceId = kResourceNone;
65  frameIndex = 0;
66  resourceIdDestination = kResourceNone;
67  flags = kDrawFlagNone;
68  transTableNum = 0;
69  }
71 
73  ResourceId resourceId;
74  int ticksWait;
75  int delta;
76  uint nextTick;
77  int step;
78 };
79 
80 class Screen {
81 public:
82  Screen(AsylumEngine *_vm);
83  ~Screen();
84 
85  // Drawing
86  void draw(ResourceId resourceId);
87  void draw(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, DrawFlags flags = kDrawFlagNone, bool colorKey = true);
88  void draw(ResourceId resourceId, uint32 frameIndex, const int16 (*srcPtr)[2], DrawFlags flags = kDrawFlagNone, bool colorKey = true);
89  void draw(GraphicResource *resource, uint32 frameIndex, const Common::Point &source, DrawFlags flags = kDrawFlagNone, bool colorKey = true);
90  void drawTransparent(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, DrawFlags flags, uint32 transTableNum);
91  void drawTransparent(GraphicResource *resource, uint32 frameIndex, const Common::Point &source, DrawFlags flags, uint32 transTableNum);
92  void draw(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, DrawFlags flags, ResourceId resourceId2, const Common::Point &destination, bool colorKey = true);
93  void draw(const Graphics::Surface &surface, int x, int y);
94 
95  // Misc
96  void clear();
97  void clearDefaultColor() { memset(_mainPalette, 0, 3); setupPalette(NULL, 0, 0); }
98  void drawWideScreenBars(int16 barSize) const;
99  void fillRect(int16 x, int16 y, int16 x2, int16 y2, uint32 color);
100  void copyBackBufferToScreen();
101  void setFlag(int16 val) { _flag = (val < -1) ? -1 : val; }
102  int16 getFlag() { return _flag; }
103 
104  // Palette
105  void setPalette(ResourceId id);
106  const byte *getPalette() { return _mainPalette; }
107  void setMainPalette(const byte *data);
108  void loadGrayPalette();
109  void copyGrayPaletteToWorkingPalette();
110  void blendScenePaletteForFadeStep(int32 step);
111  void blendPaletteFromGray(int32 step, int32 stepCount);
112  void blendPaletteToGray(int32 step, int32 stepCount);
113  void setupPalette(byte *buffer, int start, int count);
114 
115  bool isFading() { return _isFading; }
116  void queuePaletteFade(ResourceId resourceId, int32 ticksWait, int32 delta);
117  void paletteFade(uint32 start, int32 ticksWait, int32 delta);
118  void stopPaletteFade(char red, char green, char blue);
119  void stopPaletteFadeAndSet(ResourceId id, int32 ticksWait, int32 delta);
120  void processPaletteFadeQueue();
121 
122  // Gamma
123  void setPaletteGamma(ResourceId id);
124  void setGammaLevel(ResourceId id);
125 
126  // Transparency tables
127  void setupTransTable(ResourceId resourceId);
128  void setupTransTables(uint32 count, ...);
129  void selectTransTable(uint32 index);
130 
131  // Graphic queue
132  void addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, const Common::Point &point, DrawFlags flags, int32 transTableNum, int32 priority);
133  void addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, const int16 (*pointPtr)[2], DrawFlags flags, int32 transTableNum, int32 priority);
134  void addGraphicToQueueCrossfade(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, int32 objectResourceId, const Common::Point &destination, uint32 transTableNum);
135  void addGraphicToQueueMasked(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, int32 objectResourceId, const Common::Point &destination, DrawFlags flags, int32 priority);
136  void addGraphicToQueue(GraphicQueueItem const &item);
137  void drawGraphicsInQueue();
138  void clearGraphicsInQueue();
139  void deleteGraphicFromQueue(ResourceId resourceId);
140  bool isGraphicQueueEmpty() { return _queueItems.empty(); }
141 
142  // Used by Video
143  void copyToBackBuffer(const byte *buffer, int32 pitch, int16 x, int16 y, uint16 width, uint16 height, bool mirrored = false);
144 
145  // Debug
146  void drawLine(const Common::Point &source, const Common::Point &destination, uint32 color = 0xFF);
147  void drawLine(const int16 (*srcPtr)[2], const int16 (*dstPtr)[2], uint32 color = 0xFF);
148  void drawRect(const Common::Rect &rect, uint32 color = 0xFF);
149  void copyToBackBufferClipped(Graphics::Surface *surface, int16 x, int16 y);
150 
151  // Used by Writings puzzle and Chinese renderer
152  Graphics::Surface *getSurface() { return &_backBuffer; };
153 
154 private:
155  AsylumEngine *_vm;
156 
157  Graphics::Surface _backBuffer;
158  Common::Rect _clipRect;
160 
161  int16 _flag;
162  bool _useColorKey;
163 
164  // Transparency tables
165  uint32 _transTableCount;
166  byte *_transTable;
167  byte *_transTableBuffer;
168  void clearTransTables();
169 
170  // Palette
171  byte _currentPalette[PALETTE_SIZE];
172  byte _mainPalette[PALETTE_SIZE];
173  byte _fromPalette[PALETTE_SIZE];
174  byte _toPalette[PALETTE_SIZE];
175  bool _isFading;
176  bool _fadeStop;
178 
179  byte *getPaletteData(ResourceId id);
180  void blendPalette(const byte *from, const byte *to, int32 step, int32 stepCount);
181  void setPaletteGamma(byte *data, byte *target = NULL);
182 
183  void stopQueuedPaletteFade();
184  void initQueuedPaletteFade(ResourceId id, int32 delta);
185  void runQueuedPaletteFade(ResourceId id, int32 delta, int i);
186 
187  // Graphic queue
188  static bool graphicQueueItemComparator(const GraphicQueueItem &item1, const GraphicQueueItem &item2);
189 
190  // Misc
191  void clip(Common::Rect *source, Common::Rect *destination, int32 flags) const;
192 
193  void draw(GraphicResource *resource, uint32 frameIndex, const Common::Point &source, DrawFlags flags, ResourceId resourceId2, const Common::Point &destination, bool colorKey = true);
194 
195  // Screen blitting
196  void blit(GraphicFrame *frame, Common::Rect *source, Common::Rect *destination, int32 flags);
197  void blitMasked(GraphicFrame *frame, Common::Rect *source, byte *maskData, Common::Rect *sourceMask, Common::Rect *destMask, uint16 maskWidth, Common::Rect *destination, int32 flags);
198  void blitTranstable (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
199  void blitTranstableMirrored(byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
200  void blitMirrored (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
201  void blitMirroredColorKey (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
202  void blitRaw (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
203  void blitRawColorKey (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
204  void blitCrossfade (byte *dstBuffer, byte *srcBuffer, byte *objectBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch, uint16 objectPitch) const;
205  void bltMasked (byte *srcBuffer, byte *maskBuffer, int16 height, int16 width, uint16 srcPitch, uint16 maskPitch, byte zoom, byte *dstBuffer, uint16 dstPitch) const;
206 
207  // DirectDraw-equivalent functions
208  void blt(Common::Rect *dest, GraphicFrame *frame, Common::Rect *source, int32 flags);
209  void bltFast(int16 dX, int16 dY, GraphicFrame *frame, Common::Rect *source);
210 
211  void copyToBackBufferWithTransparency(byte *buffer, int32 pitch, int16 x, int16 y, uint16 width, uint16 height, bool mirrored = false);
212 
213  // Debug
214  void drawZoomedMask(byte *mask, uint16 height, uint16 width, uint16 maskPitch);
215 };
216 
217 } // end of namespace Asylum
218 
219 #endif // ASYLUM_SYSTEM_SCREEN_H
Definition: surface.h:67
Definition: screen.h:80
Definition: array.h:52
Definition: asylum.h:53
Definition: rect.h:536
Definition: queue.h:42
Definition: screen.h:48
Definition: rect.h:144
Definition: asylum.h:73
Definition: screen.h:72
Definition: graphics.h:36
Definition: graphics.h:58