Replace fonticon literal characters for modifiers and separators with constants

This commit is contained in:
Jan 2021-09-20 20:29:32 +02:00
parent b8b8608a3d
commit 41e3acb833
3 changed files with 19 additions and 13 deletions

View File

@ -134,7 +134,7 @@ namespace Components
CheckChatLineEnd(text, p, len, chatHeight, chatWidth, lastSpace, lastFontIcon, lastColor); CheckChatLineEnd(text, p, len, chatHeight, chatWidth, lastSpace, lastFontIcon, lastColor);
const char* fontIconEndPos = &text[1]; 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 // 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 // which is roughly double as much as the average width of a character without an additional multiplier the calculated len of the font icon

View File

@ -199,7 +199,7 @@ namespace Components
for(auto i = 0; i < edit->cursor; i++) for(auto i = 0; i < edit->cursor; i++)
{ {
const auto c = static_cast<unsigned char>(edit->buffer[i]); const auto c = static_cast<unsigned char>(edit->buffer[i]);
if (c == ':') if (c == FONT_ICON_SEPARATOR_CHARACTER)
{ {
if(fontIconStart < 0) if(fontIconStart < 0)
{ {
@ -217,7 +217,7 @@ namespace Components
fontIconStart = -1; fontIconStart = -1;
inModifiers = false; inModifiers = false;
} }
else if(c == '+') else if(c == FONT_ICON_MODIFIER_SEPARATOR_CHARACTER)
{ {
if (fontIconStart >= 0 && !inModifiers) if (fontIconStart >= 0 && !inModifiers)
{ {
@ -568,12 +568,12 @@ namespace Components
{ {
const auto* curPos = text; 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++; curPos++;
const auto* nameEnd = curPos; const auto* nameEnd = curPos;
if(*curPos == '+') if(*curPos == FONT_ICON_MODIFIER_SEPARATOR_CHARACTER)
{ {
auto breakArgs = false; auto breakArgs = false;
while(!breakArgs) while(!breakArgs)
@ -581,19 +581,19 @@ namespace Components
curPos++; curPos++;
switch(*curPos) switch(*curPos)
{ {
case 'h': case FONT_ICON_MODIFIER_FLIP_HORIZONTALLY:
fontIcon.flipHorizontal = true; fontIcon.flipHorizontal = true;
break; break;
case 'v': case FONT_ICON_MODIFIER_FLIP_VERTICALLY:
fontIcon.flipVertical = true; fontIcon.flipVertical = true;
break; break;
case 'b': case FONT_ICON_MODIFIER_BIG:
fontIcon.big = true; fontIcon.big = true;
break; break;
case ':': case FONT_ICON_SEPARATOR_CHARACTER:
breakArgs = true; breakArgs = true;
break; break;
@ -603,7 +603,7 @@ namespace Components
} }
} }
if (*curPos != ':') if (*curPos != FONT_ICON_SEPARATOR_CHARACTER)
return false; return false;
const std::string fontIconName(text, nameEnd - text); const std::string fontIconName(text, nameEnd - text);
@ -902,7 +902,7 @@ namespace Components
continue; continue;
} }
if(letter == ':') if(letter == FONT_ICON_SEPARATOR_CHARACTER)
{ {
FontIconInfo fontIconInfo{}; FontIconInfo fontIconInfo{};
const char* fontIconEnd = curText; const char* fontIconEnd = curText;
@ -1089,7 +1089,7 @@ namespace Components
} }
} }
if (letter == ':') if (letter == FONT_ICON_SEPARATOR_CHARACTER)
{ {
FontIconInfo fontIconInfo{}; FontIconInfo fontIconInfo{};
const char* fontIconEnd = text; const char* fontIconEnd = text;
@ -1230,7 +1230,7 @@ namespace Components
continue; continue;
} }
if(*in == ':') if(*in == FONT_ICON_SEPARATOR_CHARACTER)
{ {
const auto* fontIconEndPos = &in[1]; const auto* fontIconEndPos = &in[1];
FontIconInfo fontIcon{}; FontIconInfo fontIcon{};

View File

@ -143,6 +143,12 @@ namespace Components
static Game::dvar_t** con_inputBoxColor; static Game::dvar_t** con_inputBoxColor;
public: 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_FIRST_CHAR = '0';
static constexpr char COLOR_LAST_CHAR = CharForColorIndex(TEXT_COLOR_COUNT - 1); static constexpr char COLOR_LAST_CHAR = CharForColorIndex(TEXT_COLOR_COUNT - 1);