CogImGui: Support shared mouse

This commit is contained in:
Arnaud Jamin
2024-01-05 17:25:59 -05:00
parent 5de42fd1c8
commit c90a32031b
10 changed files with 246 additions and 94 deletions
Binary file not shown.
@@ -5,7 +5,6 @@
#include "DrawDebugHelpers.h" #include "DrawDebugHelpers.h"
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakePoint(const FVector& Location, const float Size, const FColor& Color, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakePoint(const FVector& Location, const float Size, const FColor& Color, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -21,7 +20,6 @@ FCogDebugShape FCogDebugShape::MakePoint(const FVector& Location, const float Si
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawPoint(UWorld* World) const void FCogDebugShape::DrawPoint(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -42,7 +40,6 @@ void FCogDebugShape::DrawPoint(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeSegment(const FVector& StartLocation, const FVector& EndLocation, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeSegment(const FVector& StartLocation, const FVector& EndLocation, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -59,7 +56,6 @@ FCogDebugShape FCogDebugShape::MakeSegment(const FVector& StartLocation, const F
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawSegment(UWorld* World) const void FCogDebugShape::DrawSegment(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -81,7 +77,6 @@ void FCogDebugShape::DrawSegment(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeArrow(const FVector& StartLocation, const FVector& EndLocation, const float HeadSize, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeArrow(const FVector& StartLocation, const FVector& EndLocation, const float HeadSize, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -99,7 +94,6 @@ FCogDebugShape FCogDebugShape::MakeArrow(const FVector& StartLocation, const FVe
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawArrow(UWorld* World) const void FCogDebugShape::DrawArrow(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -122,7 +116,6 @@ void FCogDebugShape::DrawArrow(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeAxes(const FVector& Location, const FRotator& Rotation, const float HeadSize, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeAxes(const FVector& Location, const FRotator& Rotation, const float HeadSize, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -140,7 +133,6 @@ FCogDebugShape FCogDebugShape::MakeAxes(const FVector& Location, const FRotator&
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawAxes(UWorld* World) const void FCogDebugShape::DrawAxes(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -162,7 +154,6 @@ void FCogDebugShape::DrawAxes(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeBox(const FVector& Center, const FRotator& Rotation, const FVector& Extent, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeBox(const FVector& Center, const FRotator& Rotation, const FVector& Extent, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -180,7 +171,6 @@ FCogDebugShape FCogDebugShape::MakeBox(const FVector& Center, const FRotator& Ro
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawBox(UWorld* World) const void FCogDebugShape::DrawBox(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -203,7 +193,6 @@ void FCogDebugShape::DrawBox(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeSolidBox(const FVector& Center, const FRotator& Rotation, const FVector& Extent, const FColor& Color, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeSolidBox(const FVector& Center, const FRotator& Rotation, const FVector& Extent, const FColor& Color, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -241,7 +230,6 @@ void FCogDebugShape::DrawSolidBox(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeCone(const FVector& Location, const FVector& Direction, const float Length, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeCone(const FVector& Location, const FVector& Direction, const float Length, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -259,7 +247,6 @@ FCogDebugShape FCogDebugShape::MakeCone(const FVector& Location, const FVector&
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawCone(UWorld* World) const void FCogDebugShape::DrawCone(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -286,7 +273,6 @@ void FCogDebugShape::DrawCone(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeCylinder(const FVector& Center, const float Radius, const float HalfHeight, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeCylinder(const FVector& Center, const float Radius, const float HalfHeight, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -326,7 +312,6 @@ void FCogDebugShape::DrawCylinder(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeCircle(const FVector& Center, const FRotator& Rotation, const float Radius, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeCircle(const FVector& Center, const FRotator& Rotation, const float Radius, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -344,7 +329,6 @@ FCogDebugShape FCogDebugShape::MakeCircle(const FVector& Center, const FRotator&
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawCicle(UWorld* World) const void FCogDebugShape::DrawCicle(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -368,7 +352,6 @@ void FCogDebugShape::DrawCicle(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeCircleArc(const FVector& Center, const FRotator& Rotation, const float InnerRadius, const float OuterRadius, const float Angle, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeCircleArc(const FVector& Center, const FRotator& Rotation, const float InnerRadius, const float OuterRadius, const float Angle, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -386,7 +369,6 @@ FCogDebugShape FCogDebugShape::MakeCircleArc(const FVector& Center, const FRotat
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawCicleArc(UWorld* World) const void FCogDebugShape::DrawCicleArc(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -411,7 +393,6 @@ void FCogDebugShape::DrawCicleArc(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeCapsule(const FVector& Center, const FQuat& Rotation, const float Radius, const float HalfHeight, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeCapsule(const FVector& Center, const FQuat& Rotation, const float Radius, const float HalfHeight, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -429,7 +410,6 @@ FCogDebugShape FCogDebugShape::MakeCapsule(const FVector& Center, const FQuat& R
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawCapsule(UWorld* World) const void FCogDebugShape::DrawCapsule(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -453,7 +433,6 @@ void FCogDebugShape::DrawCapsule(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeFlatCapsule(const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeFlatCapsule(const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -496,7 +475,6 @@ void FCogDebugShape::DrawFlatCapsule(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakeBone(const FVector& BoneLocation, const FVector& ParentLocation, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakeBone(const FVector& BoneLocation, const FVector& ParentLocation, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -513,7 +491,6 @@ FCogDebugShape FCogDebugShape::MakeBone(const FVector& BoneLocation, const FVect
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawBone(UWorld* World) const void FCogDebugShape::DrawBone(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -545,7 +522,6 @@ void FCogDebugShape::DrawBone(UWorld* World) const
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FCogDebugShape FCogDebugShape::MakePolygon(const TArray<FVector>& Verts, const FColor& Color, const bool bPersistent, const uint8 DepthPriority) FCogDebugShape FCogDebugShape::MakePolygon(const TArray<FVector>& Verts, const FColor& Color, const bool bPersistent, const uint8 DepthPriority)
{ {
FCogDebugShape NewElement; FCogDebugShape NewElement;
@@ -559,7 +535,6 @@ FCogDebugShape FCogDebugShape::MakePolygon(const TArray<FVector>& Verts, const F
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::DrawPolygon(UWorld* World) const void FCogDebugShape::DrawPolygon(UWorld* World) const
{ {
#if ENABLE_COG #if ENABLE_COG
@@ -589,7 +564,6 @@ void FCogDebugShape::DrawPolygon(UWorld* World) const
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugShape::Draw(UWorld* World) const void FCogDebugShape::Draw(UWorld* World) const
{ {
switch (Type) switch (Type)
@@ -612,7 +586,6 @@ void FCogDebugShape::Draw(UWorld* World) const
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FArchive& operator<<(FArchive& Ar, FCogDebugShape& Shape) FArchive& operator<<(FArchive& Ar, FCogDebugShape& Shape)
{ {
Ar << Shape.ShapeData; Ar << Shape.ShapeData;
@@ -37,9 +37,8 @@ void FCogImguiContext::Initialize()
SAssignNew(MainWidget, SCogImguiWidget) SAssignNew(MainWidget, SCogImguiWidget)
.Context(this); .Context(this);
GameViewport->AddViewportWidgetContent(MainWidget.ToSharedRef(), TNumericLimits<int32>::Max()); GameViewport->AddViewportWidgetContent(MainWidget.ToSharedRef(), TNumericLimits<int32>::Max());
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Register input processor to forward input events to imgui // Register input processor to forward input events to imgui
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@@ -275,6 +274,8 @@ bool FCogImguiContext::BeginFrame(float InDeltaTime)
IO.AddMousePosEvent(TransformedMousePosition.X, TransformedMousePosition.Y); IO.AddMousePosEvent(TransformedMousePosition.X, TransformedMousePosition.Y);
} }
bWantCaptureMouse = ImGui::GetIO().WantCaptureMouse || (CaptureMouseCount > 0);
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
@@ -561,7 +562,7 @@ void FCogImguiContext::ImGui_RenderWindow(ImGuiViewport* Viewport, void* Data)
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
static UPlayerInput* GetPlayerInput(const UWorld* World) static APlayerController* GetLocalPlayerController(const UWorld* World)
{ {
if (World == nullptr) if (World == nullptr)
{ {
@@ -574,11 +575,22 @@ static UPlayerInput* GetPlayerInput(const UWorld* World)
APlayerController* ItPlayerController = Iterator->Get(); APlayerController* ItPlayerController = Iterator->Get();
if (ItPlayerController->IsLocalController()) if (ItPlayerController->IsLocalController())
{ {
PlayerController = ItPlayerController; return ItPlayerController;
break;
} }
} }
return nullptr;
}
//--------------------------------------------------------------------------------------------------------------------------
static UPlayerInput* GetPlayerInput(const UWorld* World)
{
if (World == nullptr)
{
return nullptr;
}
APlayerController* PlayerController = GetLocalPlayerController(World);
if (PlayerController == nullptr) if (PlayerController == nullptr)
{ {
return nullptr; return nullptr;
@@ -620,12 +632,47 @@ void FCogImguiContext::SetEnableInput(bool Value)
} }
} }
RefreshMouseCursor();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogImguiContext::SetShareMouse(bool Value) void FCogImguiContext::SetShowCursorWhenSharingMouse(bool Value)
{ {
bShareMouse = Value; bShowCursorWhenSharingMouse = Value;
RefreshMouseCursor();
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogImguiContext::SetShareMouse(bool Value)
{
bShareMouse = Value;
RefreshMouseCursor();
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogImguiContext::RefreshMouseCursor()
{
if (bEnableInput)
{
if (bShareMouse && bShowCursorWhenSharingMouse)
{
if (APlayerController* PlayerController = GetLocalPlayerController(GameViewport->GetWorld()))
{
bPlayerControllerShowMouse = PlayerController->ShouldShowMouseCursor();
PlayerController->SetShowMouseCursor(true);
}
}
}
else
{
if (bShareMouse && bShowCursorWhenSharingMouse)
{
if (APlayerController* PlayerController = GetLocalPlayerController(GameViewport->GetWorld()))
{
PlayerController->SetShowMouseCursor(bPlayerControllerShowMouse);
}
}
}
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -156,6 +156,11 @@ FReply SCogImguiWidget::HandleKeyEvent(const FKeyEvent& KeyEvent, bool Down)
IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown()); IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown());
IO.AddKeyEvent(ImGuiMod_Super, KeyEvent.IsCommandDown()); IO.AddKeyEvent(ImGuiMod_Super, KeyEvent.IsCommandDown());
if (IO.WantCaptureKeyboard == false && Context->GetShareKeyboard())
{
return FReply::Unhandled();
}
return FReply::Handled(); return FReply::Handled();
} }
@@ -249,12 +254,26 @@ FReply SCogImguiWidget::OnFocusReceived(const FGeometry& MyGeometry, const FFocu
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void SCogImguiWidget::RefreshVisibility() void SCogImguiWidget::RefreshVisibility()
{ {
EVisibility DesiredVisiblity = EVisibility::SelfHitTestInvisible;
if (Context->GetEnableInput()) if (Context->GetEnableInput())
{ {
SetVisibility(EVisibility::Visible); if (Context->GetShareMouse() && Context->GetWantCaptureMouse() == false)
{
DesiredVisiblity = EVisibility::SelfHitTestInvisible;
}
else
{
DesiredVisiblity = EVisibility::Visible;
}
} }
else else
{ {
SetVisibility(EVisibility::SelfHitTestInvisible); DesiredVisiblity = EVisibility::SelfHitTestInvisible;
}
if (DesiredVisiblity != GetVisibility())
{
SetVisibility(DesiredVisiblity);
} }
} }
@@ -10,6 +10,7 @@ class FCogImguiContext;
class IInputProcessor; class IInputProcessor;
class SCogImguiWidget; class SCogImguiWidget;
class SCogImguiWidget; class SCogImguiWidget;
class SCogImguiInputCatcherWidget;
class SWidget; class SWidget;
class SWindow; class SWindow;
class UGameViewportClient; class UGameViewportClient;
@@ -36,10 +37,20 @@ public:
void SetEnableInput(bool Value); void SetEnableInput(bool Value);
bool GetWantCaptureMouse() const { return bWantCaptureMouse; }
bool GetShareMouse() const { return bShareMouse; } bool GetShareMouse() const { return bShareMouse; }
void SetShareMouse(bool Value); void SetShareMouse(bool Value);
bool GetShowCursorWhenSharingMouse() const { return bShowCursorWhenSharingMouse; }
void SetShowCursorWhenSharingMouse(bool Value);
bool GetShareKeyboard() const { return bShareKeyboard; }
void SetShareKeyboard(bool Value) { bShareKeyboard = Value; }
bool BeginFrame(float InDeltaTime); bool BeginFrame(float InDeltaTime);
void EndFrame(); void EndFrame();
@@ -48,6 +59,10 @@ public:
void SetDPIScale(float Value); void SetDPIScale(float Value);
void PushCaptureMouse();
void PopCaptureMouse();
TObjectPtr<const UGameViewportClient> GetGameViewport() const { return GameViewport; } TObjectPtr<const UGameViewportClient> GetGameViewport() const { return GameViewport; }
TSharedPtr<const SCogImguiWidget> GetMainWidget() const { return MainWidget; } TSharedPtr<const SCogImguiWidget> GetMainWidget() const { return MainWidget; }
@@ -62,6 +77,8 @@ private:
void BuildFont(); void BuildFont();
void RefreshMouseCursor();
ULocalPlayer* GetLocalPlayer() const; ULocalPlayer* GetLocalPlayer() const;
static void ImGui_CreateWindow(ImGuiViewport* Viewport); static void ImGui_CreateWindow(ImGuiViewport* Viewport);
@@ -101,6 +118,8 @@ private:
TSharedPtr<SCogImguiWidget> MainWidget = nullptr; TSharedPtr<SCogImguiWidget> MainWidget = nullptr;
TSharedPtr<SCogImguiInputCatcherWidget> InputCatcherWidget = nullptr;
TWeakPtr<SWidget> PreviousMouseCaptor = nullptr; TWeakPtr<SWidget> PreviousMouseCaptor = nullptr;
TObjectPtr<UGameViewportClient> GameViewport = nullptr; TObjectPtr<UGameViewportClient> GameViewport = nullptr;
@@ -113,7 +132,13 @@ private:
bool bEnableInput = false; bool bEnableInput = false;
bool bShareMouse = true; bool bShareMouse = false;
bool bShowCursorWhenSharingMouse = false;
bool bPlayerControllerShowMouse = false;
bool bShareKeyboard = false;
bool bRefreshDPIScale = false; bool bRefreshDPIScale = false;
@@ -121,6 +146,9 @@ private:
bool bIsFirstFrame = true; bool bIsFirstFrame = true;
float DpiScale = 1.f; bool bWantCaptureMouse = false;
int32 CaptureMouseCount = 0;
float DpiScale = 1.f;
}; };
@@ -79,25 +79,6 @@ void FCogWindow::Render(float DeltaTime)
ImGui::PopStyleVar(1); ImGui::PopStyleVar(1);
} }
if (GetOwner()->GetSettingsWindow()->GetSettingsConfig()->bShowHelp)
{
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, IM_COL32(29, 42, 62, 240));
const float HelpWidth = FCogWindowWidgets::GetFontWidth() * 80;
ImGui::SetNextWindowSizeConstraints(ImVec2(HelpWidth / 2.0f, 0.0f),
ImVec2(HelpWidth, FLT_MAX));
if (ImGui::BeginTooltip())
{
ImGui::PushTextWrapPos(HelpWidth - 1 * FCogWindowWidgets::GetFontWidth());
RenderHelp();
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
ImGui::PopStyleColor();
}
}
if (ImGui::BeginPopupContextWindow()) if (ImGui::BeginPopupContextWindow())
{ {
if (bHasMenu) if (bHasMenu)
@@ -215,4 +196,3 @@ UWorld* FCogWindow::GetWorld() const
{ {
return Owner->GetWorld(); return Owner->GetWorld();
} }
@@ -166,6 +166,7 @@ void UCogWindowManager::Render(float DeltaTime)
ImGui::DockSpaceOverViewport(0, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingInCentralNode | ImGuiDockNodeFlags_AutoHideTabBar); ImGui::DockSpaceOverViewport(0, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingInCentralNode | ImGuiDockNodeFlags_AutoHideTabBar);
ImGui::PopStyleColor(1); ImGui::PopStyleColor(1);
const bool bCompactSaved = SettingsWindow->GetSettingsConfig()->bCompactMode; const bool bCompactSaved = SettingsWindow->GetSettingsConfig()->bCompactMode;
if (bCompactSaved) if (bCompactSaved)
{ {
@@ -518,6 +519,8 @@ void UCogWindowManager::RenderMenuItem(FCogWindow& Window, const char* MenuItemN
{ {
Window.SetIsVisible(!Window.GetIsVisible()); Window.SetIsVisible(!Window.GetIsVisible());
} }
RenderMenuItemHelp(Window);
} }
else else
{ {
@@ -526,6 +529,37 @@ void UCogWindowManager::RenderMenuItem(FCogWindow& Window, const char* MenuItemN
{ {
Window.SetIsVisible(bIsVisible); Window.SetIsVisible(bIsVisible);
} }
RenderMenuItemHelp(Window);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogWindowManager::RenderMenuItemHelp(FCogWindow& Window)
{
if (SettingsWindow->GetSettingsConfig()->bShowHelp)
{
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - FCogWindowWidgets::GetFontWidth() * 3.0f);
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, IM_COL32(29, 42, 62, 240));
const float HelpWidth = FCogWindowWidgets::GetFontWidth() * 80;
ImGui::SetNextWindowSizeConstraints(ImVec2(HelpWidth / 2.0f, 0.0f), ImVec2(HelpWidth, FLT_MAX));
if (ImGui::BeginTooltip())
{
ImGui::PushTextWrapPos(HelpWidth - 1 * FCogWindowWidgets::GetFontWidth());
Window.RenderHelp();
ImGui::Separator();
ImGui::TextDisabled("Help can be hidden in Window/Settings.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
ImGui::PopStyleColor();
}
ImGui::SameLine();
ImGui::Dummy(ImVec2(FCogWindowWidgets::GetFontWidth() * 1, 0));
} }
} }
@@ -753,4 +787,5 @@ void UCogWindowManager::ToggleInputMode()
{ {
UE_LOG(LogCogImGui, Verbose, TEXT("UCogWindowManager::ToggleInputMode")); UE_LOG(LogCogImGui, Verbose, TEXT("UCogWindowManager::ToggleInputMode"));
Context.SetEnableInput(!Context.GetEnableInput()); Context.SetEnableInput(!Context.GetEnableInput());
} }
@@ -18,17 +18,19 @@ void FCogWindow_Settings::Initialize()
ImGuiIO& IO = ImGui::GetIO(); ImGuiIO& IO = ImGui::GetIO();
FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_ViewportsEnable, Config->bEnableViewports); FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_ViewportsEnable, Config->bEnableViewports);
FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard, Config->bNavEnableKeyboard);
//FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad, Config->bNavEnableGamepad);
//FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_NavNoCaptureKeyboard, Config->bNavNoCaptureInput);
GetOwner()->GetContext().SetDPIScale(Config->DPIScale); GetOwner()->GetContext().SetDPIScale(Config->DPIScale);
FCogImguiContext& Context = GetOwner()->GetContext(); FCogImguiContext& Context = GetOwner()->GetContext();
Context.SetEnableInput(Config->bEnableInput); Context.SetEnableInput(Config->bEnableInput);
//Context.SetShareMouse(Config->bShareMouse); Context.SetShareKeyboard(Config->bShareKeyboard);
Context.SetShareMouse(Config->bShareMouse);
Context.SetShowCursorWhenSharingMouse(Config->bShowCursorWhenSharingMouse);
//FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard, Config->bNavEnableKeyboard);
//FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad, Config->bNavEnableGamepad);
//FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_NavNoCaptureKeyboard, Config->bNavNoCaptureInput);
//FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_NoMouseCursorChange, Config->bNoMouseCursorChange);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -36,15 +38,16 @@ void FCogWindow_Settings::PreSaveConfig()
{ {
Super::PreSaveConfig(); Super::PreSaveConfig();
//ImGuiIO& IO = ImGui::GetIO(); ImGuiIO& IO = ImGui::GetIO();
//Config->bNavEnableKeyboard = IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard; Config->bNavEnableKeyboard = IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard;
//Config->bNavEnableGamepad = IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad; //Config->bNavEnableGamepad = IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad;
//Config->bNavNoCaptureInput = IO.ConfigFlags & ImGuiConfigFlags_NavNoCaptureKeyboard; //Config->bNavNoCaptureInput = IO.ConfigFlags & ImGuiConfigFlags_NavNoCaptureKeyboard;
//Config->bNoMouseCursorChange = IO.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange;
const FCogImguiContext& Context = GetOwner()->GetContext(); const FCogImguiContext& Context = GetOwner()->GetContext();
Config->bEnableInput = Context.GetEnableInput(); Config->bEnableInput = Context.GetEnableInput();
//Config->bShareMouse = Context.GetShareMouse(); Config->bShareKeyboard = Context.GetShareKeyboard();
Config->bShareMouse = Context.GetShareMouse();
Config->bShowCursorWhenSharingMouse = Context.GetShowCursorWhenSharingMouse();
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -67,11 +70,16 @@ void FCogWindow_Settings::RenderContent()
ImGuiIO& IO = ImGui::GetIO(); ImGuiIO& IO = ImGui::GetIO();
FCogImguiContext& Context = GetOwner()->GetContext(); FCogImguiContext& Context = GetOwner()->GetContext();
//-----------------------------
// bEnableInput
//-----------------------------
bool bEnableInput = Context.GetEnableInput(); bool bEnableInput = Context.GetEnableInput();
if (ImGui::Checkbox("Enable Input", &bEnableInput)) if (ImGui::Checkbox("Enable Input", &bEnableInput))
{ {
Context.SetEnableInput(bEnableInput); Context.SetEnableInput(bEnableInput);
} }
ImGui::SetItemTooltip("Enable ImGui inputs. When enabled the ImGui menu is shown and inputs are forwarded to ImGui.");
const auto ShortcutText = StringCast<ANSICHAR>(*FCogImguiInputHelper::CommandToString(PlayerInput, UCogWindowManager::ToggleInputCommand)); const auto ShortcutText = StringCast<ANSICHAR>(*FCogImguiInputHelper::CommandToString(PlayerInput, UCogWindowManager::ToggleInputCommand));
const float ShortcutWidth = (ShortcutText.Get() != nullptr && ShortcutText.Get()[0]) ? ImGui::CalcTextSize(ShortcutText.Get(), NULL).x : 0.0f; const float ShortcutWidth = (ShortcutText.Get() != nullptr && ShortcutText.Get()[0]) ? ImGui::CalcTextSize(ShortcutText.Get(), NULL).x : 0.0f;
@@ -84,55 +92,109 @@ void FCogWindow_Settings::RenderContent()
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
//-----------------------------
// ShareKeyboard
//-----------------------------
bool bShareKeyboard = Context.GetShareKeyboard();
if (ImGui::Checkbox("Share Keyboard", &bShareKeyboard))
{
Context.SetShareKeyboard(bShareKeyboard);
}
ImGui::SetItemTooltip("Forward the keyboard inputs to the game when ImGui does not need them.");
//-----------------------------
// ShareMouse
//-----------------------------
bool bShareMouse = Context.GetShareMouse();
if (ImGui::Checkbox("Share Mouse", &bShareMouse))
{
Context.SetShareMouse(bShareMouse);
}
ImGui::SetItemTooltip("Forward mouse inputs to the game when ImGui does not need them.");
//-----------------------------
// ShowCursorWhenSharingMouse
//-----------------------------
if (bShareMouse == false)
{
ImGui::BeginDisabled();
}
bool bShowCursorWhenSharingMouse = Context.GetShowCursorWhenSharingMouse();
if (ImGui::Checkbox("Show Cursor When Sharing Mouse", &bShowCursorWhenSharingMouse))
{
Context.SetShowCursorWhenSharingMouse(bShowCursorWhenSharingMouse);
}
ImGui::SetItemTooltip("Show the mouse cursor when ImGui share the mouse with the game. Useful for games that require the cursor to be hidden.");
if (bShareMouse == false)
{
ImGui::EndDisabled();
}
//-----------------------------
// NavEnableKeyboard
//-----------------------------
ImGui::CheckboxFlags("Keyboard Navigation", &IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard);
ImGui::SetItemTooltip("Use the keyboard to navigate in ImGui windows with the following keys : Tab, Directional Arrows, Space, Enter.");
//-----------------------------
// NavEnableGamepad
//-----------------------------
//ImGui::CheckboxFlags("Gamepad Navigation", &IO.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad);
//ImGui::SetItemTooltip("Use the gamepad to navigate in ImGui windows.");
ImGui::Separator();
//-----------------------------
// DPI
//-----------------------------
FCogWindowWidgets::SetNextItemToShortWidth(); FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::SliderFloat("DPI Scale", &Config->DPIScale, 0.5f, 2.0f, "%.1f"); ImGui::SliderFloat("DPI Scale", &Config->DPIScale, 0.5f, 2.0f, "%.1f");
if (ImGui::IsItemDeactivatedAfterEdit()) if (ImGui::IsItemDeactivatedAfterEdit())
{ {
SetDPIScale(Config->DPIScale); SetDPIScale(Config->DPIScale);
} }
if (ImGui::BeginItemTooltip())
if (ImGui::IsItemHovered())
{ {
ImGui::BeginTooltip();
ImGui::TextUnformatted("Change DPi Scale [Mouse Wheel]"); ImGui::TextUnformatted("Change DPi Scale [Mouse Wheel]");
ImGui::TextUnformatted("Reset DPi Scale [Middle Mouse]"); ImGui::TextUnformatted("Reset DPi Scale [Middle Mouse]");
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
//-----------------------------
// EnableViewports
//-----------------------------
if (ImGui::Checkbox("Enable Viewports", &Config->bEnableViewports)) if (ImGui::Checkbox("Enable Viewports", &Config->bEnableViewports))
{ {
FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_ViewportsEnable, Config->bEnableViewports); FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_ViewportsEnable, Config->bEnableViewports);
} }
ImGui::SetItemTooltip("Enable moving ImGui windows outside of the main viewport.");
if (ImGui::IsItemHovered()) //-----------------------------
{ // CompactMode
ImGui::SetTooltip("Cog imgui viewport integration in Unreal is still experimental"); //-----------------------------
}
ImGui::Checkbox("Compact Mode", &Config->bCompactMode); ImGui::Checkbox("Compact Mode", &Config->bCompactMode);
ImGui::SetItemTooltip("Enable compact mode.");
ImGui::Checkbox("Show Windows In Main Menu", &Config->bShowWindowsInMainMenu);
ImGui::Checkbox("Show Window Help", &Config->bShowHelp);
//bool bShareMouse = Context.GetShareMouse(); //-----------------------------
//if (ImGui::Checkbox("Share Mouse", &bShareMouse)) // ShowWindowsInMainMenu
//{ //-----------------------------
// Context.SetShareMouse(bShareMouse); ImGui::Checkbox("Show Windows In Main Menu", &Config->bShowWindowsInMainMenu);
//} ImGui::SetItemTooltip("Show the content of the windows when hovering the window menu item.");
//ImGui::CheckboxFlags("Keyboard Navigation", &IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard); //-----------------------------
//ImGui::CheckboxFlags("Gamepad Navigation", &IO.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad); // ShowHelp
//ImGui::CheckboxFlags("Navigation No Capture", &IO.ConfigFlags, ImGuiConfigFlags_NavNoCaptureKeyboard); //-----------------------------
//ImGui::CheckboxFlags("No Mouse Cursor Change", &IO.ConfigFlags, ImGuiConfigFlags_NoMouseCursorChange); ImGui::Checkbox("Show Help", &Config->bShowHelp);
ImGui::SetItemTooltip("Show windows help on the window menu items.");
ImGui::Separator(); ImGui::Separator();
if (ImGui::Button("Reset All Windows Config")) if (ImGui::Button("Reset All Windows Config", ImVec2(-1.0f, 0.0f)))
{ {
GetOwner()->ResetAllWindowsConfig(); GetOwner()->ResetAllWindowsConfig();
} }
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -101,6 +101,8 @@ protected:
virtual void RenderMenuItem(FCogWindow& Window, const char* MenuItemName); virtual void RenderMenuItem(FCogWindow& Window, const char* MenuItemName);
void RenderMenuItemHelp(FCogWindow& Window);
virtual void ToggleInputMode(); virtual void ToggleInputMode();
static void SettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*); static void SettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*);
@@ -66,6 +66,12 @@ public:
UPROPERTY(Config) UPROPERTY(Config)
bool bShareMouse = false; bool bShareMouse = false;
UPROPERTY(Config)
bool bShowCursorWhenSharingMouse = false;
UPROPERTY(Config)
bool bShareKeyboard = false;
UPROPERTY(Config) UPROPERTY(Config)
bool bNavEnableKeyboard = false; bool bNavEnableKeyboard = false;
@@ -90,9 +96,9 @@ public:
bShowWindowsInMainMenu = true; bShowWindowsInMainMenu = true;
bEnableInput = false; bEnableInput = false;
bShareMouse = false; bShareMouse = false;
bShareKeyboard = false;
bNavEnableKeyboard = false; bNavEnableKeyboard = false;
bNavEnableGamepad = false; //bNavEnableGamepad = false;
bNavNoCaptureInput = true; //bNavNoCaptureInput = true;
bNoMouseCursorChange = false;
} }
}; };