Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public override void LeftDown(double x, double y)
        {
            double sx = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x;
            double sy = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y;

            switch (_currentState)
            {
            case State.None:
            {
                _shape = XRectangle.Create(
                    sx, sy,
                    _editor.Project.CurrentStyleLibrary.CurrentStyle,
                    _editor.Project.Options.PointShape,
                    _editor.Project.Options.DefaultIsStroked,
                    _editor.Project.Options.DefaultIsFilled);
                if (_editor.Project.Options.TryToConnect)
                {
                    TryToConnectTopLeft(_shape as XRectangle, sx, sy);
                }
                _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_shape);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                ToStateOne();
                Move(_shape);
                _editor.Project.CurrentContainer.HelperLayer.Invalidate();
                _currentState           = State.One;
                _editor.CancelAvailable = true;
            }
            break;

            case State.One:
            {
                var rectangle = _shape as XRectangle;
                if (rectangle != null)
                {
                    rectangle.BottomRight.X = sx;
                    rectangle.BottomRight.Y = sy;
                    if (_editor.Project.Options.TryToConnect)
                    {
                        TryToConnectBottomRight(_shape as XRectangle, sx, sy);
                    }
                    _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_shape);
                    Remove();
                    Finalize(_shape);
                    _editor.AddWithHistory(_shape);
                    _currentState           = State.None;
                    _editor.CancelAvailable = false;
                }
            }
            break;
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a new instance of the XRectangle class.
        /// </summary>
        /// <param name="topLeft"></param>
        /// <param name="bottomRight"></param>
        /// /// <param name="isStroked"></param>
        /// <param name="isFilled"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public XRectangle Rectangle(
            XPoint topLeft,
            XPoint bottomRight,
            bool isStroked = true,
            bool isFilled  = false,
            string text    = null)
        {
            var rectangle = XRectangle.Create(
                topLeft,
                bottomRight,
                Context.Editor.Project.CurrentStyleLibrary.CurrentStyle,
                Context.Editor.Project.Options.PointShape,
                isStroked,
                isFilled,
                text);

            Context.Editor.AddWithHistory(rectangle);
            return(rectangle);
        }
Пример #3
0
        /// <summary>
        /// Creates a new instance of the XRectangle class.
        /// </summary>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <param name="isStroked"></param>
        /// <param name="isFilled"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public XRectangle Rectangle(
            double x1      = 30, double y1 = 30,
            double x2      = 60, double y2 = 60,
            bool isStroked = true,
            bool isFilled  = false,
            string text    = null)
        {
            var rectangle = XRectangle.Create(
                x1, y1,
                x2, y2,
                Context.Editor.Project.CurrentStyleLibrary.CurrentStyle,
                Context.Editor.Project.Options.PointShape,
                isStroked,
                isFilled,
                text);

            Context.Editor.AddWithHistory(rectangle);
            return(rectangle);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="project"></param>
        /// <param name="container"></param>
        private void CreateGrid(Project project, Container container)
        {
            var style = project
                        .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
                        .Styles.FirstOrDefault(s => s.Name == "Grid");
            var layer   = container.Layers.FirstOrDefault();
            var builder = layer.Shapes.ToBuilder();
            var grid    = XRectangle.Create(
                0, 0,
                container.Width, container.Height,
                style,
                project.Options.PointShape);

            grid.IsStroked    = false;
            grid.IsFilled     = false;
            grid.IsGrid       = true;
            grid.OffsetX      = 30.0;
            grid.OffsetY      = 30.0;
            grid.CellWidth    = 30.0;
            grid.CellHeight   = 30.0;
            grid.State.Flags &= ~ShapeStateFlags.Printable;
            builder.Add(grid);
            layer.Shapes = builder.ToImmutable();
        }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pss"></param>
 /// <returns></returns>
 public static BaseShape FilledRectanglePointShape(ShapeStyle pss)
 {
     return(XRectangle.Create(-3, -3, 3, 3, pss, null, true, true));
 }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pss"></param>
 /// <returns></returns>
 public static BaseShape RectanglePointShape(ShapeStyle pss)
 {
     return(XRectangle.Create(-4, -4, 4, 4, pss, null, true, false));
 }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public override void LeftDown(double x, double y)
        {
            switch (_currentState)
            {
            case State.None:
            {
                _editor.Dehover();
                if (_editor.Renderers[0].State.SelectedShape == null &&
                    _editor.Renderers[0].State.SelectedShapes != null)
                {
                    var result = ShapeBounds.HitTest(_editor.Project.CurrentContainer, new Vector2(x, y), _editor.Project.Options.HitTreshold);
                    if (result != null)
                    {
                        _startX   = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x;
                        _startY   = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y;
                        _historyX = _startX;
                        _historyY = _startY;
                        GenerateMoveSelectionCache();
                        _currentState           = State.One;
                        _editor.CancelAvailable = true;
                        break;
                    }
                }

                if (_editor.TryToSelectShape(_editor.Project.CurrentContainer, x, y))
                {
                    _startX   = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x;
                    _startY   = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y;
                    _historyX = _startX;
                    _historyY = _startY;
                    GenerateMoveSelectionCache();
                    _currentState           = State.One;
                    _editor.CancelAvailable = true;
                    break;
                }

                _shape = XRectangle.Create(
                    x, y,
                    _editor.Project.Options.SelectionStyle,
                    null,
                    true, true);
                _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_shape);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                _currentState           = State.One;
                _editor.CancelAvailable = true;
            }
            break;

            case State.One:
            {
                var rectangle = _shape as XRectangle;
                if (rectangle != null)
                {
                    rectangle.BottomRight.X = x;
                    rectangle.BottomRight.Y = y;
                    _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_shape);
                    _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                    _currentState           = State.None;
                    _editor.CancelAvailable = false;
                }
            }
            break;
            }
        }