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 updatePalette();
110  void updatePalette(int32 param);
111  void setupPalette(byte *buffer, int start, int count);
112 
113  bool isFading() { return _isFading; }
114  void queuePaletteFade(ResourceId resourceId, int32 ticksWait, int32 delta);
115  void paletteFade(uint32 start, int32 ticksWait, int32 delta);
116  void stopPaletteFade(char red, char green, char blue);
117  void stopPaletteFadeAndSet(ResourceId id, int32 ticksWait, int32 delta);
118  void processPaletteFadeQueue();
119 
120  // Gamma
121  void setPaletteGamma(ResourceId id);
122  void setGammaLevel(ResourceId id);
123 
124  // Transparency tables
125  void setupTransTable(ResourceId resourceId);
126  void setupTransTables(uint32 count, ...);
127  void selectTransTable(uint32 index);
128 
129  // Graphic queue
130  void addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, const Common::Point &point, DrawFlags flags, int32 transTableNum, int32 priority);
131  void addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, const int16 (*pointPtr)[2], DrawFlags flags, int32 transTableNum, int32 priority);
132  void addGraphicToQueueCrossfade(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, int32 objectResourceId, const Common::Point &destination, uint32 transTableNum);
133  void addGraphicToQueueMasked(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, int32 objectResourceId, const Common::Point &destination, DrawFlags flags, int32 priority);
134  void addGraphicToQueue(GraphicQueueItem const &item);
135  void drawGraphicsInQueue();
136  void clearGraphicsInQueue();
137  void deleteGraphicFromQueue(ResourceId resourceId);
138  bool isGraphicQueueEmpty() { return _queueItems.empty(); }
139 
140  // Used by Video
141  void copyToBackBuffer(const byte *buffer, int32 pitch, int16 x, int16 y, uint16 width, uint16 height, bool mirrored = false);
142 
143  // Debug
144  void drawLine(const Common::Point &source, const Common::Point &destination, uint32 color = 0xFF);
145  void drawLine(const int16 (*srcPtr)[2], const int16 (*dstPtr)[2], uint32 color = 0xFF);
146  void drawRect(const Common::Rect &rect, uint32 color = 0xFF);
147  void copyToBackBufferClipped(Graphics::Surface *surface, int16 x, int16 y);
148 
149  // Used by Writings puzzle and Chinese renderer
150  Graphics::Surface *getSurface() { return &_backBuffer; };
151 
152 private:
153  AsylumEngine *_vm;
154 
155  Graphics::Surface _backBuffer;
156  Common::Rect _clipRect;
158 
159  int16 _flag;
160  bool _useColorKey;
161 
162  // Transparency tables
163  uint32 _transTableCount;
164  byte *_transTable;
165  byte *_transTableBuffer;
166  void clearTransTables();
167 
168  // Palette
169  byte _currentPalette[PALETTE_SIZE];
170  byte _mainPalette[PALETTE_SIZE];
171  byte _fromPalette[PALETTE_SIZE];
172  byte _toPalette[PALETTE_SIZE];
173  bool _isFading;
174  bool _fadeStop;
176 
177  byte *getPaletteData(ResourceId id);
178  void setPaletteGamma(byte *data, byte *target = NULL);
179 
180  void stopQueuedPaletteFade();
181  void initQueuedPaletteFade(ResourceId id, int32 delta);
182  void runQueuedPaletteFade(ResourceId id, int32 delta, int i);
183 
184  // Graphic queue
185  static bool graphicQueueItemComparator(const GraphicQueueItem &item1, const GraphicQueueItem &item2);
186 
187  // Misc
188  void clip(Common::Rect *source, Common::Rect *destination, int32 flags) const;
189 
190  void draw(GraphicResource *resource, uint32 frameIndex, const Common::Point &source, DrawFlags flags, ResourceId resourceId2, const Common::Point &destination, bool colorKey = true);
191 
192  // Screen blitting
193  void blit(GraphicFrame *frame, Common::Rect *source, Common::Rect *destination, int32 flags);
194  void blitMasked(GraphicFrame *frame, Common::Rect *source, byte *maskData, Common::Rect *sourceMask, Common::Rect *destMask, uint16 maskWidth, Common::Rect *destination, int32 flags);
195  void blitTranstable (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
196  void blitTranstableMirrored(byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
197  void blitMirrored (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
198  void blitMirroredColorKey (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
199  void blitRaw (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
200  void blitRawColorKey (byte *dstBuffer, byte *srcBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch) const;
201  void blitCrossfade (byte *dstBuffer, byte *srcBuffer, byte *objectBuffer, int16 height, int16 width, uint16 srcPitch, uint16 dstPitch, uint16 objectPitch) const;
202  void bltMasked (byte *srcBuffer, byte *maskBuffer, int16 height, int16 width, uint16 srcPitch, uint16 maskPitch, byte zoom, byte *dstBuffer, uint16 dstPitch) const;
203 
204  // DirectDraw-equivalent functions
205  void blt(Common::Rect *dest, GraphicFrame *frame, Common::Rect *source, int32 flags);
206  void bltFast(int16 dX, int16 dY, GraphicFrame *frame, Common::Rect *source);
207 
208  void copyToBackBufferWithTransparency(byte *buffer, int32 pitch, int16 x, int16 y, uint16 width, uint16 height, bool mirrored = false);
209 
210  // Debug
211  void drawZoomedMask(byte *mask, uint16 height, uint16 width, uint16 maskPitch);
212 };
213 
214 } // end of namespace Asylum
215 
216 #endif // ASYLUM_SYSTEM_SCREEN_H
Definition: surface.h:67
Definition: screen.h:80
Definition: array.h:52
Definition: asylum.h:53
Definition: rect.h:144
Definition: queue.h:42
Definition: screen.h:48
Definition: rect.h:45
Definition: asylum.h:73
Definition: screen.h:72
Definition: graphics.h:36
Definition: graphics.h:58