2011-06-10 05:45:18 +00:00
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#include "cge/general.h"
|
|
|
|
#include "cge/talk.h"
|
|
|
|
#include "cge/vol.h"
|
|
|
|
#include "cge/game.h"
|
|
|
|
#include "cge/mouse.h"
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
namespace CGE {
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#define WID_SIZ 256
|
|
|
|
#define POS_SIZ 256
|
|
|
|
#define MAP_SIZ (256*8)
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
//uint8 FONT::Wid[WID_SIZ];
|
|
|
|
//uint16 FONT::Pos[POS_SIZ];
|
|
|
|
//uint8 FONT::Map[MAP_SIZ];
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
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");
|
2011-07-01 23:02:14 +00:00
|
|
|
mergeExt(Path, name, FONT_EXT);
|
2011-06-13 09:57:24 +00:00
|
|
|
Load();
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 06:30:23 +00:00
|
|
|
FONT::~FONT() {
|
2011-06-13 09:57:24 +00:00
|
|
|
free(Map);
|
|
|
|
free(Pos);
|
|
|
|
free(Wid);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 06:30:23 +00:00
|
|
|
void FONT::Load() {
|
2011-06-13 09:57:24 +00:00
|
|
|
INI_FILE f(Path);
|
2011-07-01 06:37:40 +00:00
|
|
|
if (!f._error) {
|
2011-06-30 06:30:23 +00:00
|
|
|
f.read(Wid, WID_SIZ);
|
2011-07-01 06:37:40 +00:00
|
|
|
if (!f._error) {
|
2011-06-13 09:57:24 +00:00
|
|
|
uint16 i, p = 0;
|
2011-06-26 10:07:42 +00:00
|
|
|
for (i = 0; i < POS_SIZ; i++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
Pos[i] = p;
|
|
|
|
p += Wid[i];
|
|
|
|
}
|
2011-06-30 06:30:23 +00:00
|
|
|
f.read(Map, p);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
uint16 FONT::Width(const char *text) {
|
|
|
|
uint16 w = 0;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (text)
|
|
|
|
while (* text)
|
2011-06-26 10:07:42 +00:00
|
|
|
w += Wid[*(text++)];
|
2011-06-13 09:57:24 +00:00
|
|
|
return w;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-06-13 09:57:24 +00:00
|
|
|
void FONT::Save(void) {
|
|
|
|
CFILE f((const char *) Path, WRI);
|
|
|
|
if (! f.Error) {
|
|
|
|
f.Write(Wid, WID_SIZ);
|
|
|
|
if (! f.Error)
|
2011-06-26 10:07:42 +00:00
|
|
|
f.Write(Map, Pos[POS_SIZ - 1] + Wid[WID_SIZ - 1]);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-06-26 23:03:47 +00:00
|
|
|
TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode)
|
2011-06-28 22:35:21 +00:00
|
|
|
: Sprite(vm, NULL), Mode(mode), _vm(vm) {
|
2011-06-13 09:57:24 +00:00
|
|
|
TS[0] = TS[1] = NULL;
|
2011-06-29 14:13:17 +00:00
|
|
|
_flags._syst = true;
|
2011-06-13 09:57:24 +00:00
|
|
|
Update(tx);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-26 23:03:47 +00:00
|
|
|
TALK::TALK(CGEEngine *vm)
|
2011-06-28 22:35:21 +00:00
|
|
|
: Sprite(vm, NULL), Mode(PURE), _vm(vm) {
|
2011-06-13 09:57:24 +00:00
|
|
|
TS[0] = TS[1] = NULL;
|
2011-06-29 14:13:17 +00:00
|
|
|
_flags._syst = true;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-06-13 09:57:24 +00:00
|
|
|
TALK::~TALK (void) {
|
2011-06-26 10:07:42 +00:00
|
|
|
for (uint16 i = 0; i < ShpCnt; i++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
if (FP_SEG(ShpList[i]) != _DS) { // small model: always false
|
|
|
|
delete ShpList[i];
|
|
|
|
ShpList[i] = NULL;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2011-06-28 12:18:21 +00:00
|
|
|
FONT *TALK::_Font;
|
|
|
|
|
|
|
|
void TALK::init() {
|
2011-07-01 23:02:14 +00:00
|
|
|
_Font = new FONT(progName());
|
2011-06-28 12:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TALK::deinit() {
|
|
|
|
delete _Font;
|
|
|
|
}
|
|
|
|
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
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;
|
2011-06-26 10:07:42 +00:00
|
|
|
for (p = tx; *p; p++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
if (*p == '|' || *p == '\n') {
|
|
|
|
mh += FONT_HIG + TEXT_LS;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (k > mw)
|
2011-06-13 09:57:24 +00:00
|
|
|
mw = k;
|
|
|
|
k = 2 * hmarg;
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-06-28 12:18:21 +00:00
|
|
|
k += _Font->Wid[*p];
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-13 11:07:45 +00:00
|
|
|
if (k > mw)
|
2011-06-13 09:57:24 +00:00
|
|
|
mw = k;
|
|
|
|
TS[0] = Box(mw, mh);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
m = TS[0]->_m + ln * mw + hmarg;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
while (* tx) {
|
|
|
|
if (*tx == '|' || *tx == '\n')
|
2011-06-29 14:13:17 +00:00
|
|
|
m = TS[0]->_m + (ln += FONT_HIG + TEXT_LS) * mw + hmarg;
|
2011-06-13 09:57:24 +00:00
|
|
|
else {
|
2011-06-28 12:18:21 +00:00
|
|
|
int cw = _Font->Wid[*tx], i;
|
|
|
|
uint8 *f = _Font->Map + _Font->Pos[*tx];
|
2011-06-13 09:57:24 +00:00
|
|
|
for (i = 0; i < cw; i++) {
|
2011-06-29 07:57:16 +00:00
|
|
|
uint8 *pp = m;
|
2011-06-13 09:57:24 +00:00
|
|
|
uint16 n;
|
|
|
|
register uint16 b = *(f++);
|
|
|
|
for (n = 0; n < FONT_HIG; n++) {
|
2011-06-13 11:07:45 +00:00
|
|
|
if (b & 1)
|
2011-06-29 07:57:16 +00:00
|
|
|
*pp = TEXT_FG;
|
2011-06-13 09:57:24 +00:00
|
|
|
b >>= 1;
|
2011-06-29 07:57:16 +00:00
|
|
|
pp += mw;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
m++;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
tx++;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-30 06:30:23 +00:00
|
|
|
TS[0]->code();
|
2011-07-01 23:02:14 +00:00
|
|
|
setShapeList(TS);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
Bitmap *TALK::Box(uint16 w, uint16 h) {
|
2011-06-13 09:57:24 +00:00
|
|
|
uint8 *b, * p, * q;
|
|
|
|
uint16 n, r = (Mode == ROUND) ? TEXT_RD : 0;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 11:07:45 +00:00
|
|
|
if (w < 8)
|
2011-06-13 09:57:24 +00:00
|
|
|
w = 8;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (h < 8)
|
2011-06-13 09:57:24 +00:00
|
|
|
h = 8;
|
|
|
|
b = farnew(uint8, n = w * h);
|
|
|
|
if (! b)
|
|
|
|
error("No core");
|
|
|
|
memset(b, TEXT_BG, n);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
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;
|
2011-06-26 10:07:42 +00:00
|
|
|
for (int i = 0; i < r; i++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int j;
|
2011-06-26 10:07:42 +00:00
|
|
|
for (j = 0; j < r - i; j++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
return new Bitmap(w, h, b);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
void TALK::PutLine(int line, const char *text) {
|
2011-06-09 06:20:53 +00:00
|
|
|
// Note: (TS[0].W % 4) have to be 0
|
2011-06-29 14:13:17 +00:00
|
|
|
uint16 w = TS[0]->_w, h = TS[0]->_h;
|
|
|
|
uint8 *v = TS[0]->_v, * p;
|
2011-06-13 09:57:24 +00:00
|
|
|
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
|
|
|
|
memcpy(p, p - lsiz, rsiz);
|
|
|
|
p += psiz; // tricky replicate lines for plane 0
|
|
|
|
memcpy(p, p - lsiz, rsiz);
|
|
|
|
p += psiz; // same for plane 1
|
|
|
|
memcpy(p, p - lsiz, rsiz);
|
|
|
|
p += psiz; // same for plane 2
|
|
|
|
memcpy(p, p - lsiz, rsiz); // same for plane 3
|
|
|
|
|
|
|
|
// paint text line
|
|
|
|
if (text) {
|
|
|
|
uint8 *q;
|
|
|
|
p = v + 2 + TEXT_HM / 4 + (TEXT_HM % 4) * psiz;
|
|
|
|
q = v + size;
|
|
|
|
|
|
|
|
while (* text) {
|
2011-06-28 12:18:21 +00:00
|
|
|
uint16 cw = _Font->Wid[*text], i;
|
|
|
|
uint8 *fp = _Font->Map + _Font->Pos[*text];
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-06-26 10:07:42 +00:00
|
|
|
for (i = 0; i < cw; i++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
register uint16 b = fp[i];
|
|
|
|
uint16 n;
|
2011-06-26 10:07:42 +00:00
|
|
|
for (n = 0; n < FONT_HIG; n++) {
|
2011-06-13 11:07:45 +00:00
|
|
|
if (b & 1)
|
2011-06-13 09:57:24 +00:00
|
|
|
*p = TEXT_FG;
|
|
|
|
b >>= 1;
|
|
|
|
p += lsiz;
|
|
|
|
}
|
|
|
|
p = p - rsiz + psiz;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (p >= q)
|
2011-06-13 09:57:24 +00:00
|
|
|
p = p - size + 1;
|
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
text++;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-26 23:03:47 +00:00
|
|
|
INFO_LINE::INFO_LINE(CGEEngine *vm, uint16 w) : TALK(vm), OldTxt(NULL), _vm(vm) {
|
2011-06-29 14:13:17 +00:00
|
|
|
TS[0] = new Bitmap(w, FONT_HIG, TEXT_BG);
|
2011-07-01 23:02:14 +00:00
|
|
|
setShapeList(TS);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
void INFO_LINE::Update(const char *tx) {
|
|
|
|
if (tx != OldTxt) {
|
2011-06-29 14:13:17 +00:00
|
|
|
uint16 w = TS[0]->_w, h = TS[0]->_h;
|
|
|
|
uint8 *v = (uint8 *) TS[0]->_v;
|
2011-06-13 09:57:24 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
// claer whole rectangle
|
|
|
|
memset(v + 2, TEXT_BG, dsiz); // data bytes
|
|
|
|
memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines
|
2011-06-26 10:07:42 +00:00
|
|
|
*(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16
|
2011-06-13 09:57:24 +00:00
|
|
|
memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes
|
|
|
|
|
|
|
|
// paint text line
|
|
|
|
if (tx) {
|
|
|
|
uint8 *p = v + 2, * q = p + size;
|
|
|
|
|
|
|
|
while (*tx) {
|
2011-06-28 12:18:21 +00:00
|
|
|
uint16 cw = _Font->Wid[*tx];
|
|
|
|
uint8 *fp = _Font->Map + _Font->Pos[*tx];
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
for (uint16 i = 0; i < cw; i++) {
|
|
|
|
register uint16 b = fp[i];
|
2011-06-26 10:07:42 +00:00
|
|
|
for (uint16 n = 0; n < FONT_HIG; n++) {
|
2011-06-13 11:07:45 +00:00
|
|
|
if (b & 1)
|
2011-06-13 09:57:24 +00:00
|
|
|
*p = TEXT_FG;
|
|
|
|
b >>= 1;
|
|
|
|
p += lsiz;
|
|
|
|
}
|
2011-06-13 11:07:45 +00:00
|
|
|
if (p >= q)
|
2011-06-13 09:57:24 +00:00
|
|
|
p = p - size + 1;
|
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
tx++;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
OldTxt = tx;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-10 20:57:09 +00:00
|
|
|
|
|
|
|
} // End of namespace CGE
|