14 changed files with 272 additions and 15 deletions
@ -0,0 +1,14 @@ |
|||||
|
namespace Perspex.Media |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
public enum BrushMappingMode |
||||
|
{ |
||||
|
Absolute, |
||||
|
RelativeToBoundingBox |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
namespace Perspex.Media |
||||
|
{ |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
public abstract class GradientBrush : Brush |
||||
|
{ |
||||
|
public static readonly PerspexProperty<BrushMappingMode> MappingModeProperty = |
||||
|
PerspexProperty.Register<GradientBrush, BrushMappingMode>(nameof(MappingMode), BrushMappingMode.RelativeToBoundingBox); |
||||
|
|
||||
|
public static readonly PerspexProperty<GradientSpreadMethod> SpreadMethodProperty = |
||||
|
PerspexProperty.Register<GradientBrush, GradientSpreadMethod>(nameof(SpreadMethod), GradientSpreadMethod.Pad); |
||||
|
|
||||
|
public static readonly PerspexProperty<List<GradientStop>> GradientStopsProperty = |
||||
|
PerspexProperty.Register<GradientBrush, List<GradientStop>>(nameof(Opacity), new List<GradientStop>()); |
||||
|
|
||||
|
public GradientBrush() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public BrushMappingMode MappingMode |
||||
|
{ |
||||
|
get { return this.GetValue(MappingModeProperty); } |
||||
|
set { this.SetValue(MappingModeProperty, value); } |
||||
|
} |
||||
|
|
||||
|
public GradientSpreadMethod SpreadMethod |
||||
|
{ |
||||
|
get { return this.GetValue(SpreadMethodProperty); } |
||||
|
set { this.SetValue(SpreadMethodProperty, value); } |
||||
|
} |
||||
|
|
||||
|
public List<GradientStop> GradientStops |
||||
|
{ |
||||
|
get { return this.GetValue(GradientStopsProperty); } |
||||
|
set { this.SetValue(GradientStopsProperty, value); } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
namespace Perspex.Media |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
public enum GradientSpreadMethod |
||||
|
{ |
||||
|
Pad, |
||||
|
Reflect, |
||||
|
Repeat |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
namespace Perspex.Media |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// GradientStop
|
||||
|
/// </summary>
|
||||
|
public sealed class GradientStop |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="GradientStop"/> class.
|
||||
|
/// </summary>
|
||||
|
public GradientStop() { } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="GradientStop"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="color">The color</param>
|
||||
|
/// <param name="offset">The offset</param>
|
||||
|
public GradientStop(Color color, double offset) |
||||
|
{ |
||||
|
this.Color = color; |
||||
|
this.Offset = offset; |
||||
|
} |
||||
|
|
||||
|
// TODO: Make these dependency properties.
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The offset
|
||||
|
/// </summary>
|
||||
|
public double Offset { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The color
|
||||
|
/// </summary>
|
||||
|
public Color Color { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
namespace Perspex.Media |
||||
|
{ |
||||
|
public class LinearGradientBrush : GradientBrush |
||||
|
{ |
||||
|
public static readonly PerspexProperty<Point> StartPointProperty = |
||||
|
PerspexProperty.Register<LinearGradientBrush, Point>(nameof(StartPoint), new Point(0,0)); |
||||
|
|
||||
|
public static readonly PerspexProperty<Point> EndPointProperty = |
||||
|
PerspexProperty.Register<LinearGradientBrush, Point>(nameof(EndPoint), new Point(0, 0)); |
||||
|
|
||||
|
public Point StartPoint |
||||
|
{ |
||||
|
get { return this.GetValue(StartPointProperty); } |
||||
|
set { this.SetValue(StartPointProperty, value); } |
||||
|
} |
||||
|
|
||||
|
public Point EndPoint |
||||
|
{ |
||||
|
get { return this.GetValue(EndPointProperty); } |
||||
|
set { this.SetValue(EndPointProperty, value); } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Perspex.Direct2D1.Media |
||||
|
{ |
||||
|
public abstract class BrushImpl : IDisposable |
||||
|
{ |
||||
|
public SharpDX.Direct2D1.Brush PlatformBrush { get; set; } |
||||
|
|
||||
|
public BrushImpl(Perspex.Media.Brush brush, SharpDX.Direct2D1.RenderTarget target, Size destinationSize) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual void Dispose() |
||||
|
{ |
||||
|
if (this.PlatformBrush != null) |
||||
|
this.PlatformBrush.Dispose(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
namespace Perspex.Direct2D1.Media |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
public class LinearGradientBrushImpl : BrushImpl |
||||
|
{ |
||||
|
public LinearGradientBrushImpl(Perspex.Media.LinearGradientBrush brush, SharpDX.Direct2D1.RenderTarget target, Size destinationSize) |
||||
|
: base(brush, target, destinationSize) |
||||
|
{ |
||||
|
if (brush != null) |
||||
|
{ |
||||
|
var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop { Color = s.Color.ToDirect2D(), Position = (float)s.Offset }).ToArray(); |
||||
|
|
||||
|
Point startPoint = new Point(0, 0); |
||||
|
Point endPoint = new Point(0, 0); |
||||
|
|
||||
|
switch (brush.MappingMode) |
||||
|
{ |
||||
|
case Perspex.Media.BrushMappingMode.Absolute: |
||||
|
// TODO:
|
||||
|
|
||||
|
break; |
||||
|
case Perspex.Media.BrushMappingMode.RelativeToBoundingBox: |
||||
|
startPoint = new Point(brush.StartPoint.X * destinationSize.Width, brush.StartPoint.Y * destinationSize.Height); |
||||
|
endPoint = new Point(brush.EndPoint.X * destinationSize.Width, brush.EndPoint.Y * destinationSize.Height); |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
this.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 = target.Transform }, |
||||
|
new SharpDX.Direct2D1.GradientStopCollection(target, gradientStops, brush.SpreadMethod.ToDirect2D()) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
namespace Perspex.Direct2D1.Media |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
public class SolidColorBrushImpl : BrushImpl |
||||
|
{ |
||||
|
public SolidColorBrushImpl(Perspex.Media.SolidColorBrush brush, SharpDX.Direct2D1.RenderTarget target, Size destinationSize) |
||||
|
: base(brush, target, destinationSize) |
||||
|
{ |
||||
|
this.PlatformBrush = new SharpDX.Direct2D1.SolidColorBrush(target, brush?.Color.ToDirect2D() ?? new SharpDX.Color4()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue