Messing around trying to get input sharing to work

This commit is contained in:
ben 2022-03-26 07:45:04 -07:00
parent 14749e50bb
commit 91825ac883
7 changed files with 95 additions and 0 deletions

View File

@ -28,8 +28,12 @@ void FImGuiDrawList::CopyVertexData(TArray<FSlateVertex>& OutVertexBuffer, const
SlateVertex.Position[0] = VertexPosition.X; SlateVertex.Position[0] = VertexPosition.X;
SlateVertex.Position[1] = VertexPosition.Y; SlateVertex.Position[1] = VertexPosition.Y;
SlateVertex.ClipRect = VertexClippingRect; SlateVertex.ClipRect = VertexClippingRect;
#else
#if ENGINE_COMPATIBILITY_LEGACY_VECTOR2F
SlateVertex.Position = Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos));
#else #else
SlateVertex.Position = (FVector2f)Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos)); SlateVertex.Position = (FVector2f)Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos));
#endif // ENGINE_COMPATIBILITY_LEGACY_VECTOR2F
#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API #endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API
// Unpack ImU32 color. // Unpack ImU32 color.

View File

@ -126,6 +126,15 @@ FReply UImGuiInputHandler::OnMouseButtonDown(const FPointerEvent& MouseEvent)
} }
InputState->SetMouseDown(MouseEvent, true); 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); return ToReply(true);
} }

View File

@ -0,0 +1 @@
#include "ImGuiInputPreprocessor.h"

View File

@ -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<ICursor> 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;
};

View File

@ -4,6 +4,7 @@
#include "ImGuiDelegatesContainer.h" #include "ImGuiDelegatesContainer.h"
#include "ImGuiModuleManager.h" #include "ImGuiModuleManager.h"
#include "ImGuiInputPreprocessor.h"
#include "TextureManager.h" #include "TextureManager.h"
#include "Utilities/WorldContext.h" #include "Utilities/WorldContext.h"
#include "Utilities/WorldContextIndex.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.")); checkf(!ImGuiModuleManager, TEXT("Instance of the ImGui Module Manager already exists. Instance should be created only during module startup."));
ImGuiModuleManager = new FImGuiModuleManager(); ImGuiModuleManager = new FImGuiModuleManager();
ImGuiInputPreprocessor = MakeShared<FImGuiInputPreprocessor>(*ImGuiModuleManager);
FSlateApplication::Get().RegisterInputPreProcessor(ImGuiInputPreprocessor, 0);
#if WITH_EDITOR #if WITH_EDITOR
checkf(!ImGuiEditor, TEXT("Instance of the ImGui Editor already exists. Instance should be created only during module startup.")); checkf(!ImGuiEditor, TEXT("Instance of the ImGui Editor already exists. Instance should be created only during module startup."));
ImGuiEditor = new FImGuiEditor(); ImGuiEditor = new FImGuiEditor();

View File

@ -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. // 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_KEY_AXIS_API BELOW_ENGINE_VERSION(4, 26)
#define ENGINE_COMPATIBILITY_LEGACY_VECTOR2F BELOW_ENGINE_VERSION(5, 0)

View File

@ -165,6 +165,7 @@ public:
virtual void ShutdownModule() override; virtual void ShutdownModule() override;
private: private:
TSharedPtr<class FImGuiInputPreprocessor> ImGuiInputPreprocessor;
#if WITH_EDITOR #if WITH_EDITOR
virtual void SetProperties(const FImGuiModuleProperties& Properties); virtual void SetProperties(const FImGuiModuleProperties& Properties);