From 1e57288a69e9dda7dd4e4f83189ece6eba0edbf6 Mon Sep 17 00:00:00 2001 From: JanSeliv Date: Sat, 3 Jun 2023 20:56:19 -0400 Subject: [PATCH] Fixed hover is flickering for 2D widget: simplified logic --- .../Private/SCustomShapeButton.cpp | 29 +------------------ .../Public/SCustomShapeButton.h | 4 --- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/Source/CustomShapeButton/Private/SCustomShapeButton.cpp b/Source/CustomShapeButton/Private/SCustomShapeButton.cpp index c34f0ef..673745b 100644 --- a/Source/CustomShapeButton/Private/SCustomShapeButton.cpp +++ b/Source/CustomShapeButton/Private/SCustomShapeButton.cpp @@ -35,13 +35,6 @@ void SCustomShapeButton::SetCanHover(bool bAllow) TryDetectOnHovered(); } -void SCustomShapeButton::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) -{ - SButton::Tick(AllottedGeometry, InCurrentTime, InDeltaTime); - - TickDetectMouseLeave(InDeltaTime); -} - FReply SCustomShapeButton::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { UpdateMouseData(MyGeometry, MouseEvent); @@ -103,10 +96,7 @@ void SCustomShapeButton::OnMouseLeave(const FPointerEvent& MouseEvent) { SButton::OnMouseLeave(MouseEvent); - if (!IsAlphaPixelHovered()) - { - SetCanHover(false); - } + SetCanHover(false); } void SCustomShapeButton::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) @@ -210,23 +200,6 @@ void SCustomShapeButton::TryUpdateRawColorsOnce() }); } -// Try register leaving the button (e.g. another widget opens above) -void SCustomShapeButton::TickDetectMouseLeave(float DeltaTime) -{ - if (bCanHover - && CurrentGeometry.GetLocalSize().IsZero()) - { - // Current data is zero, so widget is not hovered anymore - OnMouseLeave(CurrentMouseEvent); - } - - // Reset data every tick, it will actualised during OnMouseMove - // so if data is empty, then Mouse Move did not happen - // and widget is not hovered anymore - static const FGeometry EmptyGeometry{}; - CurrentGeometry = EmptyGeometry; -} - // Try register On Hovered and On Unhovered events void SCustomShapeButton::TryDetectOnHovered() { diff --git a/Source/CustomShapeButton/Public/SCustomShapeButton.h b/Source/CustomShapeButton/Public/SCustomShapeButton.h index 4861fc6..252f34f 100644 --- a/Source/CustomShapeButton/Public/SCustomShapeButton.h +++ b/Source/CustomShapeButton/Public/SCustomShapeButton.h @@ -38,7 +38,6 @@ class CUSTOMSHAPEBUTTON_API SCustomShapeButton : public SButton /** Contains cached information about the mouse event. */ FPointerEvent CurrentMouseEvent; - virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override; virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; @@ -52,9 +51,6 @@ class CUSTOMSHAPEBUTTON_API SCustomShapeButton : public SButton /** Set once on render thread the buffer data about all pixels of current texture if was not set before. */ virtual void TryUpdateRawColorsOnce(); - /** Try register leaving the button (e.g. another widget opens above). */ - virtual void TickDetectMouseLeave(float DeltaTime); - /** Try register On Hovered and On Unhovered events. */ virtual void TryDetectOnHovered();