committed by
GitHub
35 changed files with 578 additions and 65 deletions
@ -0,0 +1,23 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Avalonia.Collections; |
|||
using Avalonia.Media.Immutable; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
/// <summary>
|
|||
/// A collection of <see cref="GradientStop"/>s.
|
|||
/// </summary>
|
|||
public class GradientStops : AvaloniaList<GradientStop> |
|||
{ |
|||
public GradientStops() |
|||
{ |
|||
ResetBehavior = ResetBehavior.Remove; |
|||
} |
|||
|
|||
public IReadOnlyList<ImmutableGradientStop> ToImmutable() |
|||
{ |
|||
return this.Select(x => new ImmutableGradientStop(x.Offset, x.Color)).ToList(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
/// <summary>
|
|||
/// Signals to a self-rendering control that changes to the resource should invoke
|
|||
/// <see cref="Visual.InvalidateVisual"/>.
|
|||
/// </summary>
|
|||
public interface IAffectsRender |
|||
{ |
|||
/// <summary>
|
|||
/// Raised when the resource changes visually.
|
|||
/// </summary>
|
|||
event EventHandler Invalidated; |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
namespace Avalonia.Media |
|||
{ |
|||
/// <summary>
|
|||
/// Describes the location and color of a transition point in a gradient.
|
|||
/// </summary>
|
|||
public interface IGradientStop |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the gradient stop color.
|
|||
/// </summary>
|
|||
Color Color { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the gradient stop offset.
|
|||
/// </summary>
|
|||
double Offset { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
namespace Avalonia.Media.Immutable |
|||
{ |
|||
/// <summary>
|
|||
/// Describes the location and color of a transition point in a gradient.
|
|||
/// </summary>
|
|||
public class ImmutableGradientStop : IGradientStop |
|||
{ |
|||
public ImmutableGradientStop(double offset, Color color) |
|||
{ |
|||
Offset = offset; |
|||
Color = color; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public double Offset { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
public Color Color { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Avalonia.Controls.Shapes; |
|||
using Avalonia.Media; |
|||
using Avalonia.UnitTests; |
|||
using Moq; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Controls.UnitTests.Shapes |
|||
{ |
|||
public class RectangleTests |
|||
{ |
|||
[Fact] |
|||
public void Changing_Fill_Brush_Color_Should_Invalidate_Visual() |
|||
{ |
|||
var target = new Rectangle() |
|||
{ |
|||
Fill = new SolidColorBrush(Colors.Red), |
|||
}; |
|||
|
|||
var root = new TestRoot(target); |
|||
var renderer = Mock.Get(root.Renderer); |
|||
renderer.ResetCalls(); |
|||
|
|||
((SolidColorBrush)target.Fill).Color = Colors.Green; |
|||
|
|||
renderer.Verify(x => x.AddDirty(target), Times.Once); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Changing_Stroke_Brush_Color_Should_Invalidate_Visual() |
|||
{ |
|||
var target = new Rectangle() |
|||
{ |
|||
Stroke = new SolidColorBrush(Colors.Red), |
|||
}; |
|||
|
|||
var root = new TestRoot(target); |
|||
var renderer = Mock.Get(root.Renderer); |
|||
renderer.ResetCalls(); |
|||
|
|||
((SolidColorBrush)target.Stroke).Color = Colors.Green; |
|||
|
|||
renderer.Verify(x => x.AddDirty(target), Times.Once); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Imaging; |
|||
using Moq; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media |
|||
{ |
|||
public class ImageBrushTests |
|||
{ |
|||
[Fact] |
|||
public void Changing_Source_Raises_Invalidated() |
|||
{ |
|||
var bitmap1 = Mock.Of<IBitmap>(); |
|||
var bitmap2 = Mock.Of<IBitmap>(); |
|||
var target = new ImageBrush(bitmap1); |
|||
var raised = false; |
|||
|
|||
target.Invalidated += (s, e) => raised = true; |
|||
target.Source = bitmap2; |
|||
|
|||
Assert.True(raised); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
using System; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Imaging; |
|||
using Moq; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media |
|||
{ |
|||
public class LinearGradientBrushTests |
|||
{ |
|||
[Fact] |
|||
public void Changing_StartPoint_Raises_Invalidated() |
|||
{ |
|||
var bitmap1 = Mock.Of<IBitmap>(); |
|||
var bitmap2 = Mock.Of<IBitmap>(); |
|||
var target = new LinearGradientBrush(); |
|||
var raised = false; |
|||
|
|||
target.StartPoint = new RelativePoint(); |
|||
target.Invalidated += (s, e) => raised = true; |
|||
target.StartPoint = new RelativePoint(10, 10, RelativeUnit.Absolute); |
|||
|
|||
Assert.True(raised); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Changing_EndPoint_Raises_Invalidated() |
|||
{ |
|||
var bitmap1 = Mock.Of<IBitmap>(); |
|||
var bitmap2 = Mock.Of<IBitmap>(); |
|||
var target = new LinearGradientBrush(); |
|||
var raised = false; |
|||
|
|||
target.EndPoint = new RelativePoint(); |
|||
target.Invalidated += (s, e) => raised = true; |
|||
target.EndPoint = new RelativePoint(10, 10, RelativeUnit.Absolute); |
|||
|
|||
Assert.True(raised); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Changing_GradientStops_Raises_Invalidated() |
|||
{ |
|||
var bitmap1 = Mock.Of<IBitmap>(); |
|||
var bitmap2 = Mock.Of<IBitmap>(); |
|||
var target = new LinearGradientBrush(); |
|||
var raised = false; |
|||
|
|||
target.GradientStops = new GradientStops { new GradientStop(Colors.Red, 0) }; |
|||
target.Invalidated += (s, e) => raised = true; |
|||
target.GradientStops = new GradientStops { new GradientStop(Colors.Green, 0) }; |
|||
|
|||
Assert.True(raised); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Adding_GradientStop_Raises_Invalidated() |
|||
{ |
|||
var bitmap1 = Mock.Of<IBitmap>(); |
|||
var bitmap2 = Mock.Of<IBitmap>(); |
|||
var target = new LinearGradientBrush(); |
|||
var raised = false; |
|||
|
|||
target.GradientStops = new GradientStops { new GradientStop(Colors.Red, 0) }; |
|||
target.Invalidated += (s, e) => raised = true; |
|||
target.GradientStops.Add(new GradientStop(Colors.Green, 1)); |
|||
|
|||
Assert.True(raised); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Changing_GradientStop_Offset_Raises_Invalidated() |
|||
{ |
|||
var bitmap1 = Mock.Of<IBitmap>(); |
|||
var bitmap2 = Mock.Of<IBitmap>(); |
|||
var target = new LinearGradientBrush(); |
|||
var raised = false; |
|||
|
|||
target.GradientStops = new GradientStops { new GradientStop(Colors.Red, 0) }; |
|||
target.Invalidated += (s, e) => raised = true; |
|||
target.GradientStops[0].Offset = 0.5; |
|||
|
|||
Assert.True(raised); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using Avalonia.Media; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media |
|||
{ |
|||
public class SolidColorBrushTests |
|||
{ |
|||
[Fact] |
|||
public void Changing_Color_Raises_Invalidated() |
|||
{ |
|||
var target = new SolidColorBrush(Colors.Red); |
|||
var raised = false; |
|||
|
|||
target.Invalidated += (s, e) => raised = true; |
|||
target.Color = Colors.Green; |
|||
|
|||
Assert.True(raised); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue