Browse Source

Render text in screen cordinates instead of buffer offsets

pull/380/head
Anders Jenbo 7 years ago
parent
commit
337bc9b125
  1. 118
      Source/control.cpp
  2. 6
      Source/control.h
  3. 12
      Source/engine.cpp
  4. 4
      Source/engine.h
  5. 11
      Source/error.cpp
  6. 9
      Source/help.cpp
  7. 2
      Source/inv.cpp
  8. 11
      Source/items.cpp
  9. 6
      Source/plrmsg.cpp
  10. 16
      Source/quests.cpp
  11. 2
      Source/scrollrt.cpp
  12. 17
      Source/stores.cpp
  13. 2
      Source/town.cpp

118
Source/control.cpp

@ -77,32 +77,12 @@ const BYTE fontkern[68] = {
3, 2, 7, 6, 3, 10, 10, 6, 6, 7,
4, 4, 9, 6, 6, 12, 3, 7
};
const int lineoffset[25] = {
BUFFER_WIDTH * 594 + 241,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 32 + 180,
BUFFER_WIDTH * 582 + 241,
BUFFER_WIDTH * 606 + 241,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 576 + 241,
BUFFER_WIDTH * 594 + 241,
BUFFER_WIDTH * 612 + 241,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 572 + 241,
BUFFER_WIDTH * 587 + 241,
BUFFER_WIDTH * 601 + 241,
BUFFER_WIDTH * 616 + 241,
BUFFER_WIDTH * 32,
BUFFER_WIDTH * 570 + 241,
BUFFER_WIDTH * 582 + 241,
BUFFER_WIDTH * 594 + 241,
BUFFER_WIDTH * 606 + 241,
BUFFER_WIDTH * 617 + 241
const int lineOffsets[5][5] = {
{ 434 },
{ 422, 446 },
{ 416, 434, 452 },
{ 412, 427, 441, 456 },
{ 410, 422, 434, 446, 457 },
};
const BYTE gbFontTransTbl[256] = {
// clang-format off
@ -441,21 +421,17 @@ void ToggleSpell(int slot)
}
}
void CPrintString(int nOffset, int nCel, char col)
void CPrintString(int sx, int sy, int nCel, char col)
{
/// ASSERT: assert(gpBuffer);
int i, nDataSize;
int i;
BYTE pix;
BYTE *src, *dst;
BYTE tbl[256];
src = CelGetFrame(pPanelText, nCel, &nDataSize);
dst = &gpBuffer[nOffset];
switch (col) {
case COL_WHITE:
CelBlit(dst, src, nDataSize, 13);
CelDraw(sx, sy, pPanelText, nCel, 13);
return;
case COL_BLUE:
for (i = 0; i < 256; i++) {
@ -488,7 +464,7 @@ void CPrintString(int nOffset, int nCel, char col)
}
break;
}
CelBlitLight(dst, src, nDataSize, 13, tbl);
CelDrawLight(sx, sy, pPanelText, nCel, 13, tbl);
}
void AddPanelString(char *str, BOOL just)
@ -1185,45 +1161,47 @@ void control_print_info_str(int y, char *str, BOOL center, int lines)
{
BYTE c;
char *tmp;
int screen_x, line, nOffset;
int lineOffset, strWidth, sx, sy;
line = 0;
nOffset = lineoffset[y + 5 * lines] + (SCREEN_WIDTH - PANEL_WIDTH) / 2;
lineOffset = 0;
sx = 177 + SCREEN_X;
sy = lineOffsets[lines][y] + (SCREEN_WIDTH - PANEL_WIDTH) / 2 + SCREEN_Y;
if (center == 1) {
screen_x = 0;
strWidth = 0;
tmp = str;
while (*tmp) {
c = gbFontTransTbl[(BYTE)*tmp++];
screen_x += fontkern[fontframe[c]] + 1;
strWidth += fontkern[fontframe[c]] + 1;
}
if (screen_x < 288)
line = (288 - screen_x) >> 1;
nOffset += line;
if (strWidth < 288)
lineOffset = (288 - strWidth) >> 1;
sx += lineOffset;
}
while (*str) {
c = gbFontTransTbl[(BYTE)*str++];
c = fontframe[c];
line += fontkern[c] + 2;
lineOffset += fontkern[c] + 2;
if (c) {
if (line < 288) {
CPrintString(nOffset, c, infoclr);
if (lineOffset < 288) {
CPrintString(sx, sy, c, infoclr);
}
}
nOffset += fontkern[c] + 2;
sx += fontkern[c] + 2;
}
}
void PrintGameStr(int x, int y, char *str, int color)
{
BYTE c;
int off;
off = BUFFER_WIDTH * (y + SCREEN_Y) + x + SCREEN_X;
int sx, sy;
sx = x + SCREEN_X;
sy = y + SCREEN_Y;
while (*str) {
c = gbFontTransTbl[(BYTE)*str++];
c = fontframe[c];
if (c)
CPrintString(off, c, color);
off += fontkern[c] + 1;
CPrintString(sx, sy, c, color);
sx += fontkern[c] + 1;
}
}
@ -1437,9 +1415,10 @@ void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base)
{
BYTE c;
char *tmp;
int nOffset, screen_x, line, widthOffset;
int sx, sy, screen_x, line, widthOffset;
nOffset = x + BUFFER_WIDTH * (y + SCREEN_Y) + SCREEN_X;
sx = x + SCREEN_X;
sy = y + SCREEN_Y;
widthOffset = width - x + 1;
line = 0;
screen_x = 0;
@ -1450,16 +1429,16 @@ void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base)
}
if (screen_x < widthOffset)
line = (widthOffset - screen_x) >> 1;
nOffset += line;
sx += line;
while (*pszStr) {
c = gbFontTransTbl[(BYTE)*pszStr++];
c = fontframe[c];
line += fontkern[c] + base;
if (c) {
if (line < widthOffset)
CPrintString(nOffset, c, col);
CPrintString(sx, sy, c, col);
}
nOffset += fontkern[c] + base;
sx += fontkern[c] + base;
}
}
@ -1734,9 +1713,9 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col)
{
BYTE c;
char *tmp;
int screen_x, line, width;
int screen_x, line, sx;
width = BUFFER_WIDTH * y + x + SCREEN_WIDTH - 320 + 120;;
sx = x + SCREEN_WIDTH - 320 + 120;
line = 0;
if (cjustflag) {
screen_x = 0;
@ -1747,7 +1726,7 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col)
}
if (screen_x < 222)
line = (222 - screen_x) >> 1;
width += line;
sx += line;
}
while (*pszStr) {
c = gbFontTransTbl[(BYTE)*pszStr++];
@ -1755,9 +1734,9 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col)
line += fontkern[c] + 1;
if (c) {
if (line <= 222)
CPrintString(width, c, col);
CPrintString(sx, y, c, col);
}
width += fontkern[c] + 1;
sx += fontkern[c] + 1;
}
}
@ -1920,13 +1899,14 @@ void DrawTalkPan()
DrawPanelBox(170, sgbPlrTalkTbl + 80, 310, 55, 234, 576);
msg = sgszTalkMsg;
for (i = 0; i < 39; i += 13) {
msg = control_print_talk_msg(msg, 0, i, &x, 0);
x = 0;
msg = control_print_talk_msg(msg, &x, i, 0);
if (!msg)
break;
}
if (msg)
*msg = '\0';
CelBlitFrame(gpBuffer + x, pSPentSpn2Cels, frame, 12);
CelDraw(x, i + 534, pSPentSpn2Cels, frame, 12);
frame = (frame & 7) + 1;
talk_btn = 0;
for (i = 0; i < 4; i++) {
@ -1952,21 +1932,21 @@ void DrawTalkPan()
CelDraw(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61);
}
if (plr[i].plractive) {
control_print_talk_msg(plr[i]._pName, 46, 60 + talk_btn * 18, &x, color);
x = 46;
control_print_talk_msg(plr[i]._pName, &x, 60 + talk_btn * 18, color);
}
talk_btn++;
}
}
char *control_print_talk_msg(char *msg, int x, int y, int *nOffset, int color)
char *control_print_talk_msg(char *msg, int *x, int y, int color)
{
BYTE c;
int width;
x += 264;
width = x;
*nOffset = BUFFER_WIDTH * (y + 534) + x;
*x += 264;
width = *x;
while (*msg) {
c = fontframe[gbFontTransTbl[(BYTE)*msg]];
@ -1975,9 +1955,9 @@ char *control_print_talk_msg(char *msg, int x, int y, int *nOffset, int color)
return msg;
msg++;
if (c) {
CPrintString(*nOffset, c, color);
CPrintString(*x, y + 534, c, color);
}
*nOffset += fontkern[c] + 1;
*x += fontkern[c] + 1;
}
return NULL;
}

6
Source/control.h

@ -60,7 +60,7 @@ void DrawSpellList();
void SetSpell();
void SetSpeedSpell(int slot);
void ToggleSpell(int slot);
void CPrintString(int nOffset, int nCel, char col);
void CPrintString(int sx, int sy, int nCel, char col);
void AddPanelString(char *str, BOOL just);
void ClearPanel();
void DrawPanelBox(int x, int y, int w, int h, int sx, int sy);
@ -109,7 +109,7 @@ void control_drop_gold(char vkey);
void control_remove_gold(int pnum, int gold_index);
void control_set_gold_curs(int pnum);
void DrawTalkPan();
char *control_print_talk_msg(char *msg, int x, int y, int *nOffset, int just);
char *control_print_talk_msg(char *msg, int *x, int y, int just);
BOOL control_check_talk_btn();
void control_release_talk_btn();
void control_reset_talk_msg();
@ -123,7 +123,7 @@ void control_up_down(int v);
/* rdata */
extern const BYTE fontframe[128];
extern const BYTE fontkern[68];
extern const int lineoffset[25];
extern const int lineOffsets[5][5];
extern const BYTE gbFontTransTbl[256];
/* data */

12
Source/engine.cpp

@ -173,7 +173,7 @@ void CelBlitLight(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, B
}
}
void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, BYTE *tbl)
{
int nDataSize;
BYTE *pDecodeTo, *pRLEBytes;
@ -188,8 +188,8 @@ void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
pDecodeTo = &gpBuffer[sx + BUFFER_WIDTH * sy];
if (light_table_index)
CelBlitLightSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth);
if (light_table_index || tbl)
CelBlitLightSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth, tbl);
else
CelBlitSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth);
}
@ -394,10 +394,9 @@ void CelClippedBlit(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSk
/**
* @brief Same as CelBlitLight but checks for drawing outside the buffer
*/
void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *tbl)
{
int w;
BYTE *tbl;
/// ASSERT: assert(pDecodeTo != NULL);
if (!pDecodeTo)
@ -415,7 +414,8 @@ void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt
src = pRLEBytes;
dst = pDecodeTo;
tbl = &pLightTbl[light_table_index * 256];
if (tbl == NULL)
tbl = &pLightTbl[light_table_index * 256];
w = nWidth;
for (; src != &pRLEBytes[nDataSize]; dst -= BUFFER_WIDTH + w) {

4
Source/engine.h

@ -89,13 +89,13 @@ void CelBlitFrame(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth);
void CelClippedDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip = 0, int CelCap = 8);
void CelClippedBlit(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip = 0, int CelCap = 8);
void CelBlitLight(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *tbl = NULL);
void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth);
void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, BYTE *tbl = NULL);
void CelClippedDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip = 0, int CelCap = 8);
void CelClippedBlitLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip = 0, int CelCap = 8);
void CelDrawLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light);
void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth);
void CelClippedDrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip = 0, int CelCap = 8);
void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth);
void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *tbl = NULL);
void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth);
void CelDrawLightRedSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light);
void CelBlitWidth(BYTE *pBuff, int always_0, int hgt, int wdt, BYTE *pCelBuff, int nCel, int nWidth);

11
Source/error.cpp

@ -84,7 +84,7 @@ void ClrDiabloMsg()
void DrawDiabloMsg()
{
int i, len, off, width, sx, sy;
int i, len, width, sx, sy;
BYTE c;
CelDraw(165, 318, pSTextSlidCels, 1, 12);
@ -114,7 +114,8 @@ void DrawDiabloMsg()
#include "asm_trans_rect.inc"
strcpy(tempstr, MsgStrings[msgflag]);
off = 165 + BUFFER_WIDTH * 342;
sx = 165;
sy = 342;
len = strlen(tempstr);
width = 0;
@ -123,15 +124,15 @@ void DrawDiabloMsg()
}
if (width < 442) {
off += (442 - width) >> 1;
sx += (442 - width) >> 1;
}
for (i = 0; i < len; i++) {
c = fontframe[gbFontTransTbl[(BYTE)tempstr[i]]];
if (c != '\0') {
CPrintString(off, c, COL_GOLD);
CPrintString(sx, sy, c, COL_GOLD);
}
off += fontkern[c] + 1;
sx += fontkern[c] + 1;
}
if (msgdelay > 0) {

9
Source/help.cpp

@ -535,11 +535,12 @@ void DrawHelp()
void DrawHelpLine(int always_0, int help_line_nr, char *text, char color)
{
int off, width;
int sx, sy, width;
BYTE c;
width = 0;
off = BUFFER_WIDTH * (help_line_nr * 12 + 204) + always_0 + 96;
sx = always_0 + 96;
sy = help_line_nr * 12 + 204;
while (*text) {
c = gbFontTransTbl[(BYTE)*text];
text++;
@ -547,9 +548,9 @@ void DrawHelpLine(int always_0, int help_line_nr, char *text, char color)
width += fontkern[c] + 1;
if (c) {
if (width <= 577)
CPrintString(off, c, color);
CPrintString(sx, sy, c, color);
}
off += fontkern[c] + 1;
sx += fontkern[c] + 1;
}
}

2
Source/inv.cpp

@ -418,7 +418,7 @@ void DrawInvBelt()
&& plr[myplr].SpdList[i]._itype != ITYPE_GOLD) {
fi = i + 49;
ff = fontframe[gbFontTransTbl[fi]];
CPrintString(InvRect[i + 65].X + 64 + BUFFER_WIDTH * (InvRect[i + 65].Y + 159) - fontkern[ff] + 28, ff, 0);
CPrintString(InvRect[i + 65].X + SCREEN_X + 28 - fontkern[ff], InvRect[i + 65].Y + SCREEN_Y - 1, ff, 0);
}
}
}

11
Source/items.cpp

@ -2921,10 +2921,11 @@ void DrawUTextBack()
void PrintUString(int x, int y, BOOL cjustflag, char *str, int col)
{
int len, width, off, i, k;
int len, width, sx, sy, i, k;
BYTE c;
off = x + BUFFER_WIDTH * (y * 12 + 204) + 96;
sx = x + 96;
sy = y * 12 + 204;
len = strlen(str);
k = 0;
if (cjustflag) {
@ -2933,16 +2934,16 @@ void PrintUString(int x, int y, BOOL cjustflag, char *str, int col)
width += fontkern[fontframe[gbFontTransTbl[(BYTE)str[i]]]] + 1;
if (width < 257)
k = (257 - width) >> 1;
off += k;
sx += k;
}
for (i = 0; i < len; i++) {
c = fontframe[gbFontTransTbl[(BYTE)str[i]]];
k += fontkern[c] + 1;
if (c && k <= 257) {
CPrintString(off, c, col);
CPrintString(sx, sy, c, col);
}
off += fontkern[c] + 1;
sx += fontkern[c] + 1;
}
}

6
Source/plrmsg.cpp

@ -111,7 +111,7 @@ void PrintPlrMsg(DWORD x, DWORD y, DWORD width, const char *str, BYTE col)
while (*str) {
BYTE c;
int screen = BUFFER_WIDTH * y + x;
int sx = x;
DWORD len = 0;
const char *sstr = str;
const char *endstr = sstr;
@ -135,8 +135,8 @@ void PrintPlrMsg(DWORD x, DWORD y, DWORD width, const char *str, BYTE col)
c = gbFontTransTbl[(BYTE)*str++];
c = fontframe[c];
if (c)
CPrintString(screen, c, col);
screen += fontkern[c] + 1;
CPrintString(sx, y, c, col);
sx += fontkern[c] + 1;
}
y += 10;

16
Source/quests.cpp

@ -700,11 +700,11 @@ void ResyncQuests()
void PrintQLString(int x, int y, BOOL cjustflag, char *str, int col)
{
int len, width, off, i, k, s;
int len, width, i, k, sx, sy;
BYTE c;
s = y * 12;
off = x + BUFFER_WIDTH * (y * 12 + 204) + 96;
sx = x + 96;
sy = y * 12 + 204;
len = strlen(str);
k = 0;
if (cjustflag) {
@ -713,21 +713,21 @@ void PrintQLString(int x, int y, BOOL cjustflag, char *str, int col)
width += fontkern[fontframe[gbFontTransTbl[(BYTE)str[i]]]] + 1;
if (width < 257)
k = (257 - width) >> 1;
off += k;
sx += k;
}
if (qline == y) {
CelDraw(cjustflag ? x + k + 76 : x + 76, s + 205, pSPentSpn2Cels, ALLQUESTS, 12);
CelDraw(cjustflag ? x + k + 76 : x + 76, sy + 1, pSPentSpn2Cels, ALLQUESTS, 12);
}
for (i = 0; i < len; i++) {
c = fontframe[gbFontTransTbl[(BYTE)str[i]]];
k += fontkern[c] + 1;
if (c && k <= 257) {
CPrintString(off, c, col);
CPrintString(sx, sy, c, col);
}
off += fontkern[c] + 1;
sx += fontkern[c] + 1;
}
if (qline == y) {
CelDraw(cjustflag ? x + k + 100 : 340 - x, s + 205, pSPentSpn2Cels, ALLQUESTS, 12);
CelDraw(cjustflag ? x + k + 100 : 340 - x, sy + 1, pSPentSpn2Cels, ALLQUESTS, 12);
}
}

2
Source/scrollrt.cpp

@ -891,7 +891,7 @@ static void DrawGame(int x, int y)
}
/// ASSERT: assert(gpBuffer);
gpBufEnd = &gpBuffer[BUFFER_WIDTH * (VIEWPORT_HEIGHT + SCREEN_Y)];
gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_HEIGHT + SCREEN_Y)];
for (i = 0; i < blocks; i++) {
scrollrt_draw(x, y, sx, sy, chunks, i, 0);
y++;

17
Source/stores.cpp

@ -118,7 +118,7 @@ void DrawSTextBack()
void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val)
{
int xx, yy;
int len, width, off, i, k, s;
int len, width, sx, sy, i, k, s;
BYTE c;
char valstr[32];
@ -127,7 +127,8 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val)
xx = 96;
else
xx = 416;
off = xx + x + BUFFER_WIDTH * (s + 204);
sx = xx + x;
sy = s + 204;
len = strlen(str);
if (stextsize)
yy = 577;
@ -140,7 +141,7 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val)
width += fontkern[fontframe[gbFontTransTbl[(BYTE)str[i]]]] + 1;
if (width < yy)
k = (yy - width) >> 1;
off += k;
sx += k;
}
if (stextsel == y) {
CelDraw(cjustflag ? xx + x + k - 20 : xx + x - 20, s + 205, pSPentSpn2Cels, InStoreFlag, 12);
@ -149,18 +150,18 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val)
c = fontframe[gbFontTransTbl[(BYTE)str[i]]];
k += fontkern[c] + 1;
if (c && k <= yy) {
CPrintString(off, c, col);
CPrintString(sx, sy, c, col);
}
off += fontkern[c] + 1;
sx += fontkern[c] + 1;
}
if (!cjustflag && val >= 0) {
sprintf(valstr, "%i", val);
off = BUFFER_WIDTH * (s + 204) + 656 - x;
sx = 656 - x;
for (i = strlen(valstr) - 1; i >= 0; i--) {
c = fontframe[gbFontTransTbl[(BYTE)valstr[i]]];
off -= fontkern[c] + 1;
sx -= fontkern[c] + 1;
if (c) {
CPrintString(off, c, col);
CPrintString(sx, sy, c, col);
}
}
}

2
Source/town.cpp

@ -307,7 +307,7 @@ void T_DrawGame(int x, int y)
}
/// ASSERT: assert(gpBuffer);
gpBufEnd = &gpBuffer[BUFFER_WIDTH * (VIEWPORT_HEIGHT + SCREEN_Y)];
gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_HEIGHT + SCREEN_Y)];
for (i = 0; i < blocks; i++) {
town_draw(x, y, sx, sy, chunks, i, 0);
y++;

Loading…
Cancel
Save