コード例 #1
0
ファイル: EmfRenderer.cs プロジェクト: monocraft/Core2D
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="ellipse"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, XEllipse ellipse, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            var _gfx = gfx as Graphics;

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

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

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

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

            brush.Dispose();
            pen.Dispose();
        }
コード例 #2
0
ファイル: EllipseHelper.cs プロジェクト: monocraft/Core2D
        /// <summary>
        ///
        /// </summary>
        /// <param name="ellipse"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void TryToConnectBottomRight(XEllipse ellipse, double x, double y)
        {
            var result = ShapeBounds.HitTest(_editor.Project.CurrentContainer, new Vector2(x, y), _editor.Project.Options.HitTreshold);

            if (result != null && result is XPoint)
            {
                ellipse.BottomRight = result as XPoint;
            }
        }
コード例 #3
0
ファイル: ArcHelper.cs プロジェクト: monocraft/Core2D
 /// <summary>
 ///
 /// </summary>
 public override void ToStateOne()
 {
     _style   = _editor.Project.Options.HelperStyle;
     _ellipse = XEllipse.Create(0, 0, _style, null);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_ellipse);
     _p1HelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_p1HelperPoint);
     _p2HelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_p2HelperPoint);
     _centerHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_centerHelperPoint);
 }
コード例 #4
0
ファイル: ArcHelper.cs プロジェクト: monocraft/Core2D
        /// <summary>
        ///
        /// </summary>
        public override void Remove()
        {
            if (_ellipse != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_ellipse);
                _ellipse = null;
            }

            if (_startLine != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_startLine);
                _startLine = null;
            }

            if (_endLine != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_endLine);
                _endLine = null;
            }

            if (_p1HelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p1HelperPoint);
                _p1HelperPoint = null;
            }

            if (_p2HelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p2HelperPoint);
                _p2HelperPoint = null;
            }

            if (_centerHelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_centerHelperPoint);
                _centerHelperPoint = null;
            }

            if (_startHelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_startHelperPoint);
                _startHelperPoint = null;
            }

            if (_endHelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_endHelperPoint);
                _endHelperPoint = null;
            }

            _style = null;
        }
コード例 #5
0
ファイル: ArcHelper.cs プロジェクト: monocraft/Core2D
        /// <summary>
        ///
        /// </summary>
        public override void ToStateThree()
        {
            if (_ellipse != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_ellipse);
                _ellipse = null;
            }

            _endLine = XLine.Create(0, 0, _style, null);
            _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_endLine);
            _endHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
            _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_endHelperPoint);
        }
コード例 #6
0
ファイル: EllipseHelper.cs プロジェクト: monocraft/Core2D
        /// <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 = XEllipse.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 XEllipse, 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 ellipse = _shape as XEllipse;
                if (ellipse != null)
                {
                    ellipse.BottomRight.X = sx;
                    ellipse.BottomRight.Y = sy;
                    if (_editor.Project.Options.TryToConnect)
                    {
                        TryToConnectBottomRight(_shape as XEllipse, 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;
            }
        }
コード例 #7
0
ファイル: EllipseHelper.cs プロジェクト: hacklex/Core2D
 /// <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 = XEllipse.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 XEllipse, 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 ellipse = _shape as XEllipse;
                 if (ellipse != null)
                 {
                     ellipse.BottomRight.X = sx;
                     ellipse.BottomRight.Y = sy;
                     if (_editor.Project.Options.TryToConnect)
                     {
                         TryToConnectBottomRight(_shape as XEllipse, sx, sy);
                     }
                     _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_shape);
                     Remove();
                     Finalize(_shape);
                     _editor.AddShape(_shape);
                     _currentState = State.None;
                     _editor.CancelAvailable = false;
                 }
             }
             break;
     }
 }
コード例 #8
0
        /// <summary>
        /// Creates a new instance of the XEllipse 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 XEllipse Ellipse(
            XPoint topLeft,
            XPoint bottomRight,
            bool isStroked = true,
            bool isFilled  = false,
            string text    = null)
        {
            var ellipse = XEllipse.Create(
                topLeft,
                bottomRight,
                Context.Editor.Project.CurrentStyleLibrary.CurrentStyle,
                Context.Editor.Project.Options.PointShape,
                isStroked,
                isFilled,
                text);

            Context.Editor.AddWithHistory(ellipse);
            return(ellipse);
        }
コード例 #9
0
        /// <summary>
        /// Creates a new instance of the XEllipse 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 XEllipse Ellipse(
            double x1      = 30, double y1 = 30,
            double x2      = 60, double y2 = 60,
            bool isStroked = true,
            bool isFilled  = false,
            string text    = null)
        {
            var ellipse = XEllipse.Create(
                x1, y1,
                x2, y2,
                Context.Editor.Project.CurrentStyleLibrary.CurrentStyle,
                Context.Editor.Project.Options.PointShape,
                isStroked,
                isFilled,
                text);

            Context.Editor.AddWithHistory(ellipse);
            return(ellipse);
        }
コード例 #10
0
ファイル: Options.cs プロジェクト: monocraft/Core2D
 /// <summary>
 ///
 /// </summary>
 /// <param name="pss"></param>
 /// <returns></returns>
 public static BaseShape EllipsePointShape(ShapeStyle pss)
 {
     return(XEllipse.Create(-4, -4, 4, 4, pss, null, true, false));
 }
コード例 #11
0
ファイル: ArcHelper.cs プロジェクト: monocraft/Core2D
 /// <summary>
 /// 
 /// </summary>
 public override void ToStateOne()
 {
     _style = _editor.Project.Options.HelperStyle;
     _ellipse = XEllipse.Create(0, 0, _style, null);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_ellipse);
     _p1HelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_p1HelperPoint);
     _p2HelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_p2HelperPoint);
     _centerHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
     _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_centerHelperPoint);
 }
コード例 #12
0
ファイル: Win2dRenderer.cs プロジェクト: hacklex/Core2D
        public void Draw(object ds, XEllipse ellipse, double dx, double dy, ImmutableArray<Property> db, Record r)
        {
            var _ds = ds as CanvasDrawingSession;

            double thickness = ellipse.Style.Thickness / _state.Zoom;
            var brush = ToColor(ellipse.Style.Fill);
            var pen = ToColor(ellipse.Style.Stroke);
            var ss = CreateStrokeStyle(ellipse.Style);

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

            DrawEllipseInternal(
                _ds,
                brush,
                pen,
                ss,
                ellipse.IsStroked,
                ellipse.IsFilled,
                ref rect,
                thickness);

            ss.Dispose();
        }
コード例 #13
0
ファイル: PerspexRenderer.cs プロジェクト: monocraft/Core2D
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="ellipse"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _dc = dc as DrawingContext;

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

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

            DrawEllipseInternal(
                _dc,
                brush,
                pen,
                ellipse.IsStroked,
                ellipse.IsFilled,
                ref rect);

            // TODO: brush.Dispose();
            // TODO: pen.Dispose();
        }
コード例 #14
0
ファイル: Options.cs プロジェクト: monocraft/Core2D
 /// <summary>
 ///
 /// </summary>
 /// <param name="pss"></param>
 /// <returns></returns>
 public static BaseShape FilledEllipsePointShape(ShapeStyle pss)
 {
     return(XEllipse.Create(-3, -3, 3, 3, pss, null, true, true));
 }
コード例 #15
0
ファイル: WpfRenderer.cs プロジェクト: hacklex/Core2D
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="ellipse"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray<Property> db, Record r)
        {
            var _dc = dc as DrawingContext;

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

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

            Tuple<Brush, Pen> cache = null;
            Brush fill;
            Pen stroke;
            if (_enableStyleCache
                && _styleCache.TryGetValue(style, out cache))
            {
                fill = cache.Item1;
                stroke = cache.Item2;
            }
            else
            {
                fill = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                if (_enableStyleCache)
                    _styleCache.Add(style, Tuple.Create(fill, stroke));
            }

            var rect = CreateRect(
                ellipse.TopLeft,
                ellipse.BottomRight,
                dx, dy);
            double rx = rect.Width / 2.0;
            double ry = rect.Height / 2.0;
            var center = new Point(rect.X + rx, rect.Y + ry);

            DrawEllipseInternal(
                _dc,
                half,
                fill, stroke,
                ellipse.IsStroked, ellipse.IsFilled,
                ref center,
                rx, ry);
        }
コード例 #16
0
ファイル: EllipseHelper.cs プロジェクト: hacklex/Core2D
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ellipse"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void TryToConnectTopLeft(XEllipse ellipse, double x, double y)
 {
     var result = ShapeBounds.HitTest(_editor.Project.CurrentContainer, new Vector2(x, y), _editor.Project.Options.HitTreshold);
     if (result != null && result is XPoint)
     {
         ellipse.TopLeft = result as XPoint;
     }
 }
コード例 #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ellipse"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetEllipseBounds(XEllipse ellipse, double dx, double dy)
 {
     return(Rect2.Create(ellipse.TopLeft, ellipse.BottomRight, dx, dy));
 }
コード例 #18
0
ファイル: ArcHelper.cs プロジェクト: monocraft/Core2D
        /// <summary>
        /// 
        /// </summary>
        public override void Remove()
        {
            if (_ellipse != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_ellipse);
                _ellipse = null;
            }

            if (_startLine != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_startLine);
                _startLine = null;
            }

            if (_endLine != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_endLine);
                _endLine = null;
            }

            if (_p1HelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p1HelperPoint);
                _p1HelperPoint = null;
            }

            if (_p2HelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p2HelperPoint);
                _p2HelperPoint = null;
            }

            if (_centerHelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_centerHelperPoint);
                _centerHelperPoint = null;
            }

            if (_startHelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_startHelperPoint);
                _startHelperPoint = null;
            }

            if (_endHelperPoint != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_endHelperPoint);
                _endHelperPoint = null;
            }

            _style = null;
        }
コード例 #19
0
ファイル: EmfRenderer.cs プロジェクト: monocraft/Core2D
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="ellipse"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, XEllipse ellipse, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _gfx = gfx as Graphics;

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

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

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

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

            brush.Dispose();
            pen.Dispose();
        }
コード例 #20
0
ファイル: ArcHelper.cs プロジェクト: monocraft/Core2D
        /// <summary>
        /// 
        /// </summary>
        public override void ToStateThree()
        {
            if (_ellipse != null)
            {
                _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_ellipse);
                _ellipse = null;
            }

            _endLine = XLine.Create(0, 0, _style, null);
            _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_endLine);
            _endHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape);
            _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_endHelperPoint);
        }
コード例 #21
0
ファイル: ShapeBounds.cs プロジェクト: monocraft/Core2D
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ellipse"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetEllipseBounds(XEllipse ellipse, double dx, double dy)
 {
     return Rect2.Create(ellipse.TopLeft, ellipse.BottomRight, dx, dy);
 }