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; }
void InitText(SwapChain3 tempSwapChain) { init = true; device = tempSwapChain.GetDevice <SharpDX.Direct3D11.Device1>(); d3dContext = device.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>(); var texture2d = tempSwapChain.GetBackBuffer <Texture2D>(0); SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface <SharpDX.DXGI.Device2>(); SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter; SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent <SharpDX.DXGI.Factory2>(); SharpDX.Direct2D1.Device d2dDevice = new SharpDX.Direct2D1.Device(dxgiDevice2); d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None); SharpDX.Direct2D1.BitmapProperties1 properties = new SharpDX.Direct2D1.BitmapProperties1( new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), 96, 96, SharpDX.Direct2D1.BitmapOptions.Target | SharpDX.Direct2D1.BitmapOptions.CannotDraw); Surface backBuffer = tempSwapChain.GetBackBuffer <Surface>(0); d2dTarget = new SharpDX.Direct2D1.Bitmap1(d2dContext, new Size2(800, 600), properties); solidBrush = new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.Coral); // Create a linear gradient brush. // Note that the StartPoint and EndPoint values are set as absolute coordinates of the surface you are drawing to, // NOT the geometry we will apply the brush. linearGradientBrush = new SharpDX.Direct2D1.LinearGradientBrush(d2dContext, new SharpDX.Direct2D1.LinearGradientBrushProperties() { StartPoint = new Vector2(50, 0), EndPoint = new Vector2(450, 0), }, new SharpDX.Direct2D1.GradientStopCollection(d2dContext, new SharpDX.Direct2D1.GradientStop[] { new SharpDX.Direct2D1.GradientStop() { Color = Color.Blue, Position = 0, }, new SharpDX.Direct2D1.GradientStop() { Color = Color.Green, Position = 1, } })); SharpDX.Direct2D1.RadialGradientBrushProperties rgb = new SharpDX.Direct2D1.RadialGradientBrushProperties() { Center = new Vector2(250, 525), RadiusX = 100, RadiusY = 100, }; // Create a radial gradient brush. // The center is specified in absolute coordinates, too. radialGradientBrush = new SharpDX.Direct2D1.RadialGradientBrush(d2dContext, ref rgb , new SharpDX.Direct2D1.GradientStopCollection(d2dContext, new SharpDX.Direct2D1.GradientStop[] { new SharpDX.Direct2D1.GradientStop() { Color = Color.Yellow, Position = 0, }, new SharpDX.Direct2D1.GradientStop() { Color = Color.Red, Position = 1, } })); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.RadialGradientBrush"/> 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="radialGradientBrushProperties">The center, gradient origin offset, and x-radius and y-radius of the brush's 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.</param> /// <unmanaged>HRESULT CreateRadialGradientBrush([In] const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES* radialGradientBrushProperties,[In, Optional] const D2D1_BRUSH_PROPERTIES* brushProperties,[In] ID2D1GradientStopCollection* gradientStopCollection,[Out] ID2D1RadialGradientBrush** radialGradientBrush)</unmanaged> public RadialGradientBrush(RenderTarget renderTarget, ref SharpDX.Direct2D1.RadialGradientBrushProperties radialGradientBrushProperties, SharpDX.Direct2D1.BrushProperties?brushProperties, SharpDX.Direct2D1.GradientStopCollection gradientStopCollection) : base(IntPtr.Zero) { renderTarget.CreateRadialGradientBrush(ref radialGradientBrushProperties, brushProperties, gradientStopCollection, this); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.RadialGradientBrush"/> 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="radialGradientBrushProperties">The center, gradient origin offset, and x-radius and y-radius of the brush's 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.</param> /// <unmanaged>HRESULT CreateRadialGradientBrush([In] const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES* radialGradientBrushProperties,[In, Optional] const D2D1_BRUSH_PROPERTIES* brushProperties,[In] ID2D1GradientStopCollection* gradientStopCollection,[Out] ID2D1RadialGradientBrush** radialGradientBrush)</unmanaged> public RadialGradientBrush(RenderTarget renderTarget, SharpDX.Direct2D1.RadialGradientBrushProperties radialGradientBrushProperties, SharpDX.Direct2D1.BrushProperties brushProperties, SharpDX.Direct2D1.GradientStopCollection gradientStopCollection) : this(renderTarget, ref radialGradientBrushProperties, brushProperties, gradientStopCollection) { }