Skip to content

Commit

Permalink
[NUI] Add HoverEvent in Window
Browse files Browse the repository at this point in the history
Window window = NUIApplication.GetDefaultWindow();
window.HoverEvent += OnHover;

private void OnHover(object source, Window.HoverEventArgs e)
{
  // e.Hover.GetState(0); // PointStateType.Motion;
}
  • Loading branch information
JoogabYun committed Sep 21, 2023
1 parent 1a4b66f commit 462bc99
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/Tizen.NUI/src/public/Window/WindowEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);


/// <summary>
Expand Down Expand Up @@ -152,6 +155,7 @@ public event EventHandler<TouchEventArgs> TouchEvent
}
}


/// <summary>
/// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
/// The touched signal is emitted when the touch input is received.<br />
Expand Down Expand Up @@ -344,6 +348,35 @@ public event EventHandler<ResizedEventArgs> Resized
}
}

/// <summary>
/// An event for the hovered signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
/// The hovered signal is emitted when the hover input is received.<br />
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<HoverEventArgs> 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;
}
}
}

/// <summary>
/// Do not use this, that will be deprecated. Use 'FocusChanged' event instead.
/// </summary>
Expand Down Expand Up @@ -657,6 +690,7 @@ public event EventHandler<PointerConstraintsEventArgs> PointerConstraintsEvent
private event EventHandler<WindowResizeCompletedEventArgs> resizeCompletedHandler;
private event EventHandler<InsetsChangedEventArgs> insetsChangedEventHandler;
private event EventHandler<PointerConstraintsEventArgs> windowPointerConstraintsEventHandler;
private event EventHandler<HoverEventArgs> rootLayerHoverDataEventHandler;


internal event EventHandler EventProcessingFinished
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

/// <summary>
/// The focus changed event argument.
/// </summary>
Expand Down Expand Up @@ -1459,6 +1517,31 @@ public PointerConstraints PointerConstraints
}
}

/// <summary>
/// Event arguments that passed via the hover signal.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class HoverEventArgs : EventArgs
{
private Hover hover;

/// <summary>
/// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public Hover Hover
{
get
{
return hover;
}
set
{
hover = value;
}
}
}

/// <summary>
/// Do not use this, that will be deprecated.
/// </summary>
Expand Down

0 comments on commit 462bc99

Please sign in to comment.