Browse Source

Add interfaces for all brush types.

Also:
- Change `GradientBrush.GradientStops` to be a readonly list, as changes
to it would have been ignored anyway.
- Fix typo in ImageBrush filename.
pull/910/head
Steven Kirk 10 years ago
parent
commit
f6dee9eab4
  1. 2
      src/Avalonia.HtmlRenderer/Adapters/AvaloniaAdapter.cs
  2. 8
      src/Avalonia.Visuals/Avalonia.Visuals.csproj
  3. 28
      src/Avalonia.Visuals/Media/GradientBrush.cs
  4. 21
      src/Avalonia.Visuals/Media/IGradientBrush.cs
  5. 18
      src/Avalonia.Visuals/Media/ILinearGradientBrush.cs
  6. 24
      src/Avalonia.Visuals/Media/IRadialGradientBrush.cs
  7. 39
      src/Avalonia.Visuals/Media/ITileBrush.cs
  8. 15
      src/Avalonia.Visuals/Media/IVisualBrush.cs
  9. 2
      src/Avalonia.Visuals/Media/ImageBrush.cs
  10. 15
      src/Avalonia.Visuals/Media/Imaging/IImageBrush.cs
  11. 2
      src/Avalonia.Visuals/Media/LinearGradientBrush.cs
  12. 8
      src/Avalonia.Visuals/Media/RadialGradientBrush.cs
  13. 2
      src/Avalonia.Visuals/Media/TileBrush.cs
  14. 2
      src/Avalonia.Visuals/Media/VisualBrush.cs
  15. 4
      tests/Avalonia.RenderTests/Media/LinearGradientBrushTests.cs

2
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)

8
src/Avalonia.Visuals/Avalonia.Visuals.csproj

@ -69,7 +69,13 @@
<Compile Include="Media\BrushMappingMode.cs" />
<Compile Include="Media\Color.cs" />
<Compile Include="Media\Colors.cs" />
<Compile Include="Media\IGradientBrush.cs" />
<Compile Include="Media\ILinearGradientBrush.cs" />
<Compile Include="Media\Imaging\IImageBrush.cs" />
<Compile Include="Media\Imaging\WritableBitmap.cs" />
<Compile Include="Media\IRadialGradientBrush.cs" />
<Compile Include="Media\ITileBrush.cs" />
<Compile Include="Media\IVisualBrush.cs" />
<Compile Include="Media\TextWrapping.cs" />
<Compile Include="Media\TransformGroup.cs" />
<Compile Include="Media\DashStyle.cs" />
@ -133,7 +139,7 @@
<Compile Include="Media\TextHitTestResult.cs" />
<Compile Include="Media\Transform.cs" />
<Compile Include="Media\TileBrush.cs" />
<Compile Include="Media\ImageBush.cs" />
<Compile Include="Media\ImageBrush.cs" />
<Compile Include="Media\VisualBrush.cs" />
<Compile Include="Platform\IPlatformSettings.cs" />
<Compile Include="RelativePoint.cs" />

28
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
/// <summary>
/// Base class for brushes that draw with a gradient.
/// </summary>
public abstract class GradientBrush : Brush, IGradientBrush
{
/// <summary>
/// Defines the <see cref="SpreadMethod"/> property.
/// </summary>
public static readonly StyledProperty<GradientSpreadMethod> SpreadMethodProperty =
AvaloniaProperty.Register<GradientBrush, GradientSpreadMethod>(nameof(SpreadMethod));
public static readonly StyledProperty<List<GradientStop>> GradientStopsProperty =
AvaloniaProperty.Register<GradientBrush, List<GradientStop>>(nameof(Opacity));
/// <summary>
/// Defines the <see cref="GradientStops"/> property.
/// </summary>
public static readonly StyledProperty<IReadOnlyList<GradientStop>> GradientStopsProperty =
AvaloniaProperty.Register<GradientBrush, IReadOnlyList<GradientStop>>(nameof(Opacity));
/// <summary>
/// Initializes a new instance of the <see cref="GradientBrush"/> class.
/// </summary>
public GradientBrush()
{
this.GradientStops = new List<GradientStop>();
}
/// <summary>
/// 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.
/// </summary>
public GradientSpreadMethod SpreadMethod
{
get { return GetValue(SpreadMethodProperty); }
set { SetValue(SpreadMethodProperty, value); }
}
/// <summary>
/// Gets or sets the brush's gradient stops.
/// </summary>
[Content]
public List<GradientStop> GradientStops
public IReadOnlyList<GradientStop> GradientStops
{
get { return GetValue(GradientStopsProperty); }
set { SetValue(GradientStopsProperty, value); }

21
src/Avalonia.Visuals/Media/IGradientBrush.cs

@ -0,0 +1,21 @@
using System.Collections.Generic;
namespace Avalonia.Media
{
/// <summary>
/// A brush that draws with a gradient.
/// </summary>
public interface IGradientBrush : IBrush
{
/// <summary>
/// Gets the brush's gradient stops.
/// </summary>
IReadOnlyList<GradientStop> GradientStops { get; }
/// <summary>
/// Gets the brush's spread method that defines how to draw a gradient that doesn't fill
/// the bounds of the destination control.
/// </summary>
GradientSpreadMethod SpreadMethod { get; }
}
}

18
src/Avalonia.Visuals/Media/ILinearGradientBrush.cs

@ -0,0 +1,18 @@
namespace Avalonia.Media
{
/// <summary>
/// A brush that draws with a linear gradient.
/// </summary>
public interface ILinearGradientBrush : IGradientBrush
{
/// <summary>
/// Gets or sets the start point for the gradient.
/// </summary>
RelativePoint StartPoint { get; }
/// <summary>
/// Gets or sets the end point for the gradient.
/// </summary>
RelativePoint EndPoint { get; }
}
}

24
src/Avalonia.Visuals/Media/IRadialGradientBrush.cs

@ -0,0 +1,24 @@
namespace Avalonia.Media
{
/// <summary>
/// Paints an area with a radial gradient.
/// </summary>
public interface IRadialGradientBrush : IGradientBrush
{
/// <summary>
/// Gets the start point for the gradient.
/// </summary>
RelativePoint Center { get; }
/// <summary>
/// Gets the location of the two-dimensional focal point that defines the beginning of the
/// gradient.
/// </summary>
RelativePoint GradientOrigin { get; }
/// <summary>
/// Gets the horizontal and vertical radius of the outermost circle of the radial gradient.
/// </summary>
double Radius { get; }
}
}

39
src/Avalonia.Visuals/Media/ITileBrush.cs

@ -0,0 +1,39 @@
namespace Avalonia.Media
{
/// <summary>
/// A brush which displays a repeating image.
/// </summary>
public interface ITileBrush : IBrush
{
/// <summary>
/// Gets the horizontal alignment of a tile in the destination.
/// </summary>
AlignmentX AlignmentX { get; }
/// <summary>
/// Gets the horizontal alignment of a tile in the destination.
/// </summary>
AlignmentY AlignmentY { get; }
/// <summary>
/// Gets the rectangle on the destination in which to paint a tile.
/// </summary>
RelativeRect DestinationRect { get; }
/// <summary>
/// Gets the rectangle of the source image that will be displayed.
/// </summary>
RelativeRect SourceRect { get; }
/// <summary>
/// Gets a value indicating how the source rectangle will be stretched to fill the
/// destination rect.
/// </summary>
Stretch Stretch { get; }
/// <summary>
/// Gets the brush's tile mode.
/// </summary>
TileMode TileMode { get; }
}
}

15
src/Avalonia.Visuals/Media/IVisualBrush.cs

@ -0,0 +1,15 @@
using Avalonia.VisualTree;
namespace Avalonia.Media
{
/// <summary>
/// Paints an area with an <see cref="IVisual"/>.
/// </summary>
public interface IVisualBrush : ITileBrush
{
/// <summary>
/// Gets the visual to draw.
/// </summary>
IVisual Visual { get; }
}
}

2
src/Avalonia.Visuals/Media/ImageBush.cs → src/Avalonia.Visuals/Media/ImageBrush.cs

@ -8,7 +8,7 @@ namespace Avalonia.Media
/// <summary>
/// Paints an area with an <see cref="IBitmap"/>.
/// </summary>
public class ImageBrush : TileBrush
public class ImageBrush : TileBrush, IImageBrush
{
/// <summary>
/// Defines the <see cref="Visual"/> property.

15
src/Avalonia.Visuals/Media/Imaging/IImageBrush.cs

@ -0,0 +1,15 @@
using Avalonia.Media.Imaging;
namespace Avalonia.Media
{
/// <summary>
/// Paints an area with an <see cref="IBitmap"/>.
/// </summary>
public interface IImageBrush : ITileBrush
{
/// <summary>
/// Gets the image to draw.
/// </summary>
IBitmap Source { get; }
}
}

2
src/Avalonia.Visuals/Media/LinearGradientBrush.cs

@ -6,7 +6,7 @@ namespace Avalonia.Media
/// <summary>
/// A brush that draws with a linear gradient.
/// </summary>
public sealed class LinearGradientBrush : GradientBrush
public sealed class LinearGradientBrush : GradientBrush, ILinearGradientBrush
{
/// <summary>
/// Defines the <see cref="StartPoint"/> property.

8
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.
/// </summary>
public sealed class RadialGradientBrush : GradientBrush
public sealed class RadialGradientBrush : GradientBrush, IRadialGradientBrush
{
/// <summary>
/// Defines the <see cref="Center"/> property.
@ -43,7 +43,8 @@ namespace Avalonia.Media
}
/// <summary>
/// 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.
/// </summary>
public RelativePoint GradientOrigin
{
@ -52,7 +53,8 @@ namespace Avalonia.Media
}
/// <summary>
/// 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.
/// </summary>
public double Radius
{

2
src/Avalonia.Visuals/Media/TileBrush.cs

@ -37,7 +37,7 @@ namespace Avalonia.Media
/// <summary>
/// Base class for brushes which display repeating images.
/// </summary>
public abstract class TileBrush : Brush
public abstract class TileBrush : Brush, ITileBrush
{
/// <summary>
/// Defines the <see cref="AlignmentX"/> property.

2
src/Avalonia.Visuals/Media/VisualBrush.cs

@ -8,7 +8,7 @@ namespace Avalonia.Media
/// <summary>
/// Paints an area with an <see cref="IVisual"/>.
/// </summary>
public class VisualBrush : TileBrush
public class VisualBrush : TileBrush, IVisualBrush
{
/// <summary>
/// Defines the <see cref="Visual"/> property.

4
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 }

Loading…
Cancel
Save