mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 08:20:32 +00:00
Added support for curve-based DPI scaling.
This commit is contained in:
parent
9d4eb74bf0
commit
48be56de64
@ -5,11 +5,11 @@ Versions marked as 'unofficial' are labelled only for the needs of this changelo
|
|||||||
Change History
|
Change History
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Version: 1.19 (2020/03-04)
|
Version: 1.19 (2020/03-06)
|
||||||
- Integrated fix for issue with ImGui popup/modal windows not being able to be closed in transparent mouse input mode.
|
- Integrated fix for issue with ImGui popup/modal windows not being able to be closed in transparent mouse input mode.
|
||||||
- Integrated first version of Adaptive Canvas Size.
|
- Integrated first version of Adaptive Canvas Size.
|
||||||
- Added different options to define canvas size, with Adaptive Canvas Size being one of the options (viewport).
|
- Added different options to define canvas size, with Adaptive Canvas Size being one of the options (viewport).
|
||||||
- Added option for DPI scaling. Current implementation scales the whole Slate widget and invert-scales the ImGui canvas size to maintain consistent size on the screen.
|
- Added option for DPI scaling.
|
||||||
|
|
||||||
Version: 1.18 (2020/01)
|
Version: 1.18 (2020/01)
|
||||||
- Updated to engine version 4.24.
|
- Updated to engine version 4.24.
|
||||||
|
@ -8,6 +8,37 @@
|
|||||||
#include "ImGuiModuleProperties.h"
|
#include "ImGuiModuleProperties.h"
|
||||||
|
|
||||||
|
|
||||||
|
//====================================================================================================
|
||||||
|
// FImGuiDPIScaleInfo
|
||||||
|
//====================================================================================================
|
||||||
|
|
||||||
|
FImGuiDPIScaleInfo::FImGuiDPIScaleInfo()
|
||||||
|
{
|
||||||
|
if (FRichCurve* Curve = DPICurve.GetRichCurve())
|
||||||
|
{
|
||||||
|
Curve->AddKey( 0.0f, 1.f);
|
||||||
|
|
||||||
|
Curve->AddKey(2159.5f, 1.f);
|
||||||
|
Curve->AddKey(2160.0f, 2.f);
|
||||||
|
|
||||||
|
Curve->AddKey(4319.5f, 2.f);
|
||||||
|
Curve->AddKey(4320.0f, 4.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float FImGuiDPIScaleInfo::CalculateResolutionBasedScale() const
|
||||||
|
{
|
||||||
|
float ResolutionBasedScale = Scale;
|
||||||
|
if (bScaleWithCurve && GEngine && GEngine->GameUserSettings)
|
||||||
|
{
|
||||||
|
if (const FRichCurve* Curve = DPICurve.GetRichCurveConst())
|
||||||
|
{
|
||||||
|
ResolutionBasedScale *= Curve->Eval((float)GEngine->GameUserSettings->GetDesktopResolution().Y, 1.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ResolutionBasedScale;
|
||||||
|
}
|
||||||
|
|
||||||
//====================================================================================================
|
//====================================================================================================
|
||||||
// UImGuiSettings
|
// UImGuiSettings
|
||||||
//====================================================================================================
|
//====================================================================================================
|
||||||
@ -77,10 +108,10 @@ FImGuiModuleSettings::FImGuiModuleSettings(FImGuiModuleProperties& InProperties,
|
|||||||
|
|
||||||
// Delegate initializer to support settings loaded after this object creation (in stand-alone builds) and potential
|
// Delegate initializer to support settings loaded after this object creation (in stand-alone builds) and potential
|
||||||
// reloading of settings.
|
// reloading of settings.
|
||||||
UImGuiSettings::OnSettingsLoaded.AddRaw(this, &FImGuiModuleSettings::UpdateSettings);
|
UImGuiSettings::OnSettingsLoaded.AddRaw(this, &FImGuiModuleSettings::InitializeAllSettings);
|
||||||
|
|
||||||
// Call initializer to support settings already loaded (editor).
|
// Call initializer to support settings already loaded (editor).
|
||||||
UpdateSettings();
|
InitializeAllSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
FImGuiModuleSettings::~FImGuiModuleSettings()
|
FImGuiModuleSettings::~FImGuiModuleSettings()
|
||||||
@ -93,6 +124,12 @@ FImGuiModuleSettings::~FImGuiModuleSettings()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FImGuiModuleSettings::InitializeAllSettings()
|
||||||
|
{
|
||||||
|
UpdateSettings();
|
||||||
|
UpdateDPIScaleInfo();
|
||||||
|
}
|
||||||
|
|
||||||
void FImGuiModuleSettings::UpdateSettings()
|
void FImGuiModuleSettings::UpdateSettings()
|
||||||
{
|
{
|
||||||
if (UImGuiSettings* SettingsObject = UImGuiSettings::Get())
|
if (UImGuiSettings* SettingsObject = UImGuiSettings::Get())
|
||||||
@ -104,6 +141,13 @@ void FImGuiModuleSettings::UpdateSettings()
|
|||||||
SetUseSoftwareCursor(SettingsObject->bUseSoftwareCursor);
|
SetUseSoftwareCursor(SettingsObject->bUseSoftwareCursor);
|
||||||
SetToggleInputKey(SettingsObject->ToggleInput);
|
SetToggleInputKey(SettingsObject->ToggleInput);
|
||||||
SetCanvasSizeInfo(SettingsObject->CanvasSize);
|
SetCanvasSizeInfo(SettingsObject->CanvasSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FImGuiModuleSettings::UpdateDPIScaleInfo()
|
||||||
|
{
|
||||||
|
if (UImGuiSettings* SettingsObject = UImGuiSettings::Get())
|
||||||
|
{
|
||||||
SetDPIScaleInfo(SettingsObject->DPIScale);
|
SetDPIScaleInfo(SettingsObject->DPIScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,11 +217,8 @@ void FImGuiModuleSettings::SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasS
|
|||||||
|
|
||||||
void FImGuiModuleSettings::SetDPIScaleInfo(const FImGuiDPIScaleInfo& ScaleInfo)
|
void FImGuiModuleSettings::SetDPIScaleInfo(const FImGuiDPIScaleInfo& ScaleInfo)
|
||||||
{
|
{
|
||||||
if (DPIScale != ScaleInfo)
|
|
||||||
{
|
|
||||||
DPIScale = ScaleInfo;
|
DPIScale = ScaleInfo;
|
||||||
OnDPIScaleChangedDelegate.Broadcast(DPIScale);
|
OnDPIScaleChangedDelegate.Broadcast(DPIScale);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WITH_EDITOR
|
#if WITH_EDITOR
|
||||||
@ -187,6 +228,11 @@ void FImGuiModuleSettings::OnPropertyChanged(class UObject* ObjectBeingModified,
|
|||||||
if (ObjectBeingModified == UImGuiSettings::Get())
|
if (ObjectBeingModified == UImGuiSettings::Get())
|
||||||
{
|
{
|
||||||
UpdateSettings();
|
UpdateSettings();
|
||||||
|
if (PropertyChangedEvent.MemberProperty
|
||||||
|
&& (PropertyChangedEvent.MemberProperty->GetFName() == GET_MEMBER_NAME_CHECKED(FImGuiModuleSettings, DPIScale)))
|
||||||
|
{
|
||||||
|
UpdateDPIScaleInfo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Curves/CurveFloat.h>
|
||||||
#include <Delegates/Delegate.h>
|
#include <Delegates/Delegate.h>
|
||||||
#include <UObject/Object.h>
|
#include <UObject/Object.h>
|
||||||
|
|
||||||
@ -111,24 +112,34 @@ protected:
|
|||||||
UPROPERTY(EditAnywhere, Category = "DPI Scale")
|
UPROPERTY(EditAnywhere, Category = "DPI Scale")
|
||||||
EImGuiDPIScaleMethod ScalingMethod = EImGuiDPIScaleMethod::ImGui;
|
EImGuiDPIScaleMethod ScalingMethod = EImGuiDPIScaleMethod::ImGui;
|
||||||
|
|
||||||
// Fixed scale.
|
// An optional scale to apply on top or instead of the curve-based scale.
|
||||||
UPROPERTY(EditAnywhere, Category = "DPI Scale", meta = (ClampMin = 0, UIMin = 0))
|
UPROPERTY(EditAnywhere, Category = "DPI Scale", meta = (ClampMin = 0, UIMin = 0))
|
||||||
float Scale = 1.f;
|
float Scale = 1.f;
|
||||||
|
|
||||||
|
// Curve mapping resolution height to scale.
|
||||||
|
UPROPERTY(config, EditAnywhere, Category = "DPI Scale", meta = (XAxisName = "Resolution Height", YAxisName = "Scale", EditCondition = "bScaleWithCurve"))
|
||||||
|
FRuntimeFloatCurve DPICurve;
|
||||||
|
|
||||||
|
// Whether to use curve-based scaling. If enabled, Scale will be multiplied by a value read from the DPICurve.
|
||||||
|
// If disabled, only the Scale property will be used.
|
||||||
|
UPROPERTY(config, EditAnywhere, Category = "DPI Scale")
|
||||||
|
bool bScaleWithCurve = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
float GetImGuiScale() const { return ShouldScaleInSlate() ? 1.f : Scale; }
|
FImGuiDPIScaleInfo();
|
||||||
|
|
||||||
float GetSlateScale() const { return ShouldScaleInSlate() ? Scale : 1.f; }
|
float GetImGuiScale() const { return ShouldScaleInSlate() ? 1.f : CalculateScale(); }
|
||||||
|
|
||||||
|
float GetSlateScale() const { return ShouldScaleInSlate() ? CalculateScale() : 1.f; }
|
||||||
|
|
||||||
bool ShouldScaleInSlate() const { return ScalingMethod == EImGuiDPIScaleMethod::Slate; }
|
bool ShouldScaleInSlate() const { return ScalingMethod == EImGuiDPIScaleMethod::Slate; }
|
||||||
|
|
||||||
bool operator==(const FImGuiDPIScaleInfo& Other) const
|
private:
|
||||||
{
|
|
||||||
return (Scale == Other.Scale) && (ScalingMethod == Other.ScalingMethod);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const FImGuiDPIScaleInfo& Other) const { return !(*this == Other); }
|
float CalculateScale() const { return Scale * CalculateResolutionBasedScale(); }
|
||||||
|
|
||||||
|
float CalculateResolutionBasedScale() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// UObject used for loading and saving ImGui settings. To access actual settings use FImGuiModuleSettings interface.
|
// UObject used for loading and saving ImGui settings. To access actual settings use FImGuiModuleSettings interface.
|
||||||
@ -262,7 +273,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void InitializeAllSettings();
|
||||||
void UpdateSettings();
|
void UpdateSettings();
|
||||||
|
void UpdateDPIScaleInfo();
|
||||||
|
|
||||||
void SetImGuiInputHandlerClass(const FStringClassReference& ClassReference);
|
void SetImGuiInputHandlerClass(const FStringClassReference& ClassReference);
|
||||||
void SetShareKeyboardInput(bool bShare);
|
void SetShareKeyboardInput(bool bShare);
|
||||||
|
Loading…
Reference in New Issue
Block a user