Browse Source

Clean up text render

pull/1859/merge
Anders Jenbo 5 years ago
parent
commit
4c6ddc79a1
  1. 64
      Source/engine/render/text_render.cpp
  2. 18
      Source/engine/render/text_render.hpp

64
Source/engine/render/text_render.cpp

@ -116,8 +116,46 @@ const uint8_t fontkern[3][68] = {
}
};
namespace {
enum text_color : uint8_t {
COL_WHITE,
COL_BLUE,
COL_RED,
COL_GOLD,
COL_BLACK,
};
int LineHeights[3] = { 12, 43, 50 };
uint8_t fontColorTableGold[256];
uint8_t fontColorTableBlue[256];
uint8_t fontColorTableRed[256];
static void PrintChar(const CelOutputBuffer &out, int sx, int sy, int nCel, text_color col)
{
switch (col) {
case COL_WHITE:
CelDrawTo(out, sx, sy, *pPanelText, nCel);
return;
case COL_BLUE:
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, fontColorTableBlue);
break;
case COL_RED:
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, fontColorTableRed);
break;
case COL_GOLD:
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, fontColorTableGold);
break;
case COL_BLACK:
light_table_index = 15;
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, nullptr);
return;
}
}
} // namespace
std::optional<CelSprite> pPanelText;
/** Graphics for the medium size font */
std::optional<CelSprite> pMedTextCels;
@ -125,10 +163,6 @@ std::optional<CelSprite> BigTGold_cel;
std::optional<CelSprite> pSPentSpn2Cels;
uint8_t fontColorTableGold[256];
uint8_t fontColorTableBlue[256];
uint8_t fontColorTableRed[256];
void InitText()
{
pPanelText = LoadCel("CtrlPan\\SmalText.CEL", 13);
@ -172,28 +206,6 @@ void FreeText()
pSPentSpn2Cels = std::nullopt;
}
void PrintChar(const CelOutputBuffer &out, int sx, int sy, int nCel, text_color col)
{
switch (col) {
case COL_WHITE:
CelDrawTo(out, sx, sy, *pPanelText, nCel);
return;
case COL_BLUE:
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, fontColorTableBlue);
break;
case COL_RED:
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, fontColorTableRed);
break;
case COL_GOLD:
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, fontColorTableGold);
break;
case COL_BLACK:
light_table_index = 15;
CelDrawLightTo(out, sx, sy, *pPanelText, nCel, nullptr);
return;
}
}
int GetLineWidth(const char *text, GameFontTables size, int spacing, int *charactersInLine)
{
int lineWidth = 0;

18
Source/engine/render/text_render.hpp

@ -20,14 +20,6 @@ enum GameFontTables : uint8_t {
GameFontBig,
};
enum text_color : uint8_t {
COL_WHITE,
COL_BLUE,
COL_RED,
COL_GOLD,
COL_BLACK,
};
extern const uint8_t gbFontTransTbl[256];
extern const uint8_t fontframe[3][128];
extern const uint8_t fontkern[3][68];
@ -41,16 +33,6 @@ extern std::optional<CelSprite> pSPentSpn2Cels;
void InitText();
void FreeText();
/**
* @brief Print letter to the given buffer
* @param out The buffer to print to
* @param sx Backbuffer offset
* @param sy Backbuffer offset
* @param nCel Number of letter in Windows-1252
* @param col text_color color value
*/
void PrintChar(const CelOutputBuffer &out, int sx, int sy, int nCel, text_color col);
/**
* @brief Calculate pixel width of first line of text, respecting kerning
* @param text Text to check, will read until first eol or terminator

Loading…
Cancel
Save