From 829be000349a021c8329da50d63399aa3311f8f9 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Mon, 18 Dec 2023 12:47:38 -0500 Subject: [PATCH] CogImGui: Fix key down/up not properly sent to imgui --- .../CogImgui/Private/CogImguiWidget.cpp | 21 ++++++++++--------- .../Source/CogImgui/Public/CogImguiWidget.h | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp index fa6d491..ea1cb80 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp @@ -37,12 +37,12 @@ void SCogImguiWidget::Tick(const FGeometry& AllottedGeometry, const double InCur //-------------------------------------------------------------------------------------------------------------------------- int32 SCogImguiWidget::OnPaint( - const FPaintArgs& Args, - const FGeometry& AllottedGeometry, + const FPaintArgs& Args, + const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, - FSlateWindowElementList& OutDrawElements, - int32 LayerId, - const FWidgetStyle& WidgetStyle, + FSlateWindowElementList& OutDrawElements, + int32 LayerId, + const FWidgetStyle& WidgetStyle, bool bParentEnabled) const { @@ -122,17 +122,17 @@ FReply SCogImguiWidget::OnKeyChar(const FGeometry& MyGeometry, const FCharacterE //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) { - return HandleKeyEvent(MyGeometry, KeyEvent); + return HandleKeyEvent(MyGeometry, KeyEvent, true); } //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) { - return HandleKeyEvent(MyGeometry, KeyEvent); + return HandleKeyEvent(MyGeometry, KeyEvent, false); } //-------------------------------------------------------------------------------------------------------------------------- -FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) +FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down) { if (Context->GetEnableInput() == false) { @@ -152,8 +152,9 @@ FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEv { return FReply::Unhandled(); } + ImGuiIO& IO = ImGui::GetIO(); - IO.AddKeyEvent(FCogImguiInputHelper::ToImKey(KeyEvent.GetKey()), false); + IO.AddKeyEvent(FCogImguiInputHelper::ToImKey(KeyEvent.GetKey()), Down); IO.AddKeyEvent(ImGuiMod_Ctrl, KeyEvent.IsControlDown()); IO.AddKeyEvent(ImGuiMod_Shift, KeyEvent.IsShiftDown()); IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown()); @@ -177,7 +178,7 @@ FReply SCogImguiWidget::OnAnalogValueChanged(const FGeometry& MyGeometry, const // return FReply::Unhandled(); //} - return FReply::Unhandled(); + return FReply::Unhandled(); } return FReply::Handled(); diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h index 9a361e0..9c8c0d8 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h @@ -19,7 +19,7 @@ class COGIMGUI_API SCogImguiWidget : public SLeafWidget public: SLATE_BEGIN_ARGS(SCogImguiWidget) {} - SLATE_ARGUMENT(FCogImguiContext*, Context) + SLATE_ARGUMENT(FCogImguiContext*, Context) SLATE_END_ARGS() void Construct(const FArguments& InArgs); @@ -53,7 +53,7 @@ public: protected: - FReply HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent); + FReply HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down); void RefreshVisibility();