Ejemplo n.º 1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

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

            if (eraseTester.IsValid)
            {
                eraseTester.AddPoint(e.GetPosition(this));
            }
        }
Ejemplo n.º 2
0
        private void EraserCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isDown)
            {
                var point = e.GetPosition(this);
                TranslateTransform.X = point.X - EraserShape.ActualWidth / 2;
                TranslateTransform.Y = point.Y - EraserShape.ActualHeight / 2;

                _incrementalStrokeHitTester.AddPoint(point);
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        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();
                });
            });
        }