Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions src/Common.WinForms/Controls/GestureEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright Bastian Eicher
// Licensed under the MIT License

using System;

namespace NanoByte.Common.Controls;

/// <summary>
/// Flags for gesture information.
/// </summary>
[Flags]
public enum GestureFlags
{
/// <summary>Marks the beginning of a gesture.</summary>
Begin = 0x00000001,

/// <summary>Indicates that the gesture is in inertia mode.</summary>
Inertia = 0x00000002,

/// <summary>Marks the end of a gesture.</summary>
End = 0x00000004
}

/// <summary>
/// Base class for gesture event arguments.
/// </summary>
public abstract class GestureEventArgs : EventArgs
{
/// <summary>
/// The X coordinate of the gesture in client coordinates.
/// </summary>
public int LocationX { get; set; }

/// <summary>
/// The Y coordinate of the gesture in client coordinates.
/// </summary>
public int LocationY { get; set; }

/// <summary>
/// Flags indicating the state of the gesture.
/// </summary>
public GestureFlags Flags { get; set; }

/// <summary>
/// Unique identifier for this gesture sequence.
/// </summary>
public int SequenceId { get; set; }
}

/// <summary>
/// Event arguments for pan gesture.
/// </summary>
public class PanGestureEventArgs : GestureEventArgs
{
/// <summary>
/// The horizontal distance panned.
/// </summary>
public int PanDistanceX { get; set; }

/// <summary>
/// The vertical distance panned.
/// </summary>
public int PanDistanceY { get; set; }
}

/// <summary>
/// Event arguments for zoom gesture.
/// </summary>
public class ZoomGestureEventArgs : GestureEventArgs
{
/// <summary>
/// The distance between the two fingers.
/// </summary>
public long Distance { get; set; }
}

/// <summary>
/// Event arguments for rotate gesture.
/// </summary>
public class RotateGestureEventArgs : GestureEventArgs
{
/// <summary>
/// The angle of rotation in radians.
/// </summary>
public double Angle { get; set; }
}

/// <summary>
/// Event arguments for tap gesture (two-finger tap).
/// </summary>
public class TapGestureEventArgs : GestureEventArgs
{
}

/// <summary>
/// Event arguments for press and tap gesture.
/// </summary>
public class PressAndTapGestureEventArgs : GestureEventArgs
{
}
24 changes: 17 additions & 7 deletions src/Common.WinForms/Controls/ITouchControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@
namespace NanoByte.Common.Controls;

/// <summary>
/// A control that can raise touch events.
/// A control that can raise touch gesture events.
/// </summary>
public interface ITouchControl
{
/// <summary>
/// Raised when the user begins touching the screen.
/// Raised when the user performs a pan gesture.
/// </summary>
event EventHandler<TouchEventArgs> TouchDown;
event EventHandler<PanGestureEventArgs> Pan;

/// <summary>
/// Raised when the user stops touching the screen.
/// Raised when the user performs a zoom gesture.
/// </summary>
event EventHandler<TouchEventArgs> TouchUp;
event EventHandler<ZoomGestureEventArgs> Zoom;

/// <summary>
/// Raised when the user moves fingers while touching the screen.
/// Raised when the user performs a rotate gesture.
/// </summary>
event EventHandler<TouchEventArgs> TouchMove;
event EventHandler<RotateGestureEventArgs> Rotate;

/// <summary>
/// Raised when the user performs a two-finger tap gesture.
/// </summary>
event EventHandler<TapGestureEventArgs> Tap;

/// <summary>
/// Raised when the user performs a press and tap gesture.
/// </summary>
event EventHandler<PressAndTapGestureEventArgs> PressAndTap;
}
84 changes: 0 additions & 84 deletions src/Common.WinForms/Controls/TouchEventArgs.cs

This file was deleted.

20 changes: 14 additions & 6 deletions src/Common.WinForms/Controls/TouchForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
namespace NanoByte.Common.Controls;

/// <summary>
/// Represents a window that reacts to touch input on Windows 7 or newer.
/// Represents a window that reacts to touch gestures on Windows 7 or newer.
/// </summary>
public class TouchForm : Form, ITouchControl
{
/// <inheritdoc/>
public event EventHandler<TouchEventArgs>? TouchDown;
public event EventHandler<PanGestureEventArgs>? Pan;

/// <inheritdoc/>
public event EventHandler<TouchEventArgs>? TouchUp;
public event EventHandler<ZoomGestureEventArgs>? Zoom;

/// <inheritdoc/>
public event EventHandler<TouchEventArgs>? TouchMove;
public event EventHandler<RotateGestureEventArgs>? Rotate;

/// <inheritdoc/>
public event EventHandler<TapGestureEventArgs>? Tap;

/// <inheritdoc/>
public event EventHandler<PressAndTapGestureEventArgs>? PressAndTap;

protected override CreateParams CreateParams
{
Expand All @@ -39,15 +45,17 @@ protected override CreateParams CreateParams
protected override void CreateHandle()
{
base.CreateHandle();
WinFormsUtils.RegisterTouchWindow(this);
WinFormsUtils.RegisterGestureWindow(this);
}

#if NETFRAMEWORK
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
#endif
protected override void WndProc(ref Message m)
{
WinFormsUtils.HandleTouchMessage(ref m, this, TouchDown, TouchMove, TouchUp);
bool handled = WinFormsUtils.HandleGestureMessage(ref m, this, Pan, Zoom, Rotate, Tap, PressAndTap);
base.WndProc(ref m);
if (handled)
m.Result = new IntPtr(1);
}
}
20 changes: 14 additions & 6 deletions src/Common.WinForms/Controls/TouchPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
namespace NanoByte.Common.Controls;

/// <summary>
/// Represents a panel that reacts to touch input on Windows 7 or newer.
/// Represents a panel that reacts to touch gestures on Windows 7 or newer.
/// </summary>
public class TouchPanel : Panel, ITouchControl
{
/// <inheritdoc/>
public event EventHandler<TouchEventArgs>? TouchDown;
public event EventHandler<PanGestureEventArgs>? Pan;

/// <inheritdoc/>
public event EventHandler<TouchEventArgs>? TouchUp;
public event EventHandler<ZoomGestureEventArgs>? Zoom;

/// <inheritdoc/>
public event EventHandler<TouchEventArgs>? TouchMove;
public event EventHandler<RotateGestureEventArgs>? Rotate;

/// <inheritdoc/>
public event EventHandler<TapGestureEventArgs>? Tap;

/// <inheritdoc/>
public event EventHandler<PressAndTapGestureEventArgs>? PressAndTap;

protected override CreateParams CreateParams
{
Expand All @@ -39,15 +45,17 @@ protected override CreateParams CreateParams
protected override void CreateHandle()
{
base.CreateHandle();
WinFormsUtils.RegisterTouchWindow(this);
WinFormsUtils.RegisterGestureWindow(this);
}

#if NETFRAMEWORK
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
#endif
protected override void WndProc(ref Message m)
{
WinFormsUtils.HandleTouchMessage(ref m, this, TouchDown, TouchMove, TouchUp);
bool handled = WinFormsUtils.HandleGestureMessage(ref m, this, Pan, Zoom, Rotate, Tap, PressAndTap);
base.WndProc(ref m);
if (handled)
m.Result = new IntPtr(1);
}
}
Loading
Loading