From 95d27334fee52a141285413f3a1b73212aee0883 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 8 Aug 2019 18:06:07 +0100 Subject: [PATCH] Updated input handler to ignore fake mouse events potentially raised when touch input is unhandled. --- Source/ImGui/Private/ImGuiInputHandler.cpp | 20 +++++++++++++++++++ Source/ImGui/Private/Widgets/SImGuiWidget.cpp | 2 +- Source/ImGui/Public/ImGuiInputHandler.h | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Source/ImGui/Private/ImGuiInputHandler.cpp b/Source/ImGui/Private/ImGuiInputHandler.cpp index 87d0b0f..4f614fc 100644 --- a/Source/ImGui/Private/ImGuiInputHandler.cpp +++ b/Source/ImGui/Private/ImGuiInputHandler.cpp @@ -117,6 +117,11 @@ FReply UImGuiInputHandler::OnAnalogValueChanged(const FAnalogInputEvent& AnalogI FReply UImGuiInputHandler::OnMouseButtonDown(const FPointerEvent& MouseEvent) { + if (MouseEvent.IsTouchEvent()) + { + return ToReply(false); + } + InputState->SetMouseDown(MouseEvent, true); return ToReply(true); } @@ -129,6 +134,11 @@ FReply UImGuiInputHandler::OnMouseButtonDoubleClick(const FPointerEvent& MouseEv FReply UImGuiInputHandler::OnMouseButtonUp(const FPointerEvent& MouseEvent) { + if (MouseEvent.IsTouchEvent()) + { + return ToReply(false); + } + InputState->SetMouseDown(MouseEvent, false); return ToReply(true); } @@ -139,6 +149,16 @@ FReply UImGuiInputHandler::OnMouseWheel(const FPointerEvent& MouseEvent) return ToReply(true); } +FReply UImGuiInputHandler::OnMouseMove(const FVector2D& MousePosition, const FPointerEvent& MouseEvent) +{ + if (MouseEvent.IsTouchEvent()) + { + return ToReply(false); + } + + return OnMouseMove(MousePosition); +} + FReply UImGuiInputHandler::OnMouseMove(const FVector2D& MousePosition) { InputState->SetMousePosition(MousePosition); diff --git a/Source/ImGui/Private/Widgets/SImGuiWidget.cpp b/Source/ImGui/Private/Widgets/SImGuiWidget.cpp index 8a54a15..8596103 100644 --- a/Source/ImGui/Private/Widgets/SImGuiWidget.cpp +++ b/Source/ImGui/Private/Widgets/SImGuiWidget.cpp @@ -189,7 +189,7 @@ FReply SImGuiWidget::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEve FReply SImGuiWidget::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { - return InputHandler->OnMouseMove(TransformScreenPointToImGui(MyGeometry, MouseEvent.GetScreenSpacePosition())); + return InputHandler->OnMouseMove(TransformScreenPointToImGui(MyGeometry, MouseEvent.GetScreenSpacePosition()), MouseEvent); } FReply SImGuiWidget::OnFocusReceived(const FGeometry& MyGeometry, const FFocusEvent& FocusEvent) diff --git a/Source/ImGui/Public/ImGuiInputHandler.h b/Source/ImGui/Public/ImGuiInputHandler.h index a73b599..37427e0 100644 --- a/Source/ImGui/Public/ImGuiInputHandler.h +++ b/Source/ImGui/Public/ImGuiInputHandler.h @@ -83,8 +83,10 @@ public: /** * Called to handle mouse move events. * @param MousePosition Mouse position (in ImGui space) + * @param MouseEvent Optional mouse event passed from Slate * @returns Response whether the event was handled */ + virtual FReply OnMouseMove(const FVector2D& MousePosition, const FPointerEvent& MouseEvent); virtual FReply OnMouseMove(const FVector2D& MousePosition); /**