From 41e3acb8336de65cfdca5f63bbbdd4afa97ade4a Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 20 Sep 2021 20:29:32 +0200 Subject: [PATCH] Replace fonticon literal characters for modifiers and separators with constants --- src/Components/Modules/Chat.cpp | 2 +- src/Components/Modules/TextRenderer.cpp | 24 ++++++++++++------------ src/Components/Modules/TextRenderer.hpp | 6 ++++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index 2ad45ae4..332e90a4 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -134,7 +134,7 @@ namespace Components CheckChatLineEnd(text, p, len, chatHeight, chatWidth, lastSpace, lastFontIcon, lastColor); const char* fontIconEndPos = &text[1]; - if(text[0] == ':' && TextRenderer::IsFontIcon(fontIconEndPos, fontIconInfo)) + if(text[0] == TextRenderer::FONT_ICON_SEPARATOR_CHARACTER && TextRenderer::IsFontIcon(fontIconEndPos, fontIconInfo)) { // The game calculates width on a per character base. Since the width of a font icon is calculated based on the height of the font // which is roughly double as much as the average width of a character without an additional multiplier the calculated len of the font icon diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 6c74128a..64bfe462 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -199,7 +199,7 @@ namespace Components for(auto i = 0; i < edit->cursor; i++) { const auto c = static_cast(edit->buffer[i]); - if (c == ':') + if (c == FONT_ICON_SEPARATOR_CHARACTER) { if(fontIconStart < 0) { @@ -217,7 +217,7 @@ namespace Components fontIconStart = -1; inModifiers = false; } - else if(c == '+') + else if(c == FONT_ICON_MODIFIER_SEPARATOR_CHARACTER) { if (fontIconStart >= 0 && !inModifiers) { @@ -568,12 +568,12 @@ namespace Components { const auto* curPos = text; - while (*curPos != ' ' && *curPos != ':' && *curPos != 0 && *curPos != '+') + while (*curPos != ' ' && *curPos != FONT_ICON_SEPARATOR_CHARACTER && *curPos != 0 && *curPos != FONT_ICON_MODIFIER_SEPARATOR_CHARACTER) curPos++; const auto* nameEnd = curPos; - if(*curPos == '+') + if(*curPos == FONT_ICON_MODIFIER_SEPARATOR_CHARACTER) { auto breakArgs = false; while(!breakArgs) @@ -581,19 +581,19 @@ namespace Components curPos++; switch(*curPos) { - case 'h': + case FONT_ICON_MODIFIER_FLIP_HORIZONTALLY: fontIcon.flipHorizontal = true; break; - case 'v': + case FONT_ICON_MODIFIER_FLIP_VERTICALLY: fontIcon.flipVertical = true; break; - case 'b': + case FONT_ICON_MODIFIER_BIG: fontIcon.big = true; break; - case ':': + case FONT_ICON_SEPARATOR_CHARACTER: breakArgs = true; break; @@ -603,7 +603,7 @@ namespace Components } } - if (*curPos != ':') + if (*curPos != FONT_ICON_SEPARATOR_CHARACTER) return false; const std::string fontIconName(text, nameEnd - text); @@ -902,7 +902,7 @@ namespace Components continue; } - if(letter == ':') + if(letter == FONT_ICON_SEPARATOR_CHARACTER) { FontIconInfo fontIconInfo{}; const char* fontIconEnd = curText; @@ -1089,7 +1089,7 @@ namespace Components } } - if (letter == ':') + if (letter == FONT_ICON_SEPARATOR_CHARACTER) { FontIconInfo fontIconInfo{}; const char* fontIconEnd = text; @@ -1230,7 +1230,7 @@ namespace Components continue; } - if(*in == ':') + if(*in == FONT_ICON_SEPARATOR_CHARACTER) { const auto* fontIconEndPos = &in[1]; FontIconInfo fontIcon{}; diff --git a/src/Components/Modules/TextRenderer.hpp b/src/Components/Modules/TextRenderer.hpp index baf1b945..34db44aa 100644 --- a/src/Components/Modules/TextRenderer.hpp +++ b/src/Components/Modules/TextRenderer.hpp @@ -143,6 +143,12 @@ namespace Components static Game::dvar_t** con_inputBoxColor; public: + static constexpr char FONT_ICON_SEPARATOR_CHARACTER = ':'; + static constexpr char FONT_ICON_MODIFIER_SEPARATOR_CHARACTER = '+'; + static constexpr char FONT_ICON_MODIFIER_FLIP_HORIZONTALLY = 'h'; + static constexpr char FONT_ICON_MODIFIER_FLIP_VERTICALLY = 'v'; + static constexpr char FONT_ICON_MODIFIER_BIG = 'b'; + static constexpr char COLOR_FIRST_CHAR = '0'; static constexpr char COLOR_LAST_CHAR = CharForColorIndex(TEXT_COLOR_COUNT - 1);