Example #1
0
        public ArcBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            IArc arc,
            double size,
            double offset)
        {
            _arc = arc;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            _hitResult = HitResult.None;

            InitBounds(nativeConverter, canvasFactory);
        }
Example #2
0
 private void InitBounds(
     INativeConverter nativeConverter,
     ICanvasFactory canvasFactory)
 {
     _polygonPoint1 = Helper.CreateBoundsPolygon(nativeConverter, canvasFactory, 4);
     _polygonPoint2 = Helper.CreateBoundsPolygon(nativeConverter, canvasFactory, 4);
     _polygonEllipse = Helper.CreateBoundsPolygon(nativeConverter, canvasFactory, 4);
     _vertices = new Vector2[4];
 }
Example #3
0
        public EllipseBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            IEllipse ellipse,
            double size,
            double offset)
        {
            _ellipse = ellipse;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            _hitResult = HitResult.None;

            InitBounds(nativeConverter, canvasFactory);
        }
Example #4
0
 public BoundsFactory(
     INativeConverter nativeConverter,
     ICanvasFactory canvasFactory)
 {
     _nativeConverter = nativeConverter;
     _canvasFactory = canvasFactory;
 }
Example #5
0
        public static IPolygon CreateBoundsPolygon(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            int points)
        {
            var polygon = canvasFactory.CreatePolygon();
            polygon.Points = new IPoint[points];
            polygon.Lines = new ILine[points];

            for (int i = 0; i < points; i++)
            {
                polygon.Points[i] = canvasFactory.CreatePoint();

                var _xline = canvasFactory.CreateLine();
                _xline.Stroke = canvasFactory.CreateColor();
                _xline.Stroke.A = 0xFF;
                _xline.Stroke.R = 0x00;
                _xline.Stroke.G = 0xBF;
                _xline.Stroke.B = 0xFF;
                _xline.StrokeThickness = 2.0;
                var _nline = nativeConverter.Convert(_xline);
                polygon.Lines[i] = _nline;
            }

            return polygon;
        }
Example #6
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);
        }
Example #7
0
        public RectangleBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            IRectangle rectangle,
            double size,
            double offset)
        {
            _rectangle = rectangle;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            _hitResult = HitResult.None;

            InitBounds(nativeConverter, canvasFactory);
        }
Example #8
0
        public XPinEditor(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            IBoundsFactory boundsFactory,
            ICanvas canvas)
        {
            _canvas = canvas;

            Name = "Pin";
            Key = "P";
            Modifiers = "";

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

            _downs = _canvas.Downs.Where(_ => IsEnabled).Subscribe(p =>
            {
                _xpin = canvasFactory.CreatePin();
                _xpin.Point.X = p.X;
                _xpin.Point.Y = p.Y;
                _npin = nativeConverter.Convert(_xpin);
                _canvas.History.Snapshot(_canvas);
#if CONNECTORS
                ConnectPoint(p);
#endif
                _canvas.Add(_npin);
                _npin.Bounds = boundsFactory.Create(_canvas, _npin);
                _npin.Bounds.Update();
                _canvas.Render(null);
            });
        }
Example #9
0
        public PinBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            IPin pin,
            double size,
            double offset)
        {
            _pin = pin;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            _hitResult = HitResult.None;

            InitBounds(nativeConverter, canvasFactory);
        }
Example #10
0
 private void InitBounds(
     INativeConverter nativeConverter,
     ICanvasFactory canvasFactory)
 {
     _polygonStart = Helper.CreateBoundsPolygon(nativeConverter, canvasFactory, 4);
     _polygonPoint1 = Helper.CreateBoundsPolygon(nativeConverter, canvasFactory, 4);
     _polygonPoint2 = Helper.CreateBoundsPolygon(nativeConverter, canvasFactory, 4);
     _polygonQuadraticBezier = Helper.CreateBoundsPolygon(nativeConverter, canvasFactory, 3);
     _vertices = new Vector2[3];
 }
Example #11
0
        public LineBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            ILine line,
            double size,
            double offset)
        {
            _line = line;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            _hitResult = HitResult.None;

            InitBounds(nativeConverter, canvasFactory);
        }
Example #12
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 #13
0
        public XLineEditor(
            INativeConverter nativeConverter, 
            ICanvasFactory canvasFactory,
            IBoundsFactory boundsFactory,
            ICanvas canvas)
        {
            _canvas = canvas;

            Name = "Line";
            Key = "L";
            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)
                {
                    //_xline.Point2.X = p.X;
                    //_xline.Point2.Y = p.Y;
                    //_nline.Point2 = _xline.Point2;
#if CONNECTORS
                    ConnectPoint2(p);
#endif
                    _nline.Bounds.Hide();
                    _canvas.Render(null);
                    _state = State.None;
                    _canvas.ReleaseCapture();
                }
                else
                {
                    _xline = canvasFactory.CreateLine();
                    _xline.Point1.X = p.X;
                    _xline.Point1.Y = p.Y;
                    _xline.Point2.X = p.X;
                    _xline.Point2.Y = p.Y;
                    _nline = nativeConverter.Convert(_xline);
                    _canvas.History.Snapshot(_canvas);
#if CONNECTORS
                    ConnectPoint1(p);
#endif
                    _canvas.Add(_nline);
                    _nline.Bounds = boundsFactory.Create(_canvas, _nline);
                    _nline.Bounds.Update();
                    _nline.Bounds.Show();
                    _canvas.Capture();
                    _canvas.Render(null);
                    _state = State.End;
                }
            });

            _drags = drags.Where(_ => IsEnabled).Subscribe(p =>
            {
                if (_state == State.End)
                {
                    _xline.Point2.X = p.X;
                    _xline.Point2.Y = p.Y;
                    _nline.Point2 = _xline.Point2;
                    _nline.Bounds.Update();
                    _canvas.Render(null);
                }
            });
        }
Example #14
0
        private IList<INative> ToNatives(
            INativeConverter nativeConverter,
            IBoundsFactory boundsFactory,
            ICanvas nativeCanvas,
            IList<INative> xchildren)
        {
            var natives = new List<INative>();

            foreach (var child in xchildren)
            {
                if (child is IPin)
                {
                    var native = nativeConverter.Convert(child as IPin);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is ILine)
                {
                    var native = nativeConverter.Convert(child as ILine);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IBezier)
                {
                    var native = nativeConverter.Convert(child as IBezier);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IQuadraticBezier)
                {
                    var native = nativeConverter.Convert(child as IQuadraticBezier);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IArc)
                {
                    var native = nativeConverter.Convert(child as IArc);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IRectangle)
                {
                    var native = nativeConverter.Convert(child as IRectangle);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IEllipse)
                {
                    var native = nativeConverter.Convert(child as IEllipse);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IText)
                {
                    var native = nativeConverter.Convert(child as IText);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IBlock)
                {
                    var native = nativeConverter.Convert(child as IBlock);
                    natives.Add(native);
                    var blockNatives = ToNatives(
                        nativeConverter,
                        boundsFactory,
                        nativeCanvas,
                        native.Children);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            return natives;
        }
Example #15
0
        public TextBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            IText text,
            double size,
            double offset)
        {
            _text = text;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            _hitResult = HitResult.None;

            InitBounds(nativeConverter, canvasFactory);
        }
        private IList <INative> ToNatives(
            INativeConverter nativeConverter,
            IBoundsFactory boundsFactory,
            ICanvas nativeCanvas,
            IList <INative> xchildren)
        {
            var natives = new List <INative>();

            foreach (var child in xchildren)
            {
                if (child is IPin)
                {
                    var native = nativeConverter.Convert(child as IPin);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is ILine)
                {
                    var native = nativeConverter.Convert(child as ILine);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IBezier)
                {
                    var native = nativeConverter.Convert(child as IBezier);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IQuadraticBezier)
                {
                    var native = nativeConverter.Convert(child as IQuadraticBezier);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IArc)
                {
                    var native = nativeConverter.Convert(child as IArc);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IRectangle)
                {
                    var native = nativeConverter.Convert(child as IRectangle);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IEllipse)
                {
                    var native = nativeConverter.Convert(child as IEllipse);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IText)
                {
                    var native = nativeConverter.Convert(child as IText);
                    natives.Add(native);
                    native.Bounds = boundsFactory.Create(nativeCanvas, native);
                    if (native.Bounds != null)
                    {
                        native.Bounds.Update();
                    }
                }
                else if (child is IBlock)
                {
                    var native = nativeConverter.Convert(child as IBlock);
                    natives.Add(native);
                    var blockNatives = ToNatives(
                        nativeConverter,
                        boundsFactory,
                        nativeCanvas,
                        native.Children);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            return(natives);
        }
Example #17
0
        public XMultiEditor(
            INativeConverter nativeConverter, 
            ICanvasFactory canvasFactory, 
            IBoundsFactory boundsFactory,
            ICanvas canvas)
        {
            _nativeConverter = nativeConverter;
            _canvasFactory = canvasFactory;
            _boundsFactory = boundsFactory;

            _canvas = canvas;

            Name = "Multi Selection";
            Key = "J";
            Modifiers = "";

            var drags = Observable.Merge(_canvas.Downs, _canvas.Ups, _canvas.Moves);

            _downs = _canvas.Downs.Where(_ => IsEnabled).Subscribe(p => Down(p));
            _ups = _canvas.Ups.Where(_ => IsEnabled).Subscribe(p => Up(p));
            _drag = drags.Where(_ => IsEnabled).Subscribe(p => Drag(p));
        }