DrawSelfLoopAt
(
DrawingContext oDrawingContext,
GraphDrawingContext oGraphDrawingContext,
Color oColor,
Double dWidth,
Point oSelfLoopEndpoint,
RectangleEdge eFarthestGraphRectangleEdge,
Boolean bDrawArrow
)
{
Debug.Assert(oDrawingContext != null);
Debug.Assert(oGraphDrawingContext != null);
Debug.Assert(dWidth >= 0);
AssertValid();
// The self-loop is drawn as a circle. Figure out the location of the
// circle's center and the tip of the arrow, if there is an arrow.
Double dCircleX, dCircleY, dArrowTipX, dArrowTipY, dArrowAngle;
dCircleX = dArrowTipX = oSelfLoopEndpoint.X;
dCircleY = dArrowTipY = oSelfLoopEndpoint.Y;
Double dSelfLoopCircleDiameter = 2.0 * SelfLoopCircleRadius;
dArrowAngle = 0;
switch (eFarthestGraphRectangleEdge)
{
case RectangleEdge.Top:
dCircleY -= SelfLoopCircleRadius;
dArrowTipY -= dSelfLoopCircleDiameter;
break;
case RectangleEdge.Left:
dCircleX -= SelfLoopCircleRadius;
dArrowTipX -= dSelfLoopCircleDiameter;
dArrowAngle = Math.PI / 2.0; // (90 degrees.)
break;
case RectangleEdge.Right:
dCircleX += SelfLoopCircleRadius;
dArrowTipX += dSelfLoopCircleDiameter;
dArrowAngle = -Math.PI / 2.0; // (-90 degrees.)
break;
case RectangleEdge.Bottom:
dCircleY += SelfLoopCircleRadius;
dArrowTipY += dSelfLoopCircleDiameter;
dArrowAngle = Math.PI; // (180 degrees.)
break;
default:
Debug.Assert(false);
break;
}
oDrawingContext.DrawEllipse(null, GetPen(oColor, dWidth),
new Point(dCircleX, dCircleY), SelfLoopCircleRadius,
SelfLoopCircleRadius);
if (bDrawArrow)
{
// Rotate the arrow slightly to adjust to the circular shape of the
// edge connected to it.
dArrowAngle += Math.PI / 13.0;
DrawArrow(oDrawingContext, new Point(dArrowTipX, dArrowTipY),
dArrowAngle, oColor, dWidth);
}
}