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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
/* 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 RING_GRAPHICS_H
#define RING_GRAPHICS_H
#include "tsage/events.h"
#include "tsage/saveload.h"
#include "common/list.h"
#include "common/rect.h"
#include "common/system.h"
#include "graphics/surface.h"
namespace TsAGE {
class GfxSurface;
class Region;
/**
* Extended Rect class with extra support methods
*/
class Rect : public Common::Rect, public Serialisable {
public:
Rect() : Common::Rect() {}
Rect(int16 x1, int16 y1, int16 x2, int16 y2) : Common::Rect(x1, y1, x2, y2) {}
void set(int16 x1, int16 y1, int16 x2, int16 y2);
void collapse(int dx, int dy);
void center(int dx, int dy);
void center(const Rect &r);
void center(const Common::Point &pt) { center(pt.x, pt.y); }
void contain(const Rect &r);
void resize(const GfxSurface &surface, int xp, int yp, int percent);
void expandPanes();
virtual void synchronize(Serializer &s);
};
class GfxColors {
public:
uint8 foreground;
uint8 background;
GfxColors() : foreground(0), background(0) {}
};
class LineSlice {
public:
int xs, xe;
LineSlice() { xs = 0; xe = 0; }
LineSlice(int xStart, int xEnd) { xs = xStart; xe = xEnd; }
};
class GfxSurface {
private:
Graphics::Surface *_customSurface;
int _lockSurfaceCtr;
bool _disableUpdates;
Rect _bounds;
bool _trackDirtyRects;
Common::List<Rect> _dirtyRects;
void mergeDirtyRects();
bool looseIntersectRectangle(const Rect &src1, const Rect &src2);
bool unionRectangle(Common::Rect &destRect, const Rect &src1, const Rect &src2);
public:
Common::Point _centroid;
int _transColor;
public:
GfxSurface();
GfxSurface(const GfxSurface &s);
~GfxSurface();
void trackDirtyRects();
void addDirtyRect(const Rect &r);
void copyToScreen();
Graphics::Surface lockSurface();
void unlockSurface();
void synchronize(Serializer &s);
void create(int width, int height);
void setBounds(const Rect &bounds) { _bounds = bounds; }
const Rect &getBounds() const { return _bounds; }
void copyFrom(GfxSurface &src, Rect srcBounds, Rect destBounds, Region *priorityRegion = NULL);
void copyFrom(GfxSurface &src, Rect destBounds, Region *priorityRegion = NULL) {
copyFrom(src, src.getBounds(), destBounds, priorityRegion);
}
void copyFrom(GfxSurface &src, int destX = 0, int destY = 0, Region *priorityRegion = NULL) {
Rect tempRect = src.getBounds();
tempRect.moveTo(destX, destY);
copyFrom(src, tempRect, priorityRegion);
}
void draw(const Common::Point &pt, Rect *rect = NULL);
void fillRect(const Rect &bounds, int color);
GfxSurface &operator=(const GfxSurface &s);
static void loadScreenSection(Graphics::Surface &dest, int xHalf, int yHalf, int xSection, int ySection);
static bool displayText(const Common::String &msg, const Common::Point &pt = Common::Point(160, 100));
};
enum TextAlign {ALIGN_LEFT = 0, ALIGN_CENTER = 1, ALIGN_RIGHT = 2, ALIGN_JUSTIFIED = 3};
class GfxFont {
friend class GfxFontBackup;
private:
GfxManager *_gfxManager;
// Raw font details
const byte *_fontData;
int _numChars;
Common::Point _fontSize;
int _bpp;
public:
// Font fields
Common::Point _edgeSize;
Common::Point _position;
bool _fillFlag;
GfxColors _colors;
GfxColors _colors2;
uint32 _fontNumber;
Common::Point _topLeft;
public:
GfxFont();
virtual ~GfxFont();
void setFontNumber(uint32 fontNumber);
int32 getHeight() const { return _fontSize.y; }
int getCharWidth(char ch);
int getStringWidth(const char *s, int numChars);
int getStringWidth(const char *s);
int getStringFit(const char *&s, int maxWidth);
void getStringBounds(const char *s, Rect &bounds, int maxWidth);
void setOwner(GfxManager *owner) { _gfxManager = owner; }
void setPosition(int xp, int yp) { _position.x = xp; _position.y = yp; }
int writeChar(const char ch);
void writeString(const char *s);
void writeString(const char *s, int numChars);
void writeLines(const char *s, const Rect &bounds, TextAlign align);
};
class GfxFontBackup {
private:
GfxSurface *_surface;
Common::Point _edgeSize;
Common::Point _position;
GfxColors _colors;
uint32 _fontNumber;
public:
GfxFontBackup();
~GfxFontBackup();
};
enum GFX_FLAGS {GFXFLAG_THICK_FRAME = 8};
class GfxManager;
class GfxElement {
public:
GfxElement *_owner;
Rect _bounds;
uint16 _flags;
uint16 _fontNumber;
GfxColors _colors;
GfxColors _fontColors;
byte _color1, _color2, _color3;
uint16 _keycode;
public:
GfxElement();
virtual ~GfxElement() {}
void drawFrame();
// Virtual table method
virtual void setDefaults();
virtual void remove() { _owner = NULL; }
virtual void highlight();
virtual void draw() {}
virtual bool process(Event &event) { return false; }
virtual bool focusedEvent(Event &event);
};
class GfxImage : public GfxElement {
public:
GfxSurface _surface;
int _resNum;
int _rlbNum;
int _cursorNum;
public:
GfxImage();
void setDetails(int resNum, int rlbNum, int cursorNum);
virtual void setDefaults();
virtual void draw();
virtual bool process(Event &event) { return false; }
};
class GfxMessage : public GfxElement {
public:
Common::String _message;
TextAlign _textAlign;
int _width;
public:
GfxMessage();
virtual ~GfxMessage() {}
void set(const Common::String &s, int width, TextAlign textAlign);
virtual void setDefaults();
virtual void draw();
};
class GfxButton : public GfxElement {
private:
void setFocus();
public:
Common::String _message;
public:
GfxButton() : GfxElement() {}
virtual ~GfxButton() {}
void setText(const Common::String &s) {
_message = s;
setDefaults();
}
// Virtual table method
virtual void setDefaults();
virtual void draw();
virtual bool process(Event &event);
};
class GfxManager {
private:
GfxSurface &_surface;
public:
GfxManager *_oldManager;
Common::Point _topLeft;
Rect _bounds;
Rect _pane0Rect4;
GfxFont _font;
public:
GfxManager();
GfxManager(GfxSurface &s);
virtual ~GfxManager() {}
void setDefaults();
void activate();
void deactivate();
// Accessor methods
int getStringWidth(const char *s, int numChars);
int getStringWidth(const char *s);
void getStringBounds(const char *s, Rect &bounds, int maxWidth);
void setDialogPalette();
Graphics::Surface lockSurface() {
_surface.setBounds(_bounds);
return _surface.lockSurface();
}
void unlockSurface() { _surface.unlockSurface(); }
void addDirtyRect(const Rect &r);
void fillArea(int xp, int yp, int color);
void fillRect(const Rect &bounds, int color);
void fillRect2(int xs, int ys, int width, int height, int color);
void setFillFlag(bool v) { _font._fillFlag = v; }
static int getAngle(const Common::Point &p1, const Common::Point &p2);
// Virtual method table
virtual void xorArea(const Common::Rect &r, int color, int fillMode) {
//_surface->xorArea(r, color, fillMode);
}
virtual void draw(const Common::Rect &r, void *gfxData, int v1, GfxColors *colors) {
//_surface->draw(r, gfxData, v1, colors);
}
virtual void copy(const byte *src, byte *dest, int size) {
Common::copy(src, src + size, dest);
}
virtual void set(byte *dest, int size, byte val) {
Common::fill(dest, dest + size, val);
}
void copyFrom(GfxSurface &src, Rect destBounds, Region *priorityRegion = NULL) {
_surface.setBounds(_bounds);
_surface.copyFrom(src, destBounds, priorityRegion);
}
void copyFrom(GfxSurface &src, int destX, int destY) {
_surface.setBounds(_bounds);
_surface.copyFrom(src, destX, destY);
}
GfxSurface &getSurface() {
_surface.setBounds(_bounds);
return _surface;
}
};
typedef Common::List<GfxElement *> GfxElementList;
class GfxDialog : public GfxElement {
public:
GfxManager _gfxManager;
GfxElementList _elements;
GfxButton *_defaultButton;
GfxSurface *_savedArea;
public:
GfxDialog();
virtual ~GfxDialog();
void add(GfxElement *element);
void addElements(GfxElement *ge, ...);
void setTopLeft(int xp, int yp);
void setCenter(int xp, int yp);
void frame() {
setDefaults();
_bounds.collapse(6, 6);
}
GfxButton *execute(GfxButton *defaultButton = NULL);
virtual void setDefaults();
virtual void remove();
virtual void draw();
static void setPalette();
};
GfxSurface *Surface_getArea(GfxSurface &src, const Rect &bounds);
GfxSurface surfaceFromRes(const byte *imgData);
GfxSurface surfaceFromRes(int resNum, int rlbNum, int subNum);
} // End of namespace TsAGE
#endif
|