public void FillGradientEllipse(float x, float y, float width, float height, System.Drawing.Color[] colors) { // Create the radial gradient brush properties object SharpDX.Direct2D1.RadialGradientBrushProperties radProp = new SharpDX.Direct2D1.RadialGradientBrushProperties { RadiusX = width, RadiusY = height, Center = new SharpDX.Mathematics.Interop.RawVector2(x, y) }; // Create a list of gratiend stops List <SharpDX.Direct2D1.GradientStop> stops = new List <SharpDX.Direct2D1.GradientStop>(); // TODO: Create a color collection that also stores the color position // Auto calulate color position for (int i = 0; i < colors.Length; ++i) { SharpDX.Direct2D1.GradientStop stop = new SharpDX.Direct2D1.GradientStop { Color = ToColor(colors[i]), Position = (float)(1.0 / colors.Length) * (i + 1) }; stops.Add(stop); } SharpDX.Direct2D1.GradientStopCollection radStops = new SharpDX.Direct2D1.GradientStopCollection(d2dRenderTarget, stops.ToArray()); SharpDX.Direct2D1.RadialGradientBrush rgBrush = new SharpDX.Direct2D1.RadialGradientBrush(d2dRenderTarget, ref radProp, radStops); SharpDX.Mathematics.Interop.RawVector2 center = new SharpDX.Mathematics.Interop.RawVector2(x, y); SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse(center, width, height); d2dRenderTarget.FillEllipse(ellipse, rgBrush); radStops.Dispose(); rgBrush.Dispose(); }
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.RadialGradientBrushProperties rgbProps = new SharpDX.Direct2D1.RadialGradientBrushProperties(); rgbProps.Center = new SharpDX.Vector2(ChartPanel.W / 2, ChartPanel.H / 2); rgbProps.RadiusX = ChartPanel.W / 2; rgbProps.RadiusY = ChartPanel.W / 2; // 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[] rgbStops = new SharpDX.Direct2D1.GradientStop[] { stop1, stop2 }; // Make our GradientStopCollection SharpDX.Direct2D1.GradientStopCollection rgbSGC = new SharpDX.Direct2D1.GradientStopCollection(RenderTarget, rgbStops); // Finally, create the LinearGradientBrush SharpDX.Direct2D1.RadialGradientBrush rgBrush = new SharpDX.Direct2D1.RadialGradientBrush(RenderTarget, rgbProps, rgbSGC); // 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), rgBrush); // This exmaple describes implementation in OnRender(), for more effieceny, dipose and recreate class level RenderTarget dependant objects in OnRederTargetStateChange() rgbSGC.Dispose(); rgBrush.Dispose(); // Reset AA mode. RenderTarget.AntialiasMode = oldAntialiasMode; }