9 changed files with 143 additions and 4 deletions
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using global::Cairo; |
|||
|
|||
namespace Perspex.Cairo |
|||
{ |
|||
public class RadialGradientBrushImpl : BrushImpl |
|||
{ |
|||
public RadialGradientBrushImpl(Perspex.Media.RadialGradientBrush brush, Size destinationSize) |
|||
{ |
|||
var center = brush.Center.ToPixels(destinationSize); |
|||
var gradientOrigin = brush.GradientOrigin.ToPixels(destinationSize); |
|||
var radius = brush.Radius; |
|||
|
|||
this.PlatformBrush = new RadialGradient(center.X, center.Y, radius, gradientOrigin.X, gradientOrigin.Y, radius); |
|||
|
|||
foreach (var stop in brush.GradientStops) |
|||
{ |
|||
((LinearGradient)this.PlatformBrush).AddColorStop(stop.Offset, stop.Color.ToCairo()); |
|||
} |
|||
|
|||
((LinearGradient)this.PlatformBrush).Extend = Extend.Pad; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,63 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
/// <summary>
|
|||
/// Paints an area with a radial gradient. A focal point defines the beginning of the gradient,
|
|||
/// and a circle defines the end point of the gradient.
|
|||
/// </summary>
|
|||
public sealed class RadialGradientBrush : GradientBrush |
|||
{ |
|||
/// <summary>
|
|||
/// Defines the <see cref="Center"/> property.
|
|||
/// </summary>
|
|||
public static readonly PerspexProperty<RelativePoint> CenterProperty = |
|||
PerspexProperty.Register<RadialGradientBrush, RelativePoint>( |
|||
nameof(Center), |
|||
RelativePoint.Center); |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="GradientOrigin"/> property.
|
|||
/// </summary>
|
|||
public static readonly PerspexProperty<RelativePoint> GradientOriginProperty = |
|||
PerspexProperty.Register<RadialGradientBrush, RelativePoint>( |
|||
nameof(GradientOrigin), |
|||
RelativePoint.Center); |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="Radius"/> property.
|
|||
/// </summary>
|
|||
public static readonly PerspexProperty<double> RadiusProperty = |
|||
PerspexProperty.Register<RadialGradientBrush, double>( |
|||
nameof(Radius), |
|||
0.5); |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the start point for the gradient.
|
|||
/// </summary>
|
|||
public RelativePoint Center |
|||
{ |
|||
get { return GetValue(CenterProperty); } |
|||
set { SetValue(CenterProperty, value); } |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the location of the two-dimensional focal point that defines the beginning of the gradient.
|
|||
/// </summary>
|
|||
public RelativePoint GradientOrigin |
|||
{ |
|||
get { return GetValue(GradientOriginProperty); } |
|||
set { SetValue(GradientOriginProperty, value); } |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// ets or sets the horizontal and vertical radius of the outermost circle of the radial gradient.
|
|||
/// </summary>
|
|||
public double Radius |
|||
{ |
|||
get { return GetValue(RadiusProperty); } |
|||
set { SetValue(RadiusProperty, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Direct2D1.Media |
|||
{ |
|||
public class RadialGradientBrushImpl : BrushImpl |
|||
{ |
|||
public RadialGradientBrushImpl( |
|||
Perspex.Media.RadialGradientBrush brush, |
|||
SharpDX.Direct2D1.RenderTarget target, |
|||
Size destinationSize) |
|||
{ |
|||
if (brush != null) |
|||
{ |
|||
var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop { Color = s.Color.ToDirect2D(), Position = (float)s.Offset }).ToArray(); |
|||
|
|||
Point centerPoint = brush.Center.ToPixels(destinationSize); |
|||
Point GradientOriginOffset = brush.GradientOrigin.ToPixels(destinationSize); |
|||
// Note: Direct2D supports RadiusX and RadiusY but Cairo backend supports only Radius property
|
|||
double radiusX = brush.Radius; |
|||
double radiusY = brush.Radius; |
|||
|
|||
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 = target.Transform }, |
|||
new SharpDX.Direct2D1.GradientStopCollection(target, gradientStops, brush.SpreadMethod.ToDirect2D()) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue