Smrf.NodeXL.Visualization.Wpf.VertexDrawer.DrawImageShape C# (CSharp) Method

DrawImageShape() protected method

protected DrawImageShape ( IVertex oVertex, GraphDrawingContext oGraphDrawingContext, System.Windows.Media.DrawingContext oDrawingContext, DrawingVisualPlus oDrawingVisual, VisibilityKeyValue eVisibility, System.Boolean bDrawAsSelected, String sAnnotation, System.Windows.Media.ImageSource oImageSource, VertexLabelDrawer oVertexLabelDrawer, CollapsedGroupDrawingManager oCollapsedGroupDrawingManager ) : VertexDrawingHistory
oVertex IVertex
oGraphDrawingContext GraphDrawingContext
oDrawingContext System.Windows.Media.DrawingContext
oDrawingVisual Smrf.WpfGraphicsLib.DrawingVisualPlus
eVisibility VisibilityKeyValue
bDrawAsSelected System.Boolean
sAnnotation String
oImageSource System.Windows.Media.ImageSource
oVertexLabelDrawer VertexLabelDrawer
oCollapsedGroupDrawingManager CollapsedGroupDrawingManager
return VertexDrawingHistory
    DrawImageShape
    (
        IVertex oVertex,
        GraphDrawingContext oGraphDrawingContext,
        DrawingContext oDrawingContext,
        DrawingVisualPlus oDrawingVisual,
        VisibilityKeyValue eVisibility,
        Boolean bDrawAsSelected,
        String sAnnotation,
        ImageSource oImageSource,
        VertexLabelDrawer oVertexLabelDrawer,
        CollapsedGroupDrawingManager oCollapsedGroupDrawingManager
    )
    {
        Debug.Assert(oVertex != null);
        Debug.Assert(oGraphDrawingContext != null);
        Debug.Assert(oDrawingContext != null);
        Debug.Assert(oDrawingVisual != null);
        Debug.Assert(oImageSource != null);
        Debug.Assert(oVertexLabelDrawer != null);
        Debug.Assert(oCollapsedGroupDrawingManager != null);
        AssertValid();

        // Move the vertex if it falls outside the graph rectangle.

        Rect oVertexRectangle = GetVertexRectangle(
            GetVertexLocation(oVertex), oImageSource.Width * m_dGraphScale,
            oImageSource.Height * m_dGraphScale);

        MoveVertexIfNecessary(oVertex, oGraphDrawingContext,
            oCollapsedGroupDrawingManager, ref oVertexRectangle);

        Byte btAlpha = 255;

        if (!bDrawAsSelected)
        {
            // Check for a non-opaque alpha value.

            btAlpha = GetAlpha(oVertex, eVisibility, btAlpha);
        }

        VertexDrawingHistory oVertexDrawingHistory =
            new ImageVertexDrawingHistory(oVertex, oDrawingVisual,
                bDrawAsSelected, oVertexRectangle);

        if (btAlpha > 0)
        {
            oDrawingContext.DrawImage(oImageSource, oVertexRectangle);

            Color oColor = GetColor(oVertex, eVisibility, bDrawAsSelected);

            oDrawingVisual.SetEffect( GetRectangleEffect(
                oGraphDrawingContext, oColor) );

            // Draw an outline rectangle.

            WpfGraphicsUtil.DrawPixelAlignedRectangle(oDrawingContext, null,
                GetPen(oColor, DefaultPenThickness), oVertexRectangle);

            if (btAlpha < 255)
            {
                // Real transparency can't be achieved with arbitrary images,
                // so simulate transparency by drawing on top of the image with
                // a translucent brush the same color as the graph's
                // background.
                //
                // This really isn't a good solution.  Is there are better way
                // to simulate transparency?

                Color oTranslucentColor = oGraphDrawingContext.BackColor;
                oTranslucentColor.A = (Byte)( (Byte)255 - btAlpha );

                oDrawingContext.DrawRectangle(
                    CreateFrozenSolidColorBrush(oTranslucentColor), null,
                        oVertexRectangle);
            }

            if (sAnnotation != null)
            {
                oVertexLabelDrawer.DrawLabel(oDrawingContext,
                    oGraphDrawingContext, oVertexDrawingHistory,

                    CreateFormattedTextWithWrap(sAnnotation, oColor,
                        m_oFormattedTextManager.FontSize),

                    oColor
                    );
            }
        }

        return (oVertexDrawingHistory);
    }