mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 08:20:32 +00:00
Added option for DPI scaling. Current implementation scales the widget in Slate and invert-scales the ImGui canvas size to maintain consistent size on the screen.
This commit is contained in:
parent
253eff0525
commit
8de65f3d34
@ -5,9 +5,11 @@ Versions marked as 'unofficial' are labelled only for the needs of this changelo
|
||||
Change History
|
||||
--------------
|
||||
|
||||
Version: 1.19 WIP (2020/03-04)
|
||||
Version: 1.19 (2020/03-04)
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
Version: 1.18 (2020/01)
|
||||
- Updated to engine version 4.24.
|
||||
|
@ -9,7 +9,7 @@ Dear ImGui is an immediate-mode graphical user interface library that is very li
|
||||
|
||||
Status
|
||||
------
|
||||
Version: 1.19 WIP
|
||||
Version: 1.19
|
||||
|
||||
ImGui version: 1.74
|
||||
|
||||
@ -236,7 +236,7 @@ There is a self-debug functionality build into this plugin. This is hidden by de
|
||||
- `ImGui.Debug.Input` - Show debug for input state.
|
||||
|
||||
### Settings
|
||||
Plugin settings can be found in *Project Settings/Plugins/ImGui* panel. Right now they amount to a few properties that customize input handling.
|
||||
Plugin settings can be found in *Project Settings/Plugins/ImGui* panel. There is a bunch of properties allowing to tweak input handling, keyboard shortcuts (one for now), canvas size and DPI scale.
|
||||
|
||||
##### Extensions
|
||||
- `ImGui Input Handler Class` - Path to own implementation of ImGui Input Handler that allows limited customization of the input handling. If not set, then the default implementation is used.
|
||||
|
@ -104,6 +104,7 @@ void FImGuiModuleSettings::UpdateSettings()
|
||||
SetUseSoftwareCursor(SettingsObject->bUseSoftwareCursor);
|
||||
SetToggleInputKey(SettingsObject->ToggleInput);
|
||||
SetCanvasSizeInfo(SettingsObject->CanvasSize);
|
||||
SetDPIScale(SettingsObject->DPIScale);
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,6 +171,15 @@ void FImGuiModuleSettings::SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasS
|
||||
}
|
||||
}
|
||||
|
||||
void FImGuiModuleSettings::SetDPIScale(float Scale)
|
||||
{
|
||||
if (DPIScale != Scale)
|
||||
{
|
||||
DPIScale = Scale;
|
||||
OnDPIScaleChangeDelegate.Broadcast(DPIScale);
|
||||
}
|
||||
}
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
void FImGuiModuleSettings::OnPropertyChanged(class UObject* ObjectBeingModified, struct FPropertyChangedEvent& PropertyChangedEvent)
|
||||
|
@ -148,6 +148,14 @@ protected:
|
||||
UPROPERTY(EditAnywhere, config, Category = "Canvas Size")
|
||||
FImGuiCanvasSizeInfo CanvasSize;
|
||||
|
||||
// DPI scale for the ImGui widgets.
|
||||
//
|
||||
// Note that when this scale is other than 1.0, canvas size will be scaled before it is passed to the ImGui.
|
||||
// It will be scaled to keep the same screen size as defined by the Canvas Size property. If the default
|
||||
// canvas size is 3840x2160 and the DPI scale is 2.0, the size passed to the ImGui will be 1920x1080.
|
||||
UPROPERTY(EditAnywhere, Category = "DPI Scale", meta = (ClampMin = 0, UIMin = 0))
|
||||
float DPIScale = 1.f;
|
||||
|
||||
// Deprecated name for ToggleInput. Kept temporarily to automatically move old configuration.
|
||||
UPROPERTY(config)
|
||||
FImGuiKeyInfo SwitchInputModeKey_DEPRECATED;
|
||||
@ -170,6 +178,7 @@ public:
|
||||
|
||||
// Generic delegate used to notify changes of boolean properties.
|
||||
DECLARE_MULTICAST_DELEGATE_OneParam(FBoolChangeDelegate, bool);
|
||||
DECLARE_MULTICAST_DELEGATE_OneParam(FFloatChangeDelegate, float);
|
||||
DECLARE_MULTICAST_DELEGATE_OneParam(FStringClassReferenceChangeDelegate, const FStringClassReference&);
|
||||
DECLARE_MULTICAST_DELEGATE_OneParam(FImGuiCanvasSizeInfoChangeDelegate, const FImGuiCanvasSizeInfo&);
|
||||
|
||||
@ -197,6 +206,9 @@ public:
|
||||
// Get the information how to calculate the canvas size.
|
||||
const FImGuiCanvasSizeInfo& GetCanvasSizeInfo() const { return CanvasSize; }
|
||||
|
||||
// Get the DPI Scale.
|
||||
float GetDPIScale() const { return DPIScale; }
|
||||
|
||||
// Delegate raised when ImGui Input Handle is changed.
|
||||
FStringClassReferenceChangeDelegate OnImGuiInputHandlerClassChanged;
|
||||
|
||||
@ -206,6 +218,9 @@ public:
|
||||
// Delegate raised when information how to calculate the canvas size is changed.
|
||||
FImGuiCanvasSizeInfoChangeDelegate OnCanvasSizeInfoChangeDelegate;
|
||||
|
||||
// Delegate raised when the DPI scale is changed.
|
||||
FFloatChangeDelegate OnDPIScaleChangeDelegate;
|
||||
|
||||
private:
|
||||
|
||||
void UpdateSettings();
|
||||
@ -217,6 +232,7 @@ private:
|
||||
void SetUseSoftwareCursor(bool bUse);
|
||||
void SetToggleInputKey(const FImGuiKeyInfo& KeyInfo);
|
||||
void SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo);
|
||||
void SetDPIScale(float DPIScale);
|
||||
|
||||
#if WITH_EDITOR
|
||||
void OnPropertyChanged(class UObject* ObjectBeingModified, struct FPropertyChangedEvent& PropertyChangedEvent);
|
||||
@ -228,6 +244,7 @@ private:
|
||||
FStringClassReference ImGuiInputHandlerClass;
|
||||
FImGuiKeyInfo ToggleInputKey;
|
||||
FImGuiCanvasSizeInfo CanvasSize;
|
||||
float DPIScale = 1.f;
|
||||
bool bShareKeyboardInput = false;
|
||||
bool bShareGamepadInput = false;
|
||||
bool bShareMouseInput = false;
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "SImGuiLayout.h"
|
||||
#include "SImGuiWidget.h"
|
||||
|
||||
#include "ImGuiModuleManager.h"
|
||||
|
||||
#include <Widgets/Layout/SConstraintCanvas.h>
|
||||
#include <Widgets/Layout/SDPIScaler.h>
|
||||
#include <Widgets/Layout/SScaleBox.h>
|
||||
@ -15,9 +17,18 @@ void SImGuiLayout::Construct(const FArguments& InArgs)
|
||||
{
|
||||
checkf(InArgs._GameViewport, TEXT("Null Game Viewport argument"));
|
||||
|
||||
ModuleManager = InArgs._ModuleManager;
|
||||
GameViewport = InArgs._GameViewport;
|
||||
|
||||
// TODO: Remove instantiation of ImGui Widget outside of this class.
|
||||
if (ModuleManager)
|
||||
{
|
||||
auto& Settings = ModuleManager->GetSettings();
|
||||
SetDPIScale(Settings.GetDPIScale());
|
||||
if (!Settings.OnDPIScaleChangeDelegate.IsBoundToObject(this))
|
||||
{
|
||||
Settings.OnDPIScaleChangeDelegate.AddRaw(this, &SImGuiLayout::SetDPIScale);
|
||||
}
|
||||
}
|
||||
|
||||
ChildSlot
|
||||
[
|
||||
@ -28,10 +39,9 @@ void SImGuiLayout::Construct(const FArguments& InArgs)
|
||||
.VAlign(VAlign_Fill)
|
||||
.Visibility(EVisibility::SelfHitTestInvisible)
|
||||
[
|
||||
// Apply custom scale if necessary.
|
||||
// TODO: Bind to relevant parameter.
|
||||
// Apply custom scale if needed.
|
||||
SNew(SDPIScaler)
|
||||
.DPIScale(1.f)
|
||||
.DPIScale(TAttribute<float>(this, &SImGuiLayout::GetDPIScale))
|
||||
.Visibility(EVisibility::SelfHitTestInvisible)
|
||||
[
|
||||
SNew(SConstraintCanvas)
|
||||
@ -56,4 +66,13 @@ void SImGuiLayout::Construct(const FArguments& InArgs)
|
||||
|
||||
SetVisibility(EVisibility::SelfHitTestInvisible);
|
||||
}
|
||||
|
||||
SImGuiLayout::~SImGuiLayout()
|
||||
{
|
||||
if (ModuleManager)
|
||||
{
|
||||
ModuleManager->GetSettings().OnDPIScaleChangeDelegate.RemoveAll(this);
|
||||
}
|
||||
}
|
||||
|
||||
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
||||
|
@ -24,9 +24,18 @@ public:
|
||||
|
||||
void Construct(const FArguments& InArgs);
|
||||
|
||||
~SImGuiLayout();
|
||||
|
||||
const TWeakObjectPtr<UGameViewportClient>& GetGameViewport() const { return GameViewport; }
|
||||
|
||||
private:
|
||||
|
||||
float GetDPIScale() const { return DPIScale; }
|
||||
void SetDPIScale(float Scale) { DPIScale = Scale; }
|
||||
|
||||
|
||||
FImGuiModuleManager* ModuleManager = nullptr;
|
||||
TWeakObjectPtr<UGameViewportClient> GameViewport;
|
||||
|
||||
float DPIScale = 1.f;
|
||||
};
|
||||
|
@ -84,6 +84,7 @@ void SImGuiWidget::Construct(const FArguments& InArgs)
|
||||
const auto& Settings = ModuleManager->GetSettings();
|
||||
SetHideMouseCursor(Settings.UseSoftwareCursor());
|
||||
CreateInputHandler(Settings.GetImGuiInputHandlerClass());
|
||||
SetDPIScale(Settings.GetDPIScale());
|
||||
SetCanvasSizeInfo(Settings.GetCanvasSizeInfo());
|
||||
|
||||
// Initialize state.
|
||||
@ -283,6 +284,10 @@ void SImGuiWidget::RegisterImGuiSettingsDelegates()
|
||||
{
|
||||
Settings.OnUseSoftwareCursorChanged.AddRaw(this, &SImGuiWidget::SetHideMouseCursor);
|
||||
}
|
||||
if (!Settings.OnDPIScaleChangeDelegate.IsBoundToObject(this))
|
||||
{
|
||||
Settings.OnDPIScaleChangeDelegate.AddRaw(this, &SImGuiWidget::SetDPIScale);
|
||||
}
|
||||
if (!Settings.OnCanvasSizeInfoChangeDelegate.IsBoundToObject(this))
|
||||
{
|
||||
Settings.OnCanvasSizeInfoChangeDelegate.AddRaw(this, &SImGuiWidget::SetCanvasSizeInfo);
|
||||
@ -295,6 +300,7 @@ void SImGuiWidget::UnregisterImGuiSettingsDelegates()
|
||||
|
||||
Settings.OnImGuiInputHandlerClassChanged.RemoveAll(this);
|
||||
Settings.OnUseSoftwareCursorChanged.RemoveAll(this);
|
||||
Settings.OnDPIScaleChangeDelegate.RemoveAll(this);
|
||||
Settings.OnCanvasSizeInfoChangeDelegate.RemoveAll(this);
|
||||
}
|
||||
|
||||
@ -503,6 +509,15 @@ void SImGuiWidget::HandleWindowFocusLost()
|
||||
}
|
||||
}
|
||||
|
||||
void SImGuiWidget::SetDPIScale(float Scale)
|
||||
{
|
||||
if (DPIScale != Scale)
|
||||
{
|
||||
DPIScale = Scale;
|
||||
bUpdateCanvasSize = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SImGuiWidget::SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo)
|
||||
{
|
||||
switch (CanvasSizeInfo.SizeType)
|
||||
@ -535,7 +550,6 @@ void SImGuiWidget::SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo)
|
||||
}
|
||||
|
||||
bUpdateCanvasSize = true;
|
||||
UpdateCanvasSize();
|
||||
}
|
||||
|
||||
void SImGuiWidget::UpdateCanvasSize()
|
||||
@ -557,6 +571,10 @@ void SImGuiWidget::UpdateCanvasSize()
|
||||
bUpdateCanvasSize = false;
|
||||
}
|
||||
|
||||
// Clamping DPI Scale to keep the canvas size from getting too big.
|
||||
CanvasSize /= FMath::Max(DPIScale, 0.01f);
|
||||
CanvasSize = CanvasSize.RoundToVector();
|
||||
|
||||
ContextProxy->SetDisplaySize(CanvasSize);
|
||||
}
|
||||
}
|
||||
@ -820,6 +838,7 @@ void SImGuiWidget::OnDebugDraw()
|
||||
TwoColumns::Value("Is Updating", bUpdateCanvasSize);
|
||||
TwoColumns::ValueWidthHeight("Min Canvas Size", MinCanvasSize);
|
||||
TwoColumns::ValueWidthHeight("Canvas Size", CanvasSize);
|
||||
TwoColumns::Value("DPI Scale", DPIScale);
|
||||
});
|
||||
|
||||
TwoColumns::CollapsingGroup("Context", [&]()
|
||||
|
@ -103,6 +103,8 @@ private:
|
||||
void UpdateTransparentMouseInput(const FGeometry& AllottedGeometry);
|
||||
void HandleWindowFocusLost();
|
||||
|
||||
void SetDPIScale(float Scale);
|
||||
|
||||
void SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo);
|
||||
void UpdateCanvasSize();
|
||||
|
||||
@ -137,6 +139,8 @@ private:
|
||||
FVector2D MinCanvasSize = FVector2D::ZeroVector;
|
||||
FVector2D CanvasSize = FVector2D::ZeroVector;
|
||||
|
||||
float DPIScale = 1.f;
|
||||
|
||||
bool bInputEnabled = false;
|
||||
bool bForegroundWindow = false;
|
||||
bool bHideMouseCursor = true;
|
||||
|
Loading…
Reference in New Issue
Block a user