From a40f0be1d99304cfa080250d71e678656896d966 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 1 Apr 2016 17:12:36 +0200 Subject: [PATCH] Make SolidColorBrush properly immutable. Previous its color was immutable but because it inherited from Brush, its Opacity was mutable. This wasn't good, as it meant that e.g. Brushes.Red could be changed. Make it properly immutable by using the IBrush interface everywhere and not inheriting from Brush. --- samples/TestApplicationShared/GalleryStyle.cs | 4 +- samples/TestApplicationShared/MainWindow.cs | 70 +++++++++---------- src/Gtk/Perspex.Cairo/Media/DrawingContext.cs | 8 +-- .../Perspex.Cairo/Media/FormattedTextImpl.cs | 2 +- .../Context/PerspexTypeFeatureProvider.cs | 4 +- .../SolidColorBrushTypeConverter.cs | 33 --------- .../Data/StyleResourceBinding.cs | 4 ++ .../Perspex.Markup.Xaml.csproj | 1 - src/Perspex.Controls/Border.cs | 12 ++-- src/Perspex.Controls/Panel.cs | 6 +- .../Presenters/ContentPresenter.cs | 8 +-- .../Presenters/TextPresenter.cs | 4 +- .../Primitives/TemplatedControl.cs | 12 ++-- src/Perspex.Controls/Shapes/Shape.cs | 12 ++-- src/Perspex.Controls/TextBlock.cs | 16 ++--- .../Adapters/BrushAdapter.cs | 6 +- .../Adapters/PenAdapter.cs | 4 +- .../Adapters/PerspexAdapter.cs | 4 +- src/Perspex.HtmlRenderer/HtmlControl.cs | 12 ++-- src/Perspex.SceneGraph/Media/Brush.cs | 6 +- .../Media/DrawingContext.cs | 6 +- src/Perspex.SceneGraph/Media/FormattedText.cs | 2 +- src/Perspex.SceneGraph/Media/IBrush.cs | 16 +++++ .../Media/IDrawingContext.cs | 6 +- .../Media/ISolidColorBrush.cs | 16 +++++ .../Media/Mutable/SolidColorBrush.cs | 2 +- src/Perspex.SceneGraph/Media/Pen.cs | 4 +- .../Media/SolidColorBrush.cs | 16 +++-- .../Perspex.SceneGraph.csproj | 2 + .../Platform/IFormattedTextImpl.cs | 2 +- src/Skia/Perspex.Skia/DrawingContextImpl.cs | 8 +-- src/Skia/Perspex.Skia/FormattedTextImpl.cs | 2 +- .../Perspex.Direct2D1/Media/BrushWrapper.cs | 4 +- .../Perspex.Direct2D1/Media/DrawingContext.cs | 15 ++-- .../Media/FormattedTextImpl.cs | 2 +- .../Media/SolidColorBrushImpl.cs | 17 +---- 36 files changed, 170 insertions(+), 178 deletions(-) delete mode 100644 src/Markup/Perspex.Markup.Xaml/Converters/SolidColorBrushTypeConverter.cs create mode 100644 src/Perspex.SceneGraph/Media/IBrush.cs create mode 100644 src/Perspex.SceneGraph/Media/ISolidColorBrush.cs diff --git a/samples/TestApplicationShared/GalleryStyle.cs b/samples/TestApplicationShared/GalleryStyle.cs index 38b29deab9..c91f6159fe 100644 --- a/samples/TestApplicationShared/GalleryStyle.cs +++ b/samples/TestApplicationShared/GalleryStyle.cs @@ -49,7 +49,7 @@ namespace TestApplication Setters = new[] { new Setter(TemplatedControl.ForegroundProperty, Brushes.White), - new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(Colors.White) { Opacity = 0.1 }), + new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(Colors.White, 0.1)), }, }, }); @@ -91,7 +91,7 @@ namespace TestApplication new Border { Width = 190, - Background = SolidColorBrush.Parse("#1976D2"), + Background = Brush.Parse("#1976D2"), Child = new ScrollViewer { Content = new TabStrip diff --git a/samples/TestApplicationShared/MainWindow.cs b/samples/TestApplicationShared/MainWindow.cs index 30490f774b..8f1cc55faf 100644 --- a/samples/TestApplicationShared/MainWindow.cs +++ b/samples/TestApplicationShared/MainWindow.cs @@ -131,13 +131,13 @@ namespace TestApplication Text = "Button", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A button control", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new Button @@ -157,13 +157,13 @@ namespace TestApplication Text = "ToggleButton", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A toggle button control", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new ToggleButton @@ -207,13 +207,13 @@ namespace TestApplication Text = "TextBlock", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A control for displaying text.", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new TextBlock @@ -245,18 +245,18 @@ namespace TestApplication Text = "HtmlLabel", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A label capable of displaying HTML content", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new HtmlLabel { - Background = SolidColorBrush.Parse("#CCCCCC"), + Background = Brush.Parse("#CCCCCC"), Padding = new Thickness(5), Text = @"

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.

Header Level 2

@@ -300,13 +300,13 @@ namespace TestApplication Text = "TextBox", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A text box control", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, @@ -320,13 +320,13 @@ namespace TestApplication Text = "CheckBox", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A check box control", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new CheckBox { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Checked" }, @@ -337,13 +337,13 @@ namespace TestApplication Text = "RadioButton", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A radio button control", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new RadioButton { IsChecked = true, Content = "Option 1" }, @@ -398,13 +398,13 @@ namespace TestApplication Text = "ListBox", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A list box control.", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new ListBox @@ -420,13 +420,13 @@ namespace TestApplication Text = "TreeView", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A tree view control.", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new TreeView @@ -514,13 +514,13 @@ namespace TestApplication Text = "Carousel", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "An items control that displays its items as pages that fill the controls.", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new StackPanel @@ -573,13 +573,13 @@ namespace TestApplication Text = "Grid", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "Lays out child controls according to a grid.", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new Grid @@ -601,21 +601,21 @@ namespace TestApplication new Rectangle { - Fill = SolidColorBrush.Parse("#FF5722"), + Fill = Brush.Parse("#FF5722"), [Grid.ColumnSpanProperty] = 2, Height = 200, Margin = new Thickness(2.5) }, new Rectangle { - Fill = SolidColorBrush.Parse("#FF5722"), + Fill = Brush.Parse("#FF5722"), [Grid.RowProperty] = 1, Height = 100, Margin = new Thickness(2.5) }, new Rectangle { - Fill = SolidColorBrush.Parse("#FF5722"), + Fill = Brush.Parse("#FF5722"), [Grid.RowProperty] = 1, [Grid.ColumnProperty] = 1, Height = 100, @@ -629,13 +629,13 @@ namespace TestApplication Text = "StackPanel", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A panel which lays out its children horizontally or vertically.", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new StackPanel @@ -647,17 +647,17 @@ namespace TestApplication { new Rectangle { - Fill = SolidColorBrush.Parse("#FFC107"), + Fill = Brush.Parse("#FFC107"), Height = 50, }, new Rectangle { - Fill = SolidColorBrush.Parse("#FFC107"), + Fill = Brush.Parse("#FFC107"), Height = 50, }, new Rectangle { - Fill = SolidColorBrush.Parse("#FFC107"), + Fill = Brush.Parse("#FFC107"), Height = 50, }, } @@ -668,13 +668,13 @@ namespace TestApplication Text = "Canvas", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A panel which lays out its children by explicit coordinates.", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, new Canvas @@ -762,13 +762,13 @@ namespace TestApplication Text = "Animations", FontWeight = FontWeight.Medium, FontSize = 20, - Foreground = SolidColorBrush.Parse("#212121"), + Foreground = Brush.Parse("#212121"), }, new TextBlock { Text = "A few animations showcased below", FontSize = 13, - Foreground = SolidColorBrush.Parse("#727272"), + Foreground = Brush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, (button1 = new Button diff --git a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs index 99971477c4..b22bcd1893 100644 --- a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs +++ b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs @@ -135,7 +135,7 @@ namespace Perspex.Cairo.Media /// The fill brush. /// The stroke pen. /// The geometry. - public void DrawGeometry(Brush brush, Pen pen, Geometry geometry) + public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry) { var impl = geometry.PlatformImpl as StreamGeometryImpl; @@ -190,7 +190,7 @@ namespace Perspex.Cairo.Media /// The foreground brush. /// The upper-left corner of the text. /// The text. - public void DrawText(Brush foreground, Point origin, FormattedText text) + public void DrawText(IBrush foreground, Point origin, FormattedText text) { var layout = ((FormattedTextImpl)text.PlatformImpl).Layout; _context.MoveTo(origin.X, origin.Y); @@ -206,7 +206,7 @@ namespace Perspex.Cairo.Media /// /// The brush. /// The rectangle bounds. - public void FillRectangle(Brush brush, Rect rect, float cornerRadius) + public void FillRectangle(IBrush brush, Rect rect, float cornerRadius) { using (var b = SetBrush(brush, rect.Size)) { @@ -271,7 +271,7 @@ namespace Perspex.Cairo.Media private double opacityOverride = 1.0f; - private IDisposable SetBrush(Brush brush, Size destinationSize) + private IDisposable SetBrush(IBrush brush, Size destinationSize) { _context.Save (); diff --git a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs index e8fc9bc924..e3a6e50125 100644 --- a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs @@ -133,7 +133,7 @@ namespace Perspex.Cairo.Media return new Size(width, height); } - public void SetForegroundBrush(Brush brush, int startIndex, int count) + public void SetForegroundBrush(IBrush brush, int startIndex, int count) { var scb = brush as SolidColorBrush; if (scb != null) diff --git a/src/Markup/Perspex.Markup.Xaml/Context/PerspexTypeFeatureProvider.cs b/src/Markup/Perspex.Markup.Xaml/Context/PerspexTypeFeatureProvider.cs index a875a751c4..4f3d29929c 100644 --- a/src/Markup/Perspex.Markup.Xaml/Context/PerspexTypeFeatureProvider.cs +++ b/src/Markup/Perspex.Markup.Xaml/Context/PerspexTypeFeatureProvider.cs @@ -150,7 +150,7 @@ namespace Perspex.Markup.Xaml.Context RegisterTypeConverter(typeof(Type), new TypeTypeConverter()); RegisterTypeConverter(typeof(IBitmap), new BitmapTypeConverter()); - RegisterTypeConverter(typeof(Brush), new BrushTypeConverter()); + RegisterTypeConverter(typeof(IBrush), new BrushTypeConverter()); RegisterTypeConverter(typeof(Color), new ColorTypeConverter()); RegisterTypeConverter(typeof(Classes), new ClassesTypeConverter()); RegisterTypeConverter(typeof(ColumnDefinitions), new ColumnDefinitionsTypeConverter()); @@ -166,7 +166,7 @@ namespace Perspex.Markup.Xaml.Context RegisterTypeConverter(typeof(RelativeRect), new RelativeRectTypeConverter()); RegisterTypeConverter(typeof(RowDefinitions), new RowDefinitionsTypeConverter()); RegisterTypeConverter(typeof(Selector), new SelectorTypeConverter()); - RegisterTypeConverter(typeof(SolidColorBrush), new SolidColorBrushTypeConverter()); + RegisterTypeConverter(typeof(SolidColorBrush), new BrushTypeConverter()); RegisterTypeConverter(typeof(Thickness), new ThicknessTypeConverter()); RegisterTypeConverter(typeof(TimeSpan), new TimeSpanTypeConverter()); RegisterTypeConverter(typeof(Uri), new UriTypeConverter()); diff --git a/src/Markup/Perspex.Markup.Xaml/Converters/SolidColorBrushTypeConverter.cs b/src/Markup/Perspex.Markup.Xaml/Converters/SolidColorBrushTypeConverter.cs deleted file mode 100644 index fe28ea9116..0000000000 --- a/src/Markup/Perspex.Markup.Xaml/Converters/SolidColorBrushTypeConverter.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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.Globalization; -using OmniXaml.TypeConversion; -using Perspex.Media; - -namespace Perspex.Markup.Xaml.Converters -{ - public class SolidColorBrushTypeConverter : ITypeConverter - { - public bool CanConvertFrom(IValueContext context, Type sourceType) - { - return sourceType == typeof(string); - } - - public bool CanConvertTo(IValueContext context, Type destinationType) - { - return false; - } - - public object ConvertFrom(IValueContext context, CultureInfo culture, object value) - { - return Brush.Parse((string)value); - } - - public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs b/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs index 5dd656ca54..a95afe6b44 100644 --- a/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs +++ b/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs @@ -39,6 +39,10 @@ namespace Perspex.Markup.Xaml.Data PerspexProperty targetProperty, object anchor = null) { + if (Name == "Red") + { + } + var host = (target as IControl) ?? (anchor as IControl); var style = anchor as IStyle; var resource = PerspexProperty.UnsetValue; diff --git a/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj b/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj index 39a869035a..0c003e4f75 100644 --- a/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj +++ b/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj @@ -56,7 +56,6 @@ - diff --git a/src/Perspex.Controls/Border.cs b/src/Perspex.Controls/Border.cs index 3cb33eddcc..6c3da91681 100644 --- a/src/Perspex.Controls/Border.cs +++ b/src/Perspex.Controls/Border.cs @@ -13,14 +13,14 @@ namespace Perspex.Controls /// /// Defines the property. /// - public static readonly StyledProperty BackgroundProperty = - PerspexProperty.Register(nameof(Background)); + public static readonly StyledProperty BackgroundProperty = + PerspexProperty.Register(nameof(Background)); /// /// Defines the property. /// - public static readonly StyledProperty BorderBrushProperty = - PerspexProperty.Register(nameof(BorderBrush)); + public static readonly StyledProperty BorderBrushProperty = + PerspexProperty.Register(nameof(BorderBrush)); /// /// Defines the property. @@ -45,7 +45,7 @@ namespace Perspex.Controls /// /// Gets or sets a brush with which to paint the background. /// - public Brush Background + public IBrush Background { get { return GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } @@ -54,7 +54,7 @@ namespace Perspex.Controls /// /// Gets or sets a brush with which to paint the border. /// - public Brush BorderBrush + public IBrush BorderBrush { get { return GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } diff --git a/src/Perspex.Controls/Panel.cs b/src/Perspex.Controls/Panel.cs index f22926d454..545a20de26 100644 --- a/src/Perspex.Controls/Panel.cs +++ b/src/Perspex.Controls/Panel.cs @@ -22,7 +22,7 @@ namespace Perspex.Controls /// /// Defines the property. /// - public static readonly StyledProperty BackgroundProperty = + public static readonly StyledProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); private readonly Controls _children = new Controls(); @@ -73,7 +73,7 @@ namespace Perspex.Controls /// /// Gets or Sets Panel background brush. /// - public Brush Background + public IBrush Background { get { return GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } @@ -129,7 +129,7 @@ namespace Perspex.Controls /// The drawing context. public override void Render(DrawingContext context) { - Brush background = Background; + var background = Background; if (background != null) { var renderSize = Bounds.Size; diff --git a/src/Perspex.Controls/Presenters/ContentPresenter.cs b/src/Perspex.Controls/Presenters/ContentPresenter.cs index 42f300f763..f6a09f6cb1 100644 --- a/src/Perspex.Controls/Presenters/ContentPresenter.cs +++ b/src/Perspex.Controls/Presenters/ContentPresenter.cs @@ -18,13 +18,13 @@ namespace Perspex.Controls.Presenters /// /// Defines the property. /// - public static readonly StyledProperty BackgroundProperty = + public static readonly StyledProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); /// /// Defines the property. /// - public static readonly PerspexProperty BorderBrushProperty = + public static readonly PerspexProperty BorderBrushProperty = Border.BorderBrushProperty.AddOwner(); /// @@ -86,7 +86,7 @@ namespace Perspex.Controls.Presenters /// /// Gets or sets a brush with which to paint the background. /// - public Brush Background + public IBrush Background { get { return GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } @@ -95,7 +95,7 @@ namespace Perspex.Controls.Presenters /// /// Gets or sets a brush with which to paint the border. /// - public Brush BorderBrush + public IBrush BorderBrush { get { return GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } diff --git a/src/Perspex.Controls/Presenters/TextPresenter.cs b/src/Perspex.Controls/Presenters/TextPresenter.cs index 4715770c96..a08c1c7b5e 100644 --- a/src/Perspex.Controls/Presenters/TextPresenter.cs +++ b/src/Perspex.Controls/Presenters/TextPresenter.cs @@ -23,7 +23,7 @@ namespace Perspex.Controls.Presenters private readonly DispatcherTimer _caretTimer; private bool _caretBlink; - private Brush _highlightBrush; + private IBrush _highlightBrush; static TextPresenter() { @@ -82,7 +82,7 @@ namespace Perspex.Controls.Presenters if (_highlightBrush == null) { - _highlightBrush = (Brush)this.FindStyleResource("HighlightBrush"); + _highlightBrush = (IBrush)this.FindStyleResource("HighlightBrush"); } foreach (var rect in rects) diff --git a/src/Perspex.Controls/Primitives/TemplatedControl.cs b/src/Perspex.Controls/Primitives/TemplatedControl.cs index 3ce5a5df9f..090b672896 100644 --- a/src/Perspex.Controls/Primitives/TemplatedControl.cs +++ b/src/Perspex.Controls/Primitives/TemplatedControl.cs @@ -23,13 +23,13 @@ namespace Perspex.Controls.Primitives /// /// Defines the property. /// - public static readonly StyledProperty BackgroundProperty = + public static readonly StyledProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); /// /// Defines the property. /// - public static readonly StyledProperty BorderBrushProperty = + public static readonly StyledProperty BorderBrushProperty = Border.BorderBrushProperty.AddOwner(); /// @@ -65,7 +65,7 @@ namespace Perspex.Controls.Primitives /// /// Defines the property. /// - public static readonly StyledProperty ForegroundProperty = + public static readonly StyledProperty ForegroundProperty = TextBlock.ForegroundProperty.AddOwner(); /// @@ -117,7 +117,7 @@ namespace Perspex.Controls.Primitives /// /// Gets or sets the brush used to draw the control's background. /// - public Brush Background + public IBrush Background { get { return GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } @@ -126,7 +126,7 @@ namespace Perspex.Controls.Primitives /// /// Gets or sets the brush used to draw the control's border. /// - public Brush BorderBrush + public IBrush BorderBrush { get { return GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } @@ -180,7 +180,7 @@ namespace Perspex.Controls.Primitives /// /// Gets or sets the brush used to draw the control's text and other foreground elements. /// - public Brush Foreground + public IBrush Foreground { get { return GetValue(ForegroundProperty); } set { SetValue(ForegroundProperty, value); } diff --git a/src/Perspex.Controls/Shapes/Shape.cs b/src/Perspex.Controls/Shapes/Shape.cs index 465b71002f..e7a84f2d41 100644 --- a/src/Perspex.Controls/Shapes/Shape.cs +++ b/src/Perspex.Controls/Shapes/Shape.cs @@ -10,14 +10,14 @@ namespace Perspex.Controls.Shapes { public abstract class Shape : Control { - public static readonly StyledProperty FillProperty = - PerspexProperty.Register("Fill"); + public static readonly StyledProperty FillProperty = + PerspexProperty.Register("Fill"); public static readonly StyledProperty StretchProperty = PerspexProperty.Register("Stretch"); - public static readonly StyledProperty StrokeProperty = - PerspexProperty.Register("Stroke"); + public static readonly StyledProperty StrokeProperty = + PerspexProperty.Register("Stroke"); public static readonly StyledProperty> StrokeDashArrayProperty = PerspexProperty.Register>("StrokeDashArray"); @@ -48,7 +48,7 @@ namespace Perspex.Controls.Shapes } } - public Brush Fill + public IBrush Fill { get { return GetValue(FillProperty); } set { SetValue(FillProperty, value); } @@ -77,7 +77,7 @@ namespace Perspex.Controls.Shapes set { SetValue(StretchProperty, value); } } - public Brush Stroke + public IBrush Stroke { get { return GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } diff --git a/src/Perspex.Controls/TextBlock.cs b/src/Perspex.Controls/TextBlock.cs index cf9ce6b919..0ddc3c30ee 100644 --- a/src/Perspex.Controls/TextBlock.cs +++ b/src/Perspex.Controls/TextBlock.cs @@ -19,7 +19,7 @@ namespace Perspex.Controls /// /// Defines the property. /// - public static readonly StyledProperty BackgroundProperty = + public static readonly StyledProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); // TODO: Define these attached properties elswhere (e.g. on a Text class) and AddOwner @@ -63,8 +63,8 @@ namespace Perspex.Controls /// /// Defines the property. /// - public static readonly AttachedProperty ForegroundProperty = - PerspexProperty.RegisterAttached( + public static readonly AttachedProperty ForegroundProperty = + PerspexProperty.RegisterAttached( nameof(Foreground), new SolidColorBrush(0xff000000), inherits: true); @@ -128,7 +128,7 @@ namespace Perspex.Controls /// /// Gets or sets a brush used to paint the control's background. /// - public Brush Background + public IBrush Background { get { return GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } @@ -183,7 +183,7 @@ namespace Perspex.Controls /// /// Gets or sets a brush used to paint the text. /// - public Brush Foreground + public IBrush Foreground { get { return GetValue(ForegroundProperty); } set { SetValue(ForegroundProperty, value); } @@ -268,7 +268,7 @@ namespace Perspex.Controls /// /// The control. /// The foreground. - public static Brush GetForeground(Control control) + public static IBrush GetForeground(Control control) { return control.GetValue(ForegroundProperty); } @@ -323,7 +323,7 @@ namespace Perspex.Controls /// The control. /// The property value to set. /// The font family. - public static void SetForeground(Control control, Brush value) + public static void SetForeground(Control control, IBrush value) { control.SetValue(ForegroundProperty, value); } @@ -334,7 +334,7 @@ namespace Perspex.Controls /// The drawing context. public override void Render(DrawingContext context) { - Brush background = Background; + var background = Background; if (background != null) { diff --git a/src/Perspex.HtmlRenderer/Adapters/BrushAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/BrushAdapter.cs index 4c8b06345e..2158f4b7d8 100644 --- a/src/Perspex.HtmlRenderer/Adapters/BrushAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/BrushAdapter.cs @@ -23,12 +23,12 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters /// /// The actual Perspex brush instance. /// - private readonly Brush _brush; + private readonly IBrush _brush; /// /// Init. /// - public BrushAdapter(Brush brush) + public BrushAdapter(IBrush brush) { _brush = brush; } @@ -36,7 +36,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters /// /// The actual Perspex brush instance. /// - public Brush Brush + public IBrush Brush { get { return _brush; } } diff --git a/src/Perspex.HtmlRenderer/Adapters/PenAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/PenAdapter.cs index fa0960cf3f..e6b89cc1d4 100644 --- a/src/Perspex.HtmlRenderer/Adapters/PenAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/PenAdapter.cs @@ -25,7 +25,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters /// /// The actual Perspex brush instance. /// - private readonly Brush _brush; + private readonly IBrush _brush; /// /// the width of the pen @@ -42,7 +42,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters /// /// Init. /// - public PenAdapter(Brush brush) + public PenAdapter(IBrush brush) { _brush = brush; } diff --git a/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs index 0411c7e26e..1c368e618f 100644 --- a/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs @@ -50,9 +50,9 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters /// /// Get solid color brush for the given color. /// - private static Brush GetSolidColorBrush(RColor color) + private static IBrush GetSolidColorBrush(RColor color) { - Brush solidBrush; + IBrush solidBrush; if (color == RColor.White) solidBrush = Brushes.White; else if (color == RColor.Black) diff --git a/src/Perspex.HtmlRenderer/HtmlControl.cs b/src/Perspex.HtmlRenderer/HtmlControl.cs index e5e8864933..e85728cd05 100644 --- a/src/Perspex.HtmlRenderer/HtmlControl.cs +++ b/src/Perspex.HtmlRenderer/HtmlControl.cs @@ -85,14 +85,14 @@ namespace Perspex.Controls.Html public static readonly PerspexProperty TextProperty = PropertyHelper.Register("Text", null, OnPerspexProperty_valueChanged); - public static readonly StyledProperty BackgroundProperty = + public static readonly StyledProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); public static readonly PerspexProperty BorderThicknessProperty = PerspexProperty.Register("BorderThickness", new Thickness(0)); public static readonly PerspexProperty BorderBrushProperty = - PerspexProperty.Register("BorderBrush"); + PerspexProperty.Register("BorderBrush"); public static readonly PerspexProperty PaddingProperty = PerspexProperty.Register("Padding", new Thickness(0)); @@ -255,9 +255,9 @@ namespace Perspex.Controls.Html set { SetValue(BorderThicknessProperty, value); } } - public Brush BorderBrush + public IBrush BorderBrush { - get { return (Brush)GetValue(BorderBrushProperty); } + get { return (IBrush)GetValue(BorderBrushProperty); } set { SetValue(BorderThicknessProperty, value); } } @@ -267,9 +267,9 @@ namespace Perspex.Controls.Html set { SetValue(PaddingProperty, value); } } - public Brush Background + public IBrush Background { - get { return (Brush) GetValue(BackgroundProperty); } + get { return (IBrush) GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value);} } diff --git a/src/Perspex.SceneGraph/Media/Brush.cs b/src/Perspex.SceneGraph/Media/Brush.cs index 6cf90502e3..6d53dd4092 100644 --- a/src/Perspex.SceneGraph/Media/Brush.cs +++ b/src/Perspex.SceneGraph/Media/Brush.cs @@ -10,7 +10,7 @@ namespace Perspex.Media /// /// Describes how an area is painted. /// - public abstract class Brush : PerspexObject + public abstract class Brush : PerspexObject, IBrush { /// /// Defines the property. @@ -32,7 +32,7 @@ namespace Perspex.Media /// /// The brush string. /// The . - public static Brush Parse(string s) + public static IBrush Parse(string s) { if (s[0] == '#') { @@ -46,7 +46,7 @@ namespace Perspex.Media if (member != null) { - return (Brush)member.GetValue(null); + return (IBrush)member.GetValue(null); } else { diff --git a/src/Perspex.SceneGraph/Media/DrawingContext.cs b/src/Perspex.SceneGraph/Media/DrawingContext.cs index 72f4bcbace..80d4be26ca 100644 --- a/src/Perspex.SceneGraph/Media/DrawingContext.cs +++ b/src/Perspex.SceneGraph/Media/DrawingContext.cs @@ -83,7 +83,7 @@ namespace Perspex.Media /// The fill brush. /// The stroke pen. /// The geometry. - public void DrawGeometry(Brush brush, Pen pen, Geometry geometry) => _impl.DrawGeometry(brush, pen, geometry); + public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry) => _impl.DrawGeometry(brush, pen, geometry); /// /// Draws the outline of a rectangle. @@ -100,7 +100,7 @@ namespace Perspex.Media /// The foreground brush. /// The upper-left corner of the text. /// The text. - public void DrawText(Brush foreground, Point origin, FormattedText text) + public void DrawText(IBrush foreground, Point origin, FormattedText text) => _impl.DrawText(foreground, origin, text); /// @@ -109,7 +109,7 @@ namespace Perspex.Media /// The brush. /// The rectangle bounds. /// The corner radius. - public void FillRectangle(Brush brush, Rect rect, float cornerRadius = 0.0f) + public void FillRectangle(IBrush brush, Rect rect, float cornerRadius = 0.0f) => _impl.FillRectangle(brush, rect, cornerRadius); public struct PushedState : IDisposable diff --git a/src/Perspex.SceneGraph/Media/FormattedText.cs b/src/Perspex.SceneGraph/Media/FormattedText.cs index e2db938612..b727a4fab9 100644 --- a/src/Perspex.SceneGraph/Media/FormattedText.cs +++ b/src/Perspex.SceneGraph/Media/FormattedText.cs @@ -206,7 +206,7 @@ namespace Perspex.Media /// The brush. /// The start of the text range. /// The length of the text range. - public void SetForegroundBrush(Brush brush, int startIndex, int length) + public void SetForegroundBrush(IBrush brush, int startIndex, int length) { CheckDisposed(); PlatformImpl.SetForegroundBrush(brush, startIndex, length); diff --git a/src/Perspex.SceneGraph/Media/IBrush.cs b/src/Perspex.SceneGraph/Media/IBrush.cs new file mode 100644 index 0000000000..368b01c43a --- /dev/null +++ b/src/Perspex.SceneGraph/Media/IBrush.cs @@ -0,0 +1,16 @@ +// 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 +{ + /// + /// Describes how an area is painted. + /// + public interface IBrush + { + /// + /// Gets the opacity of the brush. + /// + double Opacity { get; } + } +} \ No newline at end of file diff --git a/src/Perspex.SceneGraph/Media/IDrawingContext.cs b/src/Perspex.SceneGraph/Media/IDrawingContext.cs index 4d144b33e0..2667856dc3 100644 --- a/src/Perspex.SceneGraph/Media/IDrawingContext.cs +++ b/src/Perspex.SceneGraph/Media/IDrawingContext.cs @@ -39,7 +39,7 @@ namespace Perspex.Media /// The fill brush. /// The stroke pen. /// The geometry. - void DrawGeometry(Brush brush, Pen pen, Geometry geometry); + void DrawGeometry(IBrush brush, Pen pen, Geometry geometry); /// /// Draws the outline of a rectangle. @@ -55,7 +55,7 @@ namespace Perspex.Media /// The foreground brush. /// The upper-left corner of the text. /// The text. - void DrawText(Brush foreground, Point origin, FormattedText text); + void DrawText(IBrush foreground, Point origin, FormattedText text); /// /// Draws a filled rectangle. @@ -63,7 +63,7 @@ namespace Perspex.Media /// The brush. /// The rectangle bounds. /// The corner radius. - void FillRectangle(Brush brush, Rect rect, float cornerRadius = 0.0f); + void FillRectangle(IBrush brush, Rect rect, float cornerRadius = 0.0f); /// /// Pushes a clip rectange. diff --git a/src/Perspex.SceneGraph/Media/ISolidColorBrush.cs b/src/Perspex.SceneGraph/Media/ISolidColorBrush.cs new file mode 100644 index 0000000000..56bd1b6f93 --- /dev/null +++ b/src/Perspex.SceneGraph/Media/ISolidColorBrush.cs @@ -0,0 +1,16 @@ +// 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 +{ + /// + /// Fills an area with a solid color. + /// + public interface ISolidColorBrush : IBrush + { + /// + /// Gets the color of the brush. + /// + Color Color { get; } + } +} \ No newline at end of file diff --git a/src/Perspex.SceneGraph/Media/Mutable/SolidColorBrush.cs b/src/Perspex.SceneGraph/Media/Mutable/SolidColorBrush.cs index 73272e9ee6..928a9bd22c 100644 --- a/src/Perspex.SceneGraph/Media/Mutable/SolidColorBrush.cs +++ b/src/Perspex.SceneGraph/Media/Mutable/SolidColorBrush.cs @@ -10,7 +10,7 @@ namespace Perspex.Media.Mutable /// 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 class SolidColorBrush : Brush, ISolidColorBrush { public static readonly DirectProperty ColorProperty = PerspexProperty.RegisterDirect( diff --git a/src/Perspex.SceneGraph/Media/Pen.cs b/src/Perspex.SceneGraph/Media/Pen.cs index 489860a87a..d881ef53f4 100644 --- a/src/Perspex.SceneGraph/Media/Pen.cs +++ b/src/Perspex.SceneGraph/Media/Pen.cs @@ -20,7 +20,7 @@ namespace Perspex.Media /// The line join. /// The miter limit. public Pen( - Brush brush, + IBrush brush, double thickness = 1.0, DashStyle dashStyle = null, PenLineCap dashCap = PenLineCap.Flat, @@ -73,7 +73,7 @@ namespace Perspex.Media /// /// Gets the brush used to draw the stroke. /// - public Brush Brush { get; } + public IBrush Brush { get; } /// /// Gets the stroke thickness. diff --git a/src/Perspex.SceneGraph/Media/SolidColorBrush.cs b/src/Perspex.SceneGraph/Media/SolidColorBrush.cs index 48423de385..4be96eadd7 100644 --- a/src/Perspex.SceneGraph/Media/SolidColorBrush.cs +++ b/src/Perspex.SceneGraph/Media/SolidColorBrush.cs @@ -6,15 +6,17 @@ namespace Perspex.Media /// /// Fills an area with a solid color. /// - public class SolidColorBrush : Brush + public class SolidColorBrush : ISolidColorBrush { /// /// Initializes a new instance of the class. /// /// The color to use. - public SolidColorBrush(Color color) + /// The opacity of the brush. + public SolidColorBrush(Color color, double opacity = 1) { Color = color; + Opacity = opacity; } /// @@ -29,10 +31,12 @@ namespace Perspex.Media /// /// Gets the color of the brush. /// - public Color Color - { - get; - } + public Color Color { get; } + + /// + /// Gets the opacity of the brush. + /// + public double Opacity { get; } /// /// Returns a string representation of the brush. diff --git a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj index 819ee3376e..ea84ae710e 100644 --- a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj +++ b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj @@ -72,6 +72,8 @@ + + diff --git a/src/Perspex.SceneGraph/Platform/IFormattedTextImpl.cs b/src/Perspex.SceneGraph/Platform/IFormattedTextImpl.cs index 85a674c330..306e710f3f 100644 --- a/src/Perspex.SceneGraph/Platform/IFormattedTextImpl.cs +++ b/src/Perspex.SceneGraph/Platform/IFormattedTextImpl.cs @@ -61,6 +61,6 @@ namespace Perspex.Platform /// The brush. /// The start of the text range. /// The length of the text range. - void SetForegroundBrush(Brush brush, int startIndex, int length); + void SetForegroundBrush(IBrush brush, int startIndex, int length); } } diff --git a/src/Skia/Perspex.Skia/DrawingContextImpl.cs b/src/Skia/Perspex.Skia/DrawingContextImpl.cs index 61f4bc4a4d..0139932160 100644 --- a/src/Skia/Perspex.Skia/DrawingContextImpl.cs +++ b/src/Skia/Perspex.Skia/DrawingContextImpl.cs @@ -34,7 +34,7 @@ namespace Perspex.Skia } static readonly NativeBrushContainer _dummy = new NativeBrushContainer(null); - public void DrawGeometry(Brush brush, Pen pen, Geometry geometry) + public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry) { var impl = ((StreamGeometryImpl) geometry.PlatformImpl); var size = geometry.Bounds.Size; @@ -46,7 +46,7 @@ namespace Perspex.Skia } } - unsafe NativeBrushContainer CreateBrush(Brush brush, Size targetSize) + unsafe NativeBrushContainer CreateBrush(IBrush brush, Size targetSize) { var rv = NativeBrushPool.Instance.Get(); rv.Brush->Opacity = brush.Opacity; @@ -141,7 +141,7 @@ namespace Perspex.Skia } } - public void FillRectangle(Brush pbrush, Rect rect, float cornerRadius = 0) + public void FillRectangle(IBrush pbrush, Rect rect, float cornerRadius = 0) { using (var brush = CreateBrush(pbrush, rect.Size)) { @@ -150,7 +150,7 @@ namespace Perspex.Skia } } - public void DrawText(Brush foreground, Point origin, FormattedText text) + public void DrawText(IBrush foreground, Point origin, FormattedText text) { using (var br = CreateBrush(foreground, text.Measure())) MethodTable.Instance.DrawFormattedText(Handle, br.Brush, ((FormattedTextImpl) text.PlatformImpl).Handle, diff --git a/src/Skia/Perspex.Skia/FormattedTextImpl.cs b/src/Skia/Perspex.Skia/FormattedTextImpl.cs index 808935e99e..13888334ad 100644 --- a/src/Skia/Perspex.Skia/FormattedTextImpl.cs +++ b/src/Skia/Perspex.Skia/FormattedTextImpl.cs @@ -73,7 +73,7 @@ namespace Perspex.Skia return _size; } - public void SetForegroundBrush(Brush brush, int startIndex, int length) + public void SetForegroundBrush(IBrush brush, int startIndex, int length) { } diff --git a/src/Windows/Perspex.Direct2D1/Media/BrushWrapper.cs b/src/Windows/Perspex.Direct2D1/Media/BrushWrapper.cs index 0c8f8d1373..ed4e44a7aa 100644 --- a/src/Windows/Perspex.Direct2D1/Media/BrushWrapper.cs +++ b/src/Windows/Perspex.Direct2D1/Media/BrushWrapper.cs @@ -8,11 +8,11 @@ namespace Perspex.Direct2D1.Media { internal class BrushWrapper : ComObject { - public BrushWrapper(Brush brush) + public BrushWrapper(IBrush brush) { Brush = brush; } - public Brush Brush { get; private set; } + public IBrush Brush { get; private set; } } } diff --git a/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs b/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs index 6031d4a8e9..196588b5ad 100644 --- a/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs +++ b/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs @@ -114,7 +114,7 @@ namespace Perspex.Direct2D1.Media /// The fill brush. /// The stroke pen. /// The geometry. - public void DrawGeometry(Perspex.Media.Brush brush, Pen pen, Perspex.Media.Geometry geometry) + public void DrawGeometry(IBrush brush, Pen pen, Perspex.Media.Geometry geometry) { if (brush != null) { @@ -181,7 +181,7 @@ namespace Perspex.Direct2D1.Media /// The foreground brush. /// The upper-left corner of the text. /// The text. - public void DrawText(Perspex.Media.Brush foreground, Point origin, FormattedText text) + public void DrawText(IBrush foreground, Point origin, FormattedText text) { if (!string.IsNullOrEmpty(text.Text)) { @@ -204,7 +204,7 @@ namespace Perspex.Direct2D1.Media /// The brush. /// The rectangle bounds. /// The corner radius. - public void FillRectangle(Perspex.Media.Brush brush, Rect rect, float cornerRadius) + public void FillRectangle(IBrush brush, Rect rect, float cornerRadius) { using (var b = CreateBrush(brush, rect.Size)) { @@ -291,10 +291,9 @@ namespace Perspex.Direct2D1.Media /// The perspex brush. /// The size of the brush's target area. /// The Direct2D brush wrapper. - public BrushImpl CreateBrush(Perspex.Media.Brush brush, Size destinationSize) + public BrushImpl CreateBrush(IBrush brush, Size destinationSize) { - var solidColorBrush = brush as Perspex.Media.SolidColorBrush; - var mutableSolidColorBrush = brush as Perspex.Media.Mutable.SolidColorBrush; + var solidColorBrush = brush as Perspex.Media.ISolidColorBrush; var linearGradientBrush = brush as Perspex.Media.LinearGradientBrush; var radialGradientBrush = brush as Perspex.Media.RadialGradientBrush; var imageBrush = brush as Perspex.Media.ImageBrush; @@ -304,10 +303,6 @@ 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); diff --git a/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs b/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs index 22f8b94491..4daeb685fb 100644 --- a/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs @@ -118,7 +118,7 @@ namespace Perspex.Direct2D1.Media return new Size(width, TextLayout.Metrics.Height); } - public void SetForegroundBrush(Brush brush, int startIndex, int count) + public void SetForegroundBrush(IBrush brush, int startIndex, int count) { TextLayout.SetDrawingEffect( new BrushWrapper(brush), diff --git a/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs b/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs index 88d5413843..09012934b0 100644 --- a/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs @@ -1,24 +1,13 @@ // 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 Perspex.Media; + namespace Perspex.Direct2D1.Media { public class SolidColorBrushImpl : BrushImpl { - public SolidColorBrushImpl(Perspex.Media.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 - } - ); - } - - public SolidColorBrushImpl(Perspex.Media.Mutable.SolidColorBrush brush, SharpDX.Direct2D1.RenderTarget target) + public SolidColorBrushImpl(ISolidColorBrush brush, SharpDX.Direct2D1.RenderTarget target) { PlatformBrush = new SharpDX.Direct2D1.SolidColorBrush( target,