From c90a32031bb38ba41fd3a584245717ab550da229 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Fri, 5 Jan 2024 17:25:59 -0500 Subject: [PATCH] CogImGui: Support shared mouse --- .../Core/GameModes/BP_PlayerController.uasset | Bin 109591 -> 109591 bytes .../Source/CogDebug/Private/CogDebugShape.cpp | 27 ---- .../CogImgui/Private/CogImguiContext.cpp | 61 ++++++++- .../CogImgui/Private/CogImguiWidget.cpp | 23 +++- .../Source/CogImgui/Public/CogImguiContext.h | 32 ++++- .../Source/CogWindow/Private/CogWindow.cpp | 20 --- .../CogWindow/Private/CogWindowManager.cpp | 37 ++++- .../CogWindow/Private/CogWindow_Settings.cpp | 126 +++++++++++++----- .../CogWindow/Public/CogWindowManager.h | 2 + .../CogWindow/Public/CogWindow_Settings.h | 12 +- 10 files changed, 246 insertions(+), 94 deletions(-) diff --git a/Content/Core/GameModes/BP_PlayerController.uasset b/Content/Core/GameModes/BP_PlayerController.uasset index 425556970588ed6b20bfeefa50d4f12c9698a02f..67de1347e91950d59689df825fff96ea51ecec45 100644 GIT binary patch delta 108 zcmbP!gKhc^wheuZ0{H>k9Tm=g@#$Qem2u2&;`+_=7)9mzEEyOWo&zxmO!_-rP>fNn z`MJXO=L(E+g{l@t28M2?M$RTi#zrot=8hJQE=Gu+I`tc>nhGtt`gQX>Mp1b_Lk0$h=Rgbslm1Q@6k}9t zey*_nxdNkHp{lvLlcS@Pp}C2(xv7DRxw(<4k&~l|qqC)(larCLg%g7aP}k&%Ji^;; JCo$fV1OP|H9~%Gw diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp index aa03ba6..90dafb9 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp @@ -5,7 +5,6 @@ #include "DrawDebugHelpers.h" //-------------------------------------------------------------------------------------------------------------------------- - FCogDebugShape FCogDebugShape::MakePoint(const FVector& Location, const float Size, const FColor& Color, const bool bPersistent, const uint8 DepthPriority) { FCogDebugShape NewElement; @@ -21,7 +20,6 @@ FCogDebugShape FCogDebugShape::MakePoint(const FVector& Location, const float Si } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawPoint(UWorld* World) const { #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 NewElement; @@ -59,7 +56,6 @@ FCogDebugShape FCogDebugShape::MakeSegment(const FVector& StartLocation, const F } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawSegment(UWorld* World) const { #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 NewElement; @@ -99,7 +94,6 @@ FCogDebugShape FCogDebugShape::MakeArrow(const FVector& StartLocation, const FVe } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawArrow(UWorld* World) const { #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 NewElement; @@ -140,7 +133,6 @@ FCogDebugShape FCogDebugShape::MakeAxes(const FVector& Location, const FRotator& } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawAxes(UWorld* World) const { #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 NewElement; @@ -180,7 +171,6 @@ FCogDebugShape FCogDebugShape::MakeBox(const FVector& Center, const FRotator& Ro } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawBox(UWorld* World) const { #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 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 NewElement; @@ -259,7 +247,6 @@ FCogDebugShape FCogDebugShape::MakeCone(const FVector& Location, const FVector& } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawCone(UWorld* World) const { #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 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 NewElement; @@ -344,7 +329,6 @@ FCogDebugShape FCogDebugShape::MakeCircle(const FVector& Center, const FRotator& } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawCicle(UWorld* World) const { #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 NewElement; @@ -386,7 +369,6 @@ FCogDebugShape FCogDebugShape::MakeCircleArc(const FVector& Center, const FRotat } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawCicleArc(UWorld* World) const { #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 NewElement; @@ -429,7 +410,6 @@ FCogDebugShape FCogDebugShape::MakeCapsule(const FVector& Center, const FQuat& R } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawCapsule(UWorld* World) const { #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 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 NewElement; @@ -513,7 +491,6 @@ FCogDebugShape FCogDebugShape::MakeBone(const FVector& BoneLocation, const FVect } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawBone(UWorld* World) const { #if ENABLE_COG @@ -545,7 +522,6 @@ void FCogDebugShape::DrawBone(UWorld* World) const //-------------------------------------------------------------------------------------------------------------------------- - FCogDebugShape FCogDebugShape::MakePolygon(const TArray& Verts, const FColor& Color, const bool bPersistent, const uint8 DepthPriority) { FCogDebugShape NewElement; @@ -559,7 +535,6 @@ FCogDebugShape FCogDebugShape::MakePolygon(const TArray& Verts, const F } //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::DrawPolygon(UWorld* World) const { #if ENABLE_COG @@ -589,7 +564,6 @@ void FCogDebugShape::DrawPolygon(UWorld* World) const //-------------------------------------------------------------------------------------------------------------------------- - void FCogDebugShape::Draw(UWorld* World) const { switch (Type) @@ -612,7 +586,6 @@ void FCogDebugShape::Draw(UWorld* World) const } //-------------------------------------------------------------------------------------------------------------------------- - FArchive& operator<<(FArchive& Ar, FCogDebugShape& Shape) { Ar << Shape.ShapeData; diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp index 475380c..5605880 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp @@ -37,9 +37,8 @@ void FCogImguiContext::Initialize() SAssignNew(MainWidget, SCogImguiWidget) .Context(this); - GameViewport->AddViewportWidgetContent(MainWidget.ToSharedRef(), TNumericLimits::Max()); - + //-------------------------------------------------------------------- // Register input processor to forward input events to imgui //-------------------------------------------------------------------- @@ -275,6 +274,8 @@ bool FCogImguiContext::BeginFrame(float InDeltaTime) 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) { @@ -574,11 +575,22 @@ static UPlayerInput* GetPlayerInput(const UWorld* World) APlayerController* ItPlayerController = Iterator->Get(); if (ItPlayerController->IsLocalController()) { - PlayerController = ItPlayerController; - break; + return ItPlayerController; } } + return nullptr; +} + +//-------------------------------------------------------------------------------------------------------------------------- +static UPlayerInput* GetPlayerInput(const UWorld* World) +{ + if (World == nullptr) + { + return nullptr; + } + + APlayerController* PlayerController = GetLocalPlayerController(World); if (PlayerController == 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); + } + } + } } //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp index 301c1fd..dd736e4 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp @@ -156,6 +156,11 @@ FReply SCogImguiWidget::HandleKeyEvent(const FKeyEvent& KeyEvent, bool Down) IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown()); IO.AddKeyEvent(ImGuiMod_Super, KeyEvent.IsCommandDown()); + if (IO.WantCaptureKeyboard == false && Context->GetShareKeyboard()) + { + return FReply::Unhandled(); + } + return FReply::Handled(); } @@ -249,12 +254,26 @@ FReply SCogImguiWidget::OnFocusReceived(const FGeometry& MyGeometry, const FFocu //-------------------------------------------------------------------------------------------------------------------------- void SCogImguiWidget::RefreshVisibility() { + EVisibility DesiredVisiblity = EVisibility::SelfHitTestInvisible; + if (Context->GetEnableInput()) { - SetVisibility(EVisibility::Visible); + if (Context->GetShareMouse() && Context->GetWantCaptureMouse() == false) + { + DesiredVisiblity = EVisibility::SelfHitTestInvisible; + } + else + { + DesiredVisiblity = EVisibility::Visible; + } } else { - SetVisibility(EVisibility::SelfHitTestInvisible); + DesiredVisiblity = EVisibility::SelfHitTestInvisible; + } + + if (DesiredVisiblity != GetVisibility()) + { + SetVisibility(DesiredVisiblity); } } diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h index 82e68ff..c79b295 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h @@ -10,6 +10,7 @@ class FCogImguiContext; class IInputProcessor; class SCogImguiWidget; class SCogImguiWidget; +class SCogImguiInputCatcherWidget; class SWidget; class SWindow; class UGameViewportClient; @@ -36,10 +37,20 @@ public: void SetEnableInput(bool Value); + bool GetWantCaptureMouse() const { return bWantCaptureMouse; } + bool GetShareMouse() const { return bShareMouse; } 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); void EndFrame(); @@ -48,6 +59,10 @@ public: void SetDPIScale(float Value); + void PushCaptureMouse(); + + void PopCaptureMouse(); + TObjectPtr GetGameViewport() const { return GameViewport; } TSharedPtr GetMainWidget() const { return MainWidget; } @@ -62,6 +77,8 @@ private: void BuildFont(); + void RefreshMouseCursor(); + ULocalPlayer* GetLocalPlayer() const; static void ImGui_CreateWindow(ImGuiViewport* Viewport); @@ -101,6 +118,8 @@ private: TSharedPtr MainWidget = nullptr; + TSharedPtr InputCatcherWidget = nullptr; + TWeakPtr PreviousMouseCaptor = nullptr; TObjectPtr GameViewport = nullptr; @@ -113,7 +132,13 @@ private: bool bEnableInput = false; - bool bShareMouse = true; + bool bShareMouse = false; + + bool bShowCursorWhenSharingMouse = false; + + bool bPlayerControllerShowMouse = false; + + bool bShareKeyboard = false; bool bRefreshDPIScale = false; @@ -121,6 +146,9 @@ private: bool bIsFirstFrame = true; - float DpiScale = 1.f; + bool bWantCaptureMouse = false; + int32 CaptureMouseCount = 0; + + float DpiScale = 1.f; }; diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp index 22dfbed..4743a8b 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp @@ -79,25 +79,6 @@ void FCogWindow::Render(float DeltaTime) 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 (bHasMenu) @@ -215,4 +196,3 @@ UWorld* FCogWindow::GetWorld() const { return Owner->GetWorld(); } - diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp index 5e271d1..1deed0c 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp @@ -166,6 +166,7 @@ void UCogWindowManager::Render(float DeltaTime) ImGui::DockSpaceOverViewport(0, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingInCentralNode | ImGuiDockNodeFlags_AutoHideTabBar); ImGui::PopStyleColor(1); + const bool bCompactSaved = SettingsWindow->GetSettingsConfig()->bCompactMode; if (bCompactSaved) { @@ -518,6 +519,8 @@ void UCogWindowManager::RenderMenuItem(FCogWindow& Window, const char* MenuItemN { Window.SetIsVisible(!Window.GetIsVisible()); } + + RenderMenuItemHelp(Window); } else { @@ -526,6 +529,37 @@ void UCogWindowManager::RenderMenuItem(FCogWindow& Window, const char* MenuItemN { 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")); Context.SetEnableInput(!Context.GetEnableInput()); -} \ No newline at end of file +} + diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp index bda2800..c4dfc77 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp @@ -18,17 +18,19 @@ void FCogWindow_Settings::Initialize() ImGuiIO& IO = ImGui::GetIO(); 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); FCogImguiContext& Context = GetOwner()->GetContext(); 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(); - //ImGuiIO& IO = ImGui::GetIO(); - //Config->bNavEnableKeyboard = IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard; + ImGuiIO& IO = ImGui::GetIO(); + Config->bNavEnableKeyboard = IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard; //Config->bNavEnableGamepad = IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad; //Config->bNavNoCaptureInput = IO.ConfigFlags & ImGuiConfigFlags_NavNoCaptureKeyboard; - //Config->bNoMouseCursorChange = IO.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange; const FCogImguiContext& Context = GetOwner()->GetContext(); 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(); FCogImguiContext& Context = GetOwner()->GetContext(); + + //----------------------------- + // bEnableInput + //----------------------------- bool bEnableInput = Context.GetEnableInput(); if (ImGui::Checkbox("Enable Input", &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(*FCogImguiInputHelper::CommandToString(PlayerInput, UCogWindowManager::ToggleInputCommand)); 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(); } + //----------------------------- + // 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(); ImGui::SliderFloat("DPI Scale", &Config->DPIScale, 0.5f, 2.0f, "%.1f"); if (ImGui::IsItemDeactivatedAfterEdit()) { SetDPIScale(Config->DPIScale); } - - if (ImGui::IsItemHovered()) + if (ImGui::BeginItemTooltip()) { - ImGui::BeginTooltip(); ImGui::TextUnformatted("Change DPi Scale [Mouse Wheel]"); ImGui::TextUnformatted("Reset DPi Scale [Middle Mouse]"); ImGui::EndTooltip(); } + //----------------------------- + // EnableViewports + //----------------------------- if (ImGui::Checkbox("Enable Viewports", &Config->bEnableViewports)) { FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_ViewportsEnable, Config->bEnableViewports); } + ImGui::SetItemTooltip("Enable moving ImGui windows outside of the main viewport."); - if (ImGui::IsItemHovered()) - { - ImGui::SetTooltip("Cog imgui viewport integration in Unreal is still experimental"); - } - + //----------------------------- + // CompactMode + //----------------------------- ImGui::Checkbox("Compact Mode", &Config->bCompactMode); - - ImGui::Checkbox("Show Windows In Main Menu", &Config->bShowWindowsInMainMenu); - - ImGui::Checkbox("Show Window Help", &Config->bShowHelp); + ImGui::SetItemTooltip("Enable compact mode."); - //bool bShareMouse = Context.GetShareMouse(); - //if (ImGui::Checkbox("Share Mouse", &bShareMouse)) - //{ - // Context.SetShareMouse(bShareMouse); - //} + //----------------------------- + // ShowWindowsInMainMenu + //----------------------------- + 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); - //ImGui::CheckboxFlags("Navigation No Capture", &IO.ConfigFlags, ImGuiConfigFlags_NavNoCaptureKeyboard); - //ImGui::CheckboxFlags("No Mouse Cursor Change", &IO.ConfigFlags, ImGuiConfigFlags_NoMouseCursorChange); + //----------------------------- + // ShowHelp + //----------------------------- + ImGui::Checkbox("Show Help", &Config->bShowHelp); + ImGui::SetItemTooltip("Show windows help on the window menu items."); ImGui::Separator(); - if (ImGui::Button("Reset All Windows Config")) + if (ImGui::Button("Reset All Windows Config", ImVec2(-1.0f, 0.0f))) { GetOwner()->ResetAllWindowsConfig(); } - } //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h index 87d8774..2913f05 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h @@ -101,6 +101,8 @@ protected: virtual void RenderMenuItem(FCogWindow& Window, const char* MenuItemName); + void RenderMenuItemHelp(FCogWindow& Window); + virtual void ToggleInputMode(); static void SettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*); diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h b/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h index 2e93c84..e4fba1f 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h @@ -66,6 +66,12 @@ public: UPROPERTY(Config) bool bShareMouse = false; + UPROPERTY(Config) + bool bShowCursorWhenSharingMouse = false; + + UPROPERTY(Config) + bool bShareKeyboard = false; + UPROPERTY(Config) bool bNavEnableKeyboard = false; @@ -90,9 +96,9 @@ public: bShowWindowsInMainMenu = true; bEnableInput = false; bShareMouse = false; + bShareKeyboard = false; bNavEnableKeyboard = false; - bNavEnableGamepad = false; - bNavNoCaptureInput = true; - bNoMouseCursorChange = false; + //bNavEnableGamepad = false; + //bNavNoCaptureInput = true; } }; \ No newline at end of file