1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Diagnostics;
7
using System.Windows.Input;
9
namespace ICSharpCode.WpfDesign.Designer.Services
12
/// Base class for mouse gestures that should start dragging only after a minimum drag distance.
14
abstract class ClickOrDragMouseGesture : MouseGestureBase
16
protected Point startPoint;
17
protected bool hasDragStarted;
18
protected IInputElement positionRelativeTo;
20
const double MinimumDragDistance = 3;
22
protected sealed override void OnStarted(MouseButtonEventArgs e)
24
Debug.Assert(positionRelativeTo != null);
25
hasDragStarted = false;
26
startPoint = e.GetPosition(positionRelativeTo);
29
protected override void OnMouseMove(object sender, MouseEventArgs e)
31
if (!hasDragStarted) {
32
Vector v = e.GetPosition(positionRelativeTo) - startPoint;
33
if (Math.Abs(v.X) >= SystemParameters.MinimumHorizontalDragDistance
34
|| Math.Abs(v.Y) >= SystemParameters.MinimumVerticalDragDistance) {
35
hasDragStarted = true;
41
protected override void OnStopped()
43
hasDragStarted = false;
46
protected virtual void OnDragStarted(MouseEventArgs e) {}