mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 16:30:32 +00:00
Cleanup in SImGuiWidget:
- Removed mouse status update. - Removed mouse notifications. - Removed unused function to copy modifier keys on mouse events (key down/up versions are still in use).
This commit is contained in:
parent
2d728f1f26
commit
22c5b42387
@ -9,7 +9,7 @@ Dear ImGui is an immediate-mode graphical user interface library that is very li
|
|||||||
|
|
||||||
Status
|
Status
|
||||||
------
|
------
|
||||||
Version: 1.16
|
Version: 1.17 WIP
|
||||||
|
|
||||||
ImGui version: 1.65
|
ImGui version: 1.65
|
||||||
|
|
||||||
|
@ -130,8 +130,6 @@ void SImGuiWidget::Tick(const FGeometry& AllottedGeometry, const double InCurren
|
|||||||
{
|
{
|
||||||
Super::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
|
Super::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
|
||||||
|
|
||||||
UpdateMouseStatus();
|
|
||||||
|
|
||||||
// Note: Moving that update to console variable sink or callback might seem like a better alternative but input
|
// Note: Moving that update to console variable sink or callback might seem like a better alternative but input
|
||||||
// setup in this function is better handled here.
|
// setup in this function is better handled here.
|
||||||
UpdateInputEnabled();
|
UpdateInputEnabled();
|
||||||
@ -239,32 +237,24 @@ FReply SImGuiWidget::OnAnalogValueChanged(const FGeometry& MyGeometry, const FAn
|
|||||||
FReply SImGuiWidget::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
FReply SImGuiWidget::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||||
{
|
{
|
||||||
InputState.SetMouseDown(MouseEvent, true);
|
InputState.SetMouseDown(MouseEvent, true);
|
||||||
CopyModifierKeys(MouseEvent);
|
|
||||||
|
|
||||||
return FReply::Handled();
|
return FReply::Handled();
|
||||||
}
|
}
|
||||||
|
|
||||||
FReply SImGuiWidget::OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
FReply SImGuiWidget::OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||||
{
|
{
|
||||||
InputState.SetMouseDown(MouseEvent, true);
|
InputState.SetMouseDown(MouseEvent, true);
|
||||||
CopyModifierKeys(MouseEvent);
|
|
||||||
|
|
||||||
return FReply::Handled();
|
return FReply::Handled();
|
||||||
}
|
}
|
||||||
|
|
||||||
FReply SImGuiWidget::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
FReply SImGuiWidget::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||||
{
|
{
|
||||||
InputState.SetMouseDown(MouseEvent, false);
|
InputState.SetMouseDown(MouseEvent, false);
|
||||||
CopyModifierKeys(MouseEvent);
|
|
||||||
|
|
||||||
return FReply::Handled();
|
return FReply::Handled();
|
||||||
}
|
}
|
||||||
|
|
||||||
FReply SImGuiWidget::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
FReply SImGuiWidget::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||||
{
|
{
|
||||||
InputState.AddMouseWheelDelta(MouseEvent.GetWheelDelta());
|
InputState.AddMouseWheelDelta(MouseEvent.GetWheelDelta());
|
||||||
CopyModifierKeys(MouseEvent);
|
|
||||||
|
|
||||||
return FReply::Handled();
|
return FReply::Handled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,11 +262,6 @@ FReply SImGuiWidget::OnMouseMove(const FGeometry& MyGeometry, const FPointerEven
|
|||||||
{
|
{
|
||||||
const FSlateRenderTransform ImGuiToScreen = ImGuiTransform.Concatenate(MyGeometry.GetAccumulatedRenderTransform());
|
const FSlateRenderTransform ImGuiToScreen = ImGuiTransform.Concatenate(MyGeometry.GetAccumulatedRenderTransform());
|
||||||
InputState.SetMousePosition(ImGuiToScreen.Inverse().TransformPoint(MouseEvent.GetScreenSpacePosition()));
|
InputState.SetMousePosition(ImGuiToScreen.Inverse().TransformPoint(MouseEvent.GetScreenSpacePosition()));
|
||||||
CopyModifierKeys(MouseEvent);
|
|
||||||
|
|
||||||
// This event is called in every frame when we have a mouse, so we can use it to raise notifications.
|
|
||||||
NotifyMouseEvent();
|
|
||||||
|
|
||||||
return FReply::Handled();
|
return FReply::Handled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,14 +380,6 @@ void SImGuiWidget::CopyModifierKeys(const FInputEvent& InputEvent)
|
|||||||
InputState.SetAltDown(InputEvent.IsAltDown());
|
InputState.SetAltDown(InputEvent.IsAltDown());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SImGuiWidget::CopyModifierKeys(const FPointerEvent& MouseEvent)
|
|
||||||
{
|
|
||||||
if (InputMode == EInputMode::MousePointerOnly)
|
|
||||||
{
|
|
||||||
CopyModifierKeys(static_cast<const FInputEvent&>(MouseEvent));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SImGuiWidget::IsConsoleOpened() const
|
bool SImGuiWidget::IsConsoleOpened() const
|
||||||
{
|
{
|
||||||
return GameViewport->ViewportConsole && GameViewport->ViewportConsole->ConsoleState != NAME_None;
|
return GameViewport->ViewportConsole && GameViewport->ViewportConsole->ConsoleState != NAME_None;
|
||||||
@ -548,29 +525,11 @@ void SImGuiWidget::UpdateInputMode(bool bHasKeyboardFocus, bool bHasMousePointer
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputMode = NewInputMode;
|
InputMode = NewInputMode;
|
||||||
|
|
||||||
ClearMouseEventNotification();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputState.SetMousePointer(bUseSoftwareCursor && bHasMousePointer);
|
InputState.SetMousePointer(bUseSoftwareCursor && bHasMousePointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SImGuiWidget::UpdateMouseStatus()
|
|
||||||
{
|
|
||||||
// Note: Mouse leave events can get lost if other viewport takes mouse capture (for instance console is opened by
|
|
||||||
// different viewport when this widget is hovered). With that we lose a chance to cleanup and hide ImGui pointer.
|
|
||||||
// We could either update ImGui pointer in every frame or like below, use mouse events to catch when mouse is lost.
|
|
||||||
|
|
||||||
if (InputMode == EInputMode::MousePointerOnly)
|
|
||||||
{
|
|
||||||
if (!HasMouseEventNotification())
|
|
||||||
{
|
|
||||||
UpdateInputMode(false, IsDirectlyHovered());
|
|
||||||
}
|
|
||||||
ClearMouseEventNotification();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SImGuiWidget::UpdateCanvasControlMode(const FInputEvent& InputEvent)
|
void SImGuiWidget::UpdateCanvasControlMode(const FInputEvent& InputEvent)
|
||||||
{
|
{
|
||||||
CanvasControlWidget->SetActive(InputEvent.IsLeftAltDown() && InputEvent.IsLeftShiftDown());
|
CanvasControlWidget->SetActive(InputEvent.IsLeftAltDown() && InputEvent.IsLeftShiftDown());
|
||||||
|
@ -96,7 +96,6 @@ private:
|
|||||||
void UnregisterImGuiSettingsDelegates();
|
void UnregisterImGuiSettingsDelegates();
|
||||||
|
|
||||||
FORCEINLINE void CopyModifierKeys(const FInputEvent& InputEvent);
|
FORCEINLINE void CopyModifierKeys(const FInputEvent& InputEvent);
|
||||||
FORCEINLINE void CopyModifierKeys(const FPointerEvent& MouseEvent);
|
|
||||||
|
|
||||||
bool IsConsoleOpened() const;
|
bool IsConsoleOpened() const;
|
||||||
|
|
||||||
@ -107,18 +106,11 @@ private:
|
|||||||
void TakeFocus();
|
void TakeFocus();
|
||||||
void ReturnFocus();
|
void ReturnFocus();
|
||||||
|
|
||||||
// Update input enabled state from console variable.
|
|
||||||
void UpdateInputEnabled();
|
void UpdateInputEnabled();
|
||||||
|
|
||||||
// Determine new input mode based on hints.
|
// Determine new input mode based on hints.
|
||||||
void UpdateInputMode(bool bHasKeyboardFocus, bool bHasMousePointer);
|
void UpdateInputMode(bool bHasKeyboardFocus, bool bHasMousePointer);
|
||||||
|
|
||||||
void UpdateMouseStatus();
|
|
||||||
|
|
||||||
FORCEINLINE bool HasMouseEventNotification() const { return bReceivedMouseEvent; }
|
|
||||||
FORCEINLINE void NotifyMouseEvent() { bReceivedMouseEvent = true; }
|
|
||||||
FORCEINLINE void ClearMouseEventNotification() { bReceivedMouseEvent = false; }
|
|
||||||
|
|
||||||
void UpdateCanvasControlMode(const FInputEvent& InputEvent);
|
void UpdateCanvasControlMode(const FInputEvent& InputEvent);
|
||||||
|
|
||||||
void OnPostImGuiUpdate();
|
void OnPostImGuiUpdate();
|
||||||
@ -149,7 +141,6 @@ private:
|
|||||||
|
|
||||||
EInputMode InputMode = EInputMode::None;
|
EInputMode InputMode = EInputMode::None;
|
||||||
bool bInputEnabled = false;
|
bool bInputEnabled = false;
|
||||||
bool bReceivedMouseEvent = false;
|
|
||||||
|
|
||||||
// Whether or not ImGui should draw its own cursor.
|
// Whether or not ImGui should draw its own cursor.
|
||||||
bool bUseSoftwareCursor = false;
|
bool bUseSoftwareCursor = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user