From e8b0102bfb011e6a7a2957c74116eb712801138a Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Mon, 29 Aug 2022 13:30:44 +0300 Subject: [PATCH] Removed unnecessary ImGui patch. --- SpaceCadetPinball/imgui_draw.cpp | 2 +- SpaceCadetPinball/winmain.cpp | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/SpaceCadetPinball/imgui_draw.cpp b/SpaceCadetPinball/imgui_draw.cpp index 05d4b6d..5e52dee 100644 --- a/SpaceCadetPinball/imgui_draw.cpp +++ b/SpaceCadetPinball/imgui_draw.cpp @@ -2141,7 +2141,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); if (!data) { - // IM_ASSERT_USER_ERROR(0, "Could not load font file!"); + IM_ASSERT_USER_ERROR(0, "Could not load font file!"); return NULL; } ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 0b88e25..0a767e2 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -116,21 +116,33 @@ int winmain::WinMain(LPCSTR lpCmdLine) // First step: just load the options options::InitPrimary(); - if(!Options.FontFileName.empty()) { + if(!Options.FontFileName.empty()) + { ImGuiSDL::Deinitialize(); io.Fonts->Clear(); ImVector ranges; translations::GetGlyphRange(&ranges); - ImFontConfig fontConfig; - fontConfig.OversampleV = 2; - fontConfig.OversampleH = 8; - - if(!io.Fonts->AddFontFromFileTTF(Options.FontFileName.c_str(), 13.f, &fontConfig, ranges.Data)) { - // Font loading failed, load default font instead - io.Fonts->AddFontDefault(); - } - io.Fonts->Build(); + ImFontConfig fontConfig{}; + // ToDo: further tweak font options, maybe try imgui_freetype + fontConfig.OversampleV = 2; + fontConfig.OversampleH = 4; + + // ToDo: improve font file test, checking if file exists is not enough + auto fileName = Options.FontFileName.c_str(); + auto fileHandle = fopenu(fileName, "rb"); + if (fileHandle) + { + fclose(fileHandle); + + // ToDo: Bind font size to UI scale + if (!io.Fonts->AddFontFromFileTTF(fileName, 13.f, &fontConfig, ranges.Data)) + io.Fonts->AddFontDefault(); + } + else + io.Fonts->AddFontDefault(); + + io.Fonts->Build(); ImGuiSDL::Initialize(renderer, 0, 0); }