Rectangle shape.
Inheritance: XText
コード例 #1
0
ファイル: RectangleSelection.cs プロジェクト: Core2D/Core2D
 /// <summary>
 /// Initialize new instance of <see cref="RectangleSelection"/> class.
 /// </summary>
 /// <param name="layer">The selection shapes layer.</param>
 /// <param name="shape">The selected shape.</param>
 /// <param name="style">The selection shapes style.</param>
 /// <param name="point">The selection point shape.</param>
 public RectangleSelection(XLayer layer, XRectangle shape, ShapeStyle style, BaseShape point)
 {
     _layer = layer;
     _rectangle = shape;
     _style = style;
     _point = point;
 }
コード例 #2
0
ファイル: ToolRectangle.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void LeftDown(double x, double y)
        {
            base.LeftDown(x, y);
            var editor = _serviceProvider.GetService<ProjectEditor>();
            double sx = editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, editor.Project.Options.SnapX) : x;
            double sy = editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, editor.Project.Options.SnapY) : y;
            switch (_currentState)
            {
                case ToolState.None:
                    {
                        var style = editor.Project.CurrentStyleLibrary.Selected;
                        _rectangle = XRectangle.Create(
                            sx, sy,
                            editor.Project.Options.CloneStyle ? style.Clone() : style,
                            editor.Project.Options.PointShape,
                            editor.Project.Options.DefaultIsStroked,
                            editor.Project.Options.DefaultIsFilled);

                        var result = editor.TryToGetConnectionPoint(sx, sy);
                        if (result != null)
                        {
                            _rectangle.TopLeft = result;
                        }

                        editor.Project.CurrentContainer.WorkingLayer.Shapes = editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_rectangle);
                        editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                        ToStateOne();
                        Move(_rectangle);
                        _currentState = ToolState.One;
                        editor.CancelAvailable = true;
                    }
                    break;
                case ToolState.One:
                    {
                        if (_rectangle != null)
                        {
                            _rectangle.BottomRight.X = sx;
                            _rectangle.BottomRight.Y = sy;

                            var result = editor.TryToGetConnectionPoint(sx, sy);
                            if (result != null)
                            {
                                _rectangle.BottomRight = result;
                            }

                            editor.Project.CurrentContainer.WorkingLayer.Shapes = editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_rectangle);
                            Remove();
                            Finalize(_rectangle);
                            editor.Project.AddShape(editor.Project.CurrentContainer.CurrentLayer, _rectangle);
                            _currentState = ToolState.None;
                            editor.CancelAvailable = false;
                        }
                    }
                    break;
            }
        }
コード例 #3
0
ファイル: TextSelection.cs プロジェクト: Core2D/Core2D
        /// <summary>
        /// Transfer selection state to <see cref="ToolState.One"/>.
        /// </summary>
        public void ToStateOne()
        {
            _helperRectangle = XRectangle.Create(0, 0, _style, null);
            _topLeftHelperPoint = XPoint.Create(0, 0, _point);
            _bottomRightHelperPoint = XPoint.Create(0, 0, _point);

            _layer.Shapes = _layer.Shapes.Add(_helperRectangle);
            _layer.Shapes = _layer.Shapes.Add(_topLeftHelperPoint);
            _layer.Shapes = _layer.Shapes.Add(_bottomRightHelperPoint);
        }
コード例 #4
0
ファイル: ShapeHitTestPoint.cs プロジェクト: Core2D/Core2D
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestRectangle(XRectangle rectangle, Vector2 v, double threshold, double dx, double dy)
        {
            if (ShapeBounds.GetPointBounds(rectangle.TopLeft, threshold, dx, dy).Contains(v))
            {
                return rectangle.TopLeft;
            }

            if (ShapeBounds.GetPointBounds(rectangle.BottomRight, threshold, dx, dy).Contains(v))
            {
                return rectangle.BottomRight;
            }

            if (ShapeBounds.GetRectangleBounds(rectangle, dx, dy).Contains(v))
            {
                return rectangle;
            }

            return null;
        }
コード例 #5
0
ファイル: WpfRenderer.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var _dc = dc as DrawingContext;

            var style = rectangle.Style;
            if (style == null)
                return;

            double thickness = style.Thickness / _state.ZoomX;
            double half = thickness / 2.0;

            Tuple<Brush, Pen> styleCached = _styleCache.Get(style);
            Brush fill;
            Pen stroke;
            if (styleCached != null)
            {
                fill = styleCached.Item1;
                stroke = styleCached.Item2;
            }
            else
            {
                fill = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                _styleCache.Set(style, Tuple.Create(fill, stroke));
            }

            var rect = CreateRect(rectangle.TopLeft, rectangle.BottomRight, dx, dy);

            DrawRectangleInternal(_dc, half, fill, stroke, rectangle.IsStroked, rectangle.IsFilled, ref rect);

            if (rectangle.IsGrid)
            {
                DrawGridInternal(_dc, half, stroke, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true);
            }
        }
コード例 #6
0
ファイル: SkiaRenderer.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var canvas = dc as SKCanvas;

            using (SKPaint brush = ToSKPaintBrush(rectangle.Style.Fill))
            using (SKPaint pen = ToSKPaintPen(rectangle.Style, _scaleToPage, _sourceDpi, _targetDpi))
            {
                var rect = CreateRect(rectangle.TopLeft, rectangle.BottomRight, dx, dy, _scaleToPage);
                DrawRectangleInternal(canvas, brush, pen, rectangle.IsStroked, rectangle.IsFilled, ref rect);
                if (rectangle.IsGrid)
                {
                    DrawGridInternal(
                        canvas,
                        pen,
                        ref rect,
                        rectangle.OffsetX,
                        rectangle.OffsetY,
                        rectangle.CellWidth,
                        rectangle.CellHeight,
                        isStroked: true);
                }
            }
        }
コード例 #7
0
ファイル: ToolSelection.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void LeftDown(double x, double y)
        {
            base.LeftDown(x, y);
            var editor = _serviceProvider.GetService<ProjectEditor>();
            switch (_currentState)
            {
                case ToolState.None:
                    {
                        editor.Dehover(editor.Project.CurrentContainer.CurrentLayer);
                        if (editor.Renderers[0].State.SelectedShape == null
                            && editor.Renderers[0].State.SelectedShapes != null)
                        {
                            var result = ShapeHitTestPoint.HitTest(editor.Project.CurrentContainer.CurrentLayer.Shapes, new Vector2(x, y), editor.Project.Options.HitThreshold);
                            if (result != null)
                            {
                                _startX = editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, editor.Project.Options.SnapX) : x;
                                _startY = editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, editor.Project.Options.SnapY) : y;
                                _historyX = _startX;
                                _historyY = _startY;
                                GenerateMoveSelectionCache();
                                _currentState = ToolState.One;
                                editor.CancelAvailable = true;
                                break;
                            }
                        }

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

                        _rectangle = XRectangle.Create(
                            x, y,
                            editor.Project.Options.SelectionStyle,
                            null,
                            true, true);
                        editor.Project.CurrentContainer.WorkingLayer.Shapes = editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_rectangle);
                        editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                        _currentState = ToolState.One;
                        editor.CancelAvailable = true;
                    }
                    break;
                case ToolState.One:
                    {
                        if (_rectangle != null)
                        {
                            _rectangle.BottomRight.X = x;
                            _rectangle.BottomRight.Y = y;
                            editor.Project.CurrentContainer.WorkingLayer.Shapes = editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_rectangle);
                            editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                            _currentState = ToolState.None;
                            editor.CancelAvailable = false;
                        }
                    }
                    break;
            }
        }
コード例 #8
0
ファイル: VdxRenderer.cs プロジェクト: Core2D/Core2D
 /// <inheritdoc/>
 public override void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
 {
     // TODO: Implement Draw rectangle.
 }
コード例 #9
0
ファイル: AvaloniaRenderer.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var _dc = dc as AM.DrawingContext;

            AM.IBrush brush = ToBrush(rectangle.Style.Fill);
            AM.Pen pen = ToPen(rectangle.Style, _scaleToPage);

            var rect = CreateRect(rectangle.TopLeft, rectangle.BottomRight, dx, dy);

            DrawRectangleInternal(
                _dc,
                brush,
                pen,
                rectangle.IsStroked,
                rectangle.IsFilled,
                ref rect);

            if (rectangle.IsGrid)
            {
                DrawGridInternal(
                    _dc,
                    pen,
                    ref rect,
                    rectangle.OffsetX, rectangle.OffsetY,
                    rectangle.CellWidth, rectangle.CellHeight,
                    true);
            }
        }
コード例 #10
0
ファイル: ShapeRenderer.cs プロジェクト: Core2D/Core2D
 /// <summary>
 /// Draws a <see cref="XRectangle"/> shape using drawing context.
 /// </summary>
 /// <param name="dc">The native drawing context.</param>
 /// <param name="rectangle">The <see cref="XRectangle"/> shape.</param>
 /// <param name="dx">The X coordinate offset.</param>
 /// <param name="dy">The Y coordinate offset.</param>
 /// <param name="db">The properties database.</param>
 /// <param name="r">The data record.</param>
 public abstract void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r);
コード例 #11
0
ファイル: TextSelection.cs プロジェクト: Core2D/Core2D
        /// <summary>
        /// Remove selection.
        /// </summary>
        public void Remove()
        {
            if (_helperRectangle != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperRectangle);
                _helperRectangle = null;
            }

            if (_topLeftHelperPoint != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_topLeftHelperPoint);
                _topLeftHelperPoint = null;
            }

            if (_bottomRightHelperPoint != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_bottomRightHelperPoint);
                _bottomRightHelperPoint = null;
            }

            _layer.Invalidate();
        }
コード例 #12
0
ファイル: WinFormsRenderer.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var _gfx = dc as Graphics;

            Brush brush = ToSolidBrush(rectangle.Style.Fill);
            Pen pen = ToPen(rectangle.Style, _scaleToPage);

            var rect = CreateRect(
                rectangle.TopLeft,
                rectangle.BottomRight,
                dx, dy);

            if (rectangle.IsFilled)
            {
                _gfx.FillRectangle(
                    brush,
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }

            if (rectangle.IsStroked)
            {
                _gfx.DrawRectangle(
                    pen,
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }

            if (rectangle.IsGrid)
            {
                DrawGridInternal(
                    _gfx,
                    pen,
                    ref rect,
                    rectangle.OffsetX, rectangle.OffsetY,
                    rectangle.CellWidth, rectangle.CellHeight,
                    true);
            }

            brush.Dispose();
            pen.Dispose();
        }
コード例 #13
0
ファイル: XRectangleTests.cs プロジェクト: Core2D/Core2D
 public void Inherits_From_XText()
 {
     var target = new XRectangle();
     Assert.True(target is XText);
 }
コード例 #14
0
ファイル: ShapeBounds.cs プロジェクト: Core2D/Core2D
 /// <summary>
 /// Get the bounding rectangle for <see cref="XRectangle"/> shape.
 /// </summary>
 /// <param name="rectangle"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetRectangleBounds(XRectangle rectangle, double dx, double dy)
 {
     return Rect2.Create(rectangle.TopLeft, rectangle.BottomRight, dx, dy);
 }
コード例 #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="rect"></param>
        /// <param name="selected"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool HitTestRectangle(XRectangle rectangle, Rect2 rect, ISet<BaseShape> selected, double dx, double dy)
        {
            if (ShapeBounds.GetRectangleBounds(rectangle, dx, dy).IntersectsWith(rect))
            {
                if (selected != null)
                {
                    selected.Add(rectangle);
                    return false;
                }
                else
                {
                    return true;
                }
            }

            return false;
        }