GetLabelLocation() public abstract method

public abstract GetLabelLocation ( VertexLabelPosition labelPosition ) : Point
labelPosition VertexLabelPosition
return Point
Ejemplo n.º 1
0
        DrawLabel
        (
            DrawingContext drawingContext,
            GraphDrawingContext graphDrawingContext,
            VertexDrawingHistory vertexDrawingHistory,
            VertexLabelPosition labelPosition,
            FormattedText formattedText,
            Color formattedTextColor,
            Boolean drawBackground
        )
        {
            Debug.Assert(drawingContext != null);
            Debug.Assert(graphDrawingContext != null);
            Debug.Assert(vertexDrawingHistory != null);
            Debug.Assert(formattedText != null);
            AssertValid();

            if (labelPosition == VertexLabelPosition.Nowhere)
            {
                return;
            }

            // The alignment needs to be set before the width and height of the
            // FormattedText are obtained.

            SetTextAlignment(formattedText, labelPosition);

            // You can't use FormattedText.Width to get the width of the actual
            // text when text wrapping is enabled (FormattedText.MaxTextWidth > 0).
            // Instead, use a method that takes wrapping into account.

            Double dLabelWidth = WpfGraphicsUtil.GetFormattedTextSize(
                formattedText).Width;

            Double dLabelHeight = formattedText.Height;

            // This is the point where the label will be drawn using
            // DrawingContext.Draw().  It initially assumes a text height of zero,
            // a margin of zero, and no adjustment for alignment (see
            // dAdjustmentForTextAlignmentX below), but this will be modified
            // appropriately within the switch statement below.

            Point  oDraw  = vertexDrawingHistory.GetLabelLocation(labelPosition);
            Double dDrawX = oDraw.X;
            Double dDrawY = oDraw.Y;

            // These are the left and right bounds of the rectangle where the text
            // will actually appear.

            Double dLabelBoundsLeft  = 0;
            Double dLabelBoundsRight = 0;

            AdjustForTextAlignment(dLabelWidth, dLabelHeight, labelPosition,
                                   formattedText, ref dDrawX, ref dDrawY, ref dLabelBoundsLeft,
                                   ref dLabelBoundsRight);

            // Don't let the text exceed the bounds of the graph rectangle.

            dDrawX = StayWithinHorizontalBounds(
                dDrawX, graphDrawingContext, dLabelBoundsLeft, dLabelBoundsRight);

            Double dLabelBoundsTop    = dDrawY;
            Double dLabelBoundsBottom = dDrawY + dLabelHeight;

            dDrawY = StayWithinVerticalBounds(
                dDrawY, graphDrawingContext, dLabelBoundsTop, dLabelBoundsBottom);

            if (drawBackground)
            {
                dLabelBoundsLeft = StayWithinHorizontalBounds(
                    dLabelBoundsLeft, graphDrawingContext,
                    dLabelBoundsLeft, dLabelBoundsRight);

                DrawLabelBackground(drawingContext, graphDrawingContext,
                                    formattedText, formattedTextColor, m_btBackgroundAlpha,
                                    new Point(dLabelBoundsLeft, dDrawY));
            }

            drawingContext.DrawText(formattedText, new Point(dDrawX, dDrawY));
        }
    DrawLabel
    (
        DrawingContext drawingContext,
        GraphDrawingContext graphDrawingContext,
        VertexDrawingHistory vertexDrawingHistory,
        VertexLabelPosition labelPosition,
        FormattedText formattedText,
        Color formattedTextColor,
        Boolean drawBackground
    )
    {
        Debug.Assert(drawingContext != null);
        Debug.Assert(graphDrawingContext != null);
        Debug.Assert(vertexDrawingHistory != null);
        Debug.Assert(formattedText != null);
        AssertValid();

        if (labelPosition == VertexLabelPosition.Nowhere)
        {
            return;
        }

        // The alignment needs to be set before the width and height of the
        // FormattedText are obtained.

        SetTextAlignment(formattedText, labelPosition);

        // You can't use FormattedText.Width to get the width of the actual
        // text when text wrapping is enabled (FormattedText.MaxTextWidth > 0).
        // Instead, use a method that takes wrapping into account.

        Double dLabelWidth = WpfGraphicsUtil.GetFormattedTextSize(
            formattedText).Width;

        Double dLabelHeight = formattedText.Height;

        // This is the point where the label will be drawn using
        // DrawingContext.Draw().  It initially assumes a text height of zero,
        // a margin of zero, and no adjustment for alignment (see
        // dAdjustmentForTextAlignmentX below), but this will be modified
        // appropriately within the switch statement below.

        Point oDraw = vertexDrawingHistory.GetLabelLocation(labelPosition);
        Double dDrawX = oDraw.X;
        Double dDrawY = oDraw.Y;

        // These are the left and right bounds of the rectangle where the text
        // will actually appear.

        Double dLabelBoundsLeft = 0;
        Double dLabelBoundsRight = 0;

        AdjustForTextAlignment(dLabelWidth, dLabelHeight, labelPosition,
            formattedText, ref dDrawX, ref dDrawY, ref dLabelBoundsLeft,
            ref dLabelBoundsRight);

        // Don't let the text exceed the bounds of the graph rectangle.

        dDrawX = StayWithinHorizontalBounds(
            dDrawX, graphDrawingContext, dLabelBoundsLeft, dLabelBoundsRight);

        Double dLabelBoundsTop = dDrawY;
        Double dLabelBoundsBottom = dDrawY + dLabelHeight;

        dDrawY = StayWithinVerticalBounds(
            dDrawY, graphDrawingContext, dLabelBoundsTop, dLabelBoundsBottom);

        if (drawBackground)
        {
            dLabelBoundsLeft = StayWithinHorizontalBounds(
                dLabelBoundsLeft, graphDrawingContext,
                dLabelBoundsLeft, dLabelBoundsRight);

            DrawLabelBackground( drawingContext, graphDrawingContext,
                formattedText, formattedTextColor, m_btBackgroundAlpha,
                new Point(dLabelBoundsLeft, dDrawY) );
        }

        drawingContext.DrawText( formattedText, new Point(dDrawX, dDrawY) );
    }