CreateFrozenSolidColorBrush ( Color oColor ) { // AssertValid(); SolidColorBrush oSolidColorBrush = new SolidColorBrush(oColor); WpfGraphicsUtil.FreezeIfFreezable(oSolidColorBrush); return(oSolidColorBrush); }
CreateVisual ( Point currentMouseLocation, Color backgroundContrastColor ) { Debug.Assert(m_bDragIsInProgress); AssertValid(); // Limit the drag to the graph margins. currentMouseLocation = ForcePointToBeWithinMargins(currentMouseLocation); m_oMarqueeRectangle = CreateMarqueeRectangle(currentMouseLocation); DrawingVisual oDrawingVisual = new DrawingVisual(); SolidColorBrush oFillBrush = new SolidColorBrush(Color.FromArgb( MarqueeFillAlpha, backgroundContrastColor.R, backgroundContrastColor.G, backgroundContrastColor.B )); SolidColorBrush oOutlineBrush = new SolidColorBrush(Color.FromArgb( MarqueeOutlineAlpha, backgroundContrastColor.R, backgroundContrastColor.G, backgroundContrastColor.B )); Pen oOutlinePen = new Pen(oOutlineBrush, 1); WpfGraphicsUtil.FreezeIfFreezable(oFillBrush); WpfGraphicsUtil.FreezeIfFreezable(oOutlineBrush); WpfGraphicsUtil.FreezeIfFreezable(oOutlinePen); using (DrawingContext oDrawingContext = oDrawingVisual.RenderOpen()) { oDrawingContext.DrawRectangle(oFillBrush, oOutlinePen, m_oMarqueeRectangle); } m_oVisual = oDrawingVisual; return(m_oVisual); }
CreateFrozenPen ( Brush oBrush, Double dThickness, DashStyle oDashStyle ) { Debug.Assert(oBrush != null); Debug.Assert(dThickness > 0); Debug.Assert(oDashStyle != null); // AssertValid(); Pen oPen = new Pen(oBrush, dThickness); oPen.DashStyle = oDashStyle; oPen.DashCap = PenLineCap.Flat; WpfGraphicsUtil.FreezeIfFreezable(oPen); return(oPen); }
CreateFormattedText ( String text, Color color, Double dFontSize, Double graphScale ) { Debug.Assert(text != null); Debug.Assert(dFontSize >= 0); Debug.Assert(graphScale > 0); SolidColorBrush oBrush = new SolidColorBrush(color); WpfGraphicsUtil.FreezeIfFreezable(oBrush); FormattedText oFormattedText = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, m_oTypeface, dFontSize * graphScale, oBrush); return(oFormattedText); }
GetDashStyle ( IEdge oEdge, Double dWidth, Boolean bDrawAsSelected ) { Debug.Assert(oEdge != null); Debug.Assert(dWidth >= 0); AssertValid(); // Note: // // An early implementation used the predefined DashStyle objects // provided by the DashStyles class, but those did not look good at // smaller edge widths. This implementation builds the DashStyle's // Dashes collection from scratch. Double [] adDashes = null; if (!bDrawAsSelected) { Object oPerEdgeStyleAsObject; // Check for a per-edge style. if (oEdge.TryGetValue(ReservedMetadataKeys.PerEdgeStyle, typeof(EdgeStyle), out oPerEdgeStyleAsObject)) { switch ((EdgeStyle)oPerEdgeStyleAsObject) { case EdgeStyle.Solid: break; case EdgeStyle.Dash: adDashes = new Double[] { 4.0, 2.0 }; break; case EdgeStyle.Dot: adDashes = new Double[] { 1.0, 2.0 }; break; case EdgeStyle.DashDot: adDashes = new Double[] { 4.0, 2.0, 1.0, 2.0 }; break; case EdgeStyle.DashDotDot: adDashes = new Double[] { 4.0, 2.0, 1.0, 2.0, 1.0, 2.0 }; break; default: throw new FormatException(String.Format( "{0}: The edge with the ID {1} has an invalid {2}" + " value." , this.ClassName, oEdge.ID, "ReservedMetadataKeys.PerEdgeStyle" )); } } } if (adDashes == null) { return(DashStyles.Solid); } DashStyle oDashStyle = new DashStyle(); oDashStyle.Dashes = new DoubleCollection(adDashes); WpfGraphicsUtil.FreezeIfFreezable(oDashStyle); return(oDashStyle); }