From 462bc99bcb08332387ad952111055a7bdc13f5d5 Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Mon, 28 Aug 2023 15:10:16 +0900 Subject: [PATCH] [NUI] Add HoverEvent in Window Window window = NUIApplication.GetDefaultWindow(); window.HoverEvent += OnHover; private void OnHover(object source, Window.HoverEventArgs e) { // e.Hover.GetState(0); // PointStateType.Motion; } --- .../src/public/Window/WindowEvent.cs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/Tizen.NUI/src/public/Window/WindowEvent.cs b/src/Tizen.NUI/src/public/Window/WindowEvent.cs index 9036e535102..72d091ff2a1 100755 --- a/src/Tizen.NUI/src/public/Window/WindowEvent.cs +++ b/src/Tizen.NUI/src/public/Window/WindowEvent.cs @@ -57,6 +57,7 @@ public partial class Window private ResizeCompletedEventCallbackType resizeCompletedEventCallback; private InsetsChangedEventCallbackType insetsChangedEventCallback; private WindowPointerConstraintsEventCallback windowPointerConstraintsEventCallback; + private RootLayerHoverDataCallbackType rootLayerHoverDataCallback; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void WindowFocusChangedEventCallbackType(IntPtr window, bool focusGained); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -91,6 +92,8 @@ public partial class Window private delegate void InsetsChangedEventCallbackType(int partType, int partState, IntPtr extents); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void WindowPointerConstraintsEventCallback(IntPtr window, IntPtr constraintsEvent); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate bool RootLayerHoverDataCallbackType(IntPtr view, IntPtr hoverData); /// @@ -152,6 +155,7 @@ public event EventHandler TouchEvent } } + /// /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The touched signal is emitted when the touch input is received.
@@ -344,6 +348,35 @@ public event EventHandler Resized } } + /// + /// An event for the hovered signal which can be used to subscribe or unsubscribe the event handler provided by the user.
+ /// The hovered signal is emitted when the hover input is received.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler HoverEvent + { + add + { + if (rootLayerHoverDataEventHandler == null) + { + rootLayerHoverDataCallback = OnWindowHover; + Interop.ActorSignal.HoveredConnect(Layer.getCPtr(GetRootLayer()), rootLayerHoverDataCallback.ToHandleRef(this)); + NDalicPINVOKE.ThrowExceptionIfExists(); + } + rootLayerHoverDataEventHandler += value; + } + remove + { + rootLayerHoverDataEventHandler -= value; + if (rootLayerHoverDataEventHandler == null && rootLayerHoverDataCallback != null) + { + Interop.ActorSignal.HoveredDisconnect(Layer.getCPtr(GetRootLayer()), rootLayerHoverDataCallback.ToHandleRef(this)); + NDalicPINVOKE.ThrowExceptionIfExists(); + rootLayerHoverDataCallback = null; + } + } + } + /// /// Do not use this, that will be deprecated. Use 'FocusChanged' event instead. /// @@ -657,6 +690,7 @@ public event EventHandler PointerConstraintsEvent private event EventHandler resizeCompletedHandler; private event EventHandler insetsChangedEventHandler; private event EventHandler windowPointerConstraintsEventHandler; + private event EventHandler rootLayerHoverDataEventHandler; internal event EventHandler EventProcessingFinished @@ -955,6 +989,13 @@ internal void DisconnectNativeSignals() signal?.Disconnect(windowPointerConstraintsEventCallback); windowPointerConstraintsEventCallback = null; } + + if (rootLayerHoverDataCallback != null) + { + Interop.ActorSignal.HoveredDisconnect(Layer.getCPtr(GetRootLayer()), rootLayerHoverDataCallback.ToHandleRef(this)); + NDalicPINVOKE.ThrowExceptionIfExists(); + rootLayerHoverDataCallback = null; + } } private void OnWindowFocusedChanged(IntPtr window, bool focusGained) @@ -1265,6 +1306,23 @@ private void OnWindowPointerConstraintsEvent(IntPtr view, IntPtr constraintsEven } } + private bool OnWindowHover(IntPtr view, IntPtr hoverData) + { + if (hoverData == global::System.IntPtr.Zero) + { + NUILog.Error("hoverData should not be null!"); + return false; + } + + if (rootLayerHoverDataEventHandler != null) + { + HoverEventArgs e = new HoverEventArgs(); + e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverData); + rootLayerHoverDataEventHandler(this, e); + } + return false; + } + /// /// The focus changed event argument. /// @@ -1459,6 +1517,31 @@ public PointerConstraints PointerConstraints } } + /// + /// Event arguments that passed via the hover signal. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class HoverEventArgs : EventArgs + { + private Hover hover; + + /// + /// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Hover Hover + { + get + { + return hover; + } + set + { + hover = value; + } + } + } + /// /// Do not use this, that will be deprecated. ///