2021-09-04 20:25:24 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
enum TextColor
|
|
|
|
{
|
|
|
|
TEXT_COLOR_BLACK = 0,
|
|
|
|
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-06 08:46:30 -04:00
|
|
|
struct FontIconInfo
|
|
|
|
{
|
|
|
|
Game::Material* material;
|
|
|
|
bool flipHorizontal;
|
|
|
|
bool flipVertical;
|
|
|
|
};
|
|
|
|
|
2021-09-04 20:25:24 -04:00
|
|
|
struct HsvColor
|
|
|
|
{
|
|
|
|
unsigned char h;
|
|
|
|
unsigned char s;
|
|
|
|
unsigned char v;
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr char COLOR_FIRST_CHAR = '0';
|
|
|
|
static constexpr char COLOR_LAST_CHAR = CharForColorIndex(TEXT_COLOR_COUNT - 1);
|
|
|
|
static constexpr unsigned MY_ALTCOLOR_TWO = 0x0DCE6FFE6;
|
|
|
|
static constexpr unsigned COLOR_MAP_HASH = 0xA0AB1041;
|
2021-09-05 08:50:56 -04:00
|
|
|
static constexpr float MY_OFFSETS[4][2]
|
|
|
|
{
|
|
|
|
{-1.0f, -1.0f},
|
|
|
|
{-1.0f, 1.0f},
|
|
|
|
{1.0f, -1.0f},
|
|
|
|
{1.0f, 1.0f},
|
|
|
|
};
|
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];
|
|
|
|
|
|
|
|
static Dvar::Var cg_newColors;
|
|
|
|
static Game::dvar_t* sv_customTextColor;
|
2021-09-07 06:49:02 -04:00
|
|
|
static Dvar::Var sv_allowColoredNames;
|
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-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);
|
|
|
|
static void StripColors(const char* in, char* out, int max);
|
|
|
|
static std::string StripColors(const std::string& in);
|
|
|
|
static void UserInfoCopy(char* buffer, const char* name, size_t size);
|
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-07 06:49:02 -04:00
|
|
|
static void ClientUserinfoChanged();
|
|
|
|
static char* GetClientName(int localClientNum, int index, char* buf, size_t size);
|
|
|
|
static void PatchColorLimit(char limit);
|
|
|
|
static char* CleanStrStub(char* string);
|
|
|
|
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 bool IsFontIcon(const char*& text, FontIconInfo& fontIcon);
|
2021-09-06 11:02:41 -04:00
|
|
|
static float GetFontIconWidth(const FontIconInfo& fontIcon, const Game::Font_s* font, float xScale);
|
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);
|
|
|
|
static unsigned R_FontGetRandomLetter(int seed);
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
}
|