diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 8197c9ea..b4190e2d 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -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; auto inModifiers = false; @@ -606,7 +606,13 @@ namespace Components if (colorMap == nullptr) return 0; const auto sizeMultiplier = fontIcon.big ? 1.5f : 1.0f; - return static_cast(font->pixelHeight) * (static_cast(colorMap->width) / static_cast(colorMap->height)) * xScale * sizeMultiplier; + auto colWidth = static_cast(colorMap->width); + auto colHeight = static_cast(colorMap->height); + if (fontIcon.material->info.textureAtlasColumnCount > 1) + colWidth /= static_cast(fontIcon.material->info.textureAtlasColumnCount); + if (fontIcon.material->info.textureAtlasRowCount > 1) + colHeight /= static_cast(fontIcon.material->info.textureAtlasRowCount); + return static_cast(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) @@ -636,10 +642,18 @@ namespace Components t0 = 0.0f; t1 = 1.0f; } + Game::Material_Process2DTextureCoordsForAtlasing(fontIcon.material, &s0, &s1, &t0, &t1); const auto sizeMultiplier = fontIcon.big ? 1.5f : 1.0f; + auto colWidth = static_cast(colorMap->width); + auto colHeight = static_cast(colorMap->height); + if (fontIcon.material->info.textureAtlasColumnCount > 1) + colWidth /= static_cast(fontIcon.material->info.textureAtlasColumnCount); + if (fontIcon.material->info.textureAtlasRowCount > 1) + colHeight /= static_cast(fontIcon.material->info.textureAtlasRowCount); + const auto h = static_cast(font->pixelHeight) * yScale * sizeMultiplier; - const auto w = static_cast(font->pixelHeight) * (static_cast(colorMap->width) / static_cast(colorMap->height)) * xScale * sizeMultiplier; + const auto w = static_cast(font->pixelHeight) * (colWidth / colHeight) * xScale * sizeMultiplier; const auto yy = y - (h + yScale * static_cast(font->pixelHeight)) * 0.5f; 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 materialNameLength = text[3]; - auto v9 = font->pixelHeight * (width - 16) + 16; - auto w = ((((v9 >> 24) & 0x1F) + v9) >> 5); + const auto v9 = font->pixelHeight * (width - 16) + 16; + const auto w = ((((v9 >> 24) & 0x1F) + v9) >> 5); lineWidth += w; if (lineWidth > maxWidth) diff --git a/src/Components/Modules/TextRenderer.hpp b/src/Components/Modules/TextRenderer.hpp index 716309f2..7328330c 100644 --- a/src/Components/Modules/TextRenderer.hpp +++ b/src/Components/Modules/TextRenderer.hpp @@ -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 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 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 Con_DrawInput_Hk(int localClientNum); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index dc1e13f9..60fafdb0 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -339,6 +339,8 @@ namespace Game R_NormalizedTextScale_t R_NormalizedTextScale = R_NormalizedTextScale_t(0x5056A0); + Material_Process2DTextureCoordsForAtlasing_t Material_Process2DTextureCoordsForAtlasing = Material_Process2DTextureCoordsForAtlasing_t(0x506090); + Byte4PackRgba_t Byte4PackRgba = Byte4PackRgba_t(0x4FE910); RandWithSeed_t RandWithSeed = RandWithSeed_t(0x495580); GetDecayingLetterInfo_t GetDecayingLetterInfo = GetDecayingLetterInfo_t(0x5351C0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 3e0ab2c3..b334f09d 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -788,6 +788,9 @@ namespace Game typedef float(__cdecl* R_NormalizedTextScale_t)(Font_s* font, float scale); 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); extern Byte4PackRgba_t Byte4PackRgba; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 860a44f2..3ca095f5 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -501,8 +501,8 @@ namespace Game const char *name; char gameFlags; char sortKey; - char textureAtlasRowCount; - char textureAtlasColumnCount; + unsigned char textureAtlasRowCount; + unsigned char textureAtlasColumnCount; GfxDrawSurf drawSurf; unsigned int surfaceTypeBits; unsigned __int16 hashIndex;