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
|
/* 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.
*
*/
/*
* This code is based on original Soltys source code
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
*/
#include "cge/general.h"
#include "cge/talk.h"
#include "cge/vol.h"
#include "cge/game.h"
#include "cge/events.h"
namespace CGE {
#define WID_SIZ 256
#define POS_SIZ 256
#define MAP_SIZ (256*8)
//uint8 FONT::Wid[WID_SIZ];
//uint16 FONT::Pos[POS_SIZ];
//uint8 FONT::Map[MAP_SIZ];
Font::Font(const char *name) {
_map = farnew(uint8, MAP_SIZ);
_pos = farnew(uint16, POS_SIZ);
_wid = farnew(uint8, WID_SIZ);
if ((_map == NULL) || (_pos == NULL) || (_wid == NULL))
error("No core");
mergeExt(_path, name, FONT_EXT);
load();
}
Font::~Font() {
free(_map);
free(_pos);
free(_wid);
}
void Font::load() {
INI_FILE f(_path);
if (!f._error) {
f.read(_wid, WID_SIZ);
if (!f._error) {
uint16 i, p = 0;
for (i = 0; i < POS_SIZ; i++) {
_pos[i] = p;
p += _wid[i];
}
f.read(_map, p);
}
}
}
uint16 Font::width(const char *text) {
uint16 w = 0;
if (text)
while (* text)
w += _wid[(unsigned char)*(text++)];
return w;
}
/*
void Font::save() {
CFILE f((const char *) _path, WRI);
if (!f._error) {
f.Write(_wid, WID_SIZ);
if (!f._error)
f.Write(_map, _pos[POS_SIZ - 1] + _wid[WID_SIZ - 1]);
}
}
*/
Talk::Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode)
: Sprite(vm, NULL), _mode(mode), _vm(vm) {
_ts[0] = _ts[1] = NULL;
_flags._syst = true;
update(tx);
}
Talk::Talk(CGEEngine *vm)
: Sprite(vm, NULL), _mode(PURE), _vm(vm) {
_ts[0] = _ts[1] = NULL;
_flags._syst = true;
}
/*
Talk::~Talk() {
for (uint16 i = 0; i < ShpCnt; i++) {
if (FP_SEG(_shpList[i]) != _DS) { // small model: always false
delete _shpList[i];
ShpList[i] = NULL;
}
}
}
*/
Font *Talk::_font;
void Talk::init() {
_font = new Font(progName());
}
void Talk::deinit() {
delete _font;
}
void Talk::update(const char *tx) {
uint16 vmarg = (_mode) ? TEXT_VM : 0;
uint16 hmarg = (_mode) ? TEXT_HM : 0;
uint16 mw = 0, mh, ln = vmarg;
const char *p;
uint8 *m;
if (!_ts[0]) {
uint16 k = 2 * hmarg;
mh = 2 * vmarg + FONT_HIG;
for (p = tx; *p; p++) {
if (*p == '|' || *p == '\n') {
mh += FONT_HIG + TEXT_LS;
if (k > mw)
mw = k;
k = 2 * hmarg;
} else
k += _font->_wid[(unsigned char)*p];
}
if (k > mw)
mw = k;
_ts[0] = box(mw, mh);
}
m = _ts[0]->_m + ln * mw + hmarg;
while (* tx) {
if (*tx == '|' || *tx == '\n')
m = _ts[0]->_m + (ln += FONT_HIG + TEXT_LS) * mw + hmarg;
else {
int cw = _font->_wid[(unsigned char)*tx], i;
uint8 *f = _font->_map + _font->_pos[(unsigned char)*tx];
for (i = 0; i < cw; i++) {
uint8 *pp = m;
uint16 n;
register uint16 b = *(f++);
for (n = 0; n < FONT_HIG; n++) {
if (b & 1)
*pp = TEXT_FG;
b >>= 1;
pp += mw;
}
m++;
}
}
tx++;
}
_ts[0]->code();
setShapeList(_ts);
}
Bitmap *Talk::box(uint16 w, uint16 h) {
uint8 *b, * p, * q;
uint16 n, r = (_mode == ROUND) ? TEXT_RD : 0;
if (w < 8)
w = 8;
if (h < 8)
h = 8;
b = farnew(uint8, n = w * h);
if (! b)
error("No core");
memset(b, TEXT_BG, n);
if (_mode) {
p = b;
q = b + n - w;
memset(p, LGRAY, w);
memset(q, DGRAY, w);
while (p < q) {
p += w;
*(p - 1) = DGRAY;
*p = LGRAY;
}
p = b;
for (int i = 0; i < r; i++) {
int j;
for (j = 0; j < r - i; j++) {
p[j] = TRANS;
p[w - j - 1] = TRANS;
q[j] = TRANS;
q[w - j - 1] = TRANS;
}
p[j] = LGRAY;
p[w - j - 1] = DGRAY;
q[j] = LGRAY;
q[w - j - 1] = DGRAY;
p += w;
q -= w;
}
}
return new Bitmap(w, h, b);
}
void Talk::putLine(int line, const char *text) {
// Note: (TS[0].W % 4) have to be 0
uint16 w = _ts[0]->_w;
uint16 h = _ts[0]->_h;
uint8 *v = _ts[0]->_v, * p;
uint16 dsiz = w >> 2; // data size (1 plane line size)
uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap
uint16 psiz = h * lsiz; // - last gap, but + plane trailer
uint16 size = 4 * psiz; // whole map size
uint16 rsiz = FONT_HIG * lsiz; // length of whole text row map
// set desired line pointer
v += (TEXT_VM + (FONT_HIG + TEXT_LS) * line) * lsiz;
// clear whole rectangle
p = v; // assume blanked line above text
byte *tmpBuf = new byte[rsiz];
memcpy(tmpBuf, p - lsiz, rsiz);
memcpy(p, tmpBuf, rsiz);
p += psiz; // tricky replicate lines for plane 0
memcpy(tmpBuf, p - lsiz, rsiz);
memcpy(p, tmpBuf, rsiz);
p += psiz; // same for plane 1
memcpy(tmpBuf, p - lsiz, rsiz);
memcpy(p, tmpBuf, rsiz);
p += psiz; // same for plane 2
memcpy(tmpBuf, p - lsiz, rsiz);
memcpy(p, tmpBuf, rsiz);
delete[] tmpBuf;
// paint text line
if (text) {
uint8 *q;
p = v + 2 + TEXT_HM / 4 + (TEXT_HM % 4) * psiz;
q = v + size;
while (* text) {
uint16 cw = _font->_wid[(unsigned char)*text], i;
uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text];
for (i = 0; i < cw; i++) {
register uint16 b = fp[i];
uint16 n;
for (n = 0; n < FONT_HIG; n++) {
if (b & 1)
*p = TEXT_FG;
b >>= 1;
p += lsiz;
}
p = p - rsiz + psiz;
if (p >= q)
p = p - size + 1;
}
text++;
}
}
}
InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldTxt(NULL), _vm(vm) {
_ts[0] = new Bitmap(w, FONT_HIG, TEXT_BG);
setShapeList(_ts);
}
void InfoLine::update(const char *tx) {
if (tx != _oldTxt) {
uint16 w = _ts[0]->_w;
uint16 h = _ts[0]->_h;
uint8 *v = (uint8 *) _ts[0]->_v;
uint16 dsiz = w >> 2; // data size (1 plane line size)
uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap
uint16 psiz = h * lsiz; // - last gape, but + plane trailer
uint16 size = 4 * psiz; // whole map size
// clear whole rectangle
byte *tmpBuf = new byte[size];
memset(v + 2, TEXT_BG, dsiz); // data bytes
memcpy(tmpBuf, v, psiz - lsiz);
memcpy(v + lsiz, tmpBuf, psiz - lsiz);
*(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16
memcpy(tmpBuf, v, 3 * psiz);
memcpy(v + psiz, tmpBuf, 3 * psiz);
delete[] tmpBuf;
// paint text line
if (tx) {
uint8 *p = v + 2, * q = p + size;
while (*tx) {
uint16 cw = _font->_wid[(unsigned char)*tx];
uint8 *fp = _font->_map + _font->_pos[(unsigned char)*tx];
for (uint16 i = 0; i < cw; i++) {
register uint16 b = fp[i];
for (uint16 n = 0; n < FONT_HIG; n++) {
if (b & 1)
*p = TEXT_FG;
b >>= 1;
p += lsiz;
}
if (p >= q)
p = p - size + 1;
}
tx++;
}
}
_oldTxt = tx;
}
}
} // End of namespace CGE
|