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 ILLUSIONS_SCREEN_H
23 #define ILLUSIONS_SCREEN_H
24 
25 #include "illusions/graphics.h"
26 #include "common/list.h"
27 #include "common/rect.h"
28 #include "graphics/surface.h"
29 
30 namespace Illusions {
31 
32 class IllusionsEngine;
33 class FontResource;
34 
36  byte *_drawFlags;
37  uint32 _flags;
38  uint32 _field8;
39  WidthHeight _dimensions;
40  byte *_compressedPixels;
41  Graphics::Surface *_surface;
42 };
43 
45 public:
48  void insert(byte *drawFlags, uint32 flags, uint32 field8, WidthHeight &dimensions,
49  byte *compressedPixels, Graphics::Surface *surface);
50  void decompressAll();
51 protected:
54  Screen *_screen;
55  SpriteDecompressQueueList _queue;
56  void decompress(SpriteDecompressQueueItem *item);
57 };
58 
60  byte *_drawFlags;
61  int16 _kind;
62  int16 _scale;
63  uint16 _flags;
64  uint32 _priority;
65  Graphics::Surface *_surface;
66  WidthHeight _dimensions;
67  Common::Point _drawPosition;
68  Common::Point _controlPosition;
69 };
70 
72 public:
73  SpriteDrawQueue(Screen *screen);
74  ~SpriteDrawQueue();
75  bool draw(SpriteDrawQueueItem *item);
76  void drawAll();
77  void insertSprite(byte *drawFlags, Graphics::Surface *surface, WidthHeight &dimensions,
78  Common::Point &drawPosition, Common::Point &controlPosition, uint32 priority, int16 scale, uint16 flags);
79  void insertSurface(Graphics::Surface *surface, WidthHeight &dimensions,
80  Common::Point &drawPosition, uint32 priority);
81  void insertTextSurface(Graphics::Surface *surface, WidthHeight &dimensions,
82  Common::Point &drawPosition, uint32 priority);
83 protected:
86  struct FindInsertionPosition : public Common::UnaryFunction<const SpriteDrawQueueItem*, bool> {
87  uint32 _priority;
88  FindInsertionPosition(uint32 priority) : _priority(priority) {}
89  bool operator()(const SpriteDrawQueueItem *item) const {
90  return item->_priority >= _priority;
91  }
92  };
93  Screen *_screen;
94  SpriteDrawQueueList _queue;
95  void insert(SpriteDrawQueueItem *item, uint32 priority);
96  bool calcItemRect(SpriteDrawQueueItem *item, Common::Rect &srcRect, Common::Rect &dstRect);
97 };
98 
99 struct Fader {
100  bool _active;
101  int _currValue;
102  bool _paused;
103  int _minValue;
104  int _maxValue;
105  int _firstIndex;
106  int _lastIndex;
107  uint32 _startTime;
108  int _duration;
109  uint32 _notifyThreadId;
110  Fader() : _active(false), _paused(false) {}
111 };
112 
114 public:
115  virtual ~ScreenPaletteBase() {};
116  virtual void setPalette(byte *colors, uint start, uint count) {};
117  virtual void setPaletteEntry(int16 index, byte r, byte g, byte b) {};
118  virtual void getPalette(byte *colors) {};
119  virtual void shiftPalette(int16 fromIndex, int16 toIndex) {};
120  virtual void updatePalette() {};
121  virtual void updateFaderPalette() {};
122  virtual void setFader(int newValue, int firstIndex, int lastIndex) {};
123  virtual bool isFaderActive() const { return false; }
124  virtual const byte* getColorTransTbl() const { return 0; }
125 };
126 
128 public:
130  void setPalette(byte *colors, uint start, uint count) override;
131  void setPaletteEntry(int16 index, byte r, byte g, byte b) override;
132  void getPalette(byte *colors) override;
133  void shiftPalette(int16 fromIndex, int16 toIndex) override;
134  void updatePalette() override;
135  void updateFaderPalette() override;
136  void setFader(int newValue, int firstIndex, int lastIndex) override;
137  bool isFaderActive() const override { return _isFaderActive; }
138  const byte* getColorTransTbl() const override { return _colorTransTbl; }
139 protected:
140  IllusionsEngine *_vm;
141  bool _needRefreshPalette;
142  byte _mainPalette[768];
143  byte _colorTransTbl[256];
144  bool _isFaderActive;
145  byte _faderPalette[768];
146  int _newFaderValue, _firstFaderIndex, _lastFaderIndex;
147  void setSystemPalette(byte *palette);
148  void buildColorTransTbl();
149 };
150 
152 };
153 
154 class Screen {
155 public:
156  Screen(IllusionsEngine *vm, int16 width, int16 height, int bpp);
157  virtual ~Screen();
158  Graphics::Surface *allocSurface(int16 width, int16 height);
159  Graphics::Surface *allocSurface(SurfInfo &surfInfo);
160  bool isDisplayOn();
161  void setDisplayOn(bool isOn);
162  void setScreenOffset(Common::Point offsPt);
163  void updateSprites();
164  void clearScreenOffsetAreas();
165  uint16 getColorKey1() const { return _colorKey1; }
166  void setColorKey1(uint16 colorKey) { _colorKey1 = colorKey; }
167  uint16 getColorKey2() const { return _colorKey2; }
168  int16 getScreenWidth() const { return _backSurface->w; }
169  int16 getScreenHeight() const { return _backSurface->h; }
170  Graphics::Surface *getBackSurface() const { return _backSurface; }
171  virtual void decompressSprite(SpriteDecompressQueueItem *item) = 0;
172  virtual void drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags) = 0;
173  virtual void drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count) = 0;
174  virtual void fillSurface(Graphics::Surface *surface, byte color) = 0;
175  virtual void fillSurfaceRect(Graphics::Surface *surface, Common::Rect r, byte color) = 0;
176  virtual bool isSpritePixelSolid(Common::Point &testPt, Common::Point &drawPosition, Common::Point &drawOffset,
177  const SurfInfo &surfInfo, int16 scale, uint flags, byte *compressedPixels) = 0;
178 public:
179  IllusionsEngine *_vm;
180  bool _displayOn;
181  uint16 _colorKey1;
182  uint16 _colorKey2;
183  SpriteDecompressQueue *_decompressQueue;
184  SpriteDrawQueue *_drawQueue;
185  Graphics::Surface *_backSurface;
186  bool _isScreenOffsetActive;
187  Common::Point _screenOffsetPt;
188 };
189 
190 class Screen8Bit : public Screen {
191 public:
192  Screen8Bit(IllusionsEngine *vm, int16 width, int16 height) : Screen(vm, width, height, 8) {}
193  void decompressSprite(SpriteDecompressQueueItem *item) override;
194  void drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags) override;
195  void drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count) override;
196  void fillSurface(Graphics::Surface *surface, byte color) override;
197  void fillSurfaceRect(Graphics::Surface *surface, Common::Rect r, byte color) override;
198  bool isSpritePixelSolid(Common::Point &testPt, Common::Point &drawPosition, Common::Point &drawOffset,
199  const SurfInfo &surfInfo, int16 scale, uint flags, byte *compressedPixels) override;
200 public:
201  int16 drawChar(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 c);
202  void drawSurfaceUnscaled(int16 destX, int16 destY, Graphics::Surface *surface, Common::Rect &srcRect);
203  void drawSurfaceScaled(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect);
204 };
205 
206 class Screen16Bit : public Screen {
207 public:
208  Screen16Bit(IllusionsEngine *vm, int16 width, int16 height) : Screen(vm, width, height, 16) {}
209  void decompressSprite(SpriteDecompressQueueItem *item) override;
210  void drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags) override;
211  void drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count) override;
212  void fillSurface(Graphics::Surface *surface, byte color) override;
213  void fillSurfaceRect(Graphics::Surface *surface, Common::Rect r, byte color) override;
214  bool isSpritePixelSolid(Common::Point &testPt, Common::Point &drawPosition, Common::Point &drawOffset,
215  const SurfInfo &surfInfo, int16 scale, uint flags, byte *compressedPixels) override;
216 public:
217  int16 drawChar(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 c);
218  void drawSurface10(int16 destX, int16 destY, Graphics::Surface *surface, Common::Rect &srcRect, uint16 colorKey);
219  void drawSurface11(int16 destX, int16 destY, Graphics::Surface *surface, Common::Rect &srcRect);
220  void drawSurface20(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, uint16 colorKey);
221  void drawSurface21(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect);
222  uint16 convertColor(byte color);
223  uint16 convertFontColor(byte color);
224 };
225 
226 } // End of namespace Illusions
227 
228 #endif // ILLUSIONS_SCREEN_H
Definition: screen.h:99
Definition: fontresource.h:60
Definition: screen.h:190
Definition: screen.h:113
Definition: surface.h:67
Definition: rect.h:144
Definition: actor.h:34
Definition: screen.h:59
Definition: screen.h:151
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: graphics.h:38
Definition: screen.h:154
Definition: graphics.h:31
Definition: screen.h:71
Definition: screen.h:127
Definition: rect.h:45
Definition: list_intern.h:51
Definition: screen.h:206
Definition: screen.h:44
Definition: func.h:43
Definition: illusions.h:92