From 71adfe509e8d467f370cee14a126c98fcb394872 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 28 Oct 2019 02:12:51 +0100 Subject: [PATCH] Document more attributes --- Source/control.cpp | 41 ++++++++++++++++++++++++++++------------- Source/gmenu.cpp | 2 +- Source/items.cpp | 26 +++++++++++++------------- Source/minitext.cpp | 6 +++--- Source/scrollrt.cpp | 16 ++++++++-------- Source/stores.cpp | 14 +++++++------- defs.h | 2 +- 7 files changed, 61 insertions(+), 46 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 896f4ced5..e79722164 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -578,6 +578,12 @@ void ToggleSpell(int slot) } } +/** + * @brief Print letter to the backbuffer + * @param nOffset Backbuffer offset + * @param nCel Number of letter in Windows-1252 + * @param col text_color color value + */ void CPrintString(int nOffset, int nCel, char col) { /// ASSERT: assert(gpBuffer); @@ -890,7 +896,7 @@ void DrawPanelBox(int x, int y, int w, int h, int sx, int sy) /// ASSERT: assert(gpBuffer); nSrcOff = x + PANEL_WIDTH * y; - nDstOff = sx + BUFFER_WIDTH * sy + PANEL_LEFT; + nDstOff = sx + BUFFER_WIDTH * sy; #ifdef USE_ASM __asm { @@ -1009,7 +1015,7 @@ void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy) * into the target buffer. * @param pCelBuff The flask cel buffer. * @param w Width of the cel. - * @param nSrcOffset Offset of the source buffer from where the bytes will start to be copied from. + * @param nSrcOff Offset of the source buffer from where the bytes will start to be copied from. * @param pBuff Target buffer. * @param nDstOff Offset of the target buffer where the bytes will start to be copied to. * @param h How many lines of the source buffer that will be copied. @@ -1073,9 +1079,9 @@ void DrawLifeFlask() filled = 11; filled += 2; - DrawFlask(pLifeBuff, 88, 277, gpBuffer, BUFFER_WIDTH * 499 + 173, filled); + DrawFlask(pLifeBuff, 88, 277, gpBuffer, SCREENXY(PANEL_LEFT + 109, PANEL_TOP - 13), filled); if (filled != 13) - DrawFlask(pBtmBuff, PANEL_WIDTH, PANEL_WIDTH * filled + 2029, gpBuffer, BUFFER_WIDTH * filled + BUFFER_WIDTH * 499 + 173, 13 - filled); + DrawFlask(pBtmBuff, PANEL_WIDTH, PANEL_WIDTH * (filled + 3) + 109, gpBuffer, SCREENXY(PANEL_LEFT + 109, PANEL_TOP - 13 + filled), 13 - filled); } /** @@ -1108,9 +1114,9 @@ void DrawManaFlask() filled = 11; filled += 2; - DrawFlask(pManaBuff, 88, 277, gpBuffer, BUFFER_WIDTH * 499 + 173 + 366, filled); + DrawFlask(pManaBuff, 88, 277, gpBuffer, SCREENXY(PANEL_LEFT + 475, PANEL_TOP - 13), filled); if (filled != 13) - DrawFlask(pBtmBuff, PANEL_WIDTH, PANEL_WIDTH * filled + 2029 + 366, gpBuffer, BUFFER_WIDTH * filled + BUFFER_WIDTH * 499 + 173 + 366, 13 - filled); + DrawFlask(pBtmBuff, PANEL_WIDTH, PANEL_WIDTH * (filled + 3) + 475, gpBuffer, SCREENXY(PANEL_LEFT + 475, PANEL_TOP - 13 + filled), 13 - filled); } void control_update_life_mana() @@ -1261,9 +1267,9 @@ void DrawCtrlPan() for (i = 0; i < 6; i++) { if (!panbtn[i]) - DrawPanelBox(PanBtnPos[i][0] - PANEL_LEFT, PanBtnPos[i][1] - (PANEL_TOP - 16), 71, 20, PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + SCREEN_Y); + DrawPanelBox(PanBtnPos[i][0] - PANEL_LEFT, PanBtnPos[i][1] - (PANEL_TOP - 16), 71, 20, PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y); else - CelDraw(PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + (PANEL_Y - 334), pPanelButtons, i + 1, 71); + CelDraw(PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + (PANEL_Y - 334), pPanelButtons, i + 1, 71); } if (numpanbtns == 8) { CelDraw(87 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[6] + 1, 33); @@ -1972,14 +1978,23 @@ void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) } } -void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base) +/** + * @brief Render text string to back buffer + * @param x Screen coordinate + * @param y Screen coordinate + * @param endX End of line in screen coordinate + * @param pszStr String to print, in Windows-1252 encoding + * @param col text_color color value + * @param base Letter spacing + */ +void MY_PlrStringXY(int x, int y, int endX, char *pszStr, char col, int base) { BYTE c; char *tmp; int nOffset, screen_x, line, widthOffset; nOffset = x + PitchTbl[y + SCREEN_Y] + SCREEN_X; - widthOffset = width - x + 1; + widthOffset = endX - x + 1; line = 0; screen_x = 0; tmp = pszStr; @@ -2021,7 +2036,7 @@ void DrawLevelUpIcon() if (!stextflag) { nCel = lvlbtndown ? 3 : 2; - ADD_PlrStringXY(0, 303, 120, "Level Up", COL_WHITE); + ADD_PlrStringXY(PANEL_LEFT + 0, PANEL_TOP - 49, PANEL_LEFT + 120, "Level Up", COL_WHITE); CelDraw(40 + PANEL_X, -17 + PANEL_Y, pChrButtons, nCel, 41); } } @@ -2207,7 +2222,7 @@ void RedBack() if (leveltype != DTYPE_HELL) { dst = &gpBuffer[SCREENXY(0, 0)]; tbl = &pLightTbl[idx]; - for (h = PANEL_TOP; h; h--, dst += BUFFER_WIDTH - SCREEN_WIDTH) { + for (h = VIEWPORT_HEIGHT; h; h--, dst += BUFFER_WIDTH - SCREEN_WIDTH) { for (w = SCREEN_WIDTH; w; w--) { *dst = tbl[*dst]; dst++; @@ -2216,7 +2231,7 @@ void RedBack() } else { dst = &gpBuffer[SCREENXY(0, 0)]; tbl = &pLightTbl[idx]; - for (h = PANEL_TOP; h; h--, dst += BUFFER_WIDTH - SCREEN_WIDTH) { + for (h = VIEWPORT_HEIGHT; h; h--, dst += BUFFER_WIDTH - SCREEN_WIDTH) { for (w = SCREEN_WIDTH; w; w--) { if (*dst >= 32) *dst = tbl[*dst]; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 314b58c2a..cb9bc137f 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -43,7 +43,7 @@ void gmenu_draw_pause() RedBack(); if (!sgpCurrentMenu) { light_table_index = 0; - gmenu_print_text(316 + PANEL_LEFT, -16 + PANEL_TOP, "Pause"); + gmenu_print_text(316 + PANEL_LEFT, 336, "Pause"); } } diff --git a/Source/items.cpp b/Source/items.cpp index e52b97d37..aca64dc99 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2908,9 +2908,9 @@ void PrintItemPower(char plidx, ItemStruct *x) void DrawUTextBack() { - CelDraw(88, 487, pSTextBoxCels, 1, 271); + CelDraw(PANEL_X + 24, SCREEN_Y + 327, pSTextBoxCels, 1, 271); -#define TRANS_RECT_X 27 +#define TRANS_RECT_X (PANEL_LEFT + 27) #define TRANS_RECT_Y 28 #define TRANS_RECT_WIDTH 265 #define TRANS_RECT_HEIGHT 297 @@ -2951,12 +2951,12 @@ void DrawULine(int y) #ifdef USE_ASM int yy; - yy = PitchTbl[SStringY[y] + 198] + 26 + 64; + yy = PitchTbl[SStringY[y] + 198] + 26 + PANEL_X; __asm { mov esi, gpBuffer mov edi, esi - add esi, SCREENXY(26, 25) + add esi, SCREENXY(PANEL_LEFT + 26, 25) add edi, yy mov ebx, BUFFER_WIDTH - 266 mov edx, 3 @@ -2973,8 +2973,8 @@ void DrawULine(int y) int i; BYTE *src, *dst; - src = &gpBuffer[SCREENXY(26, 25)]; - dst = &gpBuffer[PitchTbl[SStringY[y] + 198] + 26 + 64]; + src = &gpBuffer[SCREENXY(PANEL_LEFT + 26, 25)]; + dst = &gpBuffer[PitchTbl[SStringY[y] + 198] + 26 + PANEL_X]; for (i = 0; i < 3; i++, src += BUFFER_WIDTH, dst += BUFFER_WIDTH) memcpy(dst, src, 266); @@ -2988,30 +2988,30 @@ void DrawUniqueInfo() if (!chrflag && !questlog) { uid = curruitem._iUid; DrawUTextBack(); - PrintUString(0, 2, 1, UniqueItemList[uid].UIName, 3); + PrintUString(PANEL_LEFT + 0, 2, 1, UniqueItemList[uid].UIName, 3); DrawULine(5); PrintItemPower(UniqueItemList[uid].UIPower1, &curruitem); y = 6 - UniqueItemList[uid].UINumPL + 8; - PrintUString(0, y, 1, tempstr, 0); + PrintUString(PANEL_LEFT + 0, y, 1, tempstr, 0); if (UniqueItemList[uid].UINumPL > 1) { PrintItemPower(UniqueItemList[uid].UIPower2, &curruitem); - PrintUString(0, y + 2, 1, tempstr, 0); + PrintUString(PANEL_LEFT + 0, y + 2, 1, tempstr, 0); } if (UniqueItemList[uid].UINumPL > 2) { PrintItemPower(UniqueItemList[uid].UIPower3, &curruitem); - PrintUString(0, y + 4, 1, tempstr, 0); + PrintUString(PANEL_LEFT + 0, y + 4, 1, tempstr, 0); } if (UniqueItemList[uid].UINumPL > 3) { PrintItemPower(UniqueItemList[uid].UIPower4, &curruitem); - PrintUString(0, y + 6, 1, tempstr, 0); + PrintUString(PANEL_LEFT + 0, y + 6, 1, tempstr, 0); } if (UniqueItemList[uid].UINumPL > 4) { PrintItemPower(UniqueItemList[uid].UIPower5, &curruitem); - PrintUString(0, y + 8, 1, tempstr, 0); + PrintUString(PANEL_LEFT + 0, y + 8, 1, tempstr, 0); } if (UniqueItemList[uid].UINumPL > 5) { PrintItemPower(UniqueItemList[uid].UIPower6, &curruitem); - PrintUString(0, y + 10, 1, tempstr, 0); + PrintUString(PANEL_LEFT + 0, y + 10, 1, tempstr, 0); } } } diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 4ad8bee65..0a250b003 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -71,7 +71,7 @@ void DrawQTextBack() { CelDraw(PANEL_X + 24, 487, pTextBoxCels, 1, 591); -#define TRANS_RECT_X 27 +#define TRANS_RECT_X (PANEL_LEFT + 27) #define TRANS_RECT_Y 28 #define TRANS_RECT_WIDTH 585 #define TRANS_RECT_HEIGHT 297 @@ -208,7 +208,7 @@ void DrawQText() p = qtextptr; pnl = NULL; - tx = 112; + tx = 48 + PANEL_X; ty = qtexty; doneflag = FALSE; @@ -251,7 +251,7 @@ void DrawQText() if (pnl == NULL) { pnl = p; } - tx = 112; + tx = 48 + PANEL_X; ty += 38; if (ty > 501) { doneflag = TRUE; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 9238a4738..75d9b2b62 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2273,16 +2273,16 @@ static void DrawZoom(int x, int y) } if (chrflag || questlog) { - nSrcOff = SCREENXY(112, 159); - nDstOff = SCREENXY(320, 350); + nSrcOff = SCREENXY(112, VIEWPORT_HEIGHT / 2 - 17); + nDstOff = SCREENXY(320, VIEWPORT_HEIGHT - 2); wdt = (SCREEN_WIDTH - 320) / 2; } else if (invflag || sbookflag) { - nSrcOff = SCREENXY(112, 159); - nDstOff = SCREENXY(0, 350); + nSrcOff = SCREENXY(112, VIEWPORT_HEIGHT / 2 - 17); + nDstOff = SCREENXY(0, VIEWPORT_HEIGHT - 2); wdt = (SCREEN_WIDTH - 320) / 2; } else { - nSrcOff = SCREENXY(32, 159); - nDstOff = SCREENXY(0, 350); + nSrcOff = SCREENXY(32, VIEWPORT_HEIGHT / 2 - 17); + nDstOff = SCREENXY(0, VIEWPORT_HEIGHT - 2); wdt = SCREEN_WIDTH / 2; } @@ -2298,7 +2298,7 @@ static void DrawZoom(int x, int y) add esi, ecx mov ebx, edi add ebx, BUFFER_WIDTH - mov edx, 176 + mov edx, (VIEWPORT_HEIGHT / 2) label1: mov ecx, wdt label2: @@ -2328,7 +2328,7 @@ static void DrawZoom(int x, int y) dst1 = &gpBuffer[nDstOff]; dst2 = &gpBuffer[nDstOff + BUFFER_WIDTH]; - for (hgt = 176; hgt != 0; hgt--, src -= BUFFER_WIDTH + wdt, dst1 -= 2 * (BUFFER_WIDTH + wdt), dst2 -= 2 * (BUFFER_WIDTH + wdt)) { + for (hgt = VIEWPORT_HEIGHT / 2; hgt != 0; hgt--, src -= BUFFER_WIDTH + wdt, dst1 -= 2 * (BUFFER_WIDTH + wdt), dst2 -= 2 * (BUFFER_WIDTH + wdt)) { for (i = wdt; i != 0; i--) { *dst1++ = *src; *dst1++ = *src; diff --git a/Source/stores.cpp b/Source/stores.cpp index fd6bae1cd..7327315cd 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -132,7 +132,7 @@ void DrawSTextBack() { CelDraw(PANEL_X + 344, 487, pSTextBoxCels, 1, 271); -#define TRANS_RECT_X 347 +#define TRANS_RECT_X (PANEL_LEFT + 347) #define TRANS_RECT_Y 28 #define TRANS_RECT_WIDTH 265 #define TRANS_RECT_HEIGHT 297 @@ -179,7 +179,7 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val) } if (!cjustflag && val >= 0) { sprintf(valstr, "%i", val); - off = PitchTbl[s + 204] + 656 - x; + off = PitchTbl[s + 204] + PANEL_X + 592 - x; for (i = strlen(valstr) - 1; i >= 0; i--) { c = fontframe[gbFontTransTbl[(BYTE)valstr[i]]]; off -= fontkern[c] + 1; @@ -189,7 +189,7 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val) } } if (stextsel == y) { - CelDraw(cjustflag ? xx + x + k + 4 : 660 - x, s + 205, pSPentSpn2Cels, InStoreFlag, 12); + CelDraw(cjustflag ? (xx + x + k + 4) : (PANEL_X + 596 - x), s + 205, pSPentSpn2Cels, InStoreFlag, 12); } } @@ -199,13 +199,13 @@ void DrawSLine(int y) sy = SStringY[y]; if (stextsize == 1) { - xy = SCREENXY(26, 25); - yy = PitchTbl[sy + 198] + 26 + 64; + xy = SCREENXY(PANEL_LEFT + 26, 25); + yy = PitchTbl[sy + 198] + 26 + PANEL_X; width = 586 / 4; line = BUFFER_WIDTH - 586; } else { - xy = SCREENXY(346, 25); - yy = PitchTbl[sy + 198] + 346 + 64; + xy = SCREENXY(PANEL_LEFT + 346, 25); + yy = PitchTbl[sy + 198] + 346 + PANEL_X; width = 266 / 4; line = BUFFER_WIDTH - 266; } diff --git a/defs.h b/defs.h index d1a88fdea..10161dbf8 100644 --- a/defs.h +++ b/defs.h @@ -128,7 +128,7 @@ #define RIGHT_PANEL (SCREEN_WIDTH - 320) #define RIGHT_PANEL_X (SCREEN_X + RIGHT_PANEL) -#if SCREEN_WIDTH == PANEL_WIDTH +#if SCREEN_WIDTH <= PANEL_WIDTH #define VIEWPORT_HEIGHT (SCREEN_HEIGHT - PANEL_HEIGHT) #else #define VIEWPORT_HEIGHT SCREEN_HEIGHT