Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/gui/ProjectMGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ void ProjectMGUI::Draw()
return;
}

if (_userScalingFactor != GetClampedUserScalingFactor())
{
UpdateFontSize();
}

ImGui_ImplSDL2_NewFrame();
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
Expand Down Expand Up @@ -218,9 +223,16 @@ float ProjectMGUI::GetScalingFactor()
SDL_GetWindowSize(_renderingWindow, &windowWidth, &windowHeight);
SDL_GL_GetDrawableSize(_renderingWindow, &renderWidth, &renderHeight);

_userScalingFactor = GetClampedUserScalingFactor();

// If the OS has a scaled UI, this will return the inverse factor. E.g. if the display is scaled to 200%,
// the renderWidth (in actual pixels) will be twice as much as the "virtual" unscaled window width.
return ((static_cast<float>(windowWidth) / static_cast<float>(renderWidth)) + (static_cast<float>(windowHeight) / static_cast<float>(renderHeight))) * 0.5f;
return ((static_cast<float>(windowWidth) / static_cast<float>(renderWidth)) + (static_cast<float>(windowHeight) / static_cast<float>(renderHeight))) * 0.5f * _userScalingFactor;
}

float ProjectMGUI::GetClampedUserScalingFactor()
{
return std::min(3.0f, std::max(0.1f, static_cast<float>(Poco::Util::Application::instance().config().getDouble("window.uiScale", 1.0))));
}

void ProjectMGUI::DisplayToastNotificationHandler(const Poco::AutoPtr<DisplayToastNotification>& notification)
Expand Down
5 changes: 4 additions & 1 deletion src/gui/ProjectMGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "AboutWindow.h"
#include "HelpWindow.h"
#include "MainMenu.h"
#include "ToastMessage.h"
#include "SettingsWindow.h"
#include "ToastMessage.h"

#include "notifications/DisplayToastNotification.h"

Expand Down Expand Up @@ -107,6 +107,8 @@ class ProjectMGUI : public Poco::Util::Subsystem
private:
float GetScalingFactor();

static float GetClampedUserScalingFactor();

void DisplayToastNotificationHandler(const Poco::AutoPtr<DisplayToastNotification>& notification);

ProjectMWrapper* _projectMWrapper{nullptr};
Expand All @@ -122,6 +124,7 @@ class ProjectMGUI : public Poco::Util::Subsystem

uint64_t _lastFrameTicks{0}; //!< Tick count of the last frame (see SDL_GetTicks64)

float _userScalingFactor{1.0f}; //!< The user-defined UI scaling factor.
float _textScalingFactor{0.0f}; //!< The text scaling factor.

MainMenu _mainMenu{*this};
Expand Down
Loading
Loading