2018-07-10 16:40:57 +00:00
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
# pragma once
2020-06-14 20:50:26 +00:00
# include "VersionCompatibility.h"
2020-06-07 22:18:14 +00:00
# include <Curves/CurveFloat.h>
2018-07-10 16:40:57 +00:00
# include <Delegates/Delegate.h>
2020-06-25 09:52:46 +00:00
# include <InputCoreTypes.h>
# include <Styling/SlateTypes.h>
2018-07-10 16:40:57 +00:00
# include <UObject/Object.h>
2022-03-01 18:46:21 +00:00
// We use FSoftClassPath, which is supported by older and newer engine versions. Starting from 4.18, it is
2020-06-14 20:50:26 +00:00
// a typedef of FSoftClassPath, which is also recognized by UHT.
# if ENGINE_COMPATIBILITY_LEGACY_STRING_CLASS_REF
# include <StringClassReference.h>
# else
# include <UObject/SoftObjectPath.h>
# endif
2018-12-08 21:15:20 +00:00
# include "ImGuiModuleSettings.generated.h"
2018-07-10 16:40:57 +00:00
2018-07-30 21:05:59 +00:00
/**
* Struct containing key information that can be used for key binding . Using ' Undetermined ' value for modifier keys
* means that those keys should be ignored when testing for a match .
*/
USTRUCT ( )
struct FImGuiKeyInfo
{
GENERATED_BODY ( )
2019-07-27 17:06:29 +00:00
UPROPERTY ( EditAnywhere , Category = " Input " )
2018-07-30 21:05:59 +00:00
FKey Key ;
2019-07-27 17:06:29 +00:00
UPROPERTY ( EditAnywhere , Category = " Input " )
2018-07-30 21:05:59 +00:00
ECheckBoxState Shift = ECheckBoxState : : Undetermined ;
2019-07-27 17:06:29 +00:00
UPROPERTY ( EditAnywhere , Category = " Input " )
2018-07-30 21:05:59 +00:00
ECheckBoxState Ctrl = ECheckBoxState : : Undetermined ;
2019-07-27 17:06:29 +00:00
UPROPERTY ( EditAnywhere , Category = " Input " )
2018-07-30 21:05:59 +00:00
ECheckBoxState Alt = ECheckBoxState : : Undetermined ;
2019-07-27 17:06:29 +00:00
UPROPERTY ( EditAnywhere , Category = " Input " )
2018-07-30 21:05:59 +00:00
ECheckBoxState Cmd = ECheckBoxState : : Undetermined ;
2018-12-08 21:03:18 +00:00
friend bool operator = = ( const FImGuiKeyInfo & Lhs , const FImGuiKeyInfo & Rhs )
{
return Lhs . Key = = Rhs . Key
& & Lhs . Shift = = Rhs . Shift
& & Lhs . Ctrl = = Rhs . Ctrl
& & Lhs . Alt = = Rhs . Alt
& & Lhs . Cmd = = Rhs . Cmd ;
}
friend bool operator ! = ( const FImGuiKeyInfo & Lhs , const FImGuiKeyInfo & Rhs )
{
return ! ( Lhs = = Rhs ) ;
}
2018-07-30 21:05:59 +00:00
} ;
2020-05-10 20:05:27 +00:00
UENUM ( BlueprintType )
enum class EImGuiCanvasSizeType : uint8
{
Custom UMETA ( ToolTip = " Canvas will have a custom width and height. " ) ,
Desktop UMETA ( ToolTip = " Canvas will have the same width and height as the desktop. " ) ,
Viewport UMETA ( ToolTip = " Canvas will always have the same width and height as the viewport. " ) ,
} ;
/**
* Struct with information how to calculate canvas size .
*/
USTRUCT ( )
struct FImGuiCanvasSizeInfo
{
GENERATED_BODY ( )
// Select how to specify canvas size.
UPROPERTY ( EditAnywhere , Category = " Canvas Size " )
EImGuiCanvasSizeType SizeType = EImGuiCanvasSizeType : : Desktop ;
// Custom canvas width.
UPROPERTY ( EditAnywhere , Category = " Canvas Size " , meta = ( ClampMin = 0 , UIMin = 0 ) )
int32 Width = 3840 ;
// Custom canvas height.
UPROPERTY ( EditAnywhere , Category = " Canvas Size " , meta = ( ClampMin = 0 , UIMin = 0 ) )
int32 Height = 2160 ;
// If this is true, canvas width or height may be extended, if the viewport size is larger.
UPROPERTY ( EditAnywhere , Category = " Canvas Size " , meta = ( ClampMin = 0 , UIMin = 0 ) )
bool bExtendToViewport = true ;
bool operator = = ( const FImGuiCanvasSizeInfo & Other ) const
{
return ( SizeType = = Other . SizeType ) & & ( Width = = Other . Width )
& & ( Height = = Other . Height ) & & ( bExtendToViewport = = Other . bExtendToViewport ) ;
}
bool operator ! = ( const FImGuiCanvasSizeInfo & Other ) const { return ! ( * this = = Other ) ; }
} ;
2020-06-07 20:58:48 +00:00
UENUM ( BlueprintType )
enum class EImGuiDPIScaleMethod : uint8
{
ImGui UMETA ( DisplayName = " ImGui " , ToolTip = " Scale ImGui fonts and styles. " ) ,
Slate UMETA ( ToolTip = " Scale in Slate. ImGui canvas size will be adjusted to get the screen size that is the same as defined in the Canvas Size property. " )
} ;
/**
* Struct with DPI scale data .
*/
USTRUCT ( )
struct FImGuiDPIScaleInfo
{
GENERATED_BODY ( )
protected :
// Whether to scale in ImGui or in Slate. Scaling in ImGui gives better looking results but Slate might be a better
// option when layouts do not account for different fonts and styles. When scaling in Slate, ImGui canvas size will
// be adjusted to get the screen size that is the same as defined in the Canvas Size property.
UPROPERTY ( EditAnywhere , Category = " DPI Scale " )
EImGuiDPIScaleMethod ScalingMethod = EImGuiDPIScaleMethod : : ImGui ;
2020-06-07 22:18:14 +00:00
// An optional scale to apply on top or instead of the curve-based scale.
2020-06-07 20:58:48 +00:00
UPROPERTY ( EditAnywhere , Category = " DPI Scale " , meta = ( ClampMin = 0 , UIMin = 0 ) )
float Scale = 1.f ;
2020-06-07 22:18:14 +00:00
// 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 ;
2020-06-07 20:58:48 +00:00
public :
2020-06-07 22:18:14 +00:00
FImGuiDPIScaleInfo ( ) ;
2020-06-07 20:58:48 +00:00
2020-06-07 22:18:14 +00:00
float GetImGuiScale ( ) const { return ShouldScaleInSlate ( ) ? 1.f : CalculateScale ( ) ; }
float GetSlateScale ( ) const { return ShouldScaleInSlate ( ) ? CalculateScale ( ) : 1.f ; }
2020-06-07 20:58:48 +00:00
bool ShouldScaleInSlate ( ) const { return ScalingMethod = = EImGuiDPIScaleMethod : : Slate ; }
2020-06-07 22:18:14 +00:00
private :
float CalculateScale ( ) const { return Scale * CalculateResolutionBasedScale ( ) ; }
2020-06-07 20:58:48 +00:00
2020-06-07 22:18:14 +00:00
float CalculateResolutionBasedScale ( ) const ;
2020-06-07 20:58:48 +00:00
} ;
2018-12-08 21:03:18 +00:00
// UObject used for loading and saving ImGui settings. To access actual settings use FImGuiModuleSettings interface.
2018-07-10 16:40:57 +00:00
UCLASS ( config = ImGui , defaultconfig )
class UImGuiSettings : public UObject
{
GENERATED_BODY ( )
public :
2018-12-08 21:03:18 +00:00
// Get default instance or null if it is not loaded.
static UImGuiSettings * Get ( ) { return DefaultInstance ; }
2018-10-28 21:15:02 +00:00
2018-12-08 21:03:18 +00:00
// Delegate raised when default instance is loaded.
static FSimpleMulticastDelegate OnSettingsLoaded ;
2018-12-02 20:32:42 +00:00
2018-07-30 21:05:59 +00:00
virtual void PostInitProperties ( ) override ;
2018-11-24 19:54:01 +00:00
virtual void BeginDestroy ( ) override ;
2018-07-30 21:05:59 +00:00
2018-07-10 16:40:57 +00:00
protected :
// Path to own implementation of ImGui Input Handler allowing to customize handling of keyboard and gamepad input.
// If not set then default handler is used.
2023-02-20 17:36:08 +00:00
UPROPERTY ( EditAnywhere , config , Category = " Extensions " , meta = ( MetaClass = " /Script/ImGui.ImGuiInputHandler " ) )
2022-03-01 18:46:21 +00:00
FSoftClassPath ImGuiInputHandlerClass ;
2018-07-10 16:40:57 +00:00
2018-12-02 20:32:42 +00:00
// Whether ImGui should share keyboard input with game.
// This defines initial behaviour which can be later changed using 'ImGui.ToggleKeyboardInputSharing' command or
// module properties interface.
UPROPERTY ( EditAnywhere , config , Category = " Input " )
bool bShareKeyboardInput = false ;
// Whether ImGui should share gamepad input with game.
// This defines initial behaviour which can be later changed using 'ImGui.ToggleGamepadInputSharing' command or
// module properties interface.
UPROPERTY ( EditAnywhere , config , Category = " Input " )
bool bShareGamepadInput = false ;
2019-07-08 19:46:28 +00:00
// Whether ImGui should share mouse input with game.
// This defines initial behaviour which can be later changed using 'ImGui.ToggleMouseInputSharing' command or
// module properties interface.
UPROPERTY ( EditAnywhere , config , Category = " Input " )
bool bShareMouseInput = false ;
2024-11-23 23:27:50 +00:00
// Whether docking should be enabled.
// This defines initial behaviour which can be later changed using 'ImGui.ToggleDockingEnabled' command or
// module properties interface.
2024-11-24 05:08:45 +00:00
UPROPERTY ( EditAnywhere , config , Category = " Input " , DisplayName = " Enable Docking " )
2024-11-23 23:27:50 +00:00
bool bIsDockingEnabled = true ;
2018-12-02 20:32:42 +00:00
// If true, then in input mode ImGui will draw its own cursor in place of the hardware one.
// When disabled (default) there is a noticeable difference between cursor position seen by ImGui and position on
// the screen. Enabling this option removes that effect but with lower frame-rates UI becomes quickly unusable.
UPROPERTY ( EditAnywhere , config , Category = " Input " , AdvancedDisplay )
bool bUseSoftwareCursor = false ;
2024-11-23 23:27:50 +00:00
2018-11-24 21:16:25 +00:00
// Define a shortcut key to 'ImGui.ToggleInput' command. Binding is only set if the key field is valid.
2018-07-31 21:09:01 +00:00
// Note that modifier key properties can be set to one of the three values: undetermined means that state of the given
2018-11-24 21:16:25 +00:00
// modifier is not important, checked means that it needs to be pressed and unchecked means that it cannot be pressed.
2018-07-31 21:09:01 +00:00
//
// This binding is using Player Input's DebugExecBindings which only works in non-shipment builds.
UPROPERTY ( EditAnywhere , config , Category = " Keyboard Shortcuts " )
2018-11-24 21:16:25 +00:00
FImGuiKeyInfo ToggleInput ;
2020-05-10 20:05:27 +00:00
// Chose how to define the ImGui canvas size. Select between custom, desktop and viewport.
2020-04-16 12:08:32 +00:00
UPROPERTY ( EditAnywhere , config , Category = " Canvas Size " )
2020-05-10 20:05:27 +00:00
FImGuiCanvasSizeInfo CanvasSize ;
2020-04-16 12:08:32 +00:00
2020-06-07 20:58:48 +00:00
// Setup DPI Scale.
UPROPERTY ( EditAnywhere , config , Category = " DPI Scale " , Meta = ( ShowOnlyInnerProperties ) )
FImGuiDPIScaleInfo DPIScale ;
2020-05-11 10:24:59 +00:00
2018-12-08 21:03:18 +00:00
static UImGuiSettings * DefaultInstance ;
friend class FImGuiModuleSettings ;
} ;
class FImGuiModuleCommands ;
class FImGuiModuleProperties ;
// Interface for ImGui module settings. It shadows all the settings and keep them in sync after UImGuiSettings class is
// loaded, but it can also work before that time what simplifies workflow in early-loading scenarios.
// It binds to module properties and commands objects that need to be passed during construction.
class FImGuiModuleSettings
{
public :
// Generic delegate used to notify changes of boolean properties.
DECLARE_MULTICAST_DELEGATE_OneParam ( FBoolChangeDelegate , bool ) ;
2022-03-01 18:46:21 +00:00
DECLARE_MULTICAST_DELEGATE_OneParam ( FStringClassReferenceChangeDelegate , const FSoftClassPath & ) ;
2020-05-10 20:20:51 +00:00
DECLARE_MULTICAST_DELEGATE_OneParam ( FImGuiCanvasSizeInfoChangeDelegate , const FImGuiCanvasSizeInfo & ) ;
2020-06-07 20:58:48 +00:00
DECLARE_MULTICAST_DELEGATE_OneParam ( FImGuiDPIScaleInfoChangeDelegate , const FImGuiDPIScaleInfo & ) ;
2018-12-08 21:03:18 +00:00
// Constructor for ImGui module settings. It will bind to instances of module properties and commands and will
// update them every time when settings are changed.
//
// @param InProperties - Instance of module properties that will be bound and updated by this object.
// @param InCommands - Instance of module commands that will be bound and updated by this object.
FImGuiModuleSettings ( FImGuiModuleProperties & InProperties , FImGuiModuleCommands & InCommands ) ;
~ FImGuiModuleSettings ( ) ;
// It doesn't offer interface for settings that define initial values for properties, as those are passed during
// start-up and should be accessed trough properties interface. Remaining settings can have getter and/or change
// event that are defined depending on needs.
// Get the path to custom implementation of ImGui Input Handler.
2022-03-01 18:46:21 +00:00
const FSoftClassPath & GetImGuiInputHandlerClass ( ) const { return ImGuiInputHandlerClass ; }
2018-12-08 21:03:18 +00:00
// Get the software cursor configuration.
bool UseSoftwareCursor ( ) const { return bUseSoftwareCursor ; }
// Get the shortcut configuration for 'ImGui.ToggleInput' command.
const FImGuiKeyInfo & GetToggleInputKey ( ) const { return ToggleInputKey ; }
2020-05-10 20:05:27 +00:00
// Get the information how to calculate the canvas size.
const FImGuiCanvasSizeInfo & GetCanvasSizeInfo ( ) const { return CanvasSize ; }
2020-04-16 12:08:32 +00:00
2020-06-07 20:58:48 +00:00
// Get the DPI Scale information.
const FImGuiDPIScaleInfo & GetDPIScaleInfo ( ) const { return DPIScale ; }
2020-05-11 10:24:59 +00:00
2018-12-08 21:03:18 +00:00
// Delegate raised when ImGui Input Handle is changed.
FStringClassReferenceChangeDelegate OnImGuiInputHandlerClassChanged ;
// Delegate raised when software cursor configuration is changed.
FBoolChangeDelegate OnUseSoftwareCursorChanged ;
2020-05-10 20:20:51 +00:00
// Delegate raised when information how to calculate the canvas size is changed.
2020-06-07 20:58:48 +00:00
FImGuiCanvasSizeInfoChangeDelegate OnCanvasSizeChangedDelegate ;
2020-05-10 20:20:51 +00:00
2020-05-11 10:24:59 +00:00
// Delegate raised when the DPI scale is changed.
2020-06-07 20:58:48 +00:00
FImGuiDPIScaleInfoChangeDelegate OnDPIScaleChangedDelegate ;
2020-05-11 10:24:59 +00:00
2018-07-10 16:40:57 +00:00
private :
2020-06-07 22:18:14 +00:00
void InitializeAllSettings ( ) ;
2018-12-08 21:03:18 +00:00
void UpdateSettings ( ) ;
2020-06-07 22:18:14 +00:00
void UpdateDPIScaleInfo ( ) ;
2018-07-10 16:40:57 +00:00
2022-03-01 18:46:21 +00:00
void SetImGuiInputHandlerClass ( const FSoftClassPath & ClassReference ) ;
2018-12-08 21:03:18 +00:00
void SetShareKeyboardInput ( bool bShare ) ;
void SetShareGamepadInput ( bool bShare ) ;
2019-07-08 19:46:28 +00:00
void SetShareMouseInput ( bool bShare ) ;
2018-12-08 21:03:18 +00:00
void SetUseSoftwareCursor ( bool bUse ) ;
void SetToggleInputKey ( const FImGuiKeyInfo & KeyInfo ) ;
2024-11-23 23:27:50 +00:00
void SetIsDockingEnabled ( bool bDockingEnabled ) ;
2020-05-10 20:05:27 +00:00
void SetCanvasSizeInfo ( const FImGuiCanvasSizeInfo & CanvasSizeInfo ) ;
2020-06-07 20:58:48 +00:00
void SetDPIScaleInfo ( const FImGuiDPIScaleInfo & ScaleInfo ) ;
2018-07-10 16:40:57 +00:00
2018-12-08 21:03:18 +00:00
# if WITH_EDITOR
2018-07-10 16:40:57 +00:00
void OnPropertyChanged ( class UObject * ObjectBeingModified , struct FPropertyChangedEvent & PropertyChangedEvent ) ;
# endif // WITH_EDITOR
2018-11-24 19:54:01 +00:00
2018-12-08 21:03:18 +00:00
FImGuiModuleProperties & Properties ;
FImGuiModuleCommands & Commands ;
2022-03-01 18:46:21 +00:00
FSoftClassPath ImGuiInputHandlerClass ;
2018-12-08 21:03:18 +00:00
FImGuiKeyInfo ToggleInputKey ;
2020-05-10 20:05:27 +00:00
FImGuiCanvasSizeInfo CanvasSize ;
2020-06-07 20:58:48 +00:00
FImGuiDPIScaleInfo DPIScale ;
2018-12-08 21:03:18 +00:00
bool bShareKeyboardInput = false ;
bool bShareGamepadInput = false ;
2019-07-08 19:46:28 +00:00
bool bShareMouseInput = false ;
2018-12-08 21:03:18 +00:00
bool bUseSoftwareCursor = false ;
2024-11-23 23:27:50 +00:00
bool bIsDockingEnabled = true ;
2018-12-08 21:03:18 +00:00
} ;