Add support for animated icons as fonticons

This commit is contained in:
Jan 2021-09-08 16:44:39 +02:00
parent cdf81b8ce2
commit 5b93848ace
5 changed files with 27 additions and 8 deletions

View File

@ -189,7 +189,7 @@ namespace Components
} }
} }
void TextRenderer::UpdateAutocompleteContext(FontIconAutocompleteContext& context, Game::field_t* edit, Game::Font_s* font, const float textXScale) void TextRenderer::UpdateAutocompleteContext(TextRenderer::FontIconAutocompleteContext& context, const Game::field_t* edit, Game::Font_s* font, const float textXScale)
{ {
int fontIconStart = -1; int fontIconStart = -1;
auto inModifiers = false; auto inModifiers = false;
@ -606,7 +606,13 @@ namespace Components
if (colorMap == nullptr) if (colorMap == nullptr)
return 0; return 0;
const auto sizeMultiplier = fontIcon.big ? 1.5f : 1.0f; const auto sizeMultiplier = fontIcon.big ? 1.5f : 1.0f;
return static_cast<float>(font->pixelHeight) * (static_cast<float>(colorMap->width) / static_cast<float>(colorMap->height)) * xScale * sizeMultiplier; auto colWidth = static_cast<float>(colorMap->width);
auto colHeight = static_cast<float>(colorMap->height);
if (fontIcon.material->info.textureAtlasColumnCount > 1)
colWidth /= static_cast<float>(fontIcon.material->info.textureAtlasColumnCount);
if (fontIcon.material->info.textureAtlasRowCount > 1)
colHeight /= static_cast<float>(fontIcon.material->info.textureAtlasRowCount);
return static_cast<float>(font->pixelHeight) * (colWidth / colHeight) * xScale * sizeMultiplier;
} }
float TextRenderer::DrawFontIcon(const FontIconInfo& fontIcon, const float x, const float y, const float sinAngle, const float cosAngle, const Game::Font_s* font, const float xScale, const float yScale, const unsigned color) float TextRenderer::DrawFontIcon(const FontIconInfo& fontIcon, const float x, const float y, const float sinAngle, const float cosAngle, const Game::Font_s* font, const float xScale, const float yScale, const unsigned color)
@ -636,10 +642,18 @@ namespace Components
t0 = 0.0f; t0 = 0.0f;
t1 = 1.0f; t1 = 1.0f;
} }
Game::Material_Process2DTextureCoordsForAtlasing(fontIcon.material, &s0, &s1, &t0, &t1);
const auto sizeMultiplier = fontIcon.big ? 1.5f : 1.0f; const auto sizeMultiplier = fontIcon.big ? 1.5f : 1.0f;
auto colWidth = static_cast<float>(colorMap->width);
auto colHeight = static_cast<float>(colorMap->height);
if (fontIcon.material->info.textureAtlasColumnCount > 1)
colWidth /= static_cast<float>(fontIcon.material->info.textureAtlasColumnCount);
if (fontIcon.material->info.textureAtlasRowCount > 1)
colHeight /= static_cast<float>(fontIcon.material->info.textureAtlasRowCount);
const auto h = static_cast<float>(font->pixelHeight) * yScale * sizeMultiplier; const auto h = static_cast<float>(font->pixelHeight) * yScale * sizeMultiplier;
const auto w = static_cast<float>(font->pixelHeight) * (static_cast<float>(colorMap->width) / static_cast<float>(colorMap->height)) * xScale * sizeMultiplier; const auto w = static_cast<float>(font->pixelHeight) * (colWidth / colHeight) * xScale * sizeMultiplier;
const auto yy = y - (h + yScale * static_cast<float>(font->pixelHeight)) * 0.5f; const auto yy = y - (h + yScale * static_cast<float>(font->pixelHeight)) * 0.5f;
Game::RB_DrawStretchPicRotate(fontIcon.material, x, yy, w, h, s0, t0, s1, t1, sinAngle, cosAngle, color); Game::RB_DrawStretchPicRotate(fontIcon.material, x, yy, w, h, s0, t0, s1, t1, sinAngle, cosAngle, color);
@ -1010,8 +1024,8 @@ namespace Components
const auto width = text[1]; const auto width = text[1];
const auto materialNameLength = text[3]; const auto materialNameLength = text[3];
auto v9 = font->pixelHeight * (width - 16) + 16; const auto v9 = font->pixelHeight * (width - 16) + 16;
auto w = ((((v9 >> 24) & 0x1F) + v9) >> 5); const auto w = ((((v9 >> 24) & 0x1F) + v9) >> 5);
lineWidth += w; lineWidth += w;
if (lineWidth > maxWidth) if (lineWidth > maxWidth)

View File

@ -156,7 +156,7 @@ namespace Components
static void DrawAutocompleteResults(const FontIconAutocompleteContext& context, float x, float y, Game::Font_s* font, float textXScale, float textYScale); static void DrawAutocompleteResults(const FontIconAutocompleteContext& context, float x, float y, Game::Font_s* font, float textXScale, float textYScale);
static void DrawAutocomplete(const FontIconAutocompleteContext& context, float x, float y, Game::Font_s* font, float textXScale, float textYScale); static void DrawAutocomplete(const FontIconAutocompleteContext& context, float x, float y, Game::Font_s* font, float textXScale, float textYScale);
static void UpdateAutocompleteContextResults(FontIconAutocompleteContext& context, Game::Font_s* font, float textXScale); static void UpdateAutocompleteContextResults(FontIconAutocompleteContext& context, Game::Font_s* font, float textXScale);
static void UpdateAutocompleteContext(FontIconAutocompleteContext& context, Game::field_t* edit, Game::Font_s* font, float textXScale); static void UpdateAutocompleteContext(FontIconAutocompleteContext& context, const Game::field_t* edit, Game::Font_s* font, const float textXScale);
static void Field_Draw_Say(int localClientNum, Game::field_t* edit, int x, int y, int horzAlign, int vertAlign); 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); static void Con_DrawInput_Hk(int localClientNum);

View File

@ -339,6 +339,8 @@ namespace Game
R_NormalizedTextScale_t R_NormalizedTextScale = R_NormalizedTextScale_t(0x5056A0); R_NormalizedTextScale_t R_NormalizedTextScale = R_NormalizedTextScale_t(0x5056A0);
Material_Process2DTextureCoordsForAtlasing_t Material_Process2DTextureCoordsForAtlasing = Material_Process2DTextureCoordsForAtlasing_t(0x506090);
Byte4PackRgba_t Byte4PackRgba = Byte4PackRgba_t(0x4FE910); Byte4PackRgba_t Byte4PackRgba = Byte4PackRgba_t(0x4FE910);
RandWithSeed_t RandWithSeed = RandWithSeed_t(0x495580); RandWithSeed_t RandWithSeed = RandWithSeed_t(0x495580);
GetDecayingLetterInfo_t GetDecayingLetterInfo = GetDecayingLetterInfo_t(0x5351C0); GetDecayingLetterInfo_t GetDecayingLetterInfo = GetDecayingLetterInfo_t(0x5351C0);

View File

@ -788,6 +788,9 @@ namespace Game
typedef float(__cdecl* R_NormalizedTextScale_t)(Font_s* font, float scale); typedef float(__cdecl* R_NormalizedTextScale_t)(Font_s* font, float scale);
extern R_NormalizedTextScale_t R_NormalizedTextScale; extern R_NormalizedTextScale_t R_NormalizedTextScale;
typedef void(__cdecl * Material_Process2DTextureCoordsForAtlasing_t)(const Material* material, float* s0, float* s1, float* t0, float* t1);
extern Material_Process2DTextureCoordsForAtlasing_t Material_Process2DTextureCoordsForAtlasing;
typedef void(__cdecl* Byte4PackRgba_t)(const float* from, char* to); typedef void(__cdecl* Byte4PackRgba_t)(const float* from, char* to);
extern Byte4PackRgba_t Byte4PackRgba; extern Byte4PackRgba_t Byte4PackRgba;

View File

@ -501,8 +501,8 @@ namespace Game
const char *name; const char *name;
char gameFlags; char gameFlags;
char sortKey; char sortKey;
char textureAtlasRowCount; unsigned char textureAtlasRowCount;
char textureAtlasColumnCount; unsigned char textureAtlasColumnCount;
GfxDrawSurf drawSurf; GfxDrawSurf drawSurf;
unsigned int surfaceTypeBits; unsigned int surfaceTypeBits;
unsigned __int16 hashIndex; unsigned __int16 hashIndex;