//private void OnPointerEntered (object sender, PointerRoutedEventArgs e)
        //{
        //}

        //private void OnPointerExited (object sender, PointerRoutedEventArgs e)
        //{
        //}

        private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (!IsInputEnabled)
            {
                return;
            }

            // capture the pointer
            CapturePointer(e.Pointer);

            // create a new path and set the options
            currentPath        = new InkStroke(new PathGeometry(), new List <Point> (), StrokeColor, StrokeWidth);
            tempPathShape.Data = currentPath.Path;
            tempPathShape.Tag  = currentPath;
            SetPathProperties(tempPathShape);

            // obtain the location of the touch
            var point  = e.GetCurrentPoint(this);
            var touchX = point.Position.X;
            var touchY = point.Position.Y;

            // move to the touched point
            currentPath.Path.MoveTo(touchX, touchY);
            currentPath.GetPoints().Add(point.Position);

            // update the dirty rectangle
            ResetBounds((float)touchX, (float)touchY);
        }
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            singleTapNeeded = false;
            // create a new path and set the options
            currentPath = new InkStroke(UIBezierPath.Create(), new List <CGPoint> (), StrokeColor, StrokeWidth);

            // obtain the location of the touch
            var touch         = touches.AnyObject as UITouch;
            var touchLocation = touch.LocationInView(this);

            // move the path to that position
            currentPath.Path.MoveTo(touchLocation);
            currentPath.GetPoints().Add(touchLocation);

            // update the dirty rectangle
            ResetBounds(touchLocation);

            Console.WriteLine("InkPresenter: Touches Began");

            if (touch != null)
            {
                Console.WriteLine($"InkPresenter: TapCount: {touch.TapCount}");
                if (touch.TapCount == 2)
                {
                    OnDoubleTapped();
                }
            }
        }
        // private methods

        private bool HasMovedFarEnough(InkStroke stroke, double touchX, double touchY)
        {
            var lastPoint = stroke.GetPoints().LastOrDefault();
            var deltaX    = touchX - lastPoint.X;
            var deltaY    = touchY - lastPoint.Y;

            var distance = Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));

            return(distance >= MinimumPointDistance);
        }
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // create a new path and set the options
            currentPath = new InkStroke(UIBezierPath.Create(), new List <CGPoint> (), StrokeColor, StrokeWidth);

            // obtain the location of the touch
            var touch         = touches.AnyObject as UITouch;
            var touchLocation = touch.LocationInView(this);

            // move the path to that position
            currentPath.Path.MoveTo(touchLocation);
            currentPath.GetPoints().Add(touchLocation);

            // update the dirty rectangle
            ResetBounds(touchLocation);
        }
Exemple #5
0
        private void TouchesBegan(MotionEvent e)
        {
            // create a new path and set the options
            currentPath = new InkStroke(new Path(), new List <System.Drawing.PointF> (), StrokeColor, StrokeWidth);

            // obtain the location of the touch
            float touchX = e.GetX();
            float touchY = e.GetY();

            // move to the touched point
            currentPath.Path.MoveTo(touchX, touchY);
            currentPath.GetPoints().Add(new System.Drawing.PointF(touchX, touchY));

            // update the dirty rectangle
            ResetBounds(touchX, touchY);
            Invalidate(DirtyRect);
        }
        private void TouchesBegan(MotionEvent e)
        {
            // don't allow the event to propagate because we're handling it here
            Parent?.RequestDisallowInterceptTouchEvent(true);

            // create a new path and set the options
            currentPath = new InkStroke(new Path(), new List <System.Drawing.PointF> (), StrokeColor, StrokeWidth);

            // obtain the location of the touch
            float touchX = e.GetX();
            float touchY = e.GetY();

            // move to the touched point
            currentPath.Path.MoveTo(touchX, touchY);
            currentPath.GetPoints().Add(new System.Drawing.PointF(touchX, touchY));

            // update the dirty rectangle
            ResetBounds(touchX, touchY);
            Invalidate(DirtyRect);
        }
Exemple #7
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // create a new path and set the options
            currentPath = new InkStroke(UIBezierPath.Create(), new List <InkPoint> (), StrokeColor, StrokeWidth, InkSource.Touch, DateTime.UtcNow);

            // obtain the location of the touch
            var touch         = touches.AnyObject as UITouch;
            var touchLocation = touch.LocationInView(this);

            // move the path to that position
            currentPath.Path.MoveTo(touchLocation);
            currentPath.GetPoints().Add(new InkPoint(
                                            touchLocation,
                                            (float)touch.Force,
                                            null,
                                            TimeSpan.FromSeconds(touch.Timestamp)));

            // update the dirty rectangle
            ResetBounds(touchLocation);
        }
        public override async void TouchesEnded(NSSet touches, UIEvent evt)
        {
            // obtain the location of the touch
            var touch         = touches.AnyObject as UITouch;
            var touchLocation = touch.LocationInView(this);

            // something may have happened (clear) during the stroke
            if (currentPath != null)
            {
                if (HasMovedFarEnough(currentPath, touchLocation.X, touchLocation.Y))
                {
                    // add it to the current path
                    currentPath.Path.AddLineTo(touchLocation);
                    currentPath.GetPoints().Add(touchLocation);
                }
                else if (touch.TapCount == 1)
                {
                    // Single Tap
                    singleTapNeeded = true;
                    await Task.Delay(300);

                    if (singleTapNeeded)
                    {
                        //CGRect r = new CGRect (touchLocation.X, touchLocation.Y, StrokeWidth, StrokeWidth);
                        //var c = UIBezierPath.FromOval (r);
                        var s = new InkStroke(new UIBezierPath(), new List <CGPoint> (), StrokeColor, StrokeWidth);
                        s.Path.MoveTo(touchLocation);
                        s.GetPoints().Add(touchLocation);
                        var dest = new CGPoint(touchLocation.X + StrokeWidth, touchLocation.Y + StrokeWidth);
                        s.Path.AddLineTo(dest);
                        s.GetPoints().Add(dest);
                        paths.Add(s);

                        s = new InkStroke(new UIBezierPath(), new List <CGPoint> (), StrokeColor, StrokeWidth);
                        var src = new CGPoint(touchLocation.X + StrokeWidth, touchLocation.Y);
                        s.Path.MoveTo(src);
                        s.GetPoints().Add(src);
                        dest = new CGPoint(touchLocation.X, touchLocation.Y + StrokeWidth);
                        s.Path.AddLineTo(dest);
                        s.GetPoints().Add(dest);
                        paths.Add(s);
                    }
                    ;
                }

                // obtain the smoothed path, and add it to the old paths
                if (currentPath != null)
                {
                    var smoothed = PathSmoothing.SmoothedPathWithGranularity(currentPath, 4);
                    paths.Add(smoothed);
                }
            }

            // clear the current path
            currentPath = null;

            // update the dirty rectangle
            UpdateBounds(touchLocation);
            SetNeedsDisplay();

            // we are done with drawing
            OnStrokeCompleted();
        }