Add UI scaling combobox with 4 options (one smaller than default, two larger) and experimental tag. (#3037)

This commit is contained in:
Malkierian 2023-11-05 19:21:44 -07:00 committed by GitHub
parent ecafa87195
commit 8745881815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 0 deletions

View File

@ -46,6 +46,7 @@
#include "variables.h"
#include "z64.h"
#include "macros.h"
#include "Fonts.h"
#include <Utils/StringHelper.h>
#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;
}

View File

@ -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<SaveStateMgr> gSaveStateMgr;
std::shared_ptr<Randomizer> 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();

View File

@ -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<LUS::WindowBackend, const char*> windowBackendNames = {
{ LUS::WindowBackend::DX11, "DirectX" },