diff --git a/Source/automap.cpp b/Source/automap.cpp index 88487529c..a39ddc396 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -385,19 +385,19 @@ void DrawAutomapText(const CelOutputBuffer &out) if (gbIsMultiplayer) { if (strcasecmp("0.0.0.0", szPlayerName) != 0) { strcat(strcpy(desc, _("game: ")), szPlayerName); - PrintGameStr(out, 8, nextLine, desc, COL_GOLD); + DrawString(out, desc, { 8, nextLine, 0, 0 }); nextLine += 15; } if (szPlayerDescript[0] != '\0') { strcat(strcpy(desc, _("password: ")), szPlayerDescript); - PrintGameStr(out, 8, nextLine, desc, COL_GOLD); + DrawString(out, desc, { 8, nextLine, 0, 0 }); nextLine += 15; } } if (setlevel) { - PrintGameStr(out, 8, nextLine, _(quest_level_names[setlvlnum]), COL_GOLD); + DrawString(out, _(quest_level_names[setlvlnum]), { 8, nextLine, 0, 0 }); return; } @@ -410,7 +410,7 @@ void DrawAutomapText(const CelOutputBuffer &out) sprintf(desc, _("Level: %i"), currlevel); } - PrintGameStr(out, 8, nextLine, desc, COL_GOLD); + DrawString(out, desc, { 8, nextLine, 0, 0 }); } } diff --git a/Source/control.cpp b/Source/control.cpp index 4caf47db3..d7e5ea7a5 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -319,21 +319,15 @@ static void DrawSpell(const CelOutputBuffer &out) DrawSpellCel(out, PANEL_X + 565, PANEL_Y + 119, *pSpellCels, 27); } -static void PrintSBookHotkey(CelOutputBuffer out, int x, int y, const std::string &text, text_color col) +static void PrintSBookHotkey(CelOutputBuffer out, int x, int y, const std::string &text) { + x -= GetLineWidth(text.c_str()) + 5; x += SPLICONLENGTH; + y += 17; y -= SPLICONLENGTH; - int totalWidth = 0; - - for (const char txtChar : text) { - auto c = gbFontTransTbl[static_cast(txtChar)]; - c = fontframe[GameFontSmall][c]; - - totalWidth += fontkern[GameFontSmall][c] + 1; - } - - PrintGameStr(out, x - totalWidth - 4, y + 17, text.c_str(), col); + DrawString(out, text.c_str(), { x - 1, y + 1, 0, 0 }, UIS_BLACK); + DrawString(out, text.c_str(), { x + 0, y + 0, 0, 0 }, UIS_SILVER); } void DrawSpellList(const CelOutputBuffer &out) @@ -444,8 +438,7 @@ void DrawSpellList(const CelOutputBuffer &out) for (int t = 0; t < 4; t++) { if (plr[myplr]._pSplHotKey[t] == pSpell && plr[myplr]._pSplTHotKey[t] == pSplType) { auto hotkeyName = keymapper.keyNameForAction(quickSpellActionIndexes[t]); - PrintSBookHotkey(out, x - 1, y + 1, hotkeyName, COL_BLACK); - PrintSBookHotkey(out, x, y, hotkeyName, COL_WHITE); + PrintSBookHotkey(out, x, y, hotkeyName); sprintf(tempstr, _("Spell Hotkey %s"), hotkeyName.c_str()); AddPanelString(tempstr, true); } @@ -1221,17 +1214,6 @@ void DrawInfoBox(const CelOutputBuffer &out) #define ADD_PlrStringXY(out, x, y, width, pszStr, col) MY_PlrStringXY(out, x, y, width, pszStr, col, 1) -void PrintGameStr(const CelOutputBuffer &out, int x, int y, const char *str, text_color color) -{ - while (*str != '\0') { - BYTE c = gbFontTransTbl[(BYTE)*str++]; - c = fontframe[GameFontSmall][c]; - if (c != 0) - PrintChar(out, x, y, c, color); - x += fontkern[GameFontSmall][c] + 1; - } -} - /** * @brief Render text string to the given buffer * @param out Buffer to render to @@ -1799,27 +1781,25 @@ void CheckSBook() void DrawGoldSplit(const CelOutputBuffer &out, int amount) { - int screenX = 0; - CelDrawTo(out, 351, 178, *pGBoxBuff, 1); - sprintf(tempstr, _("You have %u gold"), initialDropGoldValue); - ADD_PlrStringXY(out, 366, 87, 600, tempstr, COL_GOLD); - sprintf(tempstr, ngettext("piece. How many do", "pieces. How many do", initialDropGoldValue), initialDropGoldValue); - ADD_PlrStringXY(out, 366, 103, 600, tempstr, COL_GOLD); - ADD_PlrStringXY(out, 366, 121, 600, _("you want to remove?"), COL_GOLD); + const int dialogX = RIGHT_PANEL_X + 30; + + CelDrawTo(out, dialogX, 178, *pGBoxBuff, 1); + + sprintf( + tempstr, + ngettext( + "You have %u gold piece. How many do you want to remove?", + "You have %u gold pieces. How many do you want to remove?", + initialDropGoldValue), + initialDropGoldValue); + WordWrapGameString(tempstr, 200); + DrawString(out, tempstr, { dialogX + 31, 87, 200, 50 }, UIS_GOLD | UIS_CENTER); + + tempstr[0] = '\0'; if (amount > 0) { sprintf(tempstr, "%u", amount); - PrintGameStr(out, 388, 140, tempstr, COL_WHITE); - } - if (amount > 0) { - for (int i = 0; i < tempstr[i]; i++) { - BYTE c = fontframe[GameFontSmall][gbFontTransTbl[(BYTE)tempstr[i]]]; - screenX += fontkern[GameFontSmall][c] + 1; - } - screenX += 388; - } else { - screenX = 386; } - CelDrawTo(out, screenX, 140, *pSPentSpn2Cels, PentSpn2Spin()); + DrawString(out, tempstr, { dialogX + 37, 140, 0, 0 }, UIS_SILVER, true); } void control_drop_gold(char vkey) diff --git a/Source/control.h b/Source/control.h index ee484ce2d..0cfb778c5 100644 --- a/Source/control.h +++ b/Source/control.h @@ -121,8 +121,6 @@ bool control_WriteStringToBuffer(BYTE *str); * Sets a string to be drawn in the info box and then draws it. */ void DrawInfoBox(const CelOutputBuffer &out); - -void PrintGameStr(const CelOutputBuffer &out, int x, int y, const char *str, text_color color); void DrawChr(const CelOutputBuffer &out); void CheckLvlBtn(); void ReleaseLvlBtn(); diff --git a/Source/controls/modifier_hints.cpp b/Source/controls/modifier_hints.cpp index 9c4d6c72f..4cd5ba33b 100644 --- a/Source/controls/modifier_hints.cpp +++ b/Source/controls/modifier_hints.cpp @@ -5,6 +5,7 @@ #include "control.h" #include "controls/controller.h" #include "controls/game_controls.h" +#include "engine/render/text_render.hpp" #include "options.h" #include "utils/language.h" @@ -12,53 +13,21 @@ namespace devilution { namespace { -int CalculateTextWidth(const char *s) -{ - int l = 0; - while (*s != '\0') { - l += fontkern[GameFontSmall][fontframe[GameFontSmall][gbFontTransTbl[static_cast(*s++)]]] + 1; - } - return l; -} - -int SpaceWidth() -{ - static const int spaceWidth = CalculateTextWidth(" "); - return spaceWidth; -} - struct CircleMenuHint { CircleMenuHint(bool isDpad, const char *top, const char *right, const char *bottom, const char *left) : is_dpad(isDpad) , top(top) - , top_w(CalculateTextWidth(top)) , right(right) - , right_w(CalculateTextWidth(right)) , bottom(bottom) - , bottom_w(CalculateTextWidth(bottom)) , left(left) - , left_w(CalculateTextWidth(left)) - , x_mid(left_w + SpaceWidth() * 2.5) { } - - int Width() const - { - return 2 * x_mid; - } - bool is_dpad; const char *top; - int top_w; const char *right; - int right_w; const char *bottom; - int bottom_w; const char *left; - int left_w; - - int x_mid; }; bool IsTopActive(const CircleMenuHint &hint) @@ -89,27 +58,27 @@ bool IsLeftActive(const CircleMenuHint &hint) return IsControllerButtonPressed(ControllerButton_BUTTON_X); } -text_color CircleMenuHintTextColor(bool active) +uint16_t CircleMenuHintTextColor(bool active) { - return active ? COL_BLUE : COL_GOLD; + return active ? UIS_BLUE : UIS_GOLD; } +const int CircleSpacing = 40; +const int CircleMarginX = 16 + CircleSpacing * 2; +const int CirclesTop = 16 + CircleSpacing * 2; + void DrawCircleMenuHint(const CelOutputBuffer &out, const CircleMenuHint &hint, int x, int y) { - const int lineHeight = 25; - PrintGameStr(out, x + hint.x_mid - hint.top_w / 2, y, hint.top, CircleMenuHintTextColor(IsTopActive(hint))); - y += lineHeight; + DrawString(out, hint.top, { x, y, CircleSpacing, 0 }, CircleMenuHintTextColor(IsTopActive(hint)) | UIS_CENTER); + y += CircleSpacing; - PrintGameStr(out, x, y, hint.left, CircleMenuHintTextColor(IsLeftActive(hint))); - PrintGameStr(out, x + hint.left_w + 5 * SpaceWidth(), y, hint.right, CircleMenuHintTextColor(IsRightActive(hint))); - y += lineHeight; + DrawString(out, hint.left, { x + CircleSpacing, y, CircleSpacing, 0 }, CircleMenuHintTextColor(IsLeftActive(hint)) | UIS_CENTER); + DrawString(out, hint.right, { x - CircleSpacing, y, CircleSpacing, 0 }, CircleMenuHintTextColor(IsRightActive(hint)) | UIS_CENTER); + y += CircleSpacing; - PrintGameStr(out, x + hint.x_mid - hint.bottom_w / 2, y, hint.bottom, CircleMenuHintTextColor(IsBottomActive(hint))); + DrawString(out, hint.bottom, { x, y, CircleSpacing, 0 }, CircleMenuHintTextColor(IsBottomActive(hint)) | UIS_CENTER); } -const int CircleMarginX = 16; -const int CirclesTop = 76; - void DrawStartModifierMenu(const CelOutputBuffer &out) { if (!start_modifier_active) @@ -117,7 +86,7 @@ void DrawStartModifierMenu(const CelOutputBuffer &out) static const CircleMenuHint dPad(/*is_dpad=*/true, /*top=*/_("Menu"), /*right=*/_("Inv"), /*bottom=*/_("Map"), /*left=*/_("Char")); static const CircleMenuHint buttons(/*is_dpad=*/false, /*top=*/"", /*right=*/"", /*bottom=*/_("Spells"), /*left=*/_("Quests")); DrawCircleMenuHint(out, dPad, PANEL_LEFT + CircleMarginX, PANEL_TOP - CirclesTop); - DrawCircleMenuHint(out, buttons, PANEL_LEFT + PANEL_WIDTH - buttons.Width() - CircleMarginX, PANEL_TOP - CirclesTop); + DrawCircleMenuHint(out, buttons, PANEL_LEFT + PANEL_WIDTH - CircleMarginX, PANEL_TOP - CirclesTop); } void DrawSelectModifierMenu(const CelOutputBuffer &out) @@ -129,7 +98,7 @@ void DrawSelectModifierMenu(const CelOutputBuffer &out) DrawCircleMenuHint(out, dPad, PANEL_LEFT + CircleMarginX, PANEL_TOP - CirclesTop); } static const CircleMenuHint spells(/*is_dpad=*/false, "F6", "F8", "F7", "F5"); - DrawCircleMenuHint(out, spells, PANEL_LEFT + PANEL_WIDTH - spells.Width() - CircleMarginX, PANEL_TOP - CirclesTop); + DrawCircleMenuHint(out, spells, PANEL_LEFT + PANEL_WIDTH - CircleMarginX, PANEL_TOP - CirclesTop); } } // namespace diff --git a/Source/qol/common.cpp b/Source/qol/common.cpp index e5fab8b20..2e2c7d3f0 100644 --- a/Source/qol/common.cpp +++ b/Source/qol/common.cpp @@ -7,7 +7,6 @@ #include #include "common.h" -#include "control.h" #include "engine.h" #include "engine/render/text_render.hpp" #include "qol/monhealthbar.h" @@ -15,15 +14,6 @@ namespace devilution { -int GetTextWidth(const char *s) -{ - int l = 0; - while (*s) { - l += fontkern[GameFontSmall][fontframe[GameFontSmall][gbFontTransTbl[static_cast(*s++)]]] + 1; - } - return l; -} - char *PrintWithSeparator(char *out, long long n) { if (n < 1000) { diff --git a/Source/qol/common.h b/Source/qol/common.h index 7353f048d..a0a60aee1 100644 --- a/Source/qol/common.h +++ b/Source/qol/common.h @@ -11,19 +11,12 @@ namespace devilution { struct CelOutputBuffer; -/** - * @brief Return width (in pixels) of the passed in string, when printed with smaltext.cel. Does not consider line breaks. - * @param s String for which to compute width - * @return Pixel width of the string -*/ -int GetTextWidth(const char *s); - /** * @brief Prints integer into buffer, using ',' as thousands separator. * @param out Destination buffer * @param n Number to print * @return Address of first character after printed number -*/ + */ char *PrintWithSeparator(char *out, long long n); void FreeQol(); diff --git a/Source/qol/monhealthbar.cpp b/Source/qol/monhealthbar.cpp index 0a242b968..286642bdc 100644 --- a/Source/qol/monhealthbar.cpp +++ b/Source/qol/monhealthbar.cpp @@ -95,15 +95,14 @@ void DrawMonsterHealthBar(const CelOutputBuffer &out) UnsafeDrawVerticalLine(out, { xPos + width - border - 1, yPos + border + 1 }, borderHeight, borderColor); } - int barLableX = xPos + width / 2 - GetTextWidth(mon.mName) / 2; int barLableY = yPos + 10 + (height - 11) / 2; - PrintGameStr(out, barLableX - 1, barLableY + 1, mon.mName, COL_BLACK); - text_color color = COL_WHITE; + DrawString(out, mon.mName, { xPos - 1, barLableY + 1, width, height }, UIS_CENTER | UIS_BLACK ); + uint16_t style = UIS_SILVER; if (mon._uniqtype != 0) - color = COL_GOLD; + style = UIS_GOLD; else if (mon.leader != 0) - color = COL_BLUE; - PrintGameStr(out, barLableX, barLableY, mon.mName, color); + style = UIS_BLUE; + DrawString(out, mon.mName, { xPos, barLableY, width, height }, UIS_CENTER | style); if (mon._uniqtype != 0 || monstkills[mon.MType->mtype] >= 15) { monster_resistance immunes[] = { IMMUNE_MAGIC, IMMUNE_FIRE, IMMUNE_LIGHTNING }; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index af29cd0c9..27b16c8f2 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -5,7 +5,6 @@ */ #include "automap.h" -#include "control.h" #include "cursor.h" #include "dead.h" #include "doom.h" @@ -13,6 +12,7 @@ #include "engine/render/cel_render.hpp" #include "engine/render/cl2_render.hpp" #include "engine/render/dun_render.hpp" +#include "engine/render/text_render.hpp" #include "error.h" #include "gmenu.h" #include "help.h" @@ -1427,7 +1427,7 @@ static void DrawFPS(const CelOutputBuffer &out) frameend = 0; } snprintf(String, 12, "%d FPS", framerate); - PrintGameStr(out, 8, 65, String, COL_RED); + DrawString(out, String, { 8, 65, 0, 0 }, UIS_RED); } }