Browse Source
With immediate renderer. Also added a render test and fixed some problems with D2D implementation.scenegraph-after-breakage
11 changed files with 163 additions and 11 deletions
@ -0,0 +1,23 @@ |
|||
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; } |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Avalonia.Media.Immutable |
|||
{ |
|||
/// <summary>
|
|||
/// A brush that draws with a radial gradient.
|
|||
/// </summary>
|
|||
public class ImmutableRadialGradientBrush : ImmutableGradientBrush, IRadialGradientBrush |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ImmutableRadialGradientBrush"/> class.
|
|||
/// </summary>
|
|||
/// <param name="gradientStops">The gradient stops.</param>
|
|||
/// <param name="opacity">The opacity of the brush.</param>
|
|||
/// <param name="spreadMethod">The spread method.</param>
|
|||
/// <param name="center">The start point for the gradient.</param>
|
|||
/// <param name="gradientOrigin">
|
|||
/// The location of the two-dimensional focal point that defines the beginning of the gradient.
|
|||
/// </param>
|
|||
/// <param name="radius">
|
|||
/// The horizontal and vertical radius of the outermost circle of the radial gradient.
|
|||
/// </param>
|
|||
public ImmutableRadialGradientBrush( |
|||
IReadOnlyList<GradientStop> gradientStops, |
|||
double opacity = 1, |
|||
GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad, |
|||
RelativePoint? center = null, |
|||
RelativePoint? gradientOrigin = null, |
|||
double radius = 0.5) |
|||
: base(gradientStops, opacity, spreadMethod) |
|||
{ |
|||
Center = center ?? RelativePoint.Center; |
|||
GradientOrigin = gradientOrigin ?? RelativePoint.Center; |
|||
Radius = radius; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ImmutableRadialGradientBrush"/> class.
|
|||
/// </summary>
|
|||
/// <param name="source">The brush from which this brush's properties should be copied.</param>
|
|||
public ImmutableRadialGradientBrush(IRadialGradientBrush source) |
|||
: base(source) |
|||
{ |
|||
Center = source.Center; |
|||
GradientOrigin = source.GradientOrigin; |
|||
Radius = source.Radius; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public RelativePoint Center { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
public RelativePoint GradientOrigin { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
public double Radius { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
// 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 Avalonia.Controls; |
|||
using Avalonia.Media; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Xunit; |
|||
|
|||
#if AVALONIA_CAIRO
|
|||
namespace Avalonia.Cairo.RenderTests.Media |
|||
#elif AVALONIA_SKIA
|
|||
namespace Avalonia.Skia.RenderTests |
|||
#else
|
|||
namespace Avalonia.Direct2D1.RenderTests.Media |
|||
#endif
|
|||
{ |
|||
public class RadialGradientBrushTests : TestBase |
|||
{ |
|||
public RadialGradientBrushTests() : base(@"Media\RadialGradientBrush") |
|||
{ |
|||
} |
|||
|
|||
#if AVALONIA_SKIA_SKIP_FAIL
|
|||
[Fact(Skip = "FIXME")] |
|||
#else
|
|||
[Fact] |
|||
#endif
|
|||
public async Task RadialGradientBrush_RedBlue() |
|||
{ |
|||
Decorator target = new Decorator |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 200, |
|||
Height = 200, |
|||
Child = new Border |
|||
{ |
|||
Background = new RadialGradientBrush |
|||
{ |
|||
GradientStops = |
|||
{ |
|||
new GradientStop { Color = Colors.Red, Offset = 0 }, |
|||
new GradientStop { Color = Colors.Blue, Offset = 1 } |
|||
} |
|||
} |
|||
} |
|||
}; |
|||
|
|||
await RenderToFile(target); |
|||
CompareImages(); |
|||
} |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 9.6 KiB |
Loading…
Reference in new issue