diff --git a/src/Avalonia.HtmlRenderer/Adapters/AvaloniaAdapter.cs b/src/Avalonia.HtmlRenderer/Adapters/AvaloniaAdapter.cs
index 12c040fab3..aab65fcbc7 100644
--- a/src/Avalonia.HtmlRenderer/Adapters/AvaloniaAdapter.cs
+++ b/src/Avalonia.HtmlRenderer/Adapters/AvaloniaAdapter.cs
@@ -80,7 +80,7 @@ namespace TheArtOfDev.HtmlRenderer.Avalonia.Adapters
{
StartPoint = new RelativePoint(x, y, RelativeUnit.Relative),
EndPoint = new RelativePoint(1 - x, 1 - y, RelativeUnit.Relative),
- GradientStops =
+ GradientStops = new[]
{
new GradientStop(startColor, 0),
new GradientStop(endColor, 1)
diff --git a/src/Avalonia.Visuals/Avalonia.Visuals.csproj b/src/Avalonia.Visuals/Avalonia.Visuals.csproj
index 812e9d48ad..d5a8a261bd 100644
--- a/src/Avalonia.Visuals/Avalonia.Visuals.csproj
+++ b/src/Avalonia.Visuals/Avalonia.Visuals.csproj
@@ -69,7 +69,13 @@
+
+
+
+
+
+
@@ -133,7 +139,7 @@
-
+
diff --git a/src/Avalonia.Visuals/Media/GradientBrush.cs b/src/Avalonia.Visuals/Media/GradientBrush.cs
index 4c62a2b836..52edf12e7f 100644
--- a/src/Avalonia.Visuals/Media/GradientBrush.cs
+++ b/src/Avalonia.Visuals/Media/GradientBrush.cs
@@ -1,32 +1,52 @@
// Copyright (c) The Avalonia 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 Avalonia.Metadata;
namespace Avalonia.Media
{
- public abstract class GradientBrush : Brush
+ ///
+ /// Base class for brushes that draw with a gradient.
+ ///
+ public abstract class GradientBrush : Brush, IGradientBrush
{
+ ///
+ /// Defines the property.
+ ///
public static readonly StyledProperty SpreadMethodProperty =
AvaloniaProperty.Register(nameof(SpreadMethod));
- public static readonly StyledProperty> GradientStopsProperty =
- AvaloniaProperty.Register>(nameof(Opacity));
+ ///
+ /// Defines the property.
+ ///
+ public static readonly StyledProperty> GradientStopsProperty =
+ AvaloniaProperty.Register>(nameof(Opacity));
+ ///
+ /// Initializes a new instance of the class.
+ ///
public GradientBrush()
{
this.GradientStops = new List();
}
+ ///
+ /// Gets or sets the brush's spread method that defines how to draw a gradient that
+ /// doesn't fill the bounds of the destination control.
+ ///
public GradientSpreadMethod SpreadMethod
{
get { return GetValue(SpreadMethodProperty); }
set { SetValue(SpreadMethodProperty, value); }
}
+ ///
+ /// Gets or sets the brush's gradient stops.
+ ///
[Content]
- public List GradientStops
+ public IReadOnlyList GradientStops
{
get { return GetValue(GradientStopsProperty); }
set { SetValue(GradientStopsProperty, value); }
diff --git a/src/Avalonia.Visuals/Media/IGradientBrush.cs b/src/Avalonia.Visuals/Media/IGradientBrush.cs
new file mode 100644
index 0000000000..ce064c4a1f
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/IGradientBrush.cs
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+
+namespace Avalonia.Media
+{
+ ///
+ /// A brush that draws with a gradient.
+ ///
+ public interface IGradientBrush : IBrush
+ {
+ ///
+ /// Gets the brush's gradient stops.
+ ///
+ IReadOnlyList GradientStops { get; }
+
+ ///
+ /// Gets the brush's spread method that defines how to draw a gradient that doesn't fill
+ /// the bounds of the destination control.
+ ///
+ GradientSpreadMethod SpreadMethod { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Avalonia.Visuals/Media/ILinearGradientBrush.cs b/src/Avalonia.Visuals/Media/ILinearGradientBrush.cs
new file mode 100644
index 0000000000..3e2a5a0e22
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/ILinearGradientBrush.cs
@@ -0,0 +1,18 @@
+namespace Avalonia.Media
+{
+ ///
+ /// A brush that draws with a linear gradient.
+ ///
+ public interface ILinearGradientBrush : IGradientBrush
+ {
+ ///
+ /// Gets or sets the start point for the gradient.
+ ///
+ RelativePoint StartPoint { get; }
+
+ ///
+ /// Gets or sets the end point for the gradient.
+ ///
+ RelativePoint EndPoint { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Avalonia.Visuals/Media/IRadialGradientBrush.cs b/src/Avalonia.Visuals/Media/IRadialGradientBrush.cs
new file mode 100644
index 0000000000..cadf53cc18
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/IRadialGradientBrush.cs
@@ -0,0 +1,24 @@
+namespace Avalonia.Media
+{
+ ///
+ /// Paints an area with a radial gradient.
+ ///
+ public interface IRadialGradientBrush : IGradientBrush
+ {
+ ///
+ /// Gets the start point for the gradient.
+ ///
+ RelativePoint Center { get; }
+
+ ///
+ /// Gets the location of the two-dimensional focal point that defines the beginning of the
+ /// gradient.
+ ///
+ RelativePoint GradientOrigin { get; }
+
+ ///
+ /// Gets the horizontal and vertical radius of the outermost circle of the radial gradient.
+ ///
+ double Radius { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Avalonia.Visuals/Media/ITileBrush.cs b/src/Avalonia.Visuals/Media/ITileBrush.cs
new file mode 100644
index 0000000000..8e2349f506
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/ITileBrush.cs
@@ -0,0 +1,39 @@
+namespace Avalonia.Media
+{
+ ///
+ /// A brush which displays a repeating image.
+ ///
+ public interface ITileBrush : IBrush
+ {
+ ///
+ /// Gets the horizontal alignment of a tile in the destination.
+ ///
+ AlignmentX AlignmentX { get; }
+
+ ///
+ /// Gets the horizontal alignment of a tile in the destination.
+ ///
+ AlignmentY AlignmentY { get; }
+
+ ///
+ /// Gets the rectangle on the destination in which to paint a tile.
+ ///
+ RelativeRect DestinationRect { get; }
+
+ ///
+ /// Gets the rectangle of the source image that will be displayed.
+ ///
+ RelativeRect SourceRect { get; }
+
+ ///
+ /// Gets a value indicating how the source rectangle will be stretched to fill the
+ /// destination rect.
+ ///
+ Stretch Stretch { get; }
+
+ ///
+ /// Gets the brush's tile mode.
+ ///
+ TileMode TileMode { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Avalonia.Visuals/Media/IVisualBrush.cs b/src/Avalonia.Visuals/Media/IVisualBrush.cs
new file mode 100644
index 0000000000..e74892b218
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/IVisualBrush.cs
@@ -0,0 +1,15 @@
+using Avalonia.VisualTree;
+
+namespace Avalonia.Media
+{
+ ///
+ /// Paints an area with an .
+ ///
+ public interface IVisualBrush : ITileBrush
+ {
+ ///
+ /// Gets the visual to draw.
+ ///
+ IVisual Visual { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Avalonia.Visuals/Media/ImageBush.cs b/src/Avalonia.Visuals/Media/ImageBrush.cs
similarity index 95%
rename from src/Avalonia.Visuals/Media/ImageBush.cs
rename to src/Avalonia.Visuals/Media/ImageBrush.cs
index caf43d19a2..85c1f6c71a 100644
--- a/src/Avalonia.Visuals/Media/ImageBush.cs
+++ b/src/Avalonia.Visuals/Media/ImageBrush.cs
@@ -8,7 +8,7 @@ namespace Avalonia.Media
///
/// Paints an area with an .
///
- public class ImageBrush : TileBrush
+ public class ImageBrush : TileBrush, IImageBrush
{
///
/// Defines the property.
diff --git a/src/Avalonia.Visuals/Media/Imaging/IImageBrush.cs b/src/Avalonia.Visuals/Media/Imaging/IImageBrush.cs
new file mode 100644
index 0000000000..aaa481bd28
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/Imaging/IImageBrush.cs
@@ -0,0 +1,15 @@
+using Avalonia.Media.Imaging;
+
+namespace Avalonia.Media
+{
+ ///
+ /// Paints an area with an .
+ ///
+ public interface IImageBrush : ITileBrush
+ {
+ ///
+ /// Gets the image to draw.
+ ///
+ IBitmap Source { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Avalonia.Visuals/Media/LinearGradientBrush.cs b/src/Avalonia.Visuals/Media/LinearGradientBrush.cs
index 6ba2c5093e..33eea4fbad 100644
--- a/src/Avalonia.Visuals/Media/LinearGradientBrush.cs
+++ b/src/Avalonia.Visuals/Media/LinearGradientBrush.cs
@@ -6,7 +6,7 @@ namespace Avalonia.Media
///
/// A brush that draws with a linear gradient.
///
- public sealed class LinearGradientBrush : GradientBrush
+ public sealed class LinearGradientBrush : GradientBrush, ILinearGradientBrush
{
///
/// Defines the property.
diff --git a/src/Avalonia.Visuals/Media/RadialGradientBrush.cs b/src/Avalonia.Visuals/Media/RadialGradientBrush.cs
index 70657abe88..b721e19138 100644
--- a/src/Avalonia.Visuals/Media/RadialGradientBrush.cs
+++ b/src/Avalonia.Visuals/Media/RadialGradientBrush.cs
@@ -7,7 +7,7 @@ namespace Avalonia.Media
/// 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.
///
- public sealed class RadialGradientBrush : GradientBrush
+ public sealed class RadialGradientBrush : GradientBrush, IRadialGradientBrush
{
///
/// Defines the property.
@@ -43,7 +43,8 @@ namespace Avalonia.Media
}
///
- /// Gets or sets the location of the two-dimensional focal point that defines the beginning of the gradient.
+ /// Gets or sets the location of the two-dimensional focal point that defines the beginning
+ /// of the gradient.
///
public RelativePoint GradientOrigin
{
@@ -52,7 +53,8 @@ namespace Avalonia.Media
}
///
- /// Gets or sets the horizontal and vertical radius of the outermost circle of the radial gradient.
+ /// Gets or sets the horizontal and vertical radius of the outermost circle of the radial
+ /// gradient.
///
public double Radius
{
diff --git a/src/Avalonia.Visuals/Media/TileBrush.cs b/src/Avalonia.Visuals/Media/TileBrush.cs
index 1708c7e9f6..3a7f9d9920 100644
--- a/src/Avalonia.Visuals/Media/TileBrush.cs
+++ b/src/Avalonia.Visuals/Media/TileBrush.cs
@@ -37,7 +37,7 @@ namespace Avalonia.Media
///
/// Base class for brushes which display repeating images.
///
- public abstract class TileBrush : Brush
+ public abstract class TileBrush : Brush, ITileBrush
{
///
/// Defines the property.
diff --git a/src/Avalonia.Visuals/Media/VisualBrush.cs b/src/Avalonia.Visuals/Media/VisualBrush.cs
index 41a61f6022..85ccf7afc9 100644
--- a/src/Avalonia.Visuals/Media/VisualBrush.cs
+++ b/src/Avalonia.Visuals/Media/VisualBrush.cs
@@ -8,7 +8,7 @@ namespace Avalonia.Media
///
/// Paints an area with an .
///
- public class VisualBrush : TileBrush
+ public class VisualBrush : TileBrush, IVisualBrush
{
///
/// Defines the property.
diff --git a/tests/Avalonia.RenderTests/Media/LinearGradientBrushTests.cs b/tests/Avalonia.RenderTests/Media/LinearGradientBrushTests.cs
index 104edf04e5..6c26d067a7 100644
--- a/tests/Avalonia.RenderTests/Media/LinearGradientBrushTests.cs
+++ b/tests/Avalonia.RenderTests/Media/LinearGradientBrushTests.cs
@@ -42,7 +42,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media
{
StartPoint = new RelativePoint(0, 0.5, RelativeUnit.Relative),
EndPoint = new RelativePoint(1, 0.5, RelativeUnit.Relative),
- GradientStops =
+ GradientStops = new[]
{
new GradientStop { Color = Colors.Red, Offset = 0 },
new GradientStop { Color = Colors.Blue, Offset = 1 }
@@ -73,7 +73,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media
{
StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0.5, 1, RelativeUnit.Relative),
- GradientStops =
+ GradientStops = new[]
{
new GradientStop { Color = Colors.Red, Offset = 0 },
new GradientStop { Color = Colors.Blue, Offset = 1 }