コード例 #1
0
        void DragControlHandle(BezierPoint controlHandle, Point pt)
        {
            if (TempLayout != null && SelectedObject.Link != null)
            {
                Rectangle rect = TempLayout.MaxRectangle;

                Link line      = SelectedObject.Link;
                var  oldPoints = line.GetBezierPoints();
                pt = View.PointToLogic(pt);
                switch (controlHandle)
                {
                case BezierPoint.StartPoint:
                    TempLayout.StartPoint    = pt;
                    TempLayout.ControlPoint1 = BezierHelper.GetControlPoint(TempLayout.StartPoint, TempLayout.CP1);
                    break;

                case BezierPoint.EndPoint:
                    TempLayout.EndPoint      = pt;
                    TempLayout.ControlPoint2 = BezierHelper.GetControlPoint(TempLayout.EndPoint, TempLayout.CP2);
                    break;

                case BezierPoint.ControlPoint1:
                    TempLayout.ControlPoint1 = pt;
                    Shape sShape = Shape.GetShaper(line.From);
                    TempLayout.StartPoint = sShape.GetBorderPoint(line.From.Bounds, TempLayout.ControlPoint1);
                    break;

                case BezierPoint.ControlPoint2:
                    TempLayout.ControlPoint2 = pt;
                    Shape dShape = Shape.GetShaper(line.Target);
                    TempLayout.EndPoint = dShape.GetBorderPoint(line.Target.Bounds, TempLayout.ControlPoint2);
                    break;

                default:
                    break;
                }

                //rect = Rectangle.Union(rect, TempLayout.MaxRectangle);
                //InvalidateChart(rect, true);
                InvalidateLink(oldPoints, line.Width, true);
                InvalidateLink(TempLayout.GetPoints(), line.Width, true);
            }

            DragingControlHandle = controlHandle;
        }
コード例 #2
0
        BezierLayoutInfo GetLayoutInfo(BezierControlPoint controlPoint1, BezierControlPoint controlPoint2)
        {
            var layout = new BezierLayoutInfo();

            layout.CP1 = controlPoint1;
            layout.CP2 = controlPoint2;

            Point     cp1, cp2;
            Rectangle rect1 = From.Bounds;
            Rectangle rect2 = Target.Bounds;
            Point     pts   = PaintHelper.CenterPoint(rect1);
            Point     ptd   = PaintHelper.CenterPoint(rect2);

            rect1.Inflate(2, 2);
            rect2.Inflate(2, 2);
            if (StartCap != LineAnchor.None)
            {
                rect1.Inflate(Layouter.LineAnchorSize, Layouter.LineAnchorSize);
            }
            if (EndCap != LineAnchor.None)
            {
                rect2.Inflate(Layouter.LineAnchorSize, Layouter.LineAnchorSize);
            }

            if (pts == ptd)
            {
                cp1 = pts;
                cp2 = ptd;

                layout.Bounds = Rectangle.Empty;
                layout.Region = null;
            }
            else
            {
                cp1 = BezierHelper.GetControlPoint(pts, controlPoint1);
                cp2 = BezierHelper.GetControlPoint(ptd, controlPoint2);

                //Point[] controlPoints = GetControlPoints(pts, ptd);

                Shape sShape = Shape.GetShaper(From);
                pts = sShape.GetBorderPoint(rect1, cp1);

                Shape dShape = Shape.GetShaper(Target);
                ptd = sShape.GetBorderPoint(rect2, cp2);

                GraphicsPath gp = new GraphicsPath();
                gp.AddBezier(pts, cp1, cp2, ptd);
                Pen penWiden = new Pen(Color.Black, LineWidth + 5);
                gp.Widen(penWiden);

                var rect = gp.GetBounds();
                rect.Inflate(LineWidth, LineWidth);
                layout.Bounds = rect;
                layout.Region = new Region(gp);
            }

            Point     ptCenter   = BezierHelper.GetPoint(pts, cp1, cp2, ptd, 0.5f);
            Rectangle textBounds = layout.TextBounds;

            textBounds.X = ptCenter.X - layout.TextBounds.Width / 2;
            textBounds.Y = ptCenter.Y - layout.TextBounds.Height / 2;

            // cache layout info
            layout.StartBounds   = rect1;
            layout.EndBounds     = rect2;
            layout.StartPoint    = pts;
            layout.EndPoint      = ptd;
            layout.ControlPoint1 = cp1;
            layout.ControlPoint2 = cp2;
            layout.TextBounds    = textBounds;

            return(layout);
        }