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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
/* 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.
*
* $URL$
* $Id$
*
*/
#ifndef PARALLACTION_GRAPHICS_H
#define PARALLACTION_GRAPHICS_H
#include "common/list.h"
#include "common/rect.h"
#include "common/hash-str.h"
#include "common/stream.h"
#include "graphics/surface.h"
namespace Parallaction {
#include "common/pack-start.h" // START STRUCT PACKING
struct PaletteFxRange {
uint16 _timer;
uint16 _step;
uint16 _flags;
byte _first;
byte _last;
} PACKED_STRUCT;
#include "common/pack-end.h" // END STRUCT PACKING
class Font {
protected:
byte _color;
public:
Font() {}
virtual ~Font() {}
virtual void setColor(byte color) {
_color = color;
}
virtual uint32 getStringWidth(const char *s) = 0;
virtual uint16 height() = 0;
virtual void drawString(byte* buffer, uint32 pitch, const char *s) = 0;
};
struct Frames {
virtual uint16 getNum() = 0;
virtual byte* getData(uint16 index) = 0;
virtual void getRect(uint16 index, Common::Rect &r) = 0;
virtual uint getRawSize(uint16 index) = 0;
virtual uint getSize(uint16 index) = 0;
virtual ~Frames() { }
};
struct SurfaceToFrames : public Frames {
Graphics::Surface *_surf;
public:
SurfaceToFrames(Graphics::Surface *surf) : _surf(surf) {
}
~SurfaceToFrames() {
_surf->free();
delete _surf;
}
uint16 getNum() {
return 1;
}
byte* getData(uint16 index) {
assert(index == 0);
return (byte*)_surf->getBasePtr(0,0);
}
void getRect(uint16 index, Common::Rect &r) {
assert(index == 0);
r.left = 0;
r.top = 0;
r.setWidth(_surf->w);
r.setHeight(_surf->h);
}
uint getRawSize(uint16 index) {
assert(index == 0);
return getSize(index);
}
uint getSize(uint16 index) {
assert(index == 0);
return _surf->w * _surf->h;
}
};
struct MaskBuffer {
// handles a 2-bit depth buffer used for z-buffering
uint16 w;
uint16 internalWidth;
uint16 h;
uint size;
byte *data;
bool bigEndian;
public:
MaskBuffer() : w(0), internalWidth(0), h(0), size(0), data(0), bigEndian(true) {
}
void clone(const MaskBuffer &buf) {
if (!buf.data)
return;
create(buf.w, buf.h);
bigEndian = buf.bigEndian;
memcpy(data, buf.data, size);
}
void create(uint16 width, uint16 height) {
free();
w = width;
internalWidth = w >> 2;
h = height;
size = (internalWidth * h);
data = (byte*)calloc(size, 1);
}
void free() {
::free(data);
data = 0;
w = 0;
h = 0;
internalWidth = 0;
size = 0;
}
inline byte getValue(uint16 x, uint16 y) {
byte m = data[(x >> 2) + y * internalWidth];
uint n;
if (bigEndian) {
n = (x & 3) << 1;
} else {
n = (3 - (x & 3)) << 1;
}
return (m >> n) & 3;
}
inline byte* getPtr(uint16 x, uint16 y) const {
return data + (x >> 2) + y * internalWidth;
}
void bltOr(uint16 dx, uint16 dy, const MaskBuffer &src, uint16 sx, uint16 sy, uint width, uint height) {
assert((width <= w) && (width <= src.w) && (height <= h) && (height <= src.h));
byte *s = src.getPtr(sx, sy);
byte *d = getPtr(dx, dy);
// this code assumes buffers are aligned on 4-pixels boundaries, as the original does
uint16 linewidth = width >> 2;
for (uint16 i = 0; i < height; i++) {
for (uint16 j = 0; j < linewidth; j++) {
*d++ |= *s++;
}
d += internalWidth - linewidth;
s += src.internalWidth - linewidth;
}
}
void bltCopy(uint16 dx, uint16 dy, const MaskBuffer &src, uint16 sx, uint16 sy, uint width, uint height) {
assert((width <= w) && (width <= src.w) && (height <= h) && (height <= src.h));
byte *s = src.getPtr(sx, sy);
byte *d = getPtr(dx, dy);
// this code assumes buffers are aligned on 4-pixels boundaries, as the original does
for (uint16 i = 0; i < height; i++) {
memcpy(d, s, (width >> 2));
d += internalWidth;
s += src.internalWidth;
}
}
};
struct PathBuffer {
// handles a 1-bit depth buffer used for masking non-walkable areas
uint16 w;
uint16 internalWidth;
uint16 h;
uint size;
byte *data;
public:
PathBuffer() : w(0), internalWidth(0), h(0), size(0), data(0) {
}
void create(uint16 width, uint16 height) {
free();
w = width;
internalWidth = w >> 3;
h = height;
size = (internalWidth * h);
data = (byte*)calloc(size, 1);
}
void free() {
::free(data);
data = 0;
w = 0;
h = 0;
internalWidth = 0;
size = 0;
}
inline byte getValue(uint16 x, uint16 y);
};
class Palette {
byte _data[768];
uint _colors;
uint _size;
bool _hb;
public:
Palette();
Palette(const Palette &pal);
void clone(const Palette &pal);
void makeBlack();
void setEntries(byte* data, uint first, uint num);
void getEntry(uint index, int &red, int &green, int &blue);
void setEntry(uint index, int red, int green, int blue);
void makeGrayscale();
void fadeTo(const Palette& target, uint step);
uint fillRGBA(byte *rgba);
void rotate(uint first, uint last, bool forward);
};
struct Cnv : public Frames {
uint16 _count; // # of frames
uint16 _width; //
uint16 _height; //
byte** field_8; // unused
byte* _data;
bool _freeData;
public:
Cnv() {
_width = _height = _count = 0;
_data = NULL;
}
Cnv(uint16 numFrames, uint16 width, uint16 height, byte* data, bool freeData = false)
: _count(numFrames), _width(width), _height(height), _data(data), _freeData(freeData) {
}
~Cnv() {
if (_freeData)
delete []_data;
}
byte* getFramePtr(uint16 index) {
if (index >= _count)
return NULL;
return &_data[index * _width * _height];
}
uint16 getNum() {
return _count;
}
byte *getData(uint16 index) {
return getFramePtr(index);
}
void getRect(uint16 index, Common::Rect &r) {
r.left = 0;
r.top = 0;
r.setWidth(_width);
r.setHeight(_height);
}
uint getRawSize(uint16 index) {
assert(index < _count);
return getSize(index);
}
uint getSize(uint16 index) {
assert(index < _count);
return _width * _height;
}
};
#define CENTER_LABEL_HORIZONTAL -1
#define CENTER_LABEL_VERTICAL -1
#define MAX_BALLOON_WIDTH 130
class Parallaction;
struct DoorData;
struct GetData;
struct Label;
class Disk;
enum {
kGfxObjVisible = 1,
kGfxObjNormal = 2,
kGfxObjCharacter = 4,
kGfxObjTypeDoor = 0,
kGfxObjTypeGet = 1,
kGfxObjTypeAnim = 2,
kGfxObjTypeLabel = 3,
kGfxObjTypeBalloon = 4,
kGfxObjTypeCharacter = 8
};
enum {
kGfxObjDoorZ = -200,
kGfxObjGetZ = -100
};
class GfxObj {
char *_name;
Frames *_frames;
bool _keep;
public:
int16 x, y;
int32 z;
uint32 _flags;
uint type;
uint frame;
uint layer;
uint transparentKey;
uint scale;
MaskBuffer _mask;
bool _hasMask;
GfxObj(uint type, Frames *frames, const char *name = NULL);
virtual ~GfxObj();
const char *getName() const;
uint getNum();
void getRect(uint frame, Common::Rect &r);
byte *getData(uint frame);
uint getRawSize(uint frame);
uint getSize(uint frame);
void setFlags(uint32 flags);
void clearFlags(uint32 flags);
bool isVisible() {
return (_flags & kGfxObjVisible) == kGfxObjVisible;
}
void release();
};
#define LAYER_FOREGROUND 3
/*
BackgroundInfo keeps information about the background bitmap that can be seen in the game.
These bitmaps can be of any size, smaller or larger than the visible screen, the latter
being the most common options.
*/
struct BackgroundInfo {
int x, y; // used to display bitmaps smaller than the screen
int width;
int height;
Graphics::Surface bg;
MaskBuffer mask;
MaskBuffer maskBackup;
PathBuffer path;
Palette palette;
int layers[4];
PaletteFxRange ranges[6];
bool hasMask;
BackgroundInfo() : x(0), y(0), width(0), height(0), hasMask(false) {
layers[0] = layers[1] = layers[2] = layers[3] = 0;
memset(ranges, 0, sizeof(ranges));
}
void setPaletteRange(int index, const PaletteFxRange& range) {
assert(index < 6);
memcpy(&ranges[index], &range, sizeof(PaletteFxRange));
}
uint16 getLayer(uint16 z) {
for (uint16 i = 0; i < 3; i++) {
if (layers[i+1] > z) return i;
}
return LAYER_FOREGROUND;
}
~BackgroundInfo() {
bg.free();
mask.free();
maskBackup.free();
path.free();
x = 0;
y = 0;
width = 0;
height = 0;
}
};
enum {
kBackgroundLocation = 1,
kBackgroundSlide = 2
};
class BalloonManager {
public:
enum TextColor {
kSelectedColor = 0,
kUnselectedColor = 1,
kNormalColor = 2
};
virtual ~BalloonManager() { }
virtual void freeBalloons() = 0;
virtual int setLocationBalloon(const char *text, bool endGame) = 0;
virtual int setDialogueBalloon(const char *text, uint16 winding, TextColor textColor) = 0;
virtual int setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) = 0;
virtual void setBalloonText(uint id, const char *text, TextColor textColor) = 0;
virtual int hitTestDialogueBalloon(int x, int y) = 0;
};
typedef Common::Array<GfxObj*> GfxObjArray;
class Gfx {
protected:
Parallaction* _vm;
public:
Disk *_disk;
GfxObjArray _sceneObjects;
GfxObj* loadAnim(const char *name);
GfxObj* loadGet(const char *name);
GfxObj* loadDoor(const char *name);
void showGfxObj(GfxObj* obj, bool visible);
void clearGfxObjects(uint filter);
void sortScene();
// labels
void showFloatingLabel(uint label);
void hideFloatingLabel();
uint renderFloatingLabel(Font *font, char *text);
uint createLabel(Font *font, const char *text, byte color);
void showLabel(uint id, int16 x, int16 y);
void hideLabel(uint id);
void freeLabels();
// dialogue balloons
GfxObj* registerBalloon(Frames *frames, const char *text);
void destroyBalloons();
// other items
int setItem(GfxObj* obj, uint16 x, uint16 y, byte transparentColor = 0);
void setItemFrame(uint item, uint16 f);
void freeItems();
// background surface
BackgroundInfo *_backgroundInfo;
void setBackground(uint type, BackgroundInfo *info);
void patchBackground(Graphics::Surface &surf, int16 x, int16 y, bool mask = false);
void grabBackground(const Common::Rect& r, Graphics::Surface &dst);
void fillBackground(const Common::Rect& r, byte color);
void invertBackground(const Common::Rect& r);
// palette
void setPalette(Palette palette);
void setBlackPalette();
void animatePalette();
// amiga specific
void applyHalfbriteEffect_NS(Graphics::Surface &surf);
void setHalfbriteMode(bool enable);
void setProjectorPos(int x, int y);
void setProjectorProgram(int16 *data);
int16 *_nextProjectorPos;
// init
Gfx(Parallaction* vm);
virtual ~Gfx();
void clearScreen();
void updateScreen();
public:
Palette _palette;
byte *_unpackedBitmap;
protected:
bool _halfbrite;
Common::Point _hbCirclePos;
int _hbCircleRadius;
// BRA specific
Palette _backupPal;
// frame data stored in programmable variables
int32 getRenderMode(const char *type);
Graphics::Surface *lockScreen();
void unlockScreen();
void updateScreenIntern();
bool _doubleBuffering;
int _gameType;
Graphics::Surface _backBuffer;
void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
int _scrollPos;
int _minScroll, _maxScroll;
// overlay mode enables drawing of graphics with automatic screen-to-game coordinate translation
bool _overlayMode;
void drawOverlay(Graphics::Surface &surf);
public:
#define MAX_NUM_LABELS 20
#define NO_FLOATING_LABEL 1000
GfxObjArray _labels;
GfxObjArray _balloons;
GfxObjArray _items;
uint _floatingLabel;
void drawInventory();
void updateFloatingLabel();
void drawList(Graphics::Surface &surface, GfxObjArray &list);
void copyRect(const Common::Rect &r, Graphics::Surface &src, Graphics::Surface &dst);
int getScrollPos();
void setScrollPos(int scrollX);
// low level text and patches
void drawText(Font *font, Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color);
void drawGfxObject(GfxObj *obj, Graphics::Surface &surf);
void blt(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor);
void unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor);
void bltMaskScale(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor);
void bltMaskNoScale(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, byte transparentColor);
void bltNoMaskNoScale(const Common::Rect& r, byte *data, Graphics::Surface *surf, byte transparentColor);
void loadGfxObjMask(const char *name, GfxObj *obj);
};
} // Parallaction
#endif
|