예제 #1
0
        public void LoadShape(ShapeBase shape, Viewport viewport)
        {
            _shape    = shape;
            _viewport = viewport;

            foreach (var ctrl in _controlPoints)
            {
                ctrl.LocationChanged -= Control_LocationChanged;
            }
            _controlPoints.Clear();

            foreach (var v in _shape.Vertices)
            {
                var control = new ControlPoint((int)Math.Round(v.X), (int)Math.Round(v.Y), null);
                control.LocationChanged += Control_LocationChanged;
                control.Tag              = v;
                control.Cursor           = Cursors.SizeAll;
                _controlPoints.Add(control);
            }

            if (_shape.GetShapeType() == ShapeType.Ellipse)
            {
                _controlPoints.Add(new ControlPoint((int)Math.Round(_shape.Location.X + _shape.Size.Width / 2),
                                                    (int)Math.Round(_shape.Location.Y), null));

                _controlPoints.Add(new ControlPoint((int)Math.Round(_shape.Location.X + _shape.Size.Width),
                                                    (int)Math.Round(_shape.Location.Y + _shape.Size.Height / 2), null));

                _controlPoints.Add(new ControlPoint((int)Math.Round(_shape.Location.X + _shape.Size.Width / 2),
                                                    (int)Math.Round(_shape.Location.Y + _shape.Size.Height), null));

                _controlPoints.Add(new ControlPoint((int)Math.Round(_shape.Location.X),
                                                    (int)Math.Round(_shape.Location.Y + _shape.Size.Height / 2), null));
            }
        }
예제 #2
0
        public void Draw(ShapeBase shape, Graphics graphic)
        {
            if (shape == null)
            {
                return;
            }
            /* Draw shape*/
            switch (shape.GetShapeType())
            {
            case ShapeType.Line:
            case ShapeType.IsoscelesTriangle:
            case ShapeType.Oblong:
            case ShapeType.FreePencil:
            case ShapeType.Polygon:
                DrawPolygon((PolygonBase)shape, graphic);
                break;

            case ShapeType.Ellipse:
                DrawEllipse((Ellipse)shape, graphic);
                break;
            }
        }
예제 #3
0
        private ShapeBase ShapesHitTest(PointF p)
        {
            ShapeBase shape = null;

            foreach (var obj in _page.DrawingObjects)
            {
                if (obj.GetObjectType() == DrawingObjectType.Shape)
                {
                    shape = obj as ShapeBase;
                    if (shape == null)
                    {
                        continue;
                    }

                    if (shape.GetShapeType() == ShapeType.Ellipse)
                    {
                        var e = shape as Ellipse;
                        var o = e.OrginalPoint.ToPoint();
                        var t = Math.Pow(p.X - o.X, 2) / Math.Pow(e.MajorAxis, 2) +
                                Math.Pow(p.Y - o.Y, 2) / Math.Pow(e.MinorAxis, 2);
                        if (t <= 1)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (Core.Util.CheckInnerPoint(shape.Vertices, new Vertex(p)))
                        {
                            break;
                        }
                    }

                    shape = null;
                }
            }
            return(shape);
        }