diff --git a/Source/automap.cpp b/Source/automap.cpp index d43afe4be..330581551 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -618,19 +618,13 @@ static void DrawAutomapText(CelOutputBuffer out) } } -/** - * @brief Renders the automap on screen. - */ -void DrawAutomap() +void DrawAutomap(CelOutputBuffer out) { int cells; int sx, sy; int i, j, d; int mapx, mapy; - CelOutputBuffer out = GlobalBackBuffer(); - out = out.subregion(0, 0, out.line_width, SCREEN_Y + VIEWPORT_HEIGHT); - if (leveltype == DTYPE_TOWN) { DrawAutomapText(out); return; diff --git a/Source/automap.h b/Source/automap.h index e9bf4265e..14836edcc 100644 --- a/Source/automap.h +++ b/Source/automap.h @@ -6,6 +6,8 @@ #ifndef __AUTOMAP_H__ #define __AUTOMAP_H__ +#include "engine.h" + DEVILUTION_BEGIN_NAMESPACE #ifdef __cplusplus @@ -32,7 +34,12 @@ void AutomapLeft(); void AutomapRight(); void AutomapZoomIn(); void AutomapZoomOut(); -void DrawAutomap(); + +/** + * @brief Renders the automap to the given buffer. + */ +void DrawAutomap(CelOutputBuffer out); + void SetAutomapView(int x, int y); void AutomapZoomReset(); diff --git a/Source/engine.cpp b/Source/engine.cpp index 6cb48ce34..554ccfa4f 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -555,6 +555,43 @@ void DrawLineTo(CelOutputBuffer out, int x0, int y0, int x1, int y1, BYTE color_ } } +static void DrawHalfTransparentBlendedRectTo(CelOutputBuffer out, int sx, int sy, int width, int height) +{ + BYTE *pix = out.at(sx, sy); + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + *pix = paletteTransparencyLookup[0][*pix]; + pix++; + } + pix += out.line_width - width; + } +} + +static void DrawHalfTransparentStippledRectTo(CelOutputBuffer out, int sx, int sy, int width, int height) +{ + BYTE *pix = out.at(sx, sy); + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + if ((row & 1 && col & 1) || (!(row & 1) && !(col & 1))) + *pix = 0; + pix++; + } + pix += out.line_width - width; + } +} + +void DrawHalfTransparentRectTo(CelOutputBuffer out, int sx, int sy, int width, int height) +{ + int row, col; + BYTE *pix = out.at(sx, sy); + + if (sgOptions.bBlendedTransparancy) { + DrawHalfTransparentBlendedRectTo(out, sx, sy, width, height); + } else { + DrawHalfTransparentStippledRectTo(out, sx, sy, width, height); + } +} + int GetDirection(int x1, int y1, int x2, int y2) { int mx, my; diff --git a/Source/engine.h b/Source/engine.h index 0d455037d..e4630dcb0 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -341,6 +341,23 @@ void Cl2DrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth); */ void DrawLineTo(CelOutputBuffer out, int x0, int y0, int x1, int y1, BYTE color_index); + +/** + * Draws a half-transparent rectangle by blacking out odd pixels on odd lines, + * even pixels on even lines. + * + * If blended transparency is enabled, uses `paletteTransparencyLookup` table instead + * of blacking pixels out. + * + * @brief Render a transparent black rectangle + * @param out Target buffer + * @param sx Screen coordinate + * @param sy Screen coordinate + * @param width Rectangle width + * @param height Rectangle height + */ +void DrawHalfTransparentRectTo(CelOutputBuffer out, int sx, int sy, int width, int height); + /** * @brief Calculate the best fit direction between two points * @param x1 Tile coordinate diff --git a/Source/error.cpp b/Source/error.cpp index e60b76545..2df9374a2 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -126,7 +126,7 @@ void DrawDiabloMsg() assert(gpBuffer); - trans_rect(PANEL_LEFT + 104, DIALOG_TOP - 8, 432, 54); + DrawHalfTransparentRectTo(GlobalBackBuffer(), PANEL_LEFT + 104, DIALOG_TOP - 8, 432, 54); strcpy(tempstr, MsgStrings[msgflag]); sx = PANEL_X + 101; diff --git a/Source/help.cpp b/Source/help.cpp index 78319f708..7c4d86409 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -468,14 +468,14 @@ static void DrawHelpLine(int x, int y, char *text, char color) } } -void DrawHelp() +void DrawHelp(CelOutputBuffer out) { int i, c, w; char col; const char *s; DrawSTextHelp(); - DrawQTextBack(); + DrawQTextBack(out); if (gbIsHellfire) PrintSString(0, 2, TRUE, "Hellfire Help", COL_GOLD, 0); else diff --git a/Source/help.h b/Source/help.h index 0f1e39a47..7a93c2cf4 100644 --- a/Source/help.h +++ b/Source/help.h @@ -15,7 +15,7 @@ extern "C" { extern BOOL helpflag; void InitHelp(); -void DrawHelp(); +void DrawHelp(CelOutputBuffer out); void DisplayHelp(); void HelpScrollUp(); void HelpScrollDown(); diff --git a/Source/items.cpp b/Source/items.cpp index 3e50d2857..7c7de63f2 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3954,10 +3954,10 @@ void PrintItemPower(char plidx, ItemStruct *x) } } -void DrawUTextBack() +static void DrawUTextBack(CelOutputBuffer out) { - CelDraw(RIGHT_PANEL_X - SPANEL_WIDTH + 24, SCREEN_Y + 327, pSTextBoxCels, 1, 271); - trans_rect(RIGHT_PANEL - SPANEL_WIDTH + 27, 28, 265, 297); + CelDrawTo(out, RIGHT_PANEL_X - SPANEL_WIDTH + 24, SCREEN_Y + 327, pSTextBoxCels, 1, 271); + DrawHalfTransparentRectTo(out, RIGHT_PANEL - SPANEL_WIDTH + 27, 28, 265, 297); } void PrintUString(int x, int y, BOOL cjustflag, const char *str, int col) @@ -4008,7 +4008,7 @@ void DrawUniqueInfo() if ((!chrflag && !questlog) || SCREEN_WIDTH >= SPANEL_WIDTH * 3) { uid = curruitem._iUid; - DrawUTextBack(); + DrawUTextBack(GlobalBackBuffer()); PrintUString(0 + RIGHT_PANEL - SPANEL_WIDTH, 2, TRUE, UniqueItemList[uid].UIName, 3); DrawULine(5); PrintItemPower(UniqueItemList[uid].UIPower1, &curruitem); diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 979f241a3..4247e7801 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -172,8 +172,9 @@ void ScrollQTextContent(const char *pnl) /** * @brief Draw the current text in the quest dialog window */ -void DrawQTextContent() +static void DrawQTextContent(CelOutputBuffer out) { + // TODO: Draw to the given `out` buffer. const char *text, *pnl; char line[128]; @@ -247,22 +248,16 @@ void InitQTextMsg(int m) PlaySFX(alltext[m].sfxnr); } -/** - * @brief Draw the quest dialog window decoration and background - */ -void DrawQTextBack() +void DrawQTextBack(CelOutputBuffer out) { - CelDraw(PANEL_X + 24, SCREEN_Y + 327 + UI_OFFSET_Y, pTextBoxCels, 1, 591); - trans_rect(PANEL_LEFT + 27, UI_OFFSET_Y + 28, 585, 297); + CelDrawTo(out, PANEL_X + 24, SCREEN_Y + 327 + UI_OFFSET_Y, pTextBoxCels, 1, 591); + DrawHalfTransparentRectTo(out, PANEL_LEFT + 27, UI_OFFSET_Y + 28, 585, 297); } -/** - * @brief Draw the quest dialog window decoration and background - */ -void DrawQText() +void DrawQText(CelOutputBuffer out) { - DrawQTextBack(); - DrawQTextContent(); + DrawQTextBack(out); + DrawQTextContent(out); } DEVILUTION_END_NAMESPACE diff --git a/Source/minitext.h b/Source/minitext.h index 632bd91ac..7e4ca7c0a 100644 --- a/Source/minitext.h +++ b/Source/minitext.h @@ -17,8 +17,16 @@ extern bool qtextflag; void FreeQuestText(); void InitQuestText(); void InitQTextMsg(int m); -void DrawQTextBack(); -void DrawQText(); + +/** + * @brief Draw the quest dialog window decoration and background. + */ +void DrawQTextBack(CelOutputBuffer out); + +/** + * @brief Draw the quest dialog window text. + */ +void DrawQText(CelOutputBuffer out); #ifdef __cplusplus } diff --git a/Source/render.cpp b/Source/render.cpp index a31a0da51..80715f76d 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -601,39 +601,4 @@ void world_draw_black_tile(int sx, int sy) } } -/** - * Draws a half-transparent rectangle by blacking out odd pixels on odd lines, - * even pixels on even lines. - * @brief Render a transparent black rectangle - * @param sx Screen coordinate - * @param sy Screen coordinate - * @param width Rectangle width - * @param height Rectangle height - */ -void trans_rect(int sx, int sy, int width, int height) -{ - int row, col; - BYTE *pix = &gpBuffer[SCREENXY(sx, sy)]; - - if (sgOptions.bBlendedTransparancy) { // Blended - for (row = 0; row < height; row++) { - for (col = 0; col < width; col++) { - *pix = paletteTransparencyLookup[0][*pix]; - pix++; - } - pix += BUFFER_WIDTH - width; - } - return; - } - - for (row = 0; row < height; row++) { - for (col = 0; col < width; col++) { - if ((row & 1 && col & 1) || (!(row & 1) && !(col & 1))) // Stippled - *pix = 0; - pix++; - } - pix += BUFFER_WIDTH - width; - } -} - DEVILUTION_END_NAMESPACE diff --git a/Source/render.h b/Source/render.h index f8b80ef51..0fb3be61d 100644 --- a/Source/render.h +++ b/Source/render.h @@ -14,7 +14,6 @@ extern "C" { void RenderTile(BYTE *pBuff); void world_draw_black_tile(int sx, int sy); -void trans_rect(int sx, int sy, int width, int height); #ifdef __cplusplus } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index cc9a78aa6..a614360a7 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1226,12 +1226,14 @@ extern void DrawControllerModifierHints(); */ void DrawView(int StartX, int StartY) { + CelOutputBuffer out = GlobalBackBuffer(); + DrawGame(StartX, StartY); if (automapflag) { - DrawAutomap(); + DrawAutomap(out.subregion(0, 0, out.line_width, SCREEN_Y + VIEWPORT_HEIGHT)); } if (stextflag && !qtextflag) - DrawSText(); + DrawSText(out); if (invflag) { DrawInv(); } else if (sbookflag) { @@ -1253,7 +1255,7 @@ void DrawView(int StartX, int StartY) DrawUniqueInfo(); } if (qtextflag) { - DrawQText(); + DrawQText(out); } if (spselflag) { DrawSpellList(); @@ -1262,7 +1264,7 @@ void DrawView(int StartX, int StartY) DrawGoldSplit(dropGoldValue); } if (helpflag) { - DrawHelp(); + DrawHelp(out); } if (msgflag) { DrawDiabloMsg(); diff --git a/Source/stores.cpp b/Source/stores.cpp index 55ee3aceb..54d426d58 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -118,10 +118,10 @@ void FreeStoreMem() MemFreeDbg(pSTextSlidCels); } -void DrawSTextBack() +static void DrawSTextBack(CelOutputBuffer out) { - CelDraw(PANEL_X + 344, 327 + SCREEN_Y + UI_OFFSET_Y, pSTextBoxCels, 1, 271); - trans_rect(PANEL_LEFT + 347, UI_OFFSET_Y + 28, 265, 297); + CelDrawTo(out, PANEL_X + 344, 327 + SCREEN_Y + UI_OFFSET_Y, pSTextBoxCels, 1, 271); + DrawHalfTransparentRectTo(out, PANEL_LEFT + 347, UI_OFFSET_Y + 28, 265, 297); } void PrintSString(int x, int y, BOOL cjustflag, const char *str, char col, int val) @@ -1575,14 +1575,14 @@ void StartStore(char s) } } -void DrawSText() +void DrawSText(CelOutputBuffer out) { int i; if (!stextsize) - DrawSTextBack(); + DrawSTextBack(out); else - DrawQTextBack(); + DrawQTextBack(out); if (stextscrl) { switch (stextflag) { diff --git a/Source/stores.h b/Source/stores.h index 92924ed85..088e2e8cd 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -46,7 +46,7 @@ void DrawSLine(int y); void DrawSTextHelp(); void ClearSText(int s, int e); void StartStore(char s); -void DrawSText(); +void DrawSText(CelOutputBuffer out); void STextESC(); void STextUp(); void STextDown();