DrawLabelShape
(
IVertex oVertex,
GraphDrawingContext oGraphDrawingContext,
DrawingContext oDrawingContext,
DrawingVisualPlus oDrawingVisual,
VisibilityKeyValue eVisibility,
Boolean bDrawAsSelected,
String sLabel,
CollapsedGroupDrawingManager oCollapsedGroupDrawingManager
)
{
Debug.Assert(oVertex != null);
Debug.Assert(oGraphDrawingContext != null);
Debug.Assert(oDrawingContext != null);
Debug.Assert(oDrawingVisual != null);
Debug.Assert( !String.IsNullOrEmpty(sLabel) );
Debug.Assert(oCollapsedGroupDrawingManager != null);
AssertValid();
// Figure out what colors to use.
Color oOutlineColor;
Color oTextColor = GetColor(oVertex, eVisibility, false);
Color oFillColor = GetColor(oVertex, eVisibility,
ReservedMetadataKeys.PerVertexLabelFillColor, m_oLabelFillColor,
true);
if (bDrawAsSelected)
{
// The outline color is always the selected color.
oOutlineColor = m_oSelectedColor;
// The text color is the default or per-vertex color with no alpha.
oTextColor.A = 255;
// The fill color is the default or per-vertex fill color with no
// alpha.
oFillColor.A = 255;
}
else
{
// The outline color is the default or per-vertex color with alpha.
oOutlineColor = oTextColor;
// The text color is the default or per-vertex color with alpha.
// The fill color is the default or per-vertex fill color with
// alpha.
}
Double dLabelFontSize = GetLabelFontSize(oVertex);
FormattedText oFormattedText = CreateFormattedTextWithWrap(
sLabel, oTextColor, dLabelFontSize);
Rect oVertexRectangle = GetVertexRectangle(
GetVertexLocation(oVertex), oFormattedText.Width,
oFormattedText.Height);
// Pad the text.
Rect oVertexRectangleWithPadding = oVertexRectangle;
Double dLabelPadding = GetLabelPadding(dLabelFontSize);
oVertexRectangleWithPadding.Inflate(dLabelPadding,
dLabelPadding * 0.7);
if (m_oFormattedTextManager.Typeface.Style != FontStyles.Normal)
{
// This is a hack to move the right edge of the padded rectangle
// to the right to adjust for wider italic text, which
// FormattedText.Width does not account for. What is the correct
// way to do this? It might involve the FormattedText.Overhang*
// properties, but I'll be darned if I can understand how those
// properties work.
Double dItalicCompensation = dLabelFontSize / 7.0;
oVertexRectangleWithPadding.Inflate(dItalicCompensation, 0);
oVertexRectangleWithPadding.Offset(dItalicCompensation, 0);
}
// Move the vertex if it falls outside the graph rectangle.
Double dOriginalVertexRectangleWithPaddingX =
oVertexRectangleWithPadding.X;
Double dOriginalVertexRectangleWithPaddingY =
oVertexRectangleWithPadding.Y;
MoveVertexIfNecessary(oVertex, oGraphDrawingContext,
oCollapsedGroupDrawingManager, ref oVertexRectangleWithPadding);
oVertexRectangle.Offset(
oVertexRectangleWithPadding.X -
dOriginalVertexRectangleWithPaddingX,
oVertexRectangleWithPadding.Y -
dOriginalVertexRectangleWithPaddingY
);
oDrawingVisual.SetEffect( GetRectangleEffect(
oGraphDrawingContext, oOutlineColor) );
// Draw the padded rectangle, then the text.
WpfGraphicsUtil.DrawPixelAlignedRectangle(oDrawingContext,
GetBrush(oFillColor), GetPen(oOutlineColor, DefaultPenThickness),
oVertexRectangleWithPadding);
oDrawingContext.DrawText(oFormattedText, oVertexRectangle.Location);
// Return information about how the vertex was drawn.
return ( new LabelVertexDrawingHistory(oVertex, oDrawingVisual,
bDrawAsSelected, oVertexRectangleWithPadding) );
}