1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ILLUSIONS_SCREEN_H
#define ILLUSIONS_SCREEN_H
#include "illusions/graphics.h"
#include "common/list.h"
#include "common/rect.h"
#include "graphics/surface.h"
namespace Illusions {
class IllusionsEngine;
class FontResource;
struct SpriteDecompressQueueItem {
byte *_drawFlags;
uint32 _flags;
uint32 _field8;
WidthHeight _dimensions;
byte *_compressedPixels;
Graphics::Surface *_surface;
};
class SpriteDecompressQueue {
public:
SpriteDecompressQueue(Screen *screen);
~SpriteDecompressQueue();
void insert(byte *drawFlags, uint32 flags, uint32 field8, WidthHeight &dimensions,
byte *compressedPixels, Graphics::Surface *surface);
void decompressAll();
protected:
typedef Common::List<SpriteDecompressQueueItem*> SpriteDecompressQueueList;
typedef SpriteDecompressQueueList::iterator SpriteDecompressQueueListIterator;
Screen *_screen;
SpriteDecompressQueueList _queue;
void decompress(SpriteDecompressQueueItem *item);
};
struct SpriteDrawQueueItem {
byte *_drawFlags;
int16 _kind;
int16 _scale;
uint16 _flags;
uint32 _priority;
Graphics::Surface *_surface;
WidthHeight _dimensions;
Common::Point _drawPosition;
Common::Point _controlPosition;
};
class SpriteDrawQueue {
public:
SpriteDrawQueue(Screen *screen);
~SpriteDrawQueue();
bool draw(SpriteDrawQueueItem *item);
void drawAll();
void insertSprite(byte *drawFlags, Graphics::Surface *surface, WidthHeight &dimensions,
Common::Point &drawPosition, Common::Point &controlPosition, uint32 priority, int16 scale, uint16 flags);
void insertSurface(Graphics::Surface *surface, WidthHeight &dimensions,
Common::Point &drawPosition, uint32 priority);
void insertTextSurface(Graphics::Surface *surface, WidthHeight &dimensions,
Common::Point &drawPosition, uint32 priority);
protected:
typedef Common::List<SpriteDrawQueueItem*> SpriteDrawQueueList;
typedef SpriteDrawQueueList::iterator SpriteDrawQueueListIterator;
struct FindInsertionPosition : public Common::UnaryFunction<const SpriteDrawQueueItem*, bool> {
uint32 _priority;
FindInsertionPosition(uint32 priority) : _priority(priority) {}
bool operator()(const SpriteDrawQueueItem *item) const {
return item->_priority >= _priority;
}
};
Screen *_screen;
SpriteDrawQueueList _queue;
void insert(SpriteDrawQueueItem *item, uint32 priority);
bool calcItemRect(SpriteDrawQueueItem *item, Common::Rect &srcRect, Common::Rect &dstRect);
};
struct Fader {
bool _active;
int _currValue;
bool _paused;
int _minValue;
int _maxValue;
int _firstIndex;
int _lastIndex;
uint32 _startTime;
int _duration;
uint32 _notifyThreadId;
Fader() : _active(false), _paused(false) {}
};
class ScreenPaletteBase {
public:
virtual ~ScreenPaletteBase() {};
virtual void setPalette(byte *colors, uint start, uint count) {};
virtual void setPaletteEntry(int16 index, byte r, byte g, byte b) {};
virtual void getPalette(byte *colors) {};
virtual void shiftPalette(int16 fromIndex, int16 toIndex) {};
virtual void updatePalette() {};
virtual void updateFaderPalette() {};
virtual void setFader(int newValue, int firstIndex, int lastIndex) {};
virtual bool isFaderActive() const { return false; }
virtual const byte* getColorTransTbl() const { return 0; }
};
class ScreenPalette : public ScreenPaletteBase {
public:
ScreenPalette(IllusionsEngine *vm);
void setPalette(byte *colors, uint start, uint count);
void setPaletteEntry(int16 index, byte r, byte g, byte b);
void getPalette(byte *colors);
void shiftPalette(int16 fromIndex, int16 toIndex);
void updatePalette();
void updateFaderPalette();
void setFader(int newValue, int firstIndex, int lastIndex);
bool isFaderActive() const { return _isFaderActive; }
const byte* getColorTransTbl() const { return _colorTransTbl; }
protected:
IllusionsEngine *_vm;
bool _needRefreshPalette;
byte _mainPalette[768];
byte _colorTransTbl[256];
bool _isFaderActive;
byte _faderPalette[768];
int _newFaderValue, _firstFaderIndex, _lastFaderIndex;
void setSystemPalette(byte *palette);
void buildColorTransTbl();
};
class NullScreenPalette : public ScreenPaletteBase {
};
class Screen {
public:
Screen(IllusionsEngine *vm, int16 width, int16 height, int bpp);
virtual ~Screen();
Graphics::Surface *allocSurface(int16 width, int16 height);
Graphics::Surface *allocSurface(SurfInfo &surfInfo);
bool isDisplayOn();
void setDisplayOn(bool isOn);
void setScreenOffset(Common::Point offsPt);
void updateSprites();
void clearScreenOffsetAreas();
uint16 getColorKey1() const { return _colorKey1; }
void setColorKey1(uint16 colorKey) { _colorKey1 = colorKey; }
uint16 getColorKey2() const { return _colorKey2; }
int16 getScreenWidth() const { return _backSurface->w; }
int16 getScreenHeight() const { return _backSurface->h; }
Graphics::Surface *getBackSurface() const { return _backSurface; }
virtual void decompressSprite(SpriteDecompressQueueItem *item) = 0;
virtual void drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags) = 0;
virtual void drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count) = 0;
virtual void fillSurface(Graphics::Surface *surface, byte color) = 0;
virtual void fillSurfaceRect(Graphics::Surface *surface, Common::Rect r, byte color) = 0;
virtual bool isSpritePixelSolid(Common::Point &testPt, Common::Point &drawPosition, Common::Point &drawOffset,
const SurfInfo &surfInfo, int16 scale, uint flags, byte *compressedPixels) = 0;
public:
IllusionsEngine *_vm;
bool _displayOn;
uint16 _colorKey1;
uint16 _colorKey2;
SpriteDecompressQueue *_decompressQueue;
SpriteDrawQueue *_drawQueue;
Graphics::Surface *_backSurface;
bool _isScreenOffsetActive;
Common::Point _screenOffsetPt;
};
class Screen8Bit : public Screen {
public:
Screen8Bit(IllusionsEngine *vm, int16 width, int16 height) : Screen(vm, width, height, 8) {}
void decompressSprite(SpriteDecompressQueueItem *item);
void drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags);
void drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count);
void fillSurface(Graphics::Surface *surface, byte color);
void fillSurfaceRect(Graphics::Surface *surface, Common::Rect r, byte color);
bool isSpritePixelSolid(Common::Point &testPt, Common::Point &drawPosition, Common::Point &drawOffset,
const SurfInfo &surfInfo, int16 scale, uint flags, byte *compressedPixels);
public:
int16 drawChar(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 c);
void drawSurfaceUnscaled(int16 destX, int16 destY, Graphics::Surface *surface, Common::Rect &srcRect);
void drawSurfaceScaled(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect);
};
class Screen16Bit : public Screen {
public:
Screen16Bit(IllusionsEngine *vm, int16 width, int16 height) : Screen(vm, width, height, 16) {}
void decompressSprite(SpriteDecompressQueueItem *item);
void drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags);
void drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count);
void fillSurface(Graphics::Surface *surface, byte color);
void fillSurfaceRect(Graphics::Surface *surface, Common::Rect r, byte color);
bool isSpritePixelSolid(Common::Point &testPt, Common::Point &drawPosition, Common::Point &drawOffset,
const SurfInfo &surfInfo, int16 scale, uint flags, byte *compressedPixels);
public:
int16 drawChar(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 c);
void drawSurface10(int16 destX, int16 destY, Graphics::Surface *surface, Common::Rect &srcRect, uint16 colorKey);
void drawSurface11(int16 destX, int16 destY, Graphics::Surface *surface, Common::Rect &srcRect);
void drawSurface20(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, uint16 colorKey);
void drawSurface21(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect);
uint16 convertColor(byte color);
uint16 convertFontColor(byte color);
};
} // End of namespace Illusions
#endif // ILLUSIONS_SCREEN_H
|