-
-
Notifications
You must be signed in to change notification settings - Fork 911
/
GestureConfigDrag.cs
105 lines (90 loc) · 3.95 KB
/
GestureConfigDrag.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using Stride.Core.Mathematics;
namespace Stride.Input
{
/// <summary>
/// Configuration class for the Drag gesture.
/// </summary>
/// <remarks>A drag gesture can be composed of 1 or more fingers.</remarks>
public sealed class GestureConfigDrag : GestureConfig
{
/// <summary>
/// Specify the minimum translation distance required before that the gesture can be recognized as a Drag.
/// </summary>
/// <exception cref="InvalidOperationException">Tried to modify the configuration after it has been frozen by the system.</exception>
/// <exception cref="ArgumentOutOfRangeException">The provided value was negative.</exception>
/// <remarks>The user can reduce this value if he needs the drag gesture to be triggered even for very small drags.
/// On the contrary, he can increase this value if he wants to avoid to deals with too small drags.</remarks>
public float MinimumDragDistance
{
get { return minimumDragDistance; }
set
{
CheckNotFrozen();
if (value < 0)
throw new ArgumentOutOfRangeException("value");
minimumDragDistance = value;
}
}
private float minimumDragDistance;
/// <summary>
/// The (x,y) error margins allowed during directional dragging.
/// </summary>
/// <exception cref="InvalidOperationException">Tried to modify the configuration after it has been frozen by the system.</exception>
/// <exception cref="ArgumentOutOfRangeException">The provided x or y value was not positive.</exception>
/// <remarks>Those values are used only for directional (vertical or horizontal) dragging.
/// Decrease those values to trigger the gesture only when the dragging is perfectly in the desired direction.
/// Increase those values to allow directional gestures to be more approximative.</remarks>
public Vector2 AllowedErrorMargins
{
get { return allowedErrorMargins; }
set
{
CheckNotFrozen();
if (value.X < 0 || value.Y < 0)
throw new ArgumentOutOfRangeException("value");
allowedErrorMargins = value;
}
}
private Vector2 allowedErrorMargins;
/// <summary>
/// The shape (direction) of the drag gesture.
/// </summary>
/// <exception cref="InvalidOperationException">Tried to modify the configuration after it has been frozen by the system.</exception>
public GestureShape DragShape
{
get { return dragShape; }
set
{
CheckNotFrozen();
dragShape = value;
}
}
private GestureShape dragShape;
/// <summary>
/// Create a default drag gesture configuration for one finger free dragging.
/// </summary>
public GestureConfigDrag()
: this(GestureShape.Free)
{
}
/// <summary>
/// Create a default drag gesture configuration for one finger dragging.
/// </summary>
/// <param name="dragShape">The dragging shape</param>
public GestureConfigDrag(GestureShape dragShape)
{
AssociatedGestureType = GestureType.Drag;
DragShape = dragShape;
RequiredNumberOfFingers = 1;
AllowedErrorMargins = 0.02f * Vector2.One;
MinimumDragDistance = 0.02f;
}
internal override GestureRecognizer CreateRecognizerImpl(float screenRatio)
{
return new GestureRecognizerDrag(this, screenRatio);
}
}
}