public WpfBezier(IBezier b)
        {
            _xb = b;

            _fillBrush = new SolidColorBrush(_xb.Fill.ToNativeColor());
            _fillBrush.Freeze();
            _strokeBrush = new SolidColorBrush(_xb.Stroke.ToNativeColor());
            _strokeBrush.Freeze();

            _path                 = new Path();
            _path.Tag             = this;
            _path.Fill            = _fillBrush;
            _path.Stroke          = _strokeBrush;
            _path.StrokeThickness = b.StrokeThickness;
            _pg            = new PathGeometry();
            _pf            = new PathFigure();
            _pf.StartPoint = new Point(b.Start.X, b.Start.Y);
            _pf.IsFilled   = b.IsFilled;
            _pf.IsClosed   = b.IsClosed;
            _bs            = new BezierSegment();
            _bs.Point1     = new Point(b.Point1.X, b.Point1.Y);
            _bs.Point2     = new Point(b.Point2.X, b.Point2.Y);
            _bs.Point3     = new Point(b.Point3.X, b.Point3.Y);
            _pf.Segments.Add(_bs);
            _pg.Figures.Add(_pf);
            _path.Data = _pg;

            Native = _path;
        }
Example #2
0
        private void Render(Canvas canvas, IBezier bezier)
        {
            var paint = new Paint()
            {
                Color       = ToNativeColor(bezier.Stroke),
                StrokeWidth = (float)bezier.StrokeThickness,
                AntiAlias   = true,
                StrokeCap   = Paint.Cap.Butt
            };

            paint.SetStyle(Paint.Style.Stroke);

            var path = new Path();

            path.SetLastPoint(
                (float)bezier.Start.X,
                (float)bezier.Start.Y);
            path.CubicTo(
                (float)bezier.Point1.X,
                (float)bezier.Point1.Y,
                (float)bezier.Point2.X,
                (float)bezier.Point2.Y,
                (float)bezier.Point3.X,
                (float)bezier.Point3.Y);

            canvas.DrawPath(path, paint);

            path.Dispose();
            paint.Dispose();
        }
Example #3
0
 private void Reset(IBezier bezier)
 {
     bezier.Id = 0;
     Reset(bezier.Start);
     Reset(bezier.Point1);
     Reset(bezier.Point2);
     Reset(bezier.Point3);
 }
Example #4
0
 private void Process(IBezier bezier)
 {
     bezier.Id = NextId();
     Process(bezier.Start);
     Process(bezier.Point1);
     Process(bezier.Point2);
     Process(bezier.Point3);
 }
Example #5
0
 private void Write(IBezier bezier)
 {
     Write(NativeType.Bezier);
     _writer.Write(bezier.Id);
     Write(bezier.Start);
     Write(bezier.Point1);
     Write(bezier.Point2);
     Write(bezier.Point3);
     Write(bezier.Stroke);
     _writer.Write(bezier.StrokeThickness);
     Write(bezier.Fill);
     _writer.Write(bezier.IsFilled);
     _writer.Write(bezier.IsClosed);
 }
 public IBezier Convert(IBezier bezier)
 {
     return(new XBezier()
     {
         Start = Convert(bezier.Start),
         Point1 = Convert(bezier.Point1),
         Point2 = Convert(bezier.Point2),
         Point3 = Convert(bezier.Point3),
         Stroke = Convert(bezier.Stroke),
         StrokeThickness = bezier.StrokeThickness,
         Fill = Convert(bezier.Fill),
         IsFilled = bezier.IsFilled,
         IsClosed = bezier.IsClosed
     });
 }
Example #7
0
    private static IEnumerable <float> FindIntersections <TVector>(
        IBezier <TVector> bezier,
        Ray <TVector> ray,
        float epsilon,
        Range <float> t1,
        int depth) where TVector : IVector <TVector>
    {
        var bounds = bezier.GetBounds();

        if (Intersect.s(ray, bounds))
        {
            var intersections1 = new float[] { };
            var intersections2 = new float[] { };
            foreach (var t in intersections1)
            {
                yield return(t);
            }
            foreach (var t in intersections2)
            {
                yield return(t);
            }
        }
    }
Example #8
0
 private void Write(IBezier bezier)
 {
     Write(NativeType.Bezier);
     _writer.Write(bezier.Id);
     Write(bezier.Start);
     Write(bezier.Point1);
     Write(bezier.Point2);
     Write(bezier.Point3);
     Write(bezier.Stroke);
     _writer.Write(bezier.StrokeThickness);
     Write(bezier.Fill);
     _writer.Write(bezier.IsFilled);
     _writer.Write(bezier.IsClosed);
 }
Example #9
0
 public IBezier Convert(IBezier bezier)
 {
     return bezier;
 }
Example #10
0
        public WpfBezier(IBezier b)
        {
            _xb = b;

            _fillBrush = new SolidColorBrush(_xb.Fill.ToNativeColor());
            _fillBrush.Freeze();
            _strokeBrush = new SolidColorBrush(_xb.Stroke.ToNativeColor());
            _strokeBrush.Freeze();

            _path = new Path();
            _path.Tag = this;
            _path.Fill = _fillBrush;
            _path.Stroke = _strokeBrush;
            _path.StrokeThickness = b.StrokeThickness;
            _pg = new PathGeometry();
            _pf = new PathFigure();
            _pf.StartPoint = new Point(b.Start.X, b.Start.Y);
            _pf.IsFilled = b.IsFilled;
            _pf.IsClosed = b.IsClosed;
            _bs = new BezierSegment();
            _bs.Point1 = new Point(b.Point1.X, b.Point1.Y);
            _bs.Point2 = new Point(b.Point2.X, b.Point2.Y);
            _bs.Point3 = new Point(b.Point3.X, b.Point3.Y);
            _pf.Segments.Add(_bs);
            _pg.Figures.Add(_pf);
            _path.Data = _pg;

            Native = _path;
        }
Example #11
0
 public IBezier Convert(IBezier bezier)
 {
     return new WpfBezier(bezier);
 }
Example #12
0
 public IBezier Convert(IBezier bezier)
 {
     return(bezier);
 }
Example #13
0
        private void DrawBezier(XGraphics gfx, IBezier bezier)
        {
            var pen = new XPen(
                ToXColor(bezier.Stroke),
                X(bezier.StrokeThickness));

            gfx.DrawBezier(pen,
                X(bezier.Start.X), Y(bezier.Start.Y),
                X(bezier.Point1.X), Y(bezier.Point1.Y),
                X(bezier.Point2.X), Y(bezier.Point2.Y),
                X(bezier.Point3.X), Y(bezier.Point3.Y));
        }
Example #14
0
 public IBounds Create(ICanvas canvas, IBezier bezier)
 {
     return new BezierBounds(
         _nativeConverter,
         _canvasFactory,
         canvas,
         bezier,
         15.0,
         0.0);
 }
Example #15
0
        public XBezierEditor(
            INativeConverter nativeConverter, 
            ICanvasFactory canvasFactory,
            IBoundsFactory boundsFactory,
            ICanvas canvas)
        {
            _canvas = canvas;

            Name = "Bézier";
            Key = "B";
            Modifiers = "";

            var moves = _canvas.Moves.Where(_ => _canvas.IsCaptured);
            var drags = Observable.Merge(_canvas.Downs, _canvas.Ups, moves);

            _downs = _canvas.Downs.Where(_ => IsEnabled).Subscribe(p =>
            {
                if (_canvas.IsCaptured)
                {
                    switch (_state)
                    {
                        case State.Start:
                            {
                                //_xb.Point3.X = p.X;
                                //_xb.Point3.Y = p.Y;
                                //_nb.Point3 = _xb.Point3;
                                //_xb.Point2.X = p.X;
                                //_xb.Point2.Y = p.Y;
                                //_nb.Point2 = _xb.Point2;
#if CONNECTORS
                                ConnectPoint3(p);
#endif
                                _nb.Bounds.Update();
                                _canvas.Render(null);
                                _state = State.Point1;
                            }
                            break;
                        case State.Point1:
                            {
                                //_xb.Point1.X = p.X;
                                //_xb.Point1.Y = p.Y;
                                //_nb.Point1 = _xb.Point1;
#if CONNECTORS
                                ConnectPoint1(p);
#endif
                                _nb.Bounds.Update();
                                _canvas.Render(null);
                                _state = State.Point2;
                            }
                            break;
                        case State.Point2:
                            {
                                //_xb.Point2.X = p.X;
                                //_xb.Point2.Y = p.Y;
                                //_nb.Point2 = _xb.Point2;
#if CONNECTORS
                                ConnectPoint2(p);
#endif
                                _nb.Bounds.Hide();
                                _canvas.Render(null);
                                _state = State.None;
                                _canvas.ReleaseCapture();
                            }
                            break;
                    }
                }
                else
                {
                    _xb = canvasFactory.CreateBezier();
                    _xb.Start.X = p.X;
                    _xb.Start.Y = p.Y;
                    _xb.Point1.X = p.X;
                    _xb.Point1.Y = p.Y;
                    _xb.Point2.X = p.X;
                    _xb.Point2.Y = p.Y;
                    _xb.Point3.X = p.X;
                    _xb.Point3.Y = p.Y;
                    _nb = nativeConverter.Convert(_xb);
                    _canvas.History.Snapshot(_canvas);
#if CONNECTORS
                    ConnectStart(p);
#endif
                    _canvas.Add(_nb);
                    _nb.Bounds = boundsFactory.Create(_canvas, _nb);
                    _nb.Bounds.Update();
                    _nb.Bounds.Show();
                    _canvas.Render(null);
                    _canvas.Capture();
                    _state = State.Start;
                }
            });

            _drags = drags.Where(_ => IsEnabled).Subscribe(p =>
            {
                switch (_state)
                {
                    case State.Start:
                        {
                            _xb.Point3.X = p.X;
                            _xb.Point3.Y = p.Y;
                            _nb.Point3 = _xb.Point3;
                            _xb.Point2.X = p.X;
                            _xb.Point2.Y = p.Y;
                            _nb.Point2 = _xb.Point2;
                            _nb.Bounds.Update();
                            _canvas.Render(null);
                        }
                        break;
                    case State.Point1:
                        {
                            _xb.Point1.X = p.X;
                            _xb.Point1.Y = p.Y;
                            _nb.Point1 = _xb.Point1;
                            _nb.Bounds.Update();
                            _canvas.Render(null);
                        }
                        break;
                    case State.Point2:
                        {
                            _xb.Point2.X = p.X;
                            _xb.Point2.Y = p.Y;
                            _nb.Point2 = _xb.Point2;
                            _nb.Bounds.Update();
                            _canvas.Render(null);
                        }
                        break;
                }
            });
        }
Example #16
0
 private void Process(IBezier bezier)
 {
     bezier.Id = NextId();
     Process(bezier.Start);
     Process(bezier.Point1);
     Process(bezier.Point2);
     Process(bezier.Point3);
 }
 public IBezier Convert(IBezier bezier)
 {
     return(new WpfBezier(bezier));
 }
Example #18
0
 private void Reset(IBezier bezier)
 {
     bezier.Id = 0;
     Reset(bezier.Start);
     Reset(bezier.Point1);
     Reset(bezier.Point2);
     Reset(bezier.Point3);
 }
Example #19
0
        public BezierBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            IBezier bezier,
            double size,
            double offset)
        {
            _bezier = bezier;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            InitBounds(nativeConverter, canvasFactory);
        }