public override void Draw(DrawingContext dc) { const double ArrowSize = 15; Point Arrow_Top = EndConn.getPort().getCenter(); double tempx1 = StartConn.getPort().getCenter().X; double tempy1 = StartConn.getPort().getCenter().Y; double tempx2 = EndConn.getPort().getCenter().X; double tempy2 = EndConn.getPort().getCenter().Y; double LineDistance = Math.Pow(Math.Pow(tempx1 - tempx2, 2) + Math.Pow(tempy1 - tempy2, 2), 0.5); Vector LineVector = new Vector(tempx2 - tempx1, tempy2 - tempy1); Vector UnitArrowVector = LineVector / LineDistance; Vector ArrowVector = UnitArrowVector * ArrowSize; Point Arrow_Bottom = Arrow_Top - ArrowVector; Vector RightDotVector = new Vector(ArrowVector.Y * (-1), ArrowVector.X); Vector LeftDotVector = RightDotVector * (-1); Point Arrow_BottomLeft = Arrow_Bottom + LeftDotVector; Point Arrow_BottomRight = Arrow_Bottom + RightDotVector; if (HasConnection()) { CoreDraw.DrawLine(dc, StartConn.getPort().getCenter(), Arrow_Bottom, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Arrow_Bottom, Arrow_BottomRight, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Arrow_BottomRight, Arrow_Top, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Arrow_Top, Arrow_BottomLeft, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Arrow_BottomLeft, Arrow_Bottom, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); } }
public override void Draw(DrawingContext dc) { if (HasConnection()) { CoreDraw.DrawLine(dc, StartConn.getPort().getCenter(), EndConn.getPort().getCenter(), LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); } }
public override void Draw(DrawingContext dc) { const double RectSize = 20; Point Rect_Top = EndConn.getPort().getCenter(); double tempx1 = StartConn.getPort().getCenter().X; double tempy1 = StartConn.getPort().getCenter().Y; double tempx2 = EndConn.getPort().getCenter().X; double tempy2 = EndConn.getPort().getCenter().Y; double LineDistance = Math.Pow(Math.Pow(tempx1 - tempx2, 2) + Math.Pow(tempy1 - tempy2, 2), 0.5); Vector LineVector = new Vector(tempx2 - tempx1, tempy2 - tempy1); Vector UnitLineVector = LineVector / LineDistance; Vector RectVector = UnitLineVector * (RectSize / Math.Pow(2, 0.5)) * 2; //size是正方形的邊長,換成對角線向量長要除更號2再乘2 Point Rect_Bottom = Rect_Top - RectVector; Vector RightDotVector = new Vector(RectVector.Y * (-1), RectVector.X); Vector LeftDotVector = RightDotVector * (-1); Point Rect_Center = new Point((Rect_Bottom.X + Rect_Top.X) / 2, (Rect_Top.Y + Rect_Bottom.Y) / 2); Point Rect_Left = Rect_Center + LeftDotVector / 2; Point Rect_Right = Rect_Center + RightDotVector / 2; if (HasConnection()) { CoreDraw.DrawLine(dc, StartConn.getPort().getCenter(), Rect_Bottom, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Rect_Bottom, Rect_Right, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Rect_Right, Rect_Top, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Rect_Top, Rect_Left, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); CoreDraw.DrawLine(dc, Rect_Left, Rect_Bottom, LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); } }