diff --git a/src/Perspex.SceneGraph/Media/Mutable/SolidColorBrush.cs b/src/Perspex.SceneGraph/Media/Mutable/SolidColorBrush.cs new file mode 100644 index 0000000000..73272e9ee6 --- /dev/null +++ b/src/Perspex.SceneGraph/Media/Mutable/SolidColorBrush.cs @@ -0,0 +1,35 @@ +// 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.Mutable +{ + /// + /// Fills an area with a solid color. + /// + /// + /// This is a mutable version of the normal immutable + /// for use in XAML. XAML really needs support for immutable data... + /// + public class SolidColorBrush : Brush + { + public static readonly DirectProperty ColorProperty = + PerspexProperty.RegisterDirect( + "Color", + o => o.Color, + (o, v) => o.Color = v); + + /// + /// Gets the color of the brush. + /// + public Color Color { get; set; } + + /// + /// Returns a string representation of the brush. + /// + /// A string representation of the brush. + public override string ToString() + { + return Color.ToString(); + } + } +} diff --git a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj index ab38fb8c0a..3d8a2d5f55 100644 --- a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj +++ b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj @@ -73,6 +73,7 @@ + diff --git a/src/Perspex.SceneGraph/Properties/AssemblyInfo.cs b/src/Perspex.SceneGraph/Properties/AssemblyInfo.cs index bfe8371a52..efff07cff0 100644 --- a/src/Perspex.SceneGraph/Properties/AssemblyInfo.cs +++ b/src/Perspex.SceneGraph/Properties/AssemblyInfo.cs @@ -5,4 +5,5 @@ using System.Reflection; using Perspex.Metadata; [assembly: AssemblyTitle("Perspex.SceneGraph")] -[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Media")] \ No newline at end of file +[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Media")] +[assembly: XmlnsDefinition("https://github.com/perspex/mutable", "Perspex.Media.Mutable")] \ No newline at end of file diff --git a/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs b/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs index 0876a2a8a3..6031d4a8e9 100644 --- a/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs +++ b/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs @@ -294,6 +294,7 @@ namespace Perspex.Direct2D1.Media public BrushImpl CreateBrush(Perspex.Media.Brush brush, Size destinationSize) { var solidColorBrush = brush as Perspex.Media.SolidColorBrush; + var mutableSolidColorBrush = brush as Perspex.Media.Mutable.SolidColorBrush; var linearGradientBrush = brush as Perspex.Media.LinearGradientBrush; var radialGradientBrush = brush as Perspex.Media.RadialGradientBrush; var imageBrush = brush as Perspex.Media.ImageBrush; @@ -303,6 +304,10 @@ namespace Perspex.Direct2D1.Media { return new SolidColorBrushImpl(solidColorBrush, _renderTarget); } + if (mutableSolidColorBrush != null) + { + return new SolidColorBrushImpl(mutableSolidColorBrush, _renderTarget); + } else if (linearGradientBrush != null) { return new LinearGradientBrushImpl(linearGradientBrush, _renderTarget, destinationSize); @@ -321,7 +326,7 @@ namespace Perspex.Direct2D1.Media } else { - return new SolidColorBrushImpl(null, _renderTarget); + return new SolidColorBrushImpl((Perspex.Media.SolidColorBrush)null, _renderTarget); } } } diff --git a/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs b/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs index 82a7db516d..88d5413843 100644 --- a/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs @@ -17,5 +17,18 @@ namespace Perspex.Direct2D1.Media } ); } + + public SolidColorBrushImpl(Perspex.Media.Mutable.SolidColorBrush brush, SharpDX.Direct2D1.RenderTarget target) + { + PlatformBrush = new SharpDX.Direct2D1.SolidColorBrush( + target, + brush?.Color.ToDirect2D() ?? new SharpDX.Mathematics.Interop.RawColor4(), + new SharpDX.Direct2D1.BrushProperties + { + Opacity = brush != null ? (float)brush.Opacity : 1.0f, + Transform = target.Transform + } + ); + } } }