protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // Call base OnRender() method to paint defined Plots. base.OnRender(chartControl, chartScale); // Store previous AA mode SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; // Create Linear Graient Brush Properties SharpDX.Direct2D1.LinearGradientBrushProperties lgbProps = new SharpDX.Direct2D1.LinearGradientBrushProperties(); lgbProps.StartPoint = new SharpDX.Vector2(0, (float)chartScale.GetYByValue(2900)); lgbProps.EndPoint = new SharpDX.Vector2(0, (float)chartScale.GetYByValue(2850)); // Create Gradient Stop1 for the Gradient Stop Collection SharpDX.Direct2D1.GradientStop stop1; stop1.Color = SharpDX.Color.DarkSalmon; stop1.Position = 0; // Create Gradient Stop2 for the Gradient Stop Collection SharpDX.Direct2D1.GradientStop stop2; stop2.Color = SharpDX.Color.DarkGreen; stop2.Position = 1; // Create GradientStop array for GradientStopCollection SharpDX.Direct2D1.GradientStop[] lgbStops = new SharpDX.Direct2D1.GradientStop[] { stop1, stop2 }; // Make our GradientStopCollection SharpDX.Direct2D1.GradientStopCollection lgbSGC = new SharpDX.Direct2D1.GradientStopCollection(RenderTarget, lgbStops); // Finally, create the LinearGradientBrush SharpDX.Direct2D1.LinearGradientBrush lgBrush = new SharpDX.Direct2D1.LinearGradientBrush(RenderTarget, lgbProps, lgbSGC); // Render Draw Method here RenderTarget.FillEllipse(new SharpDX.Direct2D1.Ellipse(new SharpDX.Vector2(ChartPanel.W / 2, ChartPanel.H / 2), ChartPanel.W / 2, ChartPanel.H / 2), lgBrush); // This exmaple describes implementation in OnRender(), for more effieceny, dipose and recreate class level RenderTarget dependant objects in OnRederTargetStateChange() lgbSGC.Dispose(); lgBrush.Dispose(); // Reset AA mode. RenderTarget.AntialiasMode = oldAntialiasMode; }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.LinearGradientBrush"/> that contains the specified gradient stops and has the specified transform and base opacity. /// </summary> /// <param name="renderTarget">an instance of <see cref = "SharpDX.Direct2D1.RenderTarget" /></param> /// <param name="linearGradientBrushProperties">The start and end points of the gradient.</param> /// <param name="brushProperties">The transform and base opacity of the new brush, or NULL. If this value is NULL, the brush defaults to a base opacity of 1.0f and the identity matrix as its transformation.</param> /// <param name="gradientStopCollection">A collection of <see cref="SharpDX.Direct2D1.GradientStop"/> structures that describe the colors in the brush's gradient and their locations along the gradient line.</param> /// <unmanaged>HRESULT CreateLinearGradientBrush([In] const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES* linearGradientBrushProperties,[In, Optional] const D2D1_BRUSH_PROPERTIES* brushProperties,[In] ID2D1GradientStopCollection* gradientStopCollection,[Out] ID2D1LinearGradientBrush** linearGradientBrush)</unmanaged> public LinearGradientBrush(RenderTarget renderTarget, SharpDX.Direct2D1.LinearGradientBrushProperties linearGradientBrushProperties, SharpDX.Direct2D1.BrushProperties?brushProperties, SharpDX.Direct2D1.GradientStopCollection gradientStopCollection) : base(IntPtr.Zero) { renderTarget.CreateLinearGradientBrush(linearGradientBrushProperties, brushProperties, gradientStopCollection, this); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.LinearGradientBrush"/> that contains the specified gradient stops and has the specified transform and base opacity. /// </summary> /// <param name="renderTarget">an instance of <see cref = "SharpDX.Direct2D1.RenderTarget" /></param> /// <param name="linearGradientBrushProperties">The start and end points of the gradient.</param> /// <param name="gradientStopCollection">A collection of <see cref="SharpDX.Direct2D1.GradientStop"/> structures that describe the colors in the brush's gradient and their locations along the gradient line.</param> /// <unmanaged>HRESULT CreateLinearGradientBrush([In] const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES* linearGradientBrushProperties,[In, Optional] const D2D1_BRUSH_PROPERTIES* brushProperties,[In] ID2D1GradientStopCollection* gradientStopCollection,[Out] ID2D1LinearGradientBrush** linearGradientBrush)</unmanaged> public LinearGradientBrush(RenderTarget renderTarget, SharpDX.Direct2D1.LinearGradientBrushProperties linearGradientBrushProperties, SharpDX.Direct2D1.GradientStopCollection gradientStopCollection) : this(renderTarget, linearGradientBrushProperties, null, gradientStopCollection) { }
public static SharpDX.Direct2D1.Brush ToBrush(DUIRenderTarget renderTarget, Brush brush, SharpDX.Direct2D1.LinearGradientBrushProperties linearGradientBrushProperties) { if (brush is LinearGradientBrush lgb) { linearGradientBrushProperties.StartPoint = ToVector2(lgb.Rectangle.Location); linearGradientBrushProperties.EndPoint = new SharpDX.Mathematics.Interop.RawVector2(lgb.Rectangle.Right, lgb.Rectangle.Bottom); SharpDX.Direct2D1.GradientStop gradientStop1 = new SharpDX.Direct2D1.GradientStop() { Color = ToColor4(lgb.LinearColors[0]), Position = 0 }; SharpDX.Direct2D1.GradientStop gradientStop2 = new SharpDX.Direct2D1.GradientStop() { Color = ToColor4(lgb.LinearColors[1]), Position = 1 }; SharpDX.Direct2D1.GradientStop[] gradientStops = new SharpDX.Direct2D1.GradientStop[2] { gradientStop1, gradientStop2 }; using (SharpDX.Direct2D1.GradientStopCollection gradientStopCollection = new SharpDX.Direct2D1.GradientStopCollection(renderTarget, gradientStops)) { return(new SharpDX.Direct2D1.LinearGradientBrush(renderTarget, linearGradientBrushProperties, gradientStopCollection)); } } return(null); }