Exemplo n.º 1
0
 static void element_PreviewTouchDown(object sender, System.Windows.Input.TouchEventArgs e)
 {
     UIElement element = sender as UIElement;
     if (element != null)
     {
         var info = _dict[element];
         if (info.TouchCounter == 0)
         {
             info.TouchCounter++;
             info.Position = e.GetTouchPoint(element).Position;
             info.Timer.Start();
         }
         else if (info.TouchCounter == 1)
         {
             // check
             var dist = e.GetTouchPoint(element).Position - info.Position;
             if (dist.Length > info.Threshold)
             {
                 info.Reset();
             }
             else
             {
                 // double tap detected
                 element.RaiseEvent(new TouchDoubleTapEventArgs(info.Position));
                 info.Reset();
                 e.Handled = true;
             }
         }
         else
         {
             // abort double tap
             info.Reset();
         }
     }
 }
        public TouchInfo GetInfoFromContactEvent(TouchAction2 action, System.Windows.Input.TouchEventArgs e)
        {
            //Get the  point position from the ContactEventArgs (can optionally use e.Contact.getCenterPosition here for more accuracy)
            System.Windows.Point position = e.GetTouchPoint(GestureFramework.LayoutRoot).Position; // new System.Windows.Point(e.TouchPoint.CenterX, e.TouchPoint.CenterY);

            //Create a new touchinfo which will be used later to add a touchpoint
            TouchInfo info = new TouchInfo();

            //IF not Using in surface there will be not size or tag, therefore all the points are fingers.
            System.Windows.Size size = e.TouchDevice.GetTouchPoint(GestureFramework.LayoutRoot).Size;
            if (size.Height <= MinimumSize.Height && size.Width <= MinimumSize.Width)
            {
                info.IsFinger = true;
                info.Tag = null;

            }
            else
            {
                info.IsFinger = e.TouchDevice.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().IsFinger;

                if (e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Tag != null)
                {

                   // info.Tag = e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Tag;
                    /*
                    switch (e.TouchPoint.Tag.Type)
                    {
                        case Microsoft.Surface.Presentation.TagType.Byte:
                            info.Tag = e.Contact.Tag.Byte.ToString();
                            break;
                        case Microsoft.Surface.Presentation.TagType.Identity:
                            info.Tag = e.Contact.Tag.Identity.ToString();
                            break;
                        default:
                            info.Tag = null;
                            break;

                    }*/

                }
                else if (!info.IsFinger)
                {
                    //info.Bounds = new Rect((double)e.TouchPoint.CenterX, (double)e.TouchPoint.CenterY, (double)e.TouchPoint.Bounds.Width, (double)e.TouchPoint.Bounds.Height);
                    info.Bounds = e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Bounds;
                }
            }

            //Set the action type to the passed in action
            info.ActionType = action;

            //Set the position of the touchinfo to the previously found position from e
            info.Position = position;

            //Set the deviceid of the touchinfo to the id of the contact
            info.TouchDeviceId = e.GetTouchPoint(GestureFramework.LayoutRoot).TouchDevice.Id;

            return info;
        }
Exemplo n.º 3
0
 public static void WriteInteractionLog(int type, string details, System.Windows.Input.TouchDevice t)
 {
     Interaction_Log i = new Interaction_Log();
     i.date = DateTime.Now;i.details = details;i.type = type;
     if (t != null)
     {
         i.touch_id = t.Id;
         i.touch_x = t.GetTouchPoint(null).Position.X;
         i.touch_y = t.GetTouchPoint(null).Position.Y;
     }
     else
     {
         i.touch_id = -1;
         i.touch_x = -1;
         i.touch_y = -1;
     }
     database_manager.InsertInteraction(i);
 }
        protected override void OnTouchMove(System.Windows.Input.TouchEventArgs e)
        {
            int id = e.TouchDevice.Id;
            TouchPoint touchPoint = e.GetTouchPoint(this);

            System.Diagnostics.Debug.WriteLine(string.Format("id:{0} x:{1} y:{2}", id, touchPoint.Position.X, touchPoint.Position.Y));

            base.OnTouchMove(e);

            e.Handled = true;
        }
Exemplo n.º 5
0
 public void Collect(System.Windows.Input.TouchEventArgs e)
 {
     Point pt = e.GetTouchPoint(_source).Position;
     PathSegment seg = new LineSegment(new Point(pt.X, pt.Y), false);
     _psCollection.Add(seg);
 }
Exemplo n.º 6
0
 protected override void OnPreviewTouchMove(System.Windows.Input.TouchEventArgs e)
 {
     base.OnPreviewTouchMove(e);
     TimeSpan ts = DateTime.Now - touchTime;
     double  currentPoint= e.GetTouchPoint(this.owner).Position.Y;
     if (ts.TotalMilliseconds > 100 & (Math.Abs(touchPoint - currentPoint) < 60))
     {
         CanVerticallyScroll = false;
         touchTime = DateTime.Now;
         touchPoint = currentPoint;
         return;
     }
     if (!CanVerticallyScroll)
     {
         CanVerticallyScroll = true;
     }
 }
Exemplo n.º 7
0
        protected override void OnPreviewTouchDown(System.Windows.Input.TouchEventArgs e)
        {
            base.OnPreviewTouchDown(e);

            touchTime = DateTime.Now;
            touchPoint = e.GetTouchPoint(this.owner).Position.Y;
        }
Exemplo n.º 8
0
        //This is to check if any mapButtons on the mapImage has been checked
        private void mapImage_TouchDown(object sender, System.Windows.Input.TouchEventArgs e)
        {
            foreach (UIElement ele in Location.Children)
            {
                SurfaceRadioButton t = ele as SurfaceRadioButton;
                Ellipse ell = ele as Ellipse;
                if (ell != null)
                {
                    Double canvasLeft = Canvas.GetLeft(ell);
                    Double canvasTop = Canvas.GetTop(ell);
                    Double width = ell.Width;
                    Double height = ell.Height;

                    if (ell.Width != 26)
                    {
                        TouchPoint p = e.GetTouchPoint(Location);
                        if (p.Position.X > canvasLeft && p.Position.X < canvasLeft + width && p.Position.Y > canvasTop && p.Position.Y < canvasTop + height)
                        {
                            foreach (SurfaceRadioButton rb in ellipses.Keys)
                            {
                                if (ellipses[rb] == ell)
                                {
                                    newButton_Click(rb);
                                }
                            }
                        }
                    }
                }
            }
        }
        void contributions_PreviewTouchUp(object sender, System.Windows.Input.TouchEventArgs e)
        {
            //TextBlock tm = new TextBlock(); tm.Foreground = Brushes.White;
            //Canvas.SetLeft(tm, 200); Canvas.SetTop(tm, debug_var);
            //tm.Text = "TOUCH UP"; tm.FontSize = 16; tm.FontWeight = FontWeights.Bold;
            ////window_manager.main_canvas.Children.Add(tm);
            //debug_canvas.Children.Add(tm);
            //debug_var = debug_var + 30;
            //if (debug_var > 600) { debug_var = 10; debug_canvas.Children.RemoveRange(0, debug_canvas.Children.Count); }
            if (touch_points.Count > 0)
            {
                ScrollViewer scroll = configurations.GetDescendantByType(this.contributions, typeof(ScrollViewer)) as ScrollViewer;
                //double dv = e.GetTouchPoint(this.contributions).Position.X - touch_points[touch_points.Count - 1].Position.X;
                double dv = e.GetTouchPoint(this.contributions).Position.X - touch_points[0].Position.X;
                try
                {
                    //scroll.ScrollToHorizontalOffset(scroll.HorizontalOffset + (-2 * dv));
                    scroll.ScrollToHorizontalOffset(last_scroll_offset + (-1 * dv));
                }
                catch (Exception) { }
                last_scroll_offset = scroll.HorizontalOffset;
            }

            this.touch_points.Clear();
            consecutive_drag_points = 0;
            UIElement element = sender as UIElement;
            element.ReleaseTouchCapture(e.TouchDevice);
            //e.Handled = false;
        }
        void contributions_PreviewTouchMove(object sender, System.Windows.Input.TouchEventArgs e)
        {
            FrameworkElement findSource = e.OriginalSource as FrameworkElement;
            ListBoxItem element = null;
            while (element == null && findSource != null)
                if ((element = findSource as ListBoxItem) == null)
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;

            if (element != null)
                last_dragged_element = element;

            //TextBlock tm = new TextBlock(); tm.Foreground = Brushes.White;
            //Canvas.SetLeft(tm, 200); Canvas.SetTop(tm, debug_var);
            //tm.Text = "MOVED"; tm.FontSize = 16; tm.FontWeight = FontWeights.Bold;
            ////window_manager.main_canvas.Children.Add(tm);
            //debug_canvas.Children.Add(tm);
            //debug_var = debug_var + 30;
            //if (debug_var > 600) { debug_var = 10; debug_canvas.Children.RemoveRange(0, debug_canvas.Children.Count); }

            this.touch_points.Add(e.GetTouchPoint(this.contributions as IInputElement));

            //TouchPointCollection points = e.GetIntermediateTouchPoints(sender as IInputElement);
            //if (points.Count < 2) return;
            if (touch_points.Count < configurations.min_touch_points) return;

            //MatrixTransform trans_mat = (MatrixTransform)parent.RenderTransform;
            //Matrix mat = trans_mat.Matrix;
            //MatrixTransform mat2 = new MatrixTransform(mat.M11, mat.M12, mat.M21, mat.M22, 0, 0);

            //Point drag_dir1 = mat2.Transform(drag_direction1);
            //Point drag_dir2 = mat2.Transform(drag_direction2);
            //double size1 = Math.Sqrt(drag_dir1.X * drag_dir1.X + drag_dir1.Y * drag_dir1.Y);
            //double size2 = Math.Sqrt(drag_dir2.X * drag_dir2.X + drag_dir2.Y * drag_dir2.Y);
            //drag_dir1.X = drag_dir1.X / size1; drag_dir1.Y = drag_dir1.Y / size1;
            //drag_dir2.X = drag_dir2.X / size2; drag_dir2.Y = drag_dir2.Y / size2;

            //double dy = points[points.Count - 1].Position.Y - points[0].Position.Y;
            //double dx = points[points.Count - 1].Position.X - points[0].Position.X;
            //double dy = touch_points[touch_points.Count - 1].Position.Y - touch_points[0].Position.Y;
            //double dx = touch_points[touch_points.Count - 1].Position.X - touch_points[0].Position.X;
            double dy = touch_points[touch_points.Count - 1].Position.Y - touch_points[touch_points.Count - 2].Position.Y;
            double dx = touch_points[touch_points.Count - 1].Position.X - touch_points[touch_points.Count - 2].Position.X;
            double size_n = Math.Sqrt(dx * dx + dy * dy);
            dx = dx / size_n; dy = dy / size_n;
            if (dx == double.NaN || dy == double.NaN) return;
            //Point dxy = mat2.Transform(new Point(dx, dy));
            //dx = Math.Abs(dx); dy = Math.Abs(dy);

            //double theta1 = Math.Acos(dx * drag_dir1.X + dy * drag_dir1.Y);
            //double theta2 = Math.Acos(dx * drag_dir2.X + dy * drag_dir2.Y);
            double theta1 = Math.Acos(dx * drag_direction1.X + dy * drag_direction1.Y);
            double theta2 = Math.Acos(dx * drag_direction2.X + dy * drag_direction2.Y);

            //convert to degree
            theta1 = theta1 * 180 / Math.PI;
            theta2 = theta2 * 180 / Math.PI;
            double theta = (theta1 < theta2) ? theta1 : theta2;

            /////////
            //double radius = 75;
            //Ellipse ell = new Ellipse();
            //ell.Fill = Brushes.White;
            //ell.Width = radius*2;
            //ell.Height = radius*2;
            //double center_x = (window_manager.main_canvas.ActualWidth / 2);
            //double center_y = (window_manager.main_canvas.ActualHeight / 2);
            //double left = center_x - radius;
            //double top = center_y - radius;
            //Canvas.SetLeft(ell, left);
            //Canvas.SetTop(ell, top);
            //window_manager.main_canvas.Children.Add(ell);
            //Line l1 = new Line();
            //l1.X1 = left; l1.X2 = left + ell.Width;
            //l1.Y1 = center_y; l1.Y2 = center_y;
            //l1.Stroke = Brushes.Black; l1.StrokeThickness = 3;
            //window_manager.main_canvas.Children.Add(l1);
            //Line l2 = new Line();
            //l2.X1 = center_x; l2.X2 = center_x;
            //l2.Y1 = top; l2.Y2 = top + ell.Height;
            //l2.Stroke = Brushes.Black; l2.StrokeThickness = 3;
            //window_manager.main_canvas.Children.Add(l2);
            //////Line l_drag1 = new Line();
            //////l_drag1.X1 = center_x; l_drag1.X2 = (drag_dir1.X*radius) + center_x;
            //////l_drag1.Y1 = center_y; l_drag1.Y2 = (drag_dir1.Y*radius) + center_y;
            //////l_drag1.Stroke = Brushes.Red; l_drag1.StrokeThickness = 5;
            //////window_manager.main_canvas.Children.Add(l_drag1);
            //////Line l_drag2 = new Line();
            //////l_drag2.X1 = center_x; l_drag2.X2 = (drag_dir2.X*radius) + center_x;
            //////l_drag2.Y1 = center_y; l_drag2.Y2 = (drag_dir2.Y*radius) + center_y;
            //////l_drag2.Stroke = Brushes.Red; l_drag2.StrokeThickness = 5;
            //////window_manager.main_canvas.Children.Add(l_drag2);
            //Line l_dxy = new Line();
            //l_dxy.X1 = center_x; l_dxy.X2 = (dx * radius) + center_x;
            //l_dxy.Y1 = center_y; l_dxy.Y2 = (dy * radius) + center_y;
            //l_dxy.Stroke = Brushes.Green; l_dxy.StrokeThickness = 5;
            //window_manager.main_canvas.Children.Add(l_dxy);
            //TextBlock t1 = new TextBlock(); t1.Foreground = Brushes.White;
            //Canvas.SetLeft(t1, 80); Canvas.SetTop(t1, debug_var);
            //t1.Text = theta1.ToString(); t1.FontSize = 14; t1.FontWeight = FontWeights.Bold;
            //debug_canvas.Children.Add(t1);
            //TextBlock t2 = new TextBlock(); t2.Foreground = Brushes.White;
            //Canvas.SetLeft(t2, 80 + (2*radius)); Canvas.SetTop(t2, debug_var);
            //t2.Text = theta2.ToString(); t2.FontSize = 14; t2.FontWeight = FontWeights.Bold;
            //debug_canvas.Children.Add(t2);
            //debug_var = debug_var + 30;
            //if (debug_var > 600) { debug_var = 10; debug_canvas.Children.RemoveRange(0, debug_canvas.Children.Count); }

            //draw points
            //double radius = 2;
            //Ellipse ell = new Ellipse();
            //ell.Fill = Brushes.White;
            //ell.Width = radius * 2;
            //ell.Height = radius * 2;
            //double center_x = e.GetTouchPoint(window_manager.main_canvas).Position.X;
            //double center_y = e.GetTouchPoint(window_manager.main_canvas).Position.Y;
            //double left = center_x - radius;
            //double top = center_y - radius;
            //Canvas.SetLeft(ell, left);
            //Canvas.SetTop(ell, top);
            //window_manager.main_canvas.Children.Add(ell);

            /////////

            if (theta < configurations.drag_collection_theta)
            {
                if (consecutive_drag_points < configurations.max_consecutive_drag_points)
                {
                    consecutive_drag_points++;
                }
                else
                {
                    if (element == null) element = last_dragged_element;
                    if (element != null)
                    {
                        Image i = (Image)element.DataContext;
                        if (i.Tag == null) return;
                        collection_item item = (collection_item)i.Tag;
                        if (i.Source != null)
                        {
                            start_drag(element, item, e.TouchDevice, i.Source.Clone());
                            touch_points.Clear();
                            consecutive_drag_points = 0;
                            e.Handled = true;
                            return;
                        }
                    }
                }
            }
            ScrollViewer scroll = configurations.GetDescendantByType(this.contributions, typeof(ScrollViewer)) as ScrollViewer;
            double dv = touch_points[touch_points.Count - 1].Position.X - touch_points[0].Position.X;
            //double new_offset = scroll.HorizontalOffset + (-1 * configurations.scroll_scale_factor * dx);
            double new_offset = last_scroll_offset + (-1 * dv);
            try { scroll.ScrollToHorizontalOffset(new_offset); }
            catch (Exception) { }
        }
Exemplo n.º 11
0
 static void element_PreviewTouchMove(object sender, System.Windows.Input.TouchEventArgs e)
 {
     UIElement element = sender as UIElement;
     if (element != null)
     {
         var info = _dict[element];
         if (info.TouchCounter == 1)
         {
             var dist = e.GetTouchPoint(element).Position - info.Position;
             if (dist.Length > info.Threshold)
             {
                 // abort
                 info.Reset();
             }
         }
     }
 }
Exemplo n.º 12
0
 protected override void OnTouchUp(System.Windows.Input.TouchEventArgs e)
 {
     Callback(e.GetTouchPoint(this).Position);
     base.OnTouchUp(e);
 }