예제 #1
0
        private void inkCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            //check penId
            if (e.Pointer.PointerId == penId)
            {
                //same input
                //for eg. a mouse and pen may interact at same time , but they will be given different pointer id
                //you can differentiate different key strokes of different at the same time using this

                var pt           = e.GetCurrentPoint(inkCanvas);
                var currentPoint = pt.Position;

                Windows.UI.Xaml.Shapes.Line line = new Windows.UI.Xaml.Shapes.Line();
                line.X1 = startPoint.X;
                line.Y1 = startPoint.Y;
                line.X2 = currentPoint.X;
                line.Y2 = currentPoint.Y;
                line.StrokeThickness = 10;
                line.Stroke          = new SolidColorBrush(Colors.Red);

                startPoint = currentPoint;

                inkCanvas.Children.Add(line);

                inkManager.ProcessPointerUpdate(pt);
            }
            else
            {
                //handle touch
            }

            e.Handled = true;
        }
예제 #2
0
        public void PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == _penID)
            {
                PointerPoint pt = e.GetCurrentPoint(DrawingCanvas);

                //Render a line using the selected foreground color as the pointer moves.
                _currentContactPt = pt.Position;
                if (Distance(_previousContactPt.X, _previousContactPt.Y, _currentContactPt.X, _currentContactPt.Y) > 1.0)
                {
                    Line line = new Line
                    {
                        X1 = _previousContactPt.X,
                        Y1 = _previousContactPt.Y,
                        X2 = _currentContactPt.X,
                        Y2 = _currentContactPt.Y,
                        StrokeThickness = StrokeThickness,
                        Stroke          = CanvasForeground
                    };

                    _previousContactPt = _currentContactPt;

                    //Add the line to the canvas (draws it)
                    DrawingCanvas.Children.Add(line);

                    _inkManager.ProcessPointerUpdate(pt);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// The pointer moved event handler
        /// </summary>
        /// <param name="sender">the sender object</param>
        /// <param name="e">The pointer moved event args</param>
        private void inkCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            //Break if the event's pointer is not the currently active pointer
            if (m_activePointerId != e.Pointer.PointerId)
            {
                return;
            }
            //We only handle pen input here so we check the device type
            if (e.Pointer.PointerDeviceType == PointerDeviceType.Pen || e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
            {
                //Check if the pen has contact or is just hovering
                if (e.Pointer.IsInContact)
                {
                    //Get a pointer point relative to the inkCanvas
                    PointerPoint pointerPoint = e.GetCurrentPoint(this.inkCanvas);
                    //Update the live stroek using the pointerPoints's position
                    m_renderer.UpdateStroek(pointerPoint);

                    //Get all of the event's intermediate points
                    IList <PointerPoint> interPointerPoints = e.GetIntermediatePoints(this.inkCanvas);
                    //Use the InkManager to process all of the pointer updates
                    for (int i = interPointerPoints.Count - 1; i >= 0; --i)
                    {
                        m_inkMan.ProcessPointerUpdate(interPointerPoints[i]);
                    }
                    //Mark the event as handled
                    e.Handled = true;
                }
                else // If the pen has no contact chances are it was lifted off while not in the controls aera
                {
                    //Use a private helper method to finalize pen input
                    HandlePenUp(e);
                }
            }
        }
예제 #4
0
파일: Drawable.cs 프로젝트: e-/FlexTable
        private void PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerDeviceType == PointerDeviceType.Pen && e.Pointer.IsInContact)
            {
                //Debug.WriteLine("Moved");

                PointerPoint pointerPoint = e.GetCurrentPoint(root);
                uint         id           = pointerPoint.PointerId;

                //Debug.WriteLine(id) ;
                if (pointerDictionary.ContainsKey(id))
                {
                    foreach (PointerPoint point in Enumerable.Reverse(e.GetIntermediatePoints(root)) /*.Reverse()*/)
                    {
                        // Give PointerPoint to InkManager
                        object obj = inkManager.ProcessPointerUpdate(point);

                        // Render the line
                        if (inkManager.Mode == InkManipulationMode.Erasing)
                        {
                            Rect rect = (Rect)obj;
                            if (rect.Width != 0 && rect.Height != 0)
                            {
                                RenderAllStrokes();
                            }
                        }
                        else
                        {
                            Point point1 = pointerDictionary[id];
                            Point point2 = pointerPoint.Position;

                            Line line = new Line
                            {
                                X1                 = point1.X,
                                Y1                 = point1.Y,
                                X2                 = point2.X,
                                Y2                 = point2.Y,
                                Stroke             = new SolidColorBrush(Color.FromArgb(200, 0, 0, 0)),
                                StrokeThickness    = inkDrawingAttributes.Size.Width,// * pointerPoint.Properties.Pressure,
                                StrokeStartLineCap = PenLineCap.Round,
                                StrokeEndLineCap   = PenLineCap.Round
                            };

                            boundingRect.Union(point2);
                            NewStrokeGrid.Children.Add(line);
                            pointerDictionary[id] = point2;
                        }
                    }

                    if (StrokeAdding != null)
                    {
                        StrokeAdding(boundingRect);
                    }
                }
                e.Handled = true;
            }
        }
예제 #5
0
        protected override void OnPointerMoved(PointerRoutedEventArgs args)
        {
            // Get information
            PointerPoint         pointerPoint         = args.GetCurrentPoint(sheetPanel);
            uint                 id                   = pointerPoint.PointerId;
            InkManager           inkManager           = this.InkFileManager.InkManager;
            InkDrawingAttributes inkDrawingAttributes =
                this.InkFileManager.InkDrawingAttributes;

            if (pointerDictionary.ContainsKey(id))
            {
                foreach (PointerPoint point in args.GetIntermediatePoints(sheetPanel).Reverse())
                {
                    Point point1 = pointerDictionary[id];
                    Point point2 = pointerPoint.Position;

                    // Give PointerPoint to InkManager
                    object obj = inkManager.ProcessPointerUpdate(point);

                    if (inkManager.Mode == InkManipulationMode.Erasing)
                    {
                        // See if something has actually been removed
                        Rect rect = (Rect)obj;

                        if (rect.Width != 0 && rect.Height != 0)
                        {
                            this.InkFileManager.RenderAll();
                        }
                    }
                    else if (inkManager.Mode == InkManipulationMode.Selecting)
                    {
                        Polyline polyline = newLineGrid.Children[0] as Polyline;
                        polyline.Points.Add(point2);
                    }
                    else // inkManager.Mode == InkManipulationMode.Inking
                    {
                        // Render the line
                        Line line = new Line
                        {
                            X1              = point1.X,
                            Y1              = point1.Y,
                            X2              = point2.X,
                            Y2              = point2.Y,
                            Stroke          = new SolidColorBrush(inkDrawingAttributes.Color),
                            StrokeThickness = inkDrawingAttributes.Size.Width *
                                              pointerPoint.Properties.Pressure,
                            StrokeStartLineCap = PenLineCap.Round,
                            StrokeEndLineCap   = PenLineCap.Round
                        };
                        newLineGrid.Children.Add(line);
                    }
                    pointerDictionary[id] = point2;
                }
            }
            base.OnPointerMoved(args);
        }
        void InkCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            string log = "Moved";

            OutputPointerData(e, log);

            if (e.Pointer.PointerId == _PenID)
            {
                PointerPoint po           = e.GetCurrentPoint(InkCanvas);
                Point        currentPoint = po.Position;

                if (GetPointDistance(_PrevPoint, currentPoint) > 0 && press == true && 5 < currentPoint.X && currentPoint.X < InkCanvas.Width - 5 && 5 < currentPoint.Y && currentPoint.Y < InkCanvas.Height - 5)
                {
                    // 線の作成
                    Line l = new Line();
                    l.X1 = _PrevPoint.X;
                    l.Y1 = _PrevPoint.Y;
                    l.X2 = currentPoint.X;
                    l.Y2 = currentPoint.Y;

                    // 線を円形にする
                    l.StrokeStartLineCap = PenLineCap.Round;
                    l.StrokeEndLineCap   = PenLineCap.Round;

                    // 線の太さ 
                    // 筆圧によって太さを変える
                    l.StrokeThickness = MAX_STROKE_WIDTH * po.Properties.Pressure;

                    // 線の色
                    if (po.Properties.IsEraser)
                    {
                        l.Stroke = new SolidColorBrush(Colors.LightCyan);
                    }
                    else
                    {
                        l.Stroke = new SolidColorBrush(Colors.Black);
                    }
                    // 線を追加
                    InkCanvas.Children.Add(l);

                    // 現在の位置を保存する
                    _PrevPoint = currentPoint;
                    try
                    {
                        inkManager.ProcessPointerUpdate(po);
                    }
                    catch
                    {
                        return;
                    }
                }
            }

            e.Handled = true;
        }
예제 #7
0
        private void OnMouseMovedCanvas(object sender, PointerRoutedEventArgs e)        //Event Handler When The Mouse Is Moved On The White Canvas
        {
            try
            {
                if (e.Pointer.PointerId == pointerId)       //For Checking If The Same Pointer Is Used[that is to differentiate mouse input from touch input]
                {
                    PointerPoint pt = e.GetCurrentPoint(InkCanvas);     //For Getting The Current Position Of The Pointer
                    currentPosition = pt.Position;            //Registering The Position
                    ShapeTypHandler();                     //Handles The Shape Of The Drawn Object
                    if (shapeKind == ShapeTyp.RECTANGLE || shapeKind == ShapeTyp.ELLIPSE || shapeKind == ShapeTyp.STRAIGHTLINE)
                    {
                        switch (shapeKind)
                        {
                            case ShapeTyp.RECTANGLE:
                                InkCanvas.Children.Add(rectangle);      //Add The Rectangle To The Canvas
                                break;
                            case ShapeTyp.ELLIPSE:
                                InkCanvas.Children.Add(ellipse);        //Add The Ellipse To The Canvas
                                break;
                            case ShapeTyp.STRAIGHTLINE:
                                InkCanvas.Children.Add(straightLine);       //Add The Line To The Canvas
                                break;
                        }
                        inkManager.ProcessPointerUpdate(pt);        //ByPass The pt Info To The InkManager For Continous Update
                        e.Handled = true;                       //Tell Event Is Success
                    }
                    else
                    {
                        previousPosition = currentPosition;      //Set The Previous Position To The Current Position So That It Will Follow The Mouse
                        InkCanvas.Children.Add(line);       //Add The Line To The Canvas
                        inkManager.ProcessPointerUpdate(pt);        //ByPass The pt Info To The InkManager For Continous Update
                        e.Handled = true;                       //Tell Event Is Success
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
예제 #8
0
        private void OnCanvasPointerMoved(object sender, PointerRoutedEventArgs e)
        {
            var pointerPoint = e.GetCurrentPoint(this);

            if (pointerPoint.PointerId == currentPointerId)
            {
                inkManager.ProcessPointerUpdate(pointerPoint);

                // update the visual
                var path = (PathGeometry)tempPathShape.Data;
                path.LineTo(pointerPoint.Position.X, pointerPoint.Position.Y);
            }
        }
예제 #9
0
        private void MyCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == _penID)
            {
                PointerPoint pt = e.GetCurrentPoint(myCanvas);

                // Render a red line on the canvas as the pointer moves.
                // Distance() is an application-defined function that tests
                // whether the pointer has moved far enough to justify
                // drawing a new line.
                currentContactPt = pt.Position;
                x1 = _previousContactPt.X;
                y1 = _previousContactPt.Y;
                x2 = currentContactPt.X;
                y2 = currentContactPt.Y;


                if (Distance(x1, y1, x2, y2) > 2.0) // We need to developp this method now
                {
                    Line line = new Line()
                    {
                        X1 = x1,
                        Y1 = y1,
                        X2 = x2,
                        Y2 = y2,
                        StrokeThickness    = thick,
                        Stroke             = sbrush,
                        StrokeStartLineCap = PenLineCap.Round,
                        StrokeLineJoin     = PenLineJoin.Round,


                        Fill = new SolidColorBrush(Colors.BlueViolet)
                    };

                    _previousContactPt = currentContactPt;

                    // Draw the line on the canvas by adding the Line object as
                    // a child of the Canvas object.
                    myCanvas.Children.Add(line);

                    // Pass the pointer information to the InkManager.
                    _inkKhaled.ProcessPointerUpdate(pt);
                }
            }

            else if (e.Pointer.PointerId == _touchID)
            {
                // Process touch input
            }
        }
        protected override void OnPointerMoved(PointerRoutedEventArgs args)
        {
            if ((args.Pointer.PointerDeviceType == PointerDeviceType.Pen || !hasPen) &&
                args.Pointer.IsInContact)
            {
                IEnumerable <PointerPoint> points = args.GetIntermediatePoints(this).Reverse();

                foreach (PointerPoint point in points)
                {
                    inkManager.ProcessPointerUpdate(point);
                }
            }
            base.OnPointerMoved(args);
        }
        public void InkCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            try
            {
                if (e.Pointer.PointerId == _penID)
                {
                    PointerPoint pt = e.GetCurrentPoint(InkCanvas);

                    // Render a red line on the canvas as the pointer moves.
                    // Distance() is an application-defined function that tests
                    // whether the pointer has moved far enough to justify
                    // drawing a new line.
                    Point currentContactPt = pt.Position;
                    if (Distance(currentContactPt, _previousContactPt) > 2)
                    {
                        Line line = new Line()
                        {
                            X1 = _previousContactPt.X,
                            Y1 = _previousContactPt.Y,
                            X2 = currentContactPt.X,
                            Y2 = currentContactPt.Y,
                            StrokeThickness = STROKETHICKNESS,
                            Stroke          = new SolidColorBrush(Windows.UI.Colors.Red)
                        };

                        _previousContactPt = currentContactPt;

                        // Draw the line on the canvas by adding the Line object as
                        // a child of the Canvas object.
                        InkCanvas.Children.Add(line);

                        // Pass the pointer information to the InkManager.
                        _inkManager.ProcessPointerUpdate(pt);
                    }
                }

                else if (e.Pointer.PointerId == _touchID)
                {
                    // Process touch input
                }

                e.Handled = true;
            }
            catch (Exception ex)
            {
                MessageDialog msg = new MessageDialog(ex.Message + " Void - InkCanvas_PointerMoved");
                //msg.ShowAsync();
            }
        }
예제 #12
0
 private void InkCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
 {
     if (e.Pointer.PointerId == pointerId)
     {
         try
         {
             PointerPoint         pt = e.GetCurrentPoint(inkCanvas);
             IList <PointerPoint> intermediatePoints = e.GetIntermediatePoints(inkCanvas);
             for (int i = intermediatePoints.Count - 1; i >= 0; i--)
             {
                 inkManager.ProcessPointerUpdate(intermediatePoints[i]);
             }
             renderer.UpdateLiveRender(pt);
         }
         catch (Exception ex)
         {
             status.Log(ex.Message);
         }
     }
 }
예제 #13
0
        //PointerPressedイベントに関連付けられているポインターがCanvas上に移動すると発生する処理
        private void InkCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == _penID)
            {
                PointerPoint pt = e.GetCurrentPoint(InkCanvas);

                //
                //
                //
                //
                //Point
                currentContactPt = pt.Position;
                if (Distance(currentContactPt, _previousContactPt) > 2)
                {
                    Line line = new Line()
                    {
                        X1 = _previousContactPt.X,
                        Y1 = _previousContactPt.Y,
                        X2 = currentContactPt.X,
                        Y2 = currentContactPt.Y,
                        StrokeThickness = 4.0,
                        Stroke          = new SolidColorBrush(Windows.UI.Colors.Red)
                    };

                    _previousContactPt = currentContactPt;

                    //
                    //
                    InkCanvas.Children.Add(line);

                    //
                    _inkManager.ProcessPointerUpdate(pt);
                }
            }

            else if (e.Pointer.PointerId == _touchID)
            {
                // Process touch input
                PointerPoint pt = e.GetCurrentPoint(InkCanvas);

                //
                //
                //
                //
                //Point
                currentContactPt = pt.Position;
                if (Distance(currentContactPt, _previousContactPt) > 2)
                {
                    Line line = new Line()
                    {
                        X1 = _previousContactPt.X,
                        Y1 = _previousContactPt.Y,
                        X2 = currentContactPt.X,
                        Y2 = currentContactPt.Y,
                        StrokeThickness = 4.0,
                        Stroke          = new SolidColorBrush(Windows.UI.Colors.Red)
                    };

                    _previousContactPt = currentContactPt;

                    //
                    //
                    InkCanvas.Children.Add(line);

                    //
                    _inkManager.ProcessPointerUpdate(pt);
                }
            }

            e.Handled = true;
        }
예제 #14
0
        private void panelcanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == _penID)
            {
                PointerPoint pt = e.GetCurrentPoint(PanelCanvas);
                // Render a red line on the canvas as the pointer moves.
                // Distance() is an application-defined function that tests
                // whether the pointer has moved far enough to justify
                // drawing a new line.
                currentContactPt = pt.Position;
                x1 = _previousContactPt.X;
                y1 = _previousContactPt.Y;
                x2 = currentContactPt.X;
                y2 = currentContactPt.Y;

                if (Distance(x1, y1, x2, y2) > 2.0)
                {
                    Line line = new Line()
                    {
                        X1 = x1,
                        Y1 = y1,
                        X2 = x2,
                        Y2 = y2,
                        StrokeThickness = 3.0,
                        Stroke          = new SolidColorBrush(this._brushColor)
                    };
                    _previousContactPt = currentContactPt;

                    // Draw the line on the canvas by adding the Line object as
                    // a child of the Canvas object.
                    PanelCanvas.Children.Add(line);

                    // Pass the pointer information to the InkManager.
                    _inkManager.ProcessPointerUpdate(pt);
                }


                this._image.DrawLine(Convert.ToInt32(x1), Convert.ToInt32(y1), Convert.ToInt32(x2), Convert.ToInt32(y2), this._brushColor);
            }

            else if (e.Pointer.PointerId == _touchID)
            {
                // Process touch input
                PointerPoint pt = e.GetCurrentPoint(PanelCanvas);

                // Render a red line on the canvas as the pointer moves.
                // Distance() is an application-defined function that tests
                // whether the pointer has moved far enough to justify
                // drawing a new line.
                currentContactPt = pt.Position;
                x1 = _previousContactPt.X;
                y1 = _previousContactPt.Y;
                x2 = currentContactPt.X;
                y2 = currentContactPt.Y;

                if (Distance(x1, y1, x2, y2) > 2.0)
                {
                    Line line = new Line()
                    {
                        X1 = x1,
                        Y1 = y1,
                        X2 = x2,
                        Y2 = y2,
                        StrokeThickness = 3.0,
                        Stroke          = new SolidColorBrush(this._brushColor)
                    };
                    _previousContactPt = currentContactPt;

                    // Draw the line on the canvas by adding the Line object as
                    // a child of the Canvas object.
                    PanelCanvas.Children.Add(line);

                    // Pass the pointer information to the InkManager.
                    _inkManager.ProcessPointerUpdate(pt);
                }

                using (this._image.GetBitmapContext())
                {
                    this._image.DrawLineAa(Convert.ToInt32(x1), Convert.ToInt32(y1), Convert.ToInt32(x2), Convert.ToInt32(y2), this._brushColor);
                }
            }
        }
예제 #15
0
        void Canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (DrawingTool != "Eraser")
            {
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Cross, 1);
            }
            else
            {
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);
            }
            Canvas     canvas     = sender as Canvas;
            InkManager inkManager = MedcialInkManager;

            switch (DrawingTool)
            {
            case "Pencil":
            {
                if (e.Pointer.PointerId == PenID || e.Pointer.PointerId == TouchID)
                {
                    // Distance() is an application-defined function that tests
                    // whether the pointer has moved far enough to justify
                    // drawing a new line.
                    CurrentContactPoint = e.GetCurrentPoint(canvas).Position;
                    X1 = PreviousContactPoint.X;
                    Y1 = PreviousContactPoint.Y;
                    X2 = CurrentContactPoint.X;
                    Y2 = CurrentContactPoint.Y;

                    if (Distance(X1, Y1, X2, Y2) > 0.5)
                    {
                        Line line = new Line()
                        {
                            X1 = X1,
                            Y1 = Y1,
                            X2 = X2,
                            Y2 = Y2,
                            StrokeThickness = StrokeThickness,
                            Stroke          = new SolidColorBrush(BorderColor)
                        };

                        PreviousContactPoint = CurrentContactPoint;
                        canvas.Children.Add(line);
                        inkManager.ProcessPointerUpdate(e.GetCurrentPoint(canvas));
                    }
                }
            }
            break;

            case "Eraser":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    if (StartPoint != e.GetCurrentPoint(canvas).Position)
                    {
                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);
                        Pencil.Points.Add(e.GetCurrentPoint(canvas).Position);
                    }
                }
            }
            break;

            default:
                break;
            }
        }
예제 #16
0
        void canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (DrawingTool != "Eraser")
            {
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Cross, 1);
            }
            else
            {
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);
            }

            switch (DrawingTool)
            {
            case "Pencil":
            {
                if (e.Pointer.PointerId == PenID || e.Pointer.PointerId == TouchID)
                {
                    // Distance() is an application-defined function that tests
                    // whether the pointer has moved far enough to justify
                    // drawing a new line.
                    CurrentContactPoint = e.GetCurrentPoint(canvas).Position;
                    X1 = PreviousContactPoint.X;
                    Y1 = PreviousContactPoint.Y;
                    X2 = CurrentContactPoint.X;
                    Y2 = CurrentContactPoint.Y;

                    if (Distance(X1, Y1, X2, Y2) > 2.0)
                    {
                        Line line = new Line()
                        {
                            X1 = X1,
                            Y1 = Y1,
                            X2 = X2,
                            Y2 = Y2,
                            StrokeThickness = StrokeThickness,
                            Stroke          = new SolidColorBrush(BorderColor)
                        };

                        PreviousContactPoint = CurrentContactPoint;
                        canvas.Children.Add(line);
                        MyInkManager.ProcessPointerUpdate(e.GetCurrentPoint(canvas));
                    }
                }
            }
            break;

            case "Line":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    NewLine.X2 = e.GetCurrentPoint(canvas).Position.X;
                    NewLine.Y2 = e.GetCurrentPoint(canvas).Position.Y;
                }
            }
            break;

            case "Rectagle":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    X2 = e.GetCurrentPoint(canvas).Position.X;
                    Y2 = e.GetCurrentPoint(canvas).Position.Y;
                    if ((X2 - X1) > 0 && (Y2 - Y1) > 0)
                    {
                        NewRectangle.Margin = new Thickness(X1, Y1, X2, Y2);
                    }
                    else if ((X2 - X1) < 0)
                    {
                        NewRectangle.Margin = new Thickness(X2, Y1, X1, Y2);
                    }
                    else if ((Y2 - Y1) < 0)
                    {
                        NewRectangle.Margin = new Thickness(X1, Y2, X2, Y1);
                    }
                    else if ((X2 - X1) < 0 && (Y2 - Y1) < 0)
                    {
                        NewRectangle.Margin = new Thickness(X2, Y1, X1, Y2);
                    }
                    NewRectangle.Width  = Math.Abs(X2 - X1);
                    NewRectangle.Height = Math.Abs(Y2 - Y1);
                }
            }
            break;

            case "Ellipse":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    X2 = e.GetCurrentPoint(canvas).Position.X;
                    Y2 = e.GetCurrentPoint(canvas).Position.Y;
                    if ((X2 - X1) > 0 && (Y2 - Y1) > 0)
                    {
                        NewEllipse.Margin = new Thickness(X1, Y1, X2, Y2);
                    }
                    else if ((X2 - X1) < 0)
                    {
                        NewEllipse.Margin = new Thickness(X2, Y1, X1, Y2);
                    }
                    else if ((Y2 - Y1) < 0)
                    {
                        NewEllipse.Margin = new Thickness(X1, Y2, X2, Y1);
                    }
                    else if ((X2 - X1) < 0 && (Y2 - Y1) < 0)
                    {
                        NewEllipse.Margin = new Thickness(X2, Y1, X1, Y2);
                    }
                    NewEllipse.Width  = Math.Abs(X2 - X1);
                    NewEllipse.Height = Math.Abs(Y2 - Y1);
                }
            }
            break;

            case "Eraser":
            {
                CurrentContactPoint = e.GetCurrentPoint(canvas).Position;
                X1 = PreviousContactPoint.X;
                Y1 = PreviousContactPoint.Y;
                X2 = CurrentContactPoint.X;
                Y2 = CurrentContactPoint.Y;

                if (Distance(X1, Y1, X2, Y2) > 2.0)
                {
                    Line line = new Line()
                    {
                        X1 = X1,
                        Y1 = Y1,
                        X2 = X2,
                        Y2 = Y2,
                        StrokeThickness = 10,
                        Stroke          = new SolidColorBrush(Colors.White)
                    };

                    PreviousContactPoint = CurrentContactPoint;
                    canvas.Children.Add(line);
                    //MyInkManager.ProcessPointerUpdate(e.GetCurrentPoint(canvas));
                }
            }
            break;

            default:
                break;
            }
        }
예제 #17
0
        private void OnCanvasPointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == m_PenId)
            {
                PointerPoint pt = e.GetCurrentPoint(InkCanvas);

                // Render a red line on the canvas as the pointer moves.
                // Distance() is an application-defined function that tests
                // whether the pointer has moved far enough to justify
                // drawing a new line.
                currentContactPt = pt.Position;
                x1 = _previousContactPt.X;
                y1 = _previousContactPt.Y;
                x2 = currentContactPt.X;
                y2 = currentContactPt.Y;

                // Emit the event with the coordinates, to be used by event subscribers
                if (LineDrawn != null)
                {
                    LineDrawn(this, new LineDrawnEventArgs()
                    {
                        FromX = x1, FromY = y1, ToX = x2, ToY = y2
                    });
                }

                var color = m_CurrentDrawingColor;
                var size  = m_CurrentDrawingSize;

                if (Distance(x1, y1, x2, y2) > 2.0 && m_CurrentMode != "Erase")
                {
                    Line line = new Line()
                    {
                        X1 = x1,
                        Y1 = y1,
                        X2 = x2,
                        Y2 = y2,
                        StrokeThickness = size,
                        Stroke          = new SolidColorBrush(color)
                    };


                    if (m_CurrentMode == "Highlight")
                    {
                        line.Opacity = 0.4;
                    }
                    _previousContactPt = currentContactPt;

                    // Draw the line on the canvas by adding the Line object as
                    // a child of the Canvas object.
                    InkCanvas.Children.Add(line);
                }

                if (m_CurrentMode == "Erase")
                {
                    System.Diagnostics.Debug.WriteLine("Erasing : Pointer Update");

                    m_InkManager.ProcessPointerUpdate(pt);
                }
                else
                {
                    // Pass the pointer information to the InkManager.
                    CurrentManager.ProcessPointerUpdate(pt);
                }
            }

            else if (e.Pointer.PointerId == _touchID)
            {
                // Process touch input
            }
        }
        void canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (DrawingTool != "Eraser")
            {
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Cross, 1);
            }
            else
            {
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);
            }

            switch (DrawingTool)
            {
            //leaving pencil remaining all will work on canvas.pencil will work on both.
            case "Pencil":
            {
                if (e.Pointer.PointerId == PenID || e.Pointer.PointerId == TouchID)
                {
                    // Distance() is an application-defined function that tests
                    // whether the pointer has moved far enough to justify
                    // drawing a new line.
                    CurrentContactPoint = e.GetCurrentPoint(canvas).Position;
                    X1 = PreviousContactPoint.X;
                    Y1 = PreviousContactPoint.Y;
                    X2 = CurrentContactPoint.X;
                    Y2 = CurrentContactPoint.Y;
                    //drawing a pencil on writablebitmap.
                    wb.DrawLine((int)X1, (int)Y1, (int)X2, (int)Y2, clr);
                    img1.Source = wb;

                    if (Distance(X1, Y1, X2, Y2) > 2.0)
                    {
                        Line line = new Line()
                        {
                            X1 = X1,
                            Y1 = Y1,
                            X2 = X2,
                            Y2 = Y2,
                            StrokeThickness = StrokeThickness,
                            Stroke          = new SolidColorBrush(BorderColor)
                        };

                        PreviousContactPoint = CurrentContactPoint;
                        canvas.Children.Add(line);
                        MyInkManager.ProcessPointerUpdate(e.GetCurrentPoint(canvas));
                    }
                }
            }
            break;


            case "Line":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    itisline   = true;
                    NewLine.X2 = e.GetCurrentPoint(canvas).Position.X;
                    NewLine.Y2 = e.GetCurrentPoint(canvas).Position.Y;
                    lineX2     = NewLine.X2;
                    lineY2     = NewLine.Y2;
                }
            }
            break;

            case "Rectagle":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    itisrectangle = true;
                    X2            = e.GetCurrentPoint(canvas).Position.X;
                    Y2            = e.GetCurrentPoint(canvas).Position.Y;
                    rectX2        = X2;
                    rectY2        = Y2;
                    if (X2 > X1 && Y2 > Y1)
                    {
                        NewRectangle.Margin = new Thickness(X1, Y1, X2, Y2);
                    }
                    else if (X2 < X1 && Y2 < Y1)
                    {
                        NewRectangle.Margin = new Thickness(X2, Y2, X1, Y1);
                    }
                    else if (X2 > X1 && Y2 < Y1)
                    {
                        NewRectangle.Margin = new Thickness(X1, Y2, X2, Y1);
                    }
                    else if (X2 < X1 && Y2 > Y1)
                    {
                        NewRectangle.Margin = new Thickness(X2, Y1, X1, Y2);
                    }
                    NewRectangle.Width  = Math.Abs(X2 - X1);
                    NewRectangle.Height = Math.Abs(Y2 - Y1);
                }
            }
            break;

            case "Ellipse":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    itisellipse = true;
                    X2          = e.GetCurrentPoint(canvas).Position.X;
                    Y2          = e.GetCurrentPoint(canvas).Position.Y;
                    elipX2      = X2;
                    elipY2      = Y2;
                    if (X2 > X1 && Y2 > Y1)
                    {
                        NewEllipse.Margin = new Thickness(X1, Y1, X2, Y2);
                    }
                    else if (X2 < X1 && Y2 < Y1)
                    {
                        NewEllipse.Margin = new Thickness(X2, Y2, X1, Y1);
                    }
                    else if (X2 > X1 && Y2 < Y1)
                    {
                        NewEllipse.Margin = new Thickness(X1, Y2, X2, Y1);
                    }
                    else if (X2 < X1 && Y2 > Y1)
                    {
                        NewEllipse.Margin = new Thickness(X2, Y1, X1, Y2);
                    }
                    NewEllipse.Width  = Math.Abs(X2 - X1);
                    NewEllipse.Height = Math.Abs(Y2 - Y1);
                }
            }
            break;

            case "Eraser":
            {
                if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed == true)
                {
                    if (StartPoint != e.GetCurrentPoint(canvas).Position)
                    {
                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);
                        Pencil.Points.Add(e.GetCurrentPoint(canvas).Position);
                    }
                }
            }
            break;

            default:
                break;
            }
        }