2021-09-04 20:25:24 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
enum TextColor
|
|
|
|
{
|
2021-09-20 12:21:38 -04:00
|
|
|
TEXT_COLOR_BLACK = 0,
|
2021-09-04 20:25:24 -04:00
|
|
|
TEXT_COLOR_RED = 1,
|
|
|
|
TEXT_COLOR_GREEN = 2,
|
|
|
|
TEXT_COLOR_YELLOW = 3,
|
|
|
|
TEXT_COLOR_BLUE = 4,
|
|
|
|
TEXT_COLOR_LIGHT_BLUE = 5,
|
|
|
|
TEXT_COLOR_PINK = 6,
|
|
|
|
TEXT_COLOR_DEFAULT = 7,
|
|
|
|
TEXT_COLOR_AXIS = 8,
|
|
|
|
TEXT_COLOR_ALLIES = 9,
|
|
|
|
TEXT_COLOR_RAINBOW = 10,
|
2021-09-07 06:49:02 -04:00
|
|
|
TEXT_COLOR_SERVER = 11, // using that color in infostrings (e.g. your name) fails, ';' is an illegal character!
|
2021-09-04 20:25:24 -04:00
|
|
|
|
|
|
|
TEXT_COLOR_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr unsigned int ColorRgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a)
|
|
|
|
{
|
|
|
|
return (r) | (g << 8) | (b << 16) | (a << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr unsigned int ColorRgb(const uint8_t r, const uint8_t g, const uint8_t b)
|
|
|
|
{
|
|
|
|
return ColorRgba(r, g, b, 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr char CharForColorIndex(const int colorIndex)
|
|
|
|
{
|
|
|
|
return static_cast<char>('0' + colorIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr int ColorIndexForChar(const char colorChar)
|
|
|
|
{
|
|
|
|
return colorChar - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
class TextRenderer : public Component
|
|
|
|
{
|
2021-09-22 16:50:22 -04:00
|
|
|
static constexpr auto STRING_BUFFER_SIZE_BIG = 1024;
|
|
|
|
static constexpr auto STRING_BUFFER_SIZE_SMALL = 128;
|
|
|
|
|
|
|
|
static constexpr auto REFERENCE_SEARCH_START_WITH = "FONT_ICON_SEARCH_START_WITH";
|
|
|
|
static constexpr auto REFERENCE_HINT_AUTO_COMPLETE = "FONT_ICON_HINT_AUTO_COMPLETE";
|
|
|
|
static constexpr auto REFERENCE_HINT_MODIFIER = "FONT_ICON_HINT_MODIFIER";
|
|
|
|
static constexpr auto REFERENCE_MODIFIER_LIST_HEADER = "FONT_ICON_MODIFIER_LIST_HEADER";
|
|
|
|
static constexpr auto REFERENCE_MODIFIER_LIST_FLIP_HORIZONTAL = "FONT_ICON_MODIFIER_LIST_FLIP_HORIZONTAL";
|
|
|
|
static constexpr auto REFERENCE_MODIFIER_LIST_FLIP_VERTICAL = "FONT_ICON_MODIFIER_LIST_FLIP_VERTICAL";
|
|
|
|
static constexpr auto REFERENCE_MODIFIER_LIST_BIG = "FONT_ICON_MODIFIER_LIST_BIG";
|
|
|
|
|
|
|
|
static constexpr unsigned MY_ALTCOLOR_TWO = 0x0DCE6FFE6;
|
|
|
|
static constexpr unsigned COLOR_MAP_HASH = 0xA0AB1041;
|
|
|
|
static constexpr auto FONT_ICON_AUTOCOMPLETE_BOX_PADDING = 6.0f;
|
|
|
|
static constexpr auto FONT_ICON_AUTOCOMPLETE_BOX_BORDER = 2.0f;
|
|
|
|
static constexpr auto FONT_ICON_AUTOCOMPLETE_COL_SPACING = 12.0f;
|
|
|
|
static constexpr auto FONT_ICON_AUTOCOMPLETE_ARROW_SIZE = 12.0f;
|
|
|
|
static constexpr float MY_OFFSETS[4][2]
|
|
|
|
{
|
|
|
|
{-1.0f, -1.0f},
|
|
|
|
{-1.0f, 1.0f},
|
|
|
|
{1.0f, -1.0f},
|
|
|
|
{1.0f, 1.0f},
|
|
|
|
};
|
|
|
|
static constexpr float WHITE_COLOR[4]
|
|
|
|
{
|
|
|
|
1.0f,
|
|
|
|
1.0f,
|
|
|
|
1.0f,
|
|
|
|
1.0f
|
|
|
|
};
|
|
|
|
static constexpr float TEXT_COLOR[4]
|
|
|
|
{
|
|
|
|
1.0f,
|
|
|
|
1.0f,
|
|
|
|
0.8f,
|
|
|
|
1.0f
|
|
|
|
};
|
|
|
|
static constexpr float HINT_COLOR[4]
|
|
|
|
{
|
|
|
|
0.6f,
|
|
|
|
0.6f,
|
|
|
|
0.6f,
|
|
|
|
1.0f
|
|
|
|
};
|
|
|
|
|
2021-09-21 16:08:12 -04:00
|
|
|
public:
|
2021-09-22 16:50:22 -04:00
|
|
|
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);
|
|
|
|
|
2021-09-21 16:08:12 -04:00
|
|
|
enum FontIconAutocompleteInstance : unsigned
|
|
|
|
{
|
|
|
|
FONT_ICON_ACI_CONSOLE,
|
|
|
|
FONT_ICON_ACI_CHAT,
|
|
|
|
|
|
|
|
FONT_ICON_ACI_COUNT
|
|
|
|
};
|
|
|
|
|
2021-09-22 16:50:22 -04:00
|
|
|
struct FontIconInfo
|
|
|
|
{
|
|
|
|
Game::Material* material;
|
|
|
|
bool flipHorizontal;
|
|
|
|
bool flipVertical;
|
|
|
|
bool big;
|
|
|
|
};
|
|
|
|
|
2021-09-21 16:08:12 -04:00
|
|
|
private:
|
2021-09-10 13:22:23 -04:00
|
|
|
struct FontIconTableEntry
|
|
|
|
{
|
|
|
|
std::string iconName;
|
|
|
|
std::string materialName;
|
|
|
|
Game::Material* material;
|
|
|
|
};
|
|
|
|
|
2021-09-04 20:25:24 -04:00
|
|
|
struct HsvColor
|
|
|
|
{
|
|
|
|
unsigned char h;
|
|
|
|
unsigned char s;
|
|
|
|
unsigned char v;
|
|
|
|
};
|
|
|
|
|
2021-09-07 18:31:56 -04:00
|
|
|
class FontIconAutocompleteResult
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string fontIconName;
|
|
|
|
std::string materialName;
|
|
|
|
};
|
|
|
|
|
2021-09-22 16:50:22 -04:00
|
|
|
class BufferedLocalizedString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BufferedLocalizedString(const char* reference, size_t bufferSize);
|
|
|
|
void Cache();
|
|
|
|
const char* Format(const char* value);
|
|
|
|
const char* GetString() const;
|
|
|
|
int GetWidth(FontIconAutocompleteInstance autocompleteInstance, Game::Font_s* font);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* stringReference;
|
|
|
|
std::unique_ptr<char[]> stringBuffer;
|
|
|
|
size_t stringBufferSize;
|
|
|
|
int stringWidth[FONT_ICON_ACI_COUNT];
|
|
|
|
};
|
|
|
|
|
2021-09-07 18:31:56 -04:00
|
|
|
class FontIconAutocompleteContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto MAX_RESULTS = 10;
|
|
|
|
|
|
|
|
bool autocompleteActive;
|
2021-09-08 08:16:54 -04:00
|
|
|
bool inModifiers;
|
2021-09-08 13:06:38 -04:00
|
|
|
bool userClosed;
|
2021-09-07 18:31:56 -04:00
|
|
|
unsigned int lastHash;
|
|
|
|
std::string lastQuery;
|
|
|
|
FontIconAutocompleteResult results[MAX_RESULTS];
|
|
|
|
size_t resultCount;
|
2021-09-08 07:08:49 -04:00
|
|
|
bool hasMoreResults;
|
2021-09-07 18:31:56 -04:00
|
|
|
size_t resultOffset;
|
|
|
|
size_t lastResultOffset;
|
2021-09-08 07:08:49 -04:00
|
|
|
size_t selectedOffset;
|
2021-09-07 18:31:56 -04:00
|
|
|
float maxFontIconWidth;
|
|
|
|
float maxMaterialNameWidth;
|
2021-09-22 16:50:22 -04:00
|
|
|
BufferedLocalizedString stringSearchStartWith;
|
2021-09-21 14:05:30 -04:00
|
|
|
|
2021-09-22 16:50:22 -04:00
|
|
|
FontIconAutocompleteContext();
|
2021-09-08 08:16:54 -04:00
|
|
|
};
|
2021-09-04 20:25:24 -04:00
|
|
|
|
|
|
|
static unsigned colorTableDefault[TEXT_COLOR_COUNT];
|
|
|
|
static unsigned colorTableNew[TEXT_COLOR_COUNT];
|
|
|
|
static unsigned(*currentColorTable)[TEXT_COLOR_COUNT];
|
2021-09-07 18:31:56 -04:00
|
|
|
static FontIconAutocompleteContext autocompleteContextArray[FONT_ICON_ACI_COUNT];
|
2021-09-10 13:22:23 -04:00
|
|
|
static std::map<std::string, FontIconTableEntry> fontIconLookup;
|
|
|
|
static std::vector<FontIconTableEntry> fontIconList;
|
2021-09-04 20:25:24 -04:00
|
|
|
|
2021-09-22 16:50:22 -04:00
|
|
|
static BufferedLocalizedString stringHintAutoComplete;
|
|
|
|
static BufferedLocalizedString stringHintModifier;
|
|
|
|
static BufferedLocalizedString stringListHeader;
|
|
|
|
static BufferedLocalizedString stringListFlipHorizontal;
|
|
|
|
static BufferedLocalizedString stringListFlipVertical;
|
|
|
|
static BufferedLocalizedString stringListBig;
|
2021-09-21 14:05:30 -04:00
|
|
|
|
2021-09-04 20:25:24 -04:00
|
|
|
static Dvar::Var cg_newColors;
|
2021-09-08 08:16:54 -04:00
|
|
|
static Dvar::Var cg_fontIconAutocomplete;
|
|
|
|
static Dvar::Var cg_fontIconAutocompleteHint;
|
2021-09-04 20:25:24 -04:00
|
|
|
static Game::dvar_t* sv_customTextColor;
|
2021-09-07 07:53:56 -04:00
|
|
|
static Dvar::Var r_colorBlind;
|
|
|
|
static Game::dvar_t* g_ColorBlind_MyTeam;
|
|
|
|
static Game::dvar_t* g_ColorBlind_EnemyTeam;
|
2021-09-07 18:31:56 -04:00
|
|
|
static Game::dvar_t** con_inputBoxColor;
|
2021-09-04 20:25:24 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
static void DrawText2D(const char* text, float x, float y, Game::Font_s* font, float xScale, float yScale, float sinAngle, float cosAngle, Game::GfxColor color, int maxLength, int renderFlags, int cursorPos, char cursorLetter, float padding, Game::GfxColor glowForcedColor, int fxBirthTime, int fxLetterTime, int fxDecayStartTime, int fxDecayDuration, Game::Material* fxMaterial, Game::Material* fxMaterialGlow);
|
2021-09-06 11:02:17 -04:00
|
|
|
static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font);
|
2021-09-07 06:49:02 -04:00
|
|
|
static unsigned int ColorIndex(char index);
|
2022-11-01 19:23:25 -04:00
|
|
|
static void StripColors(const char* in, char* out, std::size_t max);
|
2021-09-07 06:49:02 -04:00
|
|
|
static std::string StripColors(const std::string& in);
|
2022-11-01 19:23:25 -04:00
|
|
|
static void StripMaterialTextIcons(const char* in, char* out, std::size_t max);
|
2021-09-07 08:33:36 -04:00
|
|
|
static std::string StripMaterialTextIcons(const std::string& in);
|
2022-11-01 19:23:25 -04:00
|
|
|
static void StripAllTextIcons(const char* in, char* out, std::size_t max);
|
2021-09-07 08:33:36 -04:00
|
|
|
static std::string StripAllTextIcons(const std::string& in);
|
2021-09-04 20:25:24 -04:00
|
|
|
|
2021-09-19 09:49:12 -04:00
|
|
|
static bool IsFontIcon(const char*& text, FontIconInfo& fontIcon);
|
|
|
|
static float GetNormalizedFontIconWidth(const FontIconInfo& fontIcon);
|
|
|
|
static float GetFontIconWidth(const FontIconInfo& fontIcon, const Game::Font_s* font, float xScale);
|
|
|
|
|
2021-09-21 16:08:12 -04:00
|
|
|
static bool HandleFontIconAutocompleteKey(int localClientNum, FontIconAutocompleteInstance autocompleteInstance, int key);
|
|
|
|
|
2021-09-04 20:25:24 -04:00
|
|
|
TextRenderer();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static unsigned HsvToRgb(HsvColor hsv);
|
2021-09-05 09:21:11 -04:00
|
|
|
|
2021-09-08 07:08:49 -04:00
|
|
|
static void DrawAutocompleteBox(const FontIconAutocompleteContext& context, float x, float y, float w, float h, const float* color);
|
2021-09-22 16:50:22 -04:00
|
|
|
static void DrawAutocompleteModifiers(FontIconAutocompleteInstance instance, float x, float y, Game::Font_s* font, float textXScale, float textYScale);
|
|
|
|
static void DrawAutocompleteResults(FontIconAutocompleteInstance instance, float x, float y, Game::Font_s* font, float textXScale, float textYScale);
|
|
|
|
static void DrawAutocomplete(FontIconAutocompleteInstance instance, float x, float y, Game::Font_s* font, float textXScale, float textYScale);
|
2021-09-08 09:53:05 -04:00
|
|
|
static void UpdateAutocompleteContextResults(FontIconAutocompleteContext& context, Game::Font_s* font, float textXScale);
|
2021-09-08 10:44:39 -04:00
|
|
|
static void UpdateAutocompleteContext(FontIconAutocompleteContext& context, const Game::field_t* edit, Game::Font_s* font, const float textXScale);
|
2021-09-07 18:31:56 -04:00
|
|
|
static void Field_Draw_Say(int localClientNum, Game::field_t* edit, int x, int y, int horzAlign, int vertAlign);
|
|
|
|
static void Con_DrawInput_Hk(int localClientNum);
|
|
|
|
|
2021-09-08 07:08:49 -04:00
|
|
|
static void AutocompleteUp(FontIconAutocompleteContext& context);
|
|
|
|
static void AutocompleteDown(FontIconAutocompleteContext& context);
|
2021-09-21 16:08:12 -04:00
|
|
|
static void AutocompleteFill(const FontIconAutocompleteContext& context, Game::ScreenPlacement* scrPlace, Game::field_t* edit, bool closeFontIcon);
|
2021-09-08 07:08:49 -04:00
|
|
|
static bool AutocompleteHandleKeyDown(FontIconAutocompleteContext& context, int key, Game::ScreenPlacement* scrPlace, Game::field_t* edit);
|
|
|
|
static void Console_Key_Hk(int localClientNum, int key);
|
|
|
|
static bool ChatHandleKeyDown(int localClientNum, int key);
|
|
|
|
static void Message_Key_Stub();
|
|
|
|
|
2021-09-07 10:45:59 -04:00
|
|
|
static int SEH_PrintStrlenWithCursor(const char* string, const Game::field_t* field);
|
|
|
|
static void Field_AdjustScroll_PrintLen_Stub();
|
|
|
|
|
2021-09-07 06:49:02 -04:00
|
|
|
static void PatchColorLimit(char limit);
|
|
|
|
static bool Dvar_GetUnpackedColorByName(const char* name, float* expandedColor);
|
|
|
|
static void GetUnpackedColorByNameStub();
|
|
|
|
|
2021-09-06 11:02:17 -04:00
|
|
|
static Game::GfxImage* GetFontIconColorMap(const Game::Material* fontIconMaterial);
|
2021-09-06 08:46:30 -04:00
|
|
|
static float DrawFontIcon(const FontIconInfo& fontIcon, float x, float y, float sinAngle, float cosAngle, const Game::Font_s* font, float xScale, float yScale, unsigned color);
|
2021-09-05 09:21:11 -04:00
|
|
|
|
|
|
|
static float GetMonospaceWidth(Game::Font_s* font, int rendererFlags);
|
2021-09-05 08:50:56 -04:00
|
|
|
static void GlowColor(Game::GfxColor* result, Game::GfxColor baseColor, Game::GfxColor forcedGlowColor, int renderFlags);
|
2021-09-20 12:21:38 -04:00
|
|
|
static unsigned R_FontGetRandomLetter(int seed);
|
2021-09-05 08:50:56 -04:00
|
|
|
static void DrawTextFxExtraCharacter(Game::Material* material, int charIndex, float x, float y, float w, float h, float sinAngle, float cosAngle, unsigned color);
|
2021-09-04 20:25:24 -04:00
|
|
|
static float DrawHudIcon(const char*& text, float x, float y, float sinAngle, float cosAngle, const Game::Font_s* font, float xScale, float yScale, unsigned color);
|
|
|
|
static void RotateXY(float cosAngle, float sinAngle, float pivotX, float pivotY, float x, float y, float* outX, float* outY);
|
|
|
|
static void UpdateColorTable();
|
2021-09-10 13:22:23 -04:00
|
|
|
|
2021-09-21 14:05:30 -04:00
|
|
|
static void InitFontIconStrings();
|
2021-09-10 13:22:23 -04:00
|
|
|
static void InitFontIcons();
|
|
|
|
static void UI_Init_Hk(int localClientNum);
|
2021-09-04 20:25:24 -04:00
|
|
|
};
|
|
|
|
}
|