diff --git a/extern/imgui_patched/imgui.h b/extern/imgui_patched/imgui.h index b86c20b17..d826095b9 100644 --- a/extern/imgui_patched/imgui.h +++ b/extern/imgui_patched/imgui.h @@ -2989,6 +2989,7 @@ enum ImFontAtlasFlags_ ImFontAtlasFlags_NoPowerOfTwoHeight = 1 << 0, // Don't round the height to next power of two ImFontAtlasFlags_NoMouseCursors = 1 << 1, // Don't build software mouse cursors into the atlas (save a little texture memory) ImFontAtlasFlags_NoBakedLines = 1 << 2, // Don't build thick line textures into the atlas (save a little texture memory, allow support for point/nearest filtering). The AntiAliasedLinesUseTex features uses them, otherwise they will be rendered using polygons (more expensive for CPU/GPU). + ImFontAtlasFlags_Square = 1 << 3, // Make sure the texture is a square }; // Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding: diff --git a/extern/imgui_patched/imgui_draw.cpp b/extern/imgui_patched/imgui_draw.cpp index 85e62beed..e361c31a5 100644 --- a/extern/imgui_patched/imgui_draw.cpp +++ b/extern/imgui_patched/imgui_draw.cpp @@ -2678,6 +2678,15 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) // 7. Allocate texture atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight); atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight); + + if (atlas->Flags & ImFontAtlasFlags_Square) { + if (atlas->TexWidth>atlas->TexHeight) { + atlas->TexHeight=atlas->TexWidth; + } else { + atlas->TexWidth=atlas->TexHeight; + } + } + atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(atlas->TexWidth * atlas->TexHeight); memset(atlas->TexPixelsAlpha8, 0, atlas->TexWidth * atlas->TexHeight); spc.pixels = atlas->TexPixelsAlpha8; diff --git a/extern/imgui_patched/misc/freetype/imgui_freetype.cpp b/extern/imgui_patched/misc/freetype/imgui_freetype.cpp index 570d61a3a..038aded8e 100644 --- a/extern/imgui_patched/misc/freetype/imgui_freetype.cpp +++ b/extern/imgui_patched/misc/freetype/imgui_freetype.cpp @@ -643,6 +643,15 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u // 7. Allocate texture atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight); + + if (atlas->Flags & ImFontAtlasFlags_Square) { + if (atlas->TexWidth>atlas->TexHeight) { + atlas->TexHeight=atlas->TexWidth; + } else { + atlas->TexWidth=atlas->TexHeight; + } + } + atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight); if (src_load_color) { diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 989e40bac..1d2597293 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -4074,6 +4074,9 @@ bool FurnaceGUI::loop() { rend->initGUI(sdlWin); logD("building font..."); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } if (!ImGui::GetIO().Fonts->Build()) { logE("error while building font atlas!"); showError(_("error while loading fonts! please check your settings.")); @@ -4082,7 +4085,12 @@ bool FurnaceGUI::loop() { patFont=mainFont; bigFont=mainFont; headFont=mainFont; - if (rend) rend->destroyFontsTexture(); + if (rend) { + rend->destroyFontsTexture(); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } + } if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); } @@ -6692,7 +6700,12 @@ bool FurnaceGUI::loop() { applyUISettings(); - if (rend) rend->destroyFontsTexture(); + if (rend) { + rend->destroyFontsTexture(); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } + } if (!ImGui::GetIO().Fonts->Build()) { logE("error while building font atlas!"); showError(_("error while loading fonts! please check your settings.")); @@ -6701,7 +6714,12 @@ bool FurnaceGUI::loop() { patFont=mainFont; bigFont=mainFont; headFont=mainFont; - if (rend) rend->destroyFontsTexture(); + if (rend) { + rend->destroyFontsTexture(); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } + } if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); } else { @@ -6723,7 +6741,12 @@ bool FurnaceGUI::loop() { patFont=mainFont; bigFont=mainFont; headFont=mainFont; - if (rend) rend->destroyFontsTexture(); + if (rend) { + rend->destroyFontsTexture(); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } + } if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); } else { @@ -7131,6 +7154,9 @@ bool FurnaceGUI::init() { applyUISettings(); logD("building font..."); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } if (!ImGui::GetIO().Fonts->Build()) { logE("error while building font atlas!"); showError(_("error while loading fonts! please check your settings.")); @@ -7139,7 +7165,9 @@ bool FurnaceGUI::init() { patFont=mainFont; bigFont=mainFont; headFont=mainFont; - if (rend) rend->destroyFontsTexture(); + if (rend) { + rend->destroyFontsTexture(); + } if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); } diff --git a/src/gui/gui.h b/src/gui/gui.h index 307f7b20e..d168a8a0c 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1529,6 +1529,7 @@ class FurnaceGUIRender { virtual void drawOsc(float* data, size_t len, ImVec2 pos0, ImVec2 pos1, ImVec4 color, ImVec2 canvasSize, float lineWidth); virtual void present(); virtual bool supportsDrawOsc(); + virtual bool areTexturesSquare(); virtual bool getOutputSize(int& w, int& h); virtual int getWindowFlags(); virtual int getMaxTextureWidth(); diff --git a/src/gui/render/abstract.cpp b/src/gui/render/abstract.cpp index 90fc67a01..8277605e3 100644 --- a/src/gui/render/abstract.cpp +++ b/src/gui/render/abstract.cpp @@ -105,6 +105,10 @@ bool FurnaceGUIRender::supportsDrawOsc() { return false; } +bool FurnaceGUIRender::areTexturesSquare() { + return false; +} + int FurnaceGUIRender::getWindowFlags() { return 0; } diff --git a/src/gui/render/renderDX9.cpp b/src/gui/render/renderDX9.cpp index 353208114..9595c90ee 100644 --- a/src/gui/render/renderDX9.cpp +++ b/src/gui/render/renderDX9.cpp @@ -469,6 +469,11 @@ void FurnaceGUIRenderDX9::setSwapInterval(int swapInt) { swapInterval=swapInt; } +// I would use caps but... +bool FurnaceGUIRenderDX9::areTexturesSquare() { + return true; +} + void FurnaceGUIRenderDX9::preInit(const DivConfig& conf) { } diff --git a/src/gui/render/renderDX9.h b/src/gui/render/renderDX9.h index 3d46326e8..6c3ecb81a 100644 --- a/src/gui/render/renderDX9.h +++ b/src/gui/render/renderDX9.h @@ -59,6 +59,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender { void clear(ImVec4 color); bool newFrame(); bool canVSync(); + bool areTexturesSquare(); void createFontsTexture(); void destroyFontsTexture(); void renderGUI(); diff --git a/src/gui/render/renderGL1.cpp b/src/gui/render/renderGL1.cpp index 4daace8ef..ef2f313f2 100644 --- a/src/gui/render/renderGL1.cpp +++ b/src/gui/render/renderGL1.cpp @@ -225,6 +225,10 @@ int FurnaceGUIRenderGL1::getWindowFlags() { return SDL_WINDOW_OPENGL; } +bool FurnaceGUIRenderGL1::areTexturesSquare() { + return true; +} + int FurnaceGUIRenderGL1::getMaxTextureWidth() { return maxWidth; } diff --git a/src/gui/render/renderGL1.h b/src/gui/render/renderGL1.h index 9b3b6d2d3..45d8f5222 100644 --- a/src/gui/render/renderGL1.h +++ b/src/gui/render/renderGL1.h @@ -43,6 +43,7 @@ class FurnaceGUIRenderGL1: public FurnaceGUIRender { void clear(ImVec4 color); bool newFrame(); bool canVSync(); + bool areTexturesSquare(); void createFontsTexture(); void destroyFontsTexture(); void renderGUI(); diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index b3fa68fde..e29c911f8 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -5679,7 +5679,12 @@ void FurnaceGUI::commitSettings() { applyUISettings(); - if (rend) rend->destroyFontsTexture(); + if (rend) { + rend->destroyFontsTexture(); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } + } if (!ImGui::GetIO().Fonts->Build()) { logE("error while building font atlas!"); showError(_("error while loading fonts! please check your settings.")); @@ -5688,7 +5693,12 @@ void FurnaceGUI::commitSettings() { patFont=mainFont; bigFont=mainFont; headFont=mainFont; - if (rend) rend->destroyFontsTexture(); + if (rend) { + rend->destroyFontsTexture(); + if (rend->areTexturesSquare()) { + ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square; + } + } if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); } else {