Browse Source

Enginify `trans_rect`

Moves `trans_rect` to `engine` as `DrawHalfTransparentRectTo` and makes
it operate on `CelOutputBuf`.
pull/1095/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
83ce7c27af
  1. 8
      Source/automap.cpp
  2. 9
      Source/automap.h
  3. 37
      Source/engine.cpp
  4. 17
      Source/engine.h
  5. 2
      Source/error.cpp
  6. 4
      Source/help.cpp
  7. 2
      Source/help.h
  8. 8
      Source/items.cpp
  9. 21
      Source/minitext.cpp
  10. 12
      Source/minitext.h
  11. 35
      Source/render.cpp
  12. 1
      Source/render.h
  13. 10
      Source/scrollrt.cpp
  14. 12
      Source/stores.cpp
  15. 2
      Source/stores.h

8
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;

9
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();

37
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;

17
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

2
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;

4
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

2
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();

8
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);

21
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

12
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
}

35
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

1
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
}

10
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();

12
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) {

2
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();

Loading…
Cancel
Save