2018-07-10 16:40:57 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
2018-12-08 21:15:20 +00:00
|
|
|
#include "ImGuiModuleSettings.h"
|
2018-11-24 19:54:01 +00:00
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
#include "ImGuiModuleCommands.h"
|
|
|
|
#include "ImGuiModuleProperties.h"
|
2018-11-24 19:54:01 +00:00
|
|
|
|
2020-06-14 20:50:26 +00:00
|
|
|
#include <Engine/Engine.h>
|
2020-06-14 19:21:49 +00:00
|
|
|
#include <GameFramework/GameUserSettings.h>
|
2020-06-25 09:52:46 +00:00
|
|
|
#include <Misc/ConfigCacheIni.h>
|
2020-06-14 19:21:49 +00:00
|
|
|
|
2018-11-24 19:54:01 +00:00
|
|
|
|
2020-06-07 22:18:14 +00:00
|
|
|
//====================================================================================================
|
|
|
|
// 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
|
|
|
|
{
|
2020-06-28 16:35:41 +00:00
|
|
|
float ResolutionBasedScale = 1.f;
|
2020-06-07 22:18:14 +00:00
|
|
|
if (bScaleWithCurve && GEngine && GEngine->GameUserSettings)
|
|
|
|
{
|
|
|
|
if (const FRichCurve* Curve = DPICurve.GetRichCurveConst())
|
|
|
|
{
|
|
|
|
ResolutionBasedScale *= Curve->Eval((float)GEngine->GameUserSettings->GetDesktopResolution().Y, 1.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ResolutionBasedScale;
|
|
|
|
}
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
//====================================================================================================
|
|
|
|
// UImGuiSettings
|
|
|
|
//====================================================================================================
|
2018-07-10 16:40:57 +00:00
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
UImGuiSettings* UImGuiSettings::DefaultInstance = nullptr;
|
2018-07-10 16:40:57 +00:00
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
FSimpleMulticastDelegate UImGuiSettings::OnSettingsLoaded;
|
2018-07-10 16:40:57 +00:00
|
|
|
|
2018-11-24 19:54:01 +00:00
|
|
|
void UImGuiSettings::PostInitProperties()
|
2018-07-30 21:05:59 +00:00
|
|
|
{
|
2018-11-24 19:54:01 +00:00
|
|
|
Super::PostInitProperties();
|
|
|
|
|
|
|
|
if (IsTemplate())
|
|
|
|
{
|
2018-12-08 21:03:18 +00:00
|
|
|
DefaultInstance = this;
|
|
|
|
OnSettingsLoaded.Broadcast();
|
2018-11-24 19:54:01 +00:00
|
|
|
}
|
2018-07-30 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 19:54:01 +00:00
|
|
|
void UImGuiSettings::BeginDestroy()
|
2018-07-30 21:05:59 +00:00
|
|
|
{
|
2018-11-24 19:54:01 +00:00
|
|
|
Super::BeginDestroy();
|
2018-07-30 21:05:59 +00:00
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
if (DefaultInstance == this)
|
2018-11-24 19:54:01 +00:00
|
|
|
{
|
2018-12-08 21:03:18 +00:00
|
|
|
DefaultInstance = nullptr;
|
2018-11-24 19:54:01 +00:00
|
|
|
}
|
2018-07-30 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
//====================================================================================================
|
|
|
|
// FImGuiModuleSettings
|
|
|
|
//====================================================================================================
|
|
|
|
|
|
|
|
FImGuiModuleSettings::FImGuiModuleSettings(FImGuiModuleProperties& InProperties, FImGuiModuleCommands& InCommands)
|
|
|
|
: Properties(InProperties)
|
|
|
|
, Commands(InCommands)
|
|
|
|
{
|
|
|
|
#if WITH_EDITOR
|
|
|
|
FCoreUObjectDelegates::OnObjectPropertyChanged.AddRaw(this, &FImGuiModuleSettings::OnPropertyChanged);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Delegate initializer to support settings loaded after this object creation (in stand-alone builds) and potential
|
|
|
|
// reloading of settings.
|
2020-06-07 22:18:14 +00:00
|
|
|
UImGuiSettings::OnSettingsLoaded.AddRaw(this, &FImGuiModuleSettings::InitializeAllSettings);
|
2018-12-08 21:03:18 +00:00
|
|
|
|
|
|
|
// Call initializer to support settings already loaded (editor).
|
2020-06-07 22:18:14 +00:00
|
|
|
InitializeAllSettings();
|
2018-12-08 21:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FImGuiModuleSettings::~FImGuiModuleSettings()
|
|
|
|
{
|
|
|
|
|
|
|
|
UImGuiSettings::OnSettingsLoaded.RemoveAll(this);
|
|
|
|
|
2018-07-10 16:40:57 +00:00
|
|
|
#if WITH_EDITOR
|
2018-12-08 21:03:18 +00:00
|
|
|
FCoreUObjectDelegates::OnObjectPropertyChanged.RemoveAll(this);
|
|
|
|
#endif
|
|
|
|
}
|
2018-07-10 16:40:57 +00:00
|
|
|
|
2020-06-07 22:18:14 +00:00
|
|
|
void FImGuiModuleSettings::InitializeAllSettings()
|
|
|
|
{
|
|
|
|
UpdateSettings();
|
|
|
|
UpdateDPIScaleInfo();
|
|
|
|
}
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
void FImGuiModuleSettings::UpdateSettings()
|
2018-07-10 16:40:57 +00:00
|
|
|
{
|
2018-12-08 21:03:18 +00:00
|
|
|
if (UImGuiSettings* SettingsObject = UImGuiSettings::Get())
|
2018-07-10 16:40:57 +00:00
|
|
|
{
|
2018-12-08 21:03:18 +00:00
|
|
|
SetImGuiInputHandlerClass(SettingsObject->ImGuiInputHandlerClass);
|
|
|
|
SetShareKeyboardInput(SettingsObject->bShareKeyboardInput);
|
|
|
|
SetShareGamepadInput(SettingsObject->bShareGamepadInput);
|
2019-07-08 19:46:28 +00:00
|
|
|
SetShareMouseInput(SettingsObject->bShareMouseInput);
|
2018-12-08 21:03:18 +00:00
|
|
|
SetUseSoftwareCursor(SettingsObject->bUseSoftwareCursor);
|
|
|
|
SetToggleInputKey(SettingsObject->ToggleInput);
|
2020-05-10 20:05:27 +00:00
|
|
|
SetCanvasSizeInfo(SettingsObject->CanvasSize);
|
2020-06-07 22:18:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiModuleSettings::UpdateDPIScaleInfo()
|
|
|
|
{
|
|
|
|
if (UImGuiSettings* SettingsObject = UImGuiSettings::Get())
|
|
|
|
{
|
2020-06-07 20:58:48 +00:00
|
|
|
SetDPIScaleInfo(SettingsObject->DPIScale);
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 18:46:21 +00:00
|
|
|
void FImGuiModuleSettings::SetImGuiInputHandlerClass(const FSoftClassPath& ClassReference)
|
2018-07-10 16:40:57 +00:00
|
|
|
{
|
2018-12-08 21:03:18 +00:00
|
|
|
if (ImGuiInputHandlerClass != ClassReference)
|
|
|
|
{
|
|
|
|
ImGuiInputHandlerClass = ClassReference;
|
|
|
|
OnImGuiInputHandlerClassChanged.Broadcast(ClassReference);
|
|
|
|
}
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
void FImGuiModuleSettings::SetShareKeyboardInput(bool bShare)
|
2018-07-10 16:40:57 +00:00
|
|
|
{
|
2018-12-08 21:03:18 +00:00
|
|
|
if (bShareKeyboardInput != bShare)
|
2018-07-10 16:40:57 +00:00
|
|
|
{
|
2018-12-08 21:03:18 +00:00
|
|
|
bShareKeyboardInput = bShare;
|
|
|
|
Properties.SetKeyboardInputShared(bShare);
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 21:05:59 +00:00
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
void FImGuiModuleSettings::SetShareGamepadInput(bool bShare)
|
|
|
|
{
|
|
|
|
if (bShareGamepadInput != bShare)
|
|
|
|
{
|
|
|
|
bShareGamepadInput = bShare;
|
|
|
|
Properties.SetGamepadInputShared(bShare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 19:46:28 +00:00
|
|
|
void FImGuiModuleSettings::SetShareMouseInput(bool bShare)
|
|
|
|
{
|
|
|
|
if (bShareMouseInput != bShare)
|
|
|
|
{
|
|
|
|
bShareMouseInput = bShare;
|
|
|
|
Properties.SetMouseInputShared(bShare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
void FImGuiModuleSettings::SetUseSoftwareCursor(bool bUse)
|
|
|
|
{
|
|
|
|
if (bUseSoftwareCursor != bUse)
|
|
|
|
{
|
|
|
|
bUseSoftwareCursor = bUse;
|
|
|
|
OnUseSoftwareCursorChanged.Broadcast(bUse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiModuleSettings::SetToggleInputKey(const FImGuiKeyInfo& KeyInfo)
|
|
|
|
{
|
|
|
|
if (ToggleInputKey != KeyInfo)
|
|
|
|
{
|
|
|
|
ToggleInputKey = KeyInfo;
|
|
|
|
Commands.SetKeyBinding(FImGuiModuleCommands::ToggleInput, ToggleInputKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-23 23:27:50 +00:00
|
|
|
void FImGuiModuleSettings::SetIsDockingEnabled(bool bDockingEnabled)
|
|
|
|
{
|
|
|
|
if (bIsDockingEnabled != bDockingEnabled)
|
|
|
|
{
|
|
|
|
bIsDockingEnabled = bDockingEnabled;
|
|
|
|
Properties.SetDockingEnabled(bDockingEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 20:05:27 +00:00
|
|
|
void FImGuiModuleSettings::SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo)
|
2020-04-16 12:08:32 +00:00
|
|
|
{
|
2020-05-10 20:05:27 +00:00
|
|
|
if (CanvasSize != CanvasSizeInfo)
|
2020-04-16 12:08:32 +00:00
|
|
|
{
|
2020-05-10 20:05:27 +00:00
|
|
|
CanvasSize = CanvasSizeInfo;
|
2020-06-07 20:58:48 +00:00
|
|
|
OnCanvasSizeChangedDelegate.Broadcast(CanvasSize);
|
2020-04-16 12:08:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 20:58:48 +00:00
|
|
|
void FImGuiModuleSettings::SetDPIScaleInfo(const FImGuiDPIScaleInfo& ScaleInfo)
|
2020-05-11 10:24:59 +00:00
|
|
|
{
|
2020-06-07 22:18:14 +00:00
|
|
|
DPIScale = ScaleInfo;
|
|
|
|
OnDPIScaleChangedDelegate.Broadcast(DPIScale);
|
2020-05-11 10:24:59 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
#if WITH_EDITOR
|
|
|
|
|
|
|
|
void FImGuiModuleSettings::OnPropertyChanged(class UObject* ObjectBeingModified, struct FPropertyChangedEvent& PropertyChangedEvent)
|
|
|
|
{
|
|
|
|
if (ObjectBeingModified == UImGuiSettings::Get())
|
|
|
|
{
|
|
|
|
UpdateSettings();
|
2020-06-07 22:18:14 +00:00
|
|
|
if (PropertyChangedEvent.MemberProperty
|
|
|
|
&& (PropertyChangedEvent.MemberProperty->GetFName() == GET_MEMBER_NAME_CHECKED(FImGuiModuleSettings, DPIScale)))
|
|
|
|
{
|
|
|
|
UpdateDPIScaleInfo();
|
|
|
|
}
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // WITH_EDITOR
|