private void EraserCanvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            EraserCanvas.Visibility = Visibility.Collapsed;
            _isDown = false;

            _incrementalStrokeHitTester.EndHitTesting();
            _incrementalStrokeHitTester = null;
        }
Exemple #2
0
    // Prepare to collect stylus packets. Get the
    // IncrementalHitTester from the InkPresenter's
    // StrokeCollection and subscribe to its StrokeHitChanged event.
    private void InitializeEraserHitTester(StylusPointCollection points)
    {
        EllipseStylusShape eraserTip = new EllipseStylusShape(3, 3, 0);

        eraseTester =
            presenter.Strokes.GetIncrementalStrokeHitTester(eraserTip);
        eraseTester.StrokeHit += new StrokeHitEventHandler(eraseTester_StrokeHit);
        eraseTester.AddPoints(points);
    }
Exemple #3
0
        //</Snippet5>

        //<Snippet6>

        //<Snippet4>
        // Prepare to collect stylus packets. Get the
        // IncrementalHitTester from the InkPresenter's
        // StrokeCollection and subscribe to its StrokeHitChanged event.
        protected override void OnStylusDown(StylusDownEventArgs e)
        {
            base.OnStylusDown(e);

            EllipseStylusShape eraserTip = new EllipseStylusShape(3, 3, 0);

            eraseTester =
                presenter.Strokes.GetIncrementalStrokeHitTester(eraserTip);
            eraseTester.StrokeHit += new StrokeHitEventHandler(eraseTester_StrokeHit);
            eraseTester.AddPoints(e.GetStylusPoints(this));
        }
        private void EraserCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _isDown = true;

            IncrementalStrokeHitTester incrementalStrokeHitTester =
                InkCanvas.Strokes.GetIncrementalStrokeHitTester(new RectangleStylusShape(EraserShape.ActualWidth,
                                                                                         EraserShape.ActualHeight));

            _incrementalStrokeHitTester            = incrementalStrokeHitTester;
            _incrementalStrokeHitTester.StrokeHit += IncrementalStrokeHitTester_StrokeHit;
        }
Exemple #5
0
        //</Snippet2>

        //</Snippet6>

        //</snippet1>

        //<Snippet11>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            if (e.StylusDevice != null)
            {
                return;
            }

            EllipseStylusShape eraserTip = new EllipseStylusShape(3, 3, 0);

            eraseTester =
                presenter.Strokes.GetIncrementalStrokeHitTester(eraserTip);
            eraseTester.StrokeHit += new StrokeHitEventHandler(eraseTester_StrokeHit);
            eraseTester.AddPoint(e.GetPosition(this));
        }
Exemple #6
0
        public override void Perform()
        {
            IncrementalStrokeHitTester IncrementalStroke = InkCanvas.Strokes.GetIncrementalStrokeHitTester(EraserShape);
            IncrementalLassoHitTester  IncrementalLasso  = InkCanvas.Strokes.GetIncrementalLassoHitTester(OptionIndex % 100);

            switch (OptionIndex % 2)
            {
            case 0:      //AddPoint
            {
                StrokeCollection strokeCollection = InkCanvas.Strokes;

                if (IsRandomPoint == true || strokeCollection == null || strokeCollection.Count == 0)
                {
                    IncrementalStroke.AddPoint(Point);
                    IncrementalLasso.AddPoint(Point);
                }
                else
                {
                    //get list of all points on the stroke
                    foreach (Stroke stoke in strokeCollection)
                    {
                        StylusPointCollection.Add(stoke.StylusPoints.Reformat(StylusPointCollection.Description));
                    }

                    IncrementalStroke.AddPoint(StylusPointCollection[RandomIndex % StylusPointCollection.Count].ToPoint());
                    IncrementalLasso.AddPoint(StylusPointCollection[RandomIndex % StylusPointCollection.Count].ToPoint());
                }
            }
            break;

            case 1:       //AddPoints
            {
                IncrementalLasso.AddPoints(PointCollection);
                IncrementalStroke.AddPoints(PointCollection);
            }
            break;
            }
        }
        public DrawingWindow()
        {
            InitializeComponent();

            drawingAttributes           = surfaceDessin.DefaultDrawingAttributes;
            drawingAttributes.Color     = (Color)ColorConverter.ConvertFromString("#000000");
            drawingAttributes.Height    = 10;
            drawingAttributes.Width     = 10;
            drawingAttributes.StylusTip = StylusTip.Ellipse;

            socket.On(SocketEvents.STROKE_DRAWING, (points) => {
                Dispatcher.Invoke(() => {
                    Stroke newStroke                      = new Stroke(JsonConvert.DeserializeObject <StylusPointCollection>(points.ToString()));
                    newStroke.DrawingAttributes           = drawingAttributes;
                    newStroke.DrawingAttributes.Color     = drawingAttributes.Color;
                    newStroke.DrawingAttributes.Width     = drawingAttributes.Width;
                    newStroke.DrawingAttributes.Height    = drawingAttributes.Height;
                    newStroke.DrawingAttributes.StylusTip = drawingAttributes.StylusTip;
                    surfaceDessin.Strokes.Add(newStroke);
                    ongoingStrokeIndex.Add(newStroke);
                });
            });

            socket.On(SocketEvents.STROKE_COLLECTED, (points) => {
                Dispatcher.Invoke(() => {
                    Stroke newStroke = new Stroke(JsonConvert.DeserializeObject <StylusPointCollection>(points.ToString()));
                    newStroke.DrawingAttributes.Color     = drawingAttributes.Color;
                    newStroke.DrawingAttributes.Width     = drawingAttributes.Width;
                    newStroke.DrawingAttributes.Height    = drawingAttributes.Height;
                    newStroke.DrawingAttributes.StylusTip = drawingAttributes.StylusTip;

                    foreach (Stroke strokeToDelete in ongoingStrokeIndex)
                    {
                        surfaceDessin.Strokes.Remove(strokeToDelete);
                    }

                    surfaceDessin.Strokes.Add(newStroke);
                    ongoingStrokeIndex.Clear();
                });
            });

            socket.On(SocketEvents.STROKE_ERASING, (points) => {
                Dispatcher.Invoke(() => {
                    List <StylusPoint> pointsToCheck = (JsonConvert.DeserializeObject <List <StylusPoint> >(points.ToString()));
                    pointsToCheck.ForEach((point) => {
                        StrokeCollection strokesToBeErased = surfaceDessin.Strokes.HitTest(new Point(point.X, point.Y));
                        surfaceDessin.Strokes.Remove(strokesToBeErased);
                    });
                });
            });

            socket.On(SocketEvents.STROKE_SEGMENT_ERASING, (points) => {
                Dispatcher.Invoke(() => {
                    List <StylusPoint> pointsToCheck = (JsonConvert.DeserializeObject <List <StylusPoint> >(points.ToString()));

                    Console.WriteLine(pointsToCheck.Count + " POINTS");
                    IncrementalStrokeHitTester eraserTester = surfaceDessin.Strokes.GetIncrementalStrokeHitTester(generateStylusShape());
                    eraserTester.StrokeHit += EraserTester_StrokeHit;
                    pointsToCheck.ForEach((point) => eraserTester.AddPoint(new Point(point.X, point.Y)));
                    eraserTester.StrokeHit -= EraserTester_StrokeHit;
                    eraserTester.EndHitTesting();
                });
            });

            socket.On(SocketEvents.STROKE_COLOR, (color) =>
            {
                Dispatcher.Invoke(() => {
                    string hex = "#" + ((Int64)color).ToString("X8");
                    drawingAttributes.Color = (Color)ColorConverter.ConvertFromString(hex);
                });
            });

            socket.On(SocketEvents.STROKE_SIZE, (size) =>
            {
                Dispatcher.Invoke(() => {
                    drawingAttributes.Height = Convert.ToInt32(size.ToString());
                    drawingAttributes.Width  = Convert.ToInt32(size.ToString());
                });
            });

            socket.On(SocketEvents.STROKE_TIP, (tip) =>
            {
                Dispatcher.Invoke(() => {
                    drawingAttributes.StylusTip = ((string)tip == Tool.PEN_ROUND_TIP) ? StylusTip.Ellipse : StylusTip.Rectangle;
                });
            });

            socket.On(SocketEvents.STROKE_TOOL, (tool) =>
            {
                Dispatcher.Invoke(() => {
                    OutilSelectionne = tool.ToString();
                });
            });
        }