Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public RadialGradientBrushImpl(
            IRadialGradientBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Rect destinationRect)
        {
            if (brush.GradientStops.Count == 0)
            {
                return;
            }

            var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop
            {
                Color    = s.Color.ToDirect2D(),
                Position = (float)s.Offset
            }).ToArray();

            var position       = destinationRect.Position;
            var centerPoint    = position + brush.Center.ToPixels(destinationRect.Size);
            var gradientOrigin = position + brush.GradientOrigin.ToPixels(destinationRect.Size) - centerPoint;

            // Note: Direct2D supports RadiusX and RadiusY but Cairo backend supports only Radius property
            var radiusX = brush.Radius * destinationRect.Width;
            var radiusY = brush.Radius * destinationRect.Height;

            using (var stops = new SharpDX.Direct2D1.GradientStopCollection(
                       target,
                       gradientStops,
                       brush.SpreadMethod.ToDirect2D()))
            {
                PlatformBrush = new SharpDX.Direct2D1.RadialGradientBrush(
                    target,
                    new SharpDX.Direct2D1.RadialGradientBrushProperties
                {
                    Center = centerPoint.ToSharpDX(),
                    GradientOriginOffset = gradientOrigin.ToSharpDX(),
                    RadiusX = (float)radiusX,
                    RadiusY = (float)radiusY
                },
                    new SharpDX.Direct2D1.BrushProperties
                {
                    Opacity   = (float)brush.Opacity,
                    Transform = PrimitiveExtensions.Matrix3x2Identity,
                },
                    stops);
            }
        }
        public RadialGradientBrushImpl(
            Perspex.Media.RadialGradientBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size destinationSize)
        {
            if (brush.GradientStops.Count == 0)
            {
                return;
            }

            var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop
            {
                Color = s.Color.ToDirect2D(),
                Position = (float)s.Offset
            }).ToArray();

            var centerPoint = brush.Center.ToPixels(destinationSize);
            var GradientOriginOffset = brush.GradientOrigin.ToPixels(destinationSize);
            
            // Note: Direct2D supports RadiusX and RadiusY but Cairo backend supports only Radius property
            var radiusX = brush.Radius;
            var radiusY = brush.Radius;

            using (var stops = new SharpDX.Direct2D1.GradientStopCollection(
                target,
                gradientStops,
                brush.SpreadMethod.ToDirect2D()))
            {
                PlatformBrush = new SharpDX.Direct2D1.RadialGradientBrush(
                    target,
                    new SharpDX.Direct2D1.RadialGradientBrushProperties
                    {
                        Center = centerPoint.ToSharpDX(),
                        GradientOriginOffset = GradientOriginOffset.ToSharpDX(),
                        RadiusX = (float)radiusX,
                        RadiusY = (float)radiusY
                    },
                    new SharpDX.Direct2D1.BrushProperties
                    {
                        Opacity = (float)brush.Opacity,
                        Transform = PrimitiveExtensions.Matrix3x2Identity,
                    },
                    stops);
            }
        }
Exemplo n.º 4
0
        public RadialGradientBrushImpl(
            Perspex.Media.RadialGradientBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size destinationSize)
        {
            if (brush.GradientStops.Count == 0)
            {
                return;
            }

            var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop
            {
                Color    = s.Color.ToDirect2D(),
                Position = (float)s.Offset
            }).ToArray();

            var centerPoint          = brush.Center.ToPixels(destinationSize);
            var GradientOriginOffset = brush.GradientOrigin.ToPixels(destinationSize);

            // Note: Direct2D supports RadiusX and RadiusY but Cairo backend supports only Radius property
            var radiusX = brush.Radius;
            var radiusY = brush.Radius;

            using (var stops = new SharpDX.Direct2D1.GradientStopCollection(
                       target,
                       gradientStops,
                       brush.SpreadMethod.ToDirect2D()))
            {
                PlatformBrush = new SharpDX.Direct2D1.RadialGradientBrush(
                    target,
                    new SharpDX.Direct2D1.RadialGradientBrushProperties
                {
                    Center = centerPoint.ToSharpDX(),
                    GradientOriginOffset = GradientOriginOffset.ToSharpDX(),
                    RadiusX = (float)radiusX,
                    RadiusY = (float)radiusY
                },
                    new SharpDX.Direct2D1.BrushProperties
                {
                    Opacity   = (float)brush.Opacity,
                    Transform = SharpDX.Matrix3x2.Identity,
                },
                    stops);
            }
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        public LinearGradientBrushImpl(
            ILinearGradientBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Rect destinationRect)
        {
            if (brush.GradientStops.Count == 0)
            {
                return;
            }

            var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop
            {
                Color    = s.Color.ToDirect2D(),
                Position = (float)s.Offset
            }).ToArray();

            var position   = destinationRect.Position;
            var startPoint = position + brush.StartPoint.ToPixels(destinationRect.Size);
            var endPoint   = position + brush.EndPoint.ToPixels(destinationRect.Size);

            using (var stops = new SharpDX.Direct2D1.GradientStopCollection(
                       target,
                       gradientStops,
                       brush.SpreadMethod.ToDirect2D()))
            {
                PlatformBrush = new SharpDX.Direct2D1.LinearGradientBrush(
                    target,
                    new SharpDX.Direct2D1.LinearGradientBrushProperties
                {
                    StartPoint = startPoint.ToSharpDX(),
                    EndPoint   = endPoint.ToSharpDX()
                },
                    new SharpDX.Direct2D1.BrushProperties
                {
                    Opacity   = (float)brush.Opacity,
                    Transform = PrimitiveExtensions.Matrix3x2Identity,
                },
                    stops);
            }
        }
        public LinearGradientBrushImpl(
            Perspex.Media.LinearGradientBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size destinationSize)
        {
            if (brush.GradientStops.Count == 0)
            {
                return;
            }

            var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop
            {
                Color = s.Color.ToDirect2D(),
                Position = (float)s.Offset
            }).ToArray();

            var startPoint = brush.StartPoint.ToPixels(destinationSize);
            var endPoint = brush.EndPoint.ToPixels(destinationSize);

            using (var stops = new SharpDX.Direct2D1.GradientStopCollection(
                target,
                gradientStops,
                brush.SpreadMethod.ToDirect2D()))
            {
                PlatformBrush = new SharpDX.Direct2D1.LinearGradientBrush(
                    target,
                    new SharpDX.Direct2D1.LinearGradientBrushProperties
                    {
                        StartPoint = startPoint.ToSharpDX(),
                        EndPoint = endPoint.ToSharpDX()
                    },
                    new SharpDX.Direct2D1.BrushProperties
                    {
                        Opacity = (float)brush.Opacity,
                        Transform = PrimitiveExtensions.Matrix3x2Identity,
                    },
                    stops);
            }
        }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
 /// <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)
 {
 }
Exemplo n.º 11
0
 /// <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);
 }
Exemplo n.º 12
0
 /// <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)
 {
 }