From a1bf837a5e4d2523db300ccf8ffdbf6a8e35bfec Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Wed, 6 May 2020 22:56:08 +0100 Subject: [PATCH] dpi change will trigger ResizeLayout callback for render path --- Documentation/WickedEngine-Documentation.md | 2 +- Editor/Editor.cpp | 6 +++++- Editor/Editor.h | 1 + Tests/Tests.cpp | 4 ++-- Tests/Tests.h | 2 +- WickedEngine/RenderPath.cpp | 11 +++++++++++ WickedEngine/RenderPath.h | 5 ++++- WickedEngine/wiVersion.cpp | 2 +- 8 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Documentation/WickedEngine-Documentation.md b/Documentation/WickedEngine-Documentation.md index 33a5387a6..1e643730d 100644 --- a/Documentation/WickedEngine-Documentation.md +++ b/Documentation/WickedEngine-Documentation.md @@ -825,7 +825,7 @@ The custom GUI, implemented with engine features [[Header]](../WickedEngine/wiGUI.h) [[Cpp]](../WickedEngine/wiGUI.cpp) The wiGUI is responsible to run a GUI interface and manage widgets. -GUI Scaling: To ensure correct GUI scaling, GUI elements should be designed for the current window size. If they are placed inside `RenderPath2D::ResizeBuffers()` function according to current screen size, it will ensure that GUI will be scaled on a Resilution change event, which is recommended. +GUI Scaling: To ensure correct GUI scaling, GUI elements should be designed for the current window size. If they are placed inside `RenderPath2D::ResizeLayout()` function according to current screen size, it will ensure that GUI will be scaled on a Resolution or DPI change event, which is recommended. ### wiEventArgs [[Header]](../WickedEngine/wiWidget.h) [[Cpp]](../WickedEngine/wiWidget.cpp) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index a7622e719..c57474dac 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -206,7 +206,10 @@ void EditorComponent::ResizeBuffers() hr = device->CreateRenderPass(&desc, &renderpass_selectionOutline[1]); assert(SUCCEEDED(hr)); } - +} +void EditorComponent::ResizeLayout() +{ + __super::ResizeLayout(); // GUI elements scaling: @@ -724,6 +727,7 @@ void EditorComponent::Load() shaderButton->SetTooltip("Reload shaders from the default directory..."); shaderButton->SetColor(wiColor(255, 33, 140, 180), wiWidget::WIDGETSTATE::IDLE); shaderButton->SetColor(wiColor(255, 100, 140, 255), wiWidget::WIDGETSTATE::FOCUS); + shaderButton->font.params.size -= 2; shaderButton->OnClick([=](wiEventArgs args) { wiRenderer::ReloadShaders(); diff --git a/Editor/Editor.h b/Editor/Editor.h index e8c722e8b..38baf23c1 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -120,6 +120,7 @@ public: const wiGraphics::Texture* GetGUIBlurredBackground() const override { return renderPath->GetGUIBlurredBackground(); } void ResizeBuffers() override; + void ResizeLayout() override; void Load() override; void Start() override; void FixedUpdate() override; diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index c8c832d17..28e585a33 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -23,9 +23,9 @@ void Tests::Initialize() ActivatePath(&renderer); } -void TestsRenderer::ResizeBuffers() +void TestsRenderer::ResizeLayout() { - __super::ResizeBuffers(); + __super::ResizeLayout(); float screenW = wiRenderer::GetDevice()->GetScreenWidth(); float screenH = wiRenderer::GetDevice()->GetScreenHeight(); diff --git a/Tests/Tests.h b/Tests/Tests.h index aa8fff89a..21b7bca30 100644 --- a/Tests/Tests.h +++ b/Tests/Tests.h @@ -10,7 +10,7 @@ class TestsRenderer : public RenderPath3D_Deferred public: void Load() override; void Update(float dt) override; - void ResizeBuffers() override; + void ResizeLayout() override; void RunJobSystemTest(); void RunFontTest(); diff --git a/WickedEngine/RenderPath.cpp b/WickedEngine/RenderPath.cpp index 2ec40c93d..81331fe46 100644 --- a/WickedEngine/RenderPath.cpp +++ b/WickedEngine/RenderPath.cpp @@ -1,13 +1,24 @@ #include "RenderPath2D.h" #include "wiRenderer.h" +#include "wiPlatform.h" + +void RenderPath::ResizeLayout() +{ + dpi = wiPlatform::GetDPI(); +} void RenderPath::Update(float dt) { if (wiRenderer::ResolutionChanged() || !initial_resizebuffer) { ResizeBuffers(); + ResizeLayout(); initial_resizebuffer = true; } + if (dpi != wiPlatform::GetDPI()) + { + ResizeLayout(); + } } void RenderPath::Start() diff --git a/WickedEngine/RenderPath.h b/WickedEngine/RenderPath.h index b1733b9c0..ce60278e8 100644 --- a/WickedEngine/RenderPath.h +++ b/WickedEngine/RenderPath.h @@ -9,10 +9,13 @@ class RenderPath private: uint32_t layerMask = 0xFFFFFFFF; bool initial_resizebuffer = false; + uint32_t dpi = 0; protected: - // create resolution dependant resources + // create resolution dependant resources, such as render targets virtual void ResizeBuffers() {} + // update resolution dependent elements, such as elements dependent on current monitor DPI + virtual void ResizeLayout(); public: std::function onStart; std::function onStop; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 59d2e1b2e..8c56790d0 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 41; // minor bug fixes, alterations, refactors, updates - const int revision = 3; + const int revision = 4; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);