From 91825ac8832814b85bf9cd6154d5c4bac61298f1 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 26 Mar 2022 07:45:04 -0700 Subject: [PATCH] Messing around trying to get input sharing to work --- Source/ImGui/Private/ImGuiDrawData.cpp | 4 + Source/ImGui/Private/ImGuiInputHandler.cpp | 9 +++ .../ImGui/Private/ImGuiInputPreprocessor.cpp | 1 + Source/ImGui/Private/ImGuiInputPreprocessor.h | 74 +++++++++++++++++++ Source/ImGui/Private/ImGuiModule.cpp | 4 + Source/ImGui/Private/VersionCompatibility.h | 2 + Source/ImGui/Public/ImGuiModule.h | 1 + 7 files changed, 95 insertions(+) create mode 100644 Source/ImGui/Private/ImGuiInputPreprocessor.cpp create mode 100644 Source/ImGui/Private/ImGuiInputPreprocessor.h diff --git a/Source/ImGui/Private/ImGuiDrawData.cpp b/Source/ImGui/Private/ImGuiDrawData.cpp index ab6c5a9..affae9b 100644 --- a/Source/ImGui/Private/ImGuiDrawData.cpp +++ b/Source/ImGui/Private/ImGuiDrawData.cpp @@ -28,8 +28,12 @@ void FImGuiDrawList::CopyVertexData(TArray& OutVertexBuffer, const SlateVertex.Position[0] = VertexPosition.X; SlateVertex.Position[1] = VertexPosition.Y; SlateVertex.ClipRect = VertexClippingRect; +#else +#if ENGINE_COMPATIBILITY_LEGACY_VECTOR2F + SlateVertex.Position = Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos)); #else SlateVertex.Position = (FVector2f)Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos)); +#endif // ENGINE_COMPATIBILITY_LEGACY_VECTOR2F #endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API // Unpack ImU32 color. diff --git a/Source/ImGui/Private/ImGuiInputHandler.cpp b/Source/ImGui/Private/ImGuiInputHandler.cpp index b11f7d6..9b2c089 100644 --- a/Source/ImGui/Private/ImGuiInputHandler.cpp +++ b/Source/ImGui/Private/ImGuiInputHandler.cpp @@ -126,6 +126,15 @@ FReply UImGuiInputHandler::OnMouseButtonDown(const FPointerEvent& MouseEvent) } InputState->SetMouseDown(MouseEvent, true); + if (ModuleManager) + { + FImGuiContextProxy* Proxy = ModuleManager->GetContextManager().GetContextProxy(0); + if (Proxy) + { + GEngine->AddOnScreenDebugMessage(15, 10, Proxy->WantsMouseCapture() ? FColor::Green : FColor::Red, TEXT("Handler Down")); + return ToReply(Proxy->WantsMouseCapture()); + } + } return ToReply(true); } diff --git a/Source/ImGui/Private/ImGuiInputPreprocessor.cpp b/Source/ImGui/Private/ImGuiInputPreprocessor.cpp new file mode 100644 index 0000000..19dae20 --- /dev/null +++ b/Source/ImGui/Private/ImGuiInputPreprocessor.cpp @@ -0,0 +1 @@ +#include "ImGuiInputPreprocessor.h" diff --git a/Source/ImGui/Private/ImGuiInputPreprocessor.h b/Source/ImGui/Private/ImGuiInputPreprocessor.h new file mode 100644 index 0000000..dbcb3dc --- /dev/null +++ b/Source/ImGui/Private/ImGuiInputPreprocessor.h @@ -0,0 +1,74 @@ +#pragma once + +#include "ImGuiModuleManager.h" +#include "Framework/Application/IInputProcessor.h" + +class FImGuiModuleManager; + +class FImGuiInputPreprocessor : public IInputProcessor +{ +public: + FImGuiInputPreprocessor(FImGuiModuleManager& InModuleManager) + : ModuleManager(InModuleManager) + { + } + + virtual void Tick(const float DeltaTime, FSlateApplication& SlateApp, TSharedRef Cursor) override + { + } + + virtual bool HandleKeyDownEvent(FSlateApplication& SlateApp, const FKeyEvent& InKeyEvent) override + { + return false; + } + + virtual bool + HandleAnalogInputEvent(FSlateApplication& SlateApp, const FAnalogInputEvent& InAnalogInputEvent) override + { + return false; + } + + virtual bool HandleMouseMoveEvent(FSlateApplication& SlateApp, const FPointerEvent& InPointerEvent) override + { + const bool bIsWindowHovered = ImGui::IsWindowHovered(); + FImGuiContextProxy* Proxy = ModuleManager.GetContextManager().GetContextProxy(0); + if (Proxy) + { + GEngine->AddOnScreenDebugMessage(10, 0, Proxy->WantsMouseCapture() ? FColor::Green : FColor::Red, TEXT("Move Capture")); + } + else + { + GEngine->AddOnScreenDebugMessage(10, 0, FColor::Red, TEXT("No proxy")); + } + + GEngine->AddOnScreenDebugMessage(1, 0, bIsWindowHovered ? FColor::Green : FColor::Red, TEXT("Move Hover")); + return false; + } + + virtual bool HandleMouseButtonDownEvent(FSlateApplication& SlateApp, const FPointerEvent& InPointerEvent) override + { + //if (ModuleManager.GetProperties().IsMouseInputShared()) + { + const bool bIsWindowHovered = ImGui::IsWindowHovered(); + GEngine->AddOnScreenDebugMessage(2, 10, bIsWindowHovered ? FColor::Green : FColor::Red, TEXT("Click Hover")); + return bIsWindowHovered; + } + return false; + } + + virtual bool + HandleMouseButtonDoubleClickEvent(FSlateApplication& SlateApp, const FPointerEvent& InPointerEvent) override + { + return false; + } + + virtual const TCHAR* GetDebugName() const override { return TEXT("CommonInput"); } + +private: + bool IsRelevantInput(FSlateApplication& SlateApp, const FInputEvent& InputEvent) + { + return false; + } + + FImGuiModuleManager& ModuleManager; +}; diff --git a/Source/ImGui/Private/ImGuiModule.cpp b/Source/ImGui/Private/ImGuiModule.cpp index ea12089..2f22024 100644 --- a/Source/ImGui/Private/ImGuiModule.cpp +++ b/Source/ImGui/Private/ImGuiModule.cpp @@ -4,6 +4,7 @@ #include "ImGuiDelegatesContainer.h" #include "ImGuiModuleManager.h" +#include "ImGuiInputPreprocessor.h" #include "TextureManager.h" #include "Utilities/WorldContext.h" #include "Utilities/WorldContextIndex.h" @@ -117,6 +118,9 @@ void FImGuiModule::StartupModule() checkf(!ImGuiModuleManager, TEXT("Instance of the ImGui Module Manager already exists. Instance should be created only during module startup.")); ImGuiModuleManager = new FImGuiModuleManager(); + ImGuiInputPreprocessor = MakeShared(*ImGuiModuleManager); + FSlateApplication::Get().RegisterInputPreProcessor(ImGuiInputPreprocessor, 0); + #if WITH_EDITOR checkf(!ImGuiEditor, TEXT("Instance of the ImGui Editor already exists. Instance should be created only during module startup.")); ImGuiEditor = new FImGuiEditor(); diff --git a/Source/ImGui/Private/VersionCompatibility.h b/Source/ImGui/Private/VersionCompatibility.h index 8a9438b..0ddf930 100644 --- a/Source/ImGui/Private/VersionCompatibility.h +++ b/Source/ImGui/Private/VersionCompatibility.h @@ -33,3 +33,5 @@ // Starting from version 4.26, FKey::IsFloatAxis and FKey::IsVectorAxis are deprecated and replaced with FKey::IsAxis[1|2|3]D methods. #define ENGINE_COMPATIBILITY_LEGACY_KEY_AXIS_API BELOW_ENGINE_VERSION(4, 26) + +#define ENGINE_COMPATIBILITY_LEGACY_VECTOR2F BELOW_ENGINE_VERSION(5, 0) diff --git a/Source/ImGui/Public/ImGuiModule.h b/Source/ImGui/Public/ImGuiModule.h index ec2ac4a..f147727 100644 --- a/Source/ImGui/Public/ImGuiModule.h +++ b/Source/ImGui/Public/ImGuiModule.h @@ -165,6 +165,7 @@ public: virtual void ShutdownModule() override; private: + TSharedPtr ImGuiInputPreprocessor; #if WITH_EDITOR virtual void SetProperties(const FImGuiModuleProperties& Properties);