diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index b96b364dd..c9dc1aa07 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -46,6 +46,7 @@ #include "variables.h" #include "z64.h" #include "macros.h" +#include "Fonts.h" #include #include "Enhancements/custom-message/CustomMessageManager.h" @@ -129,6 +130,8 @@ Color_RGB8 kokiriColor = { 0x1E, 0x69, 0x1B }; Color_RGB8 goronColor = { 0x64, 0x14, 0x00 }; Color_RGB8 zoraColor = { 0x00, 0xEC, 0x64 }; +float previousImGuiScale; + // Same as NaviColor type from OoT src (z_actor.c), but modified to be sans alpha channel for Controller LED. typedef struct { Color_RGB8 inner; @@ -298,6 +301,12 @@ OTRGlobals::OTRGlobals() { hasMasterQuest = hasOriginal = false; + previousImGuiScale = defaultImGuiScale; + defaultFontSmaller = CreateDefaultFontWithSize(10.0f); + defaultFontLarger = CreateDefaultFontWithSize(16.0f); + defaultFontLargest = CreateDefaultFontWithSize(20.0f); + ScaleImGui(); + // Move the camera strings from read only memory onto the heap (writable memory) // This is in OTRGlobals right now because this is a place that will only ever be run once at the beginning of startup. // We should probably find some code in db_camera that does initialization and only run once, and then dealloc on deinitialization. @@ -352,6 +361,32 @@ OTRGlobals::OTRGlobals() { OTRGlobals::~OTRGlobals() { } +void OTRGlobals::ScaleImGui() { + float scale = imguiScaleOptionToValue[CVarGetInteger("gImGuiScale", defaultImGuiScale)]; + float newScale = scale / previousImGuiScale; + ImGui::GetStyle().ScaleAllSizes(newScale); + ImGui::GetIO().FontGlobalScale = scale; + previousImGuiScale = scale; +} + +ImFont* OTRGlobals::CreateDefaultFontWithSize(float size) { + auto mImGuiIo = &ImGui::GetIO(); + ImFontConfig fontCfg = ImFontConfig(); + fontCfg.OversampleH = fontCfg.OversampleV = 1; + fontCfg.PixelSnapH = true; + fontCfg.SizePixels = size; + ImFont* font = mImGuiIo->Fonts->AddFontDefault(&fontCfg); + // FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly + float iconFontSize = size * 2.0f / 3.0f; + static const ImWchar sIconsRanges[] = { ICON_MIN_FA, ICON_MAX_16_FA, 0 }; + ImFontConfig iconsConfig; + iconsConfig.MergeMode = true; + iconsConfig.PixelSnapH = true; + iconsConfig.GlyphMinAdvanceX = iconFontSize; + mImGuiIo->Fonts->AddFontFromMemoryCompressedBase85TTF(fontawesome_compressed_data_base85, iconFontSize, &iconsConfig, sIconsRanges); + return font; +} + bool OTRGlobals::HasMasterQuest() { return hasMasterQuest; } diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index b24f59d8b..82659dbc4 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -21,6 +21,14 @@ const std::string customMessageTableID = "BaseGameOverrides"; const std::string appShortName = "soh"; +#ifdef __WIIU__ +const uint32_t defaultImGuiScale = 3; +#else +const uint32_t defaultImGuiScale = 1; +#endif + +const float imguiScaleOptionToValue[4] = { 0.75f, 1.0f, 1.5f, 2.0f }; + class OTRGlobals { public: @@ -30,8 +38,14 @@ public: std::shared_ptr gSaveStateMgr; std::shared_ptr gRandomizer; + ImFont* defaultFontSmaller; + ImFont* defaultFontLarger; + ImFont* defaultFontLargest; + OTRGlobals(); ~OTRGlobals(); + + void ScaleImGui(); bool HasMasterQuest(); bool HasOriginal(); @@ -42,6 +56,7 @@ private: void CheckSaveFile(size_t sramSize) const; bool hasMasterQuest; bool hasOriginal; + ImFont* CreateDefaultFontWithSize(float size); }; uint32_t IsGameMasterQuest(); diff --git a/soh/soh/SohMenuBar.cpp b/soh/soh/SohMenuBar.cpp index ceccb1173..a5fc12299 100644 --- a/soh/soh/SohMenuBar.cpp +++ b/soh/soh/SohMenuBar.cpp @@ -51,6 +51,8 @@ std::string GetWindowButtonText(const char* text, bool menuOpen) { return buttonText; } +static const char* imguiScaleOptions[4] = { "Small", "Normal", "Large", "X-Large" }; + static const char* filters[3] = { #ifdef __WIIU__ "", @@ -380,7 +382,15 @@ void DrawSettingsMenu() { } UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f); + ImGui::Text("ImGui Menu Scale"); + ImGui::SameLine(); + ImGui::TextColored({ 0.85f, 0.35f, 0.0f, 1.0f }, "(Experimental)"); + if (UIWidgets::EnhancementCombobox("gImGuiScale", imguiScaleOptions, 1)) { + OTRGlobals::Instance->ScaleImGui(); + } + UIWidgets::Tooltip("Changes the scaling of the ImGui menu elements."); + UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f); static std::unordered_map windowBackendNames = { { LUS::WindowBackend::DX11, "DirectX" },