From ac9090470eba25bb3c789f0e87ecf70e6a7be55f Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 29 May 2018 19:44:54 +0300 Subject: Working on Mouse/Touch synchronization! --- .../Tango.DragAndDrop/DragAndDropService.cs | 37 ++++++++++++++++------ .../Visual_Studio/Tango.DragAndDrop/DragThumb.cs | 20 ++++++++++++ .../Tango.DragAndDrop/Tango.DragAndDrop.csproj | 5 +++ 3 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs (limited to 'Software/Visual_Studio/Tango.DragAndDrop') diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs index 606e8a2e5..60da36590 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs @@ -11,6 +11,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Threading; +using Tango.Core.EventArguments; using Tango.SharedUI.Helpers; namespace Tango.DragAndDrop @@ -489,9 +490,14 @@ namespace Tango.DragAndDrop { _dragElements.Add(element); - element.PreviewMouseDown += Draggable_PreviewMouseDown; - element.MouseMove += Draggable_MouseMove; + element.RegisterForPreviewMouseOrTouchDown(Draggable_PreviewMouseDown); + element.RegisterForMouseOrTouchMove(Draggable_MouseMove); element.PreviewMouseUp += Draggable_PreviewMouseUp; + element.IsManipulationEnabled = true; + + //element.AddHandler(FrameworkElement.PreviewMouseDownEvent, (MouseButtonEventHandler)Draggable_PreviewMouseDown, true); + //element.AddHandler(FrameworkElement.MouseMoveEvent, (MouseEventHandler)Draggable_MouseMove, true); + //element.AddHandler(FrameworkElement.PreviewMouseUpEvent, (MouseButtonEventHandler)Draggable_PreviewMouseUp, true); element.Unloaded += Element_Unloaded; } } @@ -630,14 +636,14 @@ namespace Tango.DragAndDrop #region Draggable Event Handlers - /// - /// Handles the PreviewMouseDown event of the Draggable control. - /// - /// The source of the event. - /// The instance containing the event data. - private static void Draggable_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) + private static void Draggable_PreviewMouseDown(object sender, MouseOrTouchEventArgs e) { - if (e.Source != sender) return; + var dragThumb = (sender as FrameworkElement).FindChild(); + + if ((e.Source != sender && dragThumb == null) || (dragThumb != null && dragThumb != e.OriginalSource)) + { + return; + } FrameworkElement element = sender as FrameworkElement; @@ -652,13 +658,17 @@ namespace Tango.DragAndDrop _isMouseDown = true; } + + /// /// Handles the MouseMove event of the Draggable control. /// /// The source of the event. /// The instance containing the event data. - private static void Draggable_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) + private static void Draggable_MouseMove(object sender, MouseOrTouchEventArgs e) { + Debug.WriteLine(e.GetPosition(_currentDragedElement)); + if (_isMouseDown) { FrameworkElement element = _currentDragedElement; @@ -673,6 +683,13 @@ namespace Tango.DragAndDrop { element.ReleaseMouseCapture(); surface.ReleaseMouseCapture(); + + if (e.TouchDevice != null) + { + element.ReleaseTouchCapture(e.TouchDevice); + surface.ReleaseTouchCapture(e.TouchDevice); + } + _isMouseDown = false; CreateDraggingElement(); _dragTimer.Start(); diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs new file mode 100644 index 000000000..952c35bb5 --- /dev/null +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +namespace Tango.DragAndDrop +{ + public class DragThumb : Grid + { + public DragThumb() + { + Background = Brushes.Transparent; + IsHitTestVisible = true; + } + } +} diff --git a/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj b/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj index 324bf9f90..771ed8079 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj +++ b/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj @@ -69,6 +69,7 @@ + @@ -98,6 +99,10 @@ + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + {8491d07b-c1f6-4b62-a412-41b9fd2d6538} Tango.SharedUI -- cgit v1.3.1