Browse Source

Merge branch 'master' into fixes/Consolidate-Package

pull/8196/head
Nikita Tsukanov 4 years ago
committed by GitHub
parent
commit
f642602653
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs
  2. 15
      src/Avalonia.Base/Media/Brush.cs
  3. 5
      src/Avalonia.Base/Media/IBrush.cs
  4. 4
      src/Avalonia.Base/Media/Immutable/ImmutableConicGradientBrush.cs
  5. 11
      src/Avalonia.Base/Media/Immutable/ImmutableGradientBrush.cs
  6. 3
      src/Avalonia.Base/Media/Immutable/ImmutableImageBrush.cs
  7. 4
      src/Avalonia.Base/Media/Immutable/ImmutableLinearGradientBrush.cs
  8. 4
      src/Avalonia.Base/Media/Immutable/ImmutableRadialGradientBrush.cs
  9. 5
      src/Avalonia.Base/Media/Immutable/ImmutableSolidColorBrush.cs
  10. 9
      src/Avalonia.Base/Media/Immutable/ImmutableTileBrush.cs
  11. 3
      src/Avalonia.Base/Media/Immutable/ImmutableVisualBrush.cs
  12. 39
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs

6
src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs

@ -31,6 +31,7 @@ namespace Avalonia.Animation.Animators
InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops), InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops),
s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity), s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity),
oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null, oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null,
s_relativePointAnimator.Interpolate(progress, oldValue.TransformOrigin, newValue.TransformOrigin),
oldValue.SpreadMethod, oldValue.SpreadMethod,
s_relativePointAnimator.Interpolate(progress, oldRadial.Center, newRadial.Center), s_relativePointAnimator.Interpolate(progress, oldRadial.Center, newRadial.Center),
s_relativePointAnimator.Interpolate(progress, oldRadial.GradientOrigin, newRadial.GradientOrigin), s_relativePointAnimator.Interpolate(progress, oldRadial.GradientOrigin, newRadial.GradientOrigin),
@ -41,6 +42,7 @@ namespace Avalonia.Animation.Animators
InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops), InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops),
s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity), s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity),
oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null, oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null,
s_relativePointAnimator.Interpolate(progress, oldValue.TransformOrigin, newValue.TransformOrigin),
oldValue.SpreadMethod, oldValue.SpreadMethod,
s_relativePointAnimator.Interpolate(progress, oldConic.Center, newConic.Center), s_relativePointAnimator.Interpolate(progress, oldConic.Center, newConic.Center),
s_doubleAnimator.Interpolate(progress, oldConic.Angle, newConic.Angle)); s_doubleAnimator.Interpolate(progress, oldConic.Angle, newConic.Angle));
@ -50,6 +52,7 @@ namespace Avalonia.Animation.Animators
InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops), InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops),
s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity), s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity),
oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null, oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null,
s_relativePointAnimator.Interpolate(progress, oldValue.TransformOrigin, newValue.TransformOrigin),
oldValue.SpreadMethod, oldValue.SpreadMethod,
s_relativePointAnimator.Interpolate(progress, oldLinear.StartPoint, newLinear.StartPoint), s_relativePointAnimator.Interpolate(progress, oldLinear.StartPoint, newLinear.StartPoint),
s_relativePointAnimator.Interpolate(progress, oldLinear.EndPoint, newLinear.EndPoint)); s_relativePointAnimator.Interpolate(progress, oldLinear.EndPoint, newLinear.EndPoint));
@ -102,18 +105,21 @@ namespace Avalonia.Animation.Animators
return new ImmutableRadialGradientBrush( return new ImmutableRadialGradientBrush(
CreateStopsFromSolidColorBrush(solidColorBrush, oldRadial.GradientStops), solidColorBrush.Opacity, CreateStopsFromSolidColorBrush(solidColorBrush, oldRadial.GradientStops), solidColorBrush.Opacity,
oldRadial.Transform is { } ? new ImmutableTransform(oldRadial.Transform.Value) : null, oldRadial.Transform is { } ? new ImmutableTransform(oldRadial.Transform.Value) : null,
oldRadial.TransformOrigin,
oldRadial.SpreadMethod, oldRadial.Center, oldRadial.GradientOrigin, oldRadial.Radius); oldRadial.SpreadMethod, oldRadial.Center, oldRadial.GradientOrigin, oldRadial.Radius);
case IConicGradientBrush oldConic: case IConicGradientBrush oldConic:
return new ImmutableConicGradientBrush( return new ImmutableConicGradientBrush(
CreateStopsFromSolidColorBrush(solidColorBrush, oldConic.GradientStops), solidColorBrush.Opacity, CreateStopsFromSolidColorBrush(solidColorBrush, oldConic.GradientStops), solidColorBrush.Opacity,
oldConic.Transform is { } ? new ImmutableTransform(oldConic.Transform.Value) : null, oldConic.Transform is { } ? new ImmutableTransform(oldConic.Transform.Value) : null,
oldConic.TransformOrigin,
oldConic.SpreadMethod, oldConic.Center, oldConic.Angle); oldConic.SpreadMethod, oldConic.Center, oldConic.Angle);
case ILinearGradientBrush oldLinear: case ILinearGradientBrush oldLinear:
return new ImmutableLinearGradientBrush( return new ImmutableLinearGradientBrush(
CreateStopsFromSolidColorBrush(solidColorBrush, oldLinear.GradientStops), solidColorBrush.Opacity, CreateStopsFromSolidColorBrush(solidColorBrush, oldLinear.GradientStops), solidColorBrush.Opacity,
oldLinear.Transform is { } ? new ImmutableTransform(oldLinear.Transform.Value) : null, oldLinear.Transform is { } ? new ImmutableTransform(oldLinear.Transform.Value) : null,
oldLinear.TransformOrigin,
oldLinear.SpreadMethod, oldLinear.StartPoint, oldLinear.EndPoint); oldLinear.SpreadMethod, oldLinear.StartPoint, oldLinear.EndPoint);
default: default:

15
src/Avalonia.Base/Media/Brush.cs

@ -24,6 +24,12 @@ namespace Avalonia.Media
public static readonly StyledProperty<ITransform?> TransformProperty = public static readonly StyledProperty<ITransform?> TransformProperty =
AvaloniaProperty.Register<Brush, ITransform?>(nameof(Transform)); AvaloniaProperty.Register<Brush, ITransform?>(nameof(Transform));
/// <summary>
/// Defines the <see cref="TransformOrigin"/> property
/// </summary>
public static readonly StyledProperty<RelativePoint> TransformOriginProperty =
AvaloniaProperty.Register<Brush, RelativePoint>(nameof(TransformOrigin));
/// <inheritdoc/> /// <inheritdoc/>
public event EventHandler? Invalidated; public event EventHandler? Invalidated;
@ -51,6 +57,15 @@ namespace Avalonia.Media
set { SetValue(TransformProperty, value); } set { SetValue(TransformProperty, value); }
} }
/// <summary>
/// Gets or sets the origin of the brush <see cref="Transform"/>
/// </summary>
public RelativePoint TransformOrigin
{
get => GetValue(TransformOriginProperty);
set => SetValue(TransformOriginProperty, value);
}
/// <summary> /// <summary>
/// Parses a brush string. /// Parses a brush string.
/// </summary> /// </summary>

5
src/Avalonia.Base/Media/IBrush.cs

@ -19,5 +19,10 @@ namespace Avalonia.Media
/// Gets the transform of the brush. /// Gets the transform of the brush.
/// </summary> /// </summary>
ITransform? Transform { get; } ITransform? Transform { get; }
/// <summary>
/// Gets the origin of the brushes <see cref="Transform"/>
/// </summary>
RelativePoint TransformOrigin { get; }
} }
} }

4
src/Avalonia.Base/Media/Immutable/ImmutableConicGradientBrush.cs

@ -13,6 +13,7 @@ namespace Avalonia.Media.Immutable
/// <param name="gradientStops">The gradient stops.</param> /// <param name="gradientStops">The gradient stops.</param>
/// <param name="opacity">The opacity of the brush.</param> /// <param name="opacity">The opacity of the brush.</param>
/// <param name="transform">The transform of the brush.</param> /// <param name="transform">The transform of the brush.</param>
/// <param name="transformOrigin">The transform origin of the brush</param>
/// <param name="spreadMethod">The spread method.</param> /// <param name="spreadMethod">The spread method.</param>
/// <param name="center">The center point for the gradient.</param> /// <param name="center">The center point for the gradient.</param>
/// <param name="angle">The starting angle for the gradient.</param> /// <param name="angle">The starting angle for the gradient.</param>
@ -20,10 +21,11 @@ namespace Avalonia.Media.Immutable
IReadOnlyList<ImmutableGradientStop> gradientStops, IReadOnlyList<ImmutableGradientStop> gradientStops,
double opacity = 1, double opacity = 1,
ImmutableTransform? transform = null, ImmutableTransform? transform = null,
RelativePoint? transformOrigin = null,
GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad, GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad,
RelativePoint? center = null, RelativePoint? center = null,
double angle = 0) double angle = 0)
: base(gradientStops, opacity, transform, spreadMethod) : base(gradientStops, opacity, transform, transformOrigin, spreadMethod)
{ {
Center = center ?? RelativePoint.Center; Center = center ?? RelativePoint.Center;
Angle = angle; Angle = angle;

11
src/Avalonia.Base/Media/Immutable/ImmutableGradientBrush.cs

@ -13,16 +13,19 @@ namespace Avalonia.Media.Immutable
/// <param name="gradientStops">The gradient stops.</param> /// <param name="gradientStops">The gradient stops.</param>
/// <param name="opacity">The opacity of the brush.</param> /// <param name="opacity">The opacity of the brush.</param>
/// <param name="transform">The transform of the brush.</param> /// <param name="transform">The transform of the brush.</param>
/// <param name="transformOrigin">The transform origin of the brush</param>
/// <param name="spreadMethod">The spread method.</param> /// <param name="spreadMethod">The spread method.</param>
protected ImmutableGradientBrush( protected ImmutableGradientBrush(
IReadOnlyList<ImmutableGradientStop> gradientStops, IReadOnlyList<ImmutableGradientStop> gradientStops,
double opacity, double opacity,
ImmutableTransform? transform, ImmutableTransform? transform,
RelativePoint? transformOrigin,
GradientSpreadMethod spreadMethod) GradientSpreadMethod spreadMethod)
{ {
GradientStops = gradientStops; GradientStops = gradientStops;
Opacity = opacity; Opacity = opacity;
Transform = transform; Transform = transform;
TransformOrigin = transformOrigin.HasValue ? transformOrigin.Value : RelativePoint.TopLeft;
SpreadMethod = spreadMethod; SpreadMethod = spreadMethod;
} }
@ -31,7 +34,8 @@ namespace Avalonia.Media.Immutable
/// </summary> /// </summary>
/// <param name="source">The brush from which this brush's properties should be copied.</param> /// <param name="source">The brush from which this brush's properties should be copied.</param>
protected ImmutableGradientBrush(GradientBrush source) protected ImmutableGradientBrush(GradientBrush source)
: this(source.GradientStops.ToImmutable(), source.Opacity, source.Transform?.ToImmutable(), source.SpreadMethod) : this(source.GradientStops.ToImmutable(), source.Opacity, source.Transform?.ToImmutable(),
source.TransformOrigin, source.SpreadMethod)
{ {
} }
@ -47,6 +51,11 @@ namespace Avalonia.Media.Immutable
/// </summary> /// </summary>
public ITransform? Transform { get; } public ITransform? Transform { get; }
/// <summary>
/// Gets the transform origin of the brush
/// </summary>
public RelativePoint TransformOrigin { get; }
/// <inheritdoc/> /// <inheritdoc/>
public GradientSpreadMethod SpreadMethod { get; } public GradientSpreadMethod SpreadMethod { get; }
} }

3
src/Avalonia.Base/Media/Immutable/ImmutableImageBrush.cs

@ -16,6 +16,7 @@ namespace Avalonia.Media.Immutable
/// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param> /// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param>
/// <param name="opacity">The opacity of the brush.</param> /// <param name="opacity">The opacity of the brush.</param>
/// <param name="transform">The transform of the brush.</param> /// <param name="transform">The transform of the brush.</param>
/// <param name="transformOrigin">The transform origin of the brush</param>
/// <param name="sourceRect">The rectangle of the source image that will be displayed.</param> /// <param name="sourceRect">The rectangle of the source image that will be displayed.</param>
/// <param name="stretch"> /// <param name="stretch">
/// How the source rectangle will be stretched to fill the destination rect. /// How the source rectangle will be stretched to fill the destination rect.
@ -29,6 +30,7 @@ namespace Avalonia.Media.Immutable
RelativeRect? destinationRect = null, RelativeRect? destinationRect = null,
double opacity = 1, double opacity = 1,
ImmutableTransform? transform = null, ImmutableTransform? transform = null,
RelativePoint transformOrigin = new RelativePoint(),
RelativeRect? sourceRect = null, RelativeRect? sourceRect = null,
Stretch stretch = Stretch.Uniform, Stretch stretch = Stretch.Uniform,
TileMode tileMode = TileMode.None, TileMode tileMode = TileMode.None,
@ -39,6 +41,7 @@ namespace Avalonia.Media.Immutable
destinationRect ?? RelativeRect.Fill, destinationRect ?? RelativeRect.Fill,
opacity, opacity,
transform, transform,
transformOrigin,
sourceRect ?? RelativeRect.Fill, sourceRect ?? RelativeRect.Fill,
stretch, stretch,
tileMode, tileMode,

4
src/Avalonia.Base/Media/Immutable/ImmutableLinearGradientBrush.cs

@ -13,6 +13,7 @@ namespace Avalonia.Media.Immutable
/// <param name="gradientStops">The gradient stops.</param> /// <param name="gradientStops">The gradient stops.</param>
/// <param name="opacity">The opacity of the brush.</param> /// <param name="opacity">The opacity of the brush.</param>
/// <param name="transform">The transform of the brush.</param> /// <param name="transform">The transform of the brush.</param>
/// <param name="transformOrigin">The transform origin of the brush</param>
/// <param name="spreadMethod">The spread method.</param> /// <param name="spreadMethod">The spread method.</param>
/// <param name="startPoint">The start point for the gradient.</param> /// <param name="startPoint">The start point for the gradient.</param>
/// <param name="endPoint">The end point for the gradient.</param> /// <param name="endPoint">The end point for the gradient.</param>
@ -20,10 +21,11 @@ namespace Avalonia.Media.Immutable
IReadOnlyList<ImmutableGradientStop> gradientStops, IReadOnlyList<ImmutableGradientStop> gradientStops,
double opacity = 1, double opacity = 1,
ImmutableTransform? transform = null, ImmutableTransform? transform = null,
RelativePoint? transformOrigin = null,
GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad, GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad,
RelativePoint? startPoint = null, RelativePoint? startPoint = null,
RelativePoint? endPoint = null) RelativePoint? endPoint = null)
: base(gradientStops, opacity, transform, spreadMethod) : base(gradientStops, opacity, transform, transformOrigin, spreadMethod)
{ {
StartPoint = startPoint ?? RelativePoint.TopLeft; StartPoint = startPoint ?? RelativePoint.TopLeft;
EndPoint = endPoint ?? RelativePoint.BottomRight; EndPoint = endPoint ?? RelativePoint.BottomRight;

4
src/Avalonia.Base/Media/Immutable/ImmutableRadialGradientBrush.cs

@ -13,6 +13,7 @@ namespace Avalonia.Media.Immutable
/// <param name="gradientStops">The gradient stops.</param> /// <param name="gradientStops">The gradient stops.</param>
/// <param name="opacity">The opacity of the brush.</param> /// <param name="opacity">The opacity of the brush.</param>
/// <param name="transform">The transform of the brush.</param> /// <param name="transform">The transform of the brush.</param>
/// <param name="transformOrigin">The transform origin of the brush</param>
/// <param name="spreadMethod">The spread method.</param> /// <param name="spreadMethod">The spread method.</param>
/// <param name="center">The start point for the gradient.</param> /// <param name="center">The start point for the gradient.</param>
/// <param name="gradientOrigin"> /// <param name="gradientOrigin">
@ -25,11 +26,12 @@ namespace Avalonia.Media.Immutable
IReadOnlyList<ImmutableGradientStop> gradientStops, IReadOnlyList<ImmutableGradientStop> gradientStops,
double opacity = 1, double opacity = 1,
ImmutableTransform? transform = null, ImmutableTransform? transform = null,
RelativePoint? transformOrigin = null,
GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad, GradientSpreadMethod spreadMethod = GradientSpreadMethod.Pad,
RelativePoint? center = null, RelativePoint? center = null,
RelativePoint? gradientOrigin = null, RelativePoint? gradientOrigin = null,
double radius = 0.5) double radius = 0.5)
: base(gradientStops, opacity, transform, spreadMethod) : base(gradientStops, opacity, transform, transformOrigin, spreadMethod)
{ {
Center = center ?? RelativePoint.Center; Center = center ?? RelativePoint.Center;
GradientOrigin = gradientOrigin ?? RelativePoint.Center; GradientOrigin = gradientOrigin ?? RelativePoint.Center;

5
src/Avalonia.Base/Media/Immutable/ImmutableSolidColorBrush.cs

@ -53,6 +53,11 @@ namespace Avalonia.Media.Immutable
/// </summary> /// </summary>
public ITransform? Transform { get; } public ITransform? Transform { get; }
/// <summary>
/// Gets the transform origin of the brush
/// </summary>
public RelativePoint TransformOrigin { get; }
public bool Equals(ImmutableSolidColorBrush? other) public bool Equals(ImmutableSolidColorBrush? other)
{ {
if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(null, other)) return false;

9
src/Avalonia.Base/Media/Immutable/ImmutableTileBrush.cs

@ -15,6 +15,7 @@ namespace Avalonia.Media.Immutable
/// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param> /// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param>
/// <param name="opacity">The opacity of the brush.</param> /// <param name="opacity">The opacity of the brush.</param>
/// <param name="transform">The transform of the brush.</param> /// <param name="transform">The transform of the brush.</param>
/// <param name="transformOrigin">The transform origin of the brush</param>
/// <param name="sourceRect">The rectangle of the source image that will be displayed.</param> /// <param name="sourceRect">The rectangle of the source image that will be displayed.</param>
/// <param name="stretch"> /// <param name="stretch">
/// How the source rectangle will be stretched to fill the destination rect. /// How the source rectangle will be stretched to fill the destination rect.
@ -27,6 +28,7 @@ namespace Avalonia.Media.Immutable
RelativeRect destinationRect, RelativeRect destinationRect,
double opacity, double opacity,
ImmutableTransform? transform, ImmutableTransform? transform,
RelativePoint transformOrigin,
RelativeRect sourceRect, RelativeRect sourceRect,
Stretch stretch, Stretch stretch,
TileMode tileMode, TileMode tileMode,
@ -37,6 +39,7 @@ namespace Avalonia.Media.Immutable
DestinationRect = destinationRect; DestinationRect = destinationRect;
Opacity = opacity; Opacity = opacity;
Transform = transform; Transform = transform;
TransformOrigin = transformOrigin;
SourceRect = sourceRect; SourceRect = sourceRect;
Stretch = stretch; Stretch = stretch;
TileMode = tileMode; TileMode = tileMode;
@ -54,6 +57,7 @@ namespace Avalonia.Media.Immutable
source.DestinationRect, source.DestinationRect,
source.Opacity, source.Opacity,
source.Transform?.ToImmutable(), source.Transform?.ToImmutable(),
source.TransformOrigin,
source.SourceRect, source.SourceRect,
source.Stretch, source.Stretch,
source.TileMode, source.TileMode,
@ -78,6 +82,11 @@ namespace Avalonia.Media.Immutable
/// </summary> /// </summary>
public ITransform? Transform { get; } public ITransform? Transform { get; }
/// <summary>
/// Gets the transform origin of the brush
/// </summary>
public RelativePoint TransformOrigin { get; }
/// <inheritdoc/> /// <inheritdoc/>
public RelativeRect SourceRect { get; } public RelativeRect SourceRect { get; }

3
src/Avalonia.Base/Media/Immutable/ImmutableVisualBrush.cs

@ -17,6 +17,7 @@ namespace Avalonia.Media.Immutable
/// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param> /// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param>
/// <param name="opacity">The opacity of the brush.</param> /// <param name="opacity">The opacity of the brush.</param>
/// <param name="transform">The transform of the brush.</param> /// <param name="transform">The transform of the brush.</param>
/// <param name="transformOrigin">The transform origin of the brush</param>
/// <param name="sourceRect">The rectangle of the source image that will be displayed.</param> /// <param name="sourceRect">The rectangle of the source image that will be displayed.</param>
/// <param name="stretch"> /// <param name="stretch">
/// How the source rectangle will be stretched to fill the destination rect. /// How the source rectangle will be stretched to fill the destination rect.
@ -30,6 +31,7 @@ namespace Avalonia.Media.Immutable
RelativeRect? destinationRect = null, RelativeRect? destinationRect = null,
double opacity = 1, double opacity = 1,
ImmutableTransform? transform = null, ImmutableTransform? transform = null,
RelativePoint transformOrigin = new RelativePoint(),
RelativeRect? sourceRect = null, RelativeRect? sourceRect = null,
Stretch stretch = Stretch.Uniform, Stretch stretch = Stretch.Uniform,
TileMode tileMode = TileMode.None, TileMode tileMode = TileMode.None,
@ -40,6 +42,7 @@ namespace Avalonia.Media.Immutable
destinationRect ?? RelativeRect.Fill, destinationRect ?? RelativeRect.Fill,
opacity, opacity,
transform, transform,
transformOrigin,
sourceRect ?? RelativeRect.Fill, sourceRect ?? RelativeRect.Fill,
stretch, stretch,
tileMode, tileMode,

39
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -181,7 +181,8 @@ namespace Avalonia.Skia
var size = geometry.Bounds.Size; var size = geometry.Bounds.Size;
using (var fill = brush != null ? CreatePaint(_fillPaint, brush, size) : default(PaintWrapper)) using (var fill = brush != null ? CreatePaint(_fillPaint, brush, size) : default(PaintWrapper))
using (var stroke = pen?.Brush != null ? CreatePaint(_strokePaint, pen, size) : default(PaintWrapper)) using (var stroke = pen?.Brush != null ? CreatePaint(_strokePaint, pen,
size.Inflate(new Thickness(pen?.Thickness / 2 ?? 0))) : default(PaintWrapper))
{ {
if (fill.Paint != null) if (fill.Paint != null)
{ {
@ -398,7 +399,7 @@ namespace Avalonia.Skia
if (pen?.Brush != null) if (pen?.Brush != null)
{ {
using (var paint = CreatePaint(_strokePaint, pen, rect.Rect.Size)) using (var paint = CreatePaint(_strokePaint, pen, rect.Rect.Size.Inflate(new Thickness(pen?.Thickness / 2 ?? 0))))
{ {
if (paint.Paint is object) if (paint.Paint is object)
{ {
@ -433,7 +434,7 @@ namespace Avalonia.Skia
if (pen?.Brush != null) if (pen?.Brush != null)
{ {
using (var paint = CreatePaint(_strokePaint, pen, rect.Size)) using (var paint = CreatePaint(_strokePaint, pen, rect.Size.Inflate(new Thickness(pen?.Thickness / 2 ?? 0))))
{ {
if (paint.Paint is object) if (paint.Paint is object)
{ {
@ -625,8 +626,12 @@ namespace Avalonia.Skia
} }
else else
{ {
var transformOrigin = linearGradient.TransformOrigin.ToPixels(targetSize);
var offset = Matrix.CreateTranslation(transformOrigin);
var transform = (-offset) * linearGradient.Transform.Value * (offset);
using (var shader = using (var shader =
SKShader.CreateLinearGradient(start, end, stopColors, stopOffsets, tileMode, linearGradient.Transform.Value.ToSKMatrix())) SKShader.CreateLinearGradient(start, end, stopColors, stopOffsets, tileMode, transform.ToSKMatrix()))
{ {
paintWrapper.Paint.Shader = shader; paintWrapper.Paint.Shader = shader;
} }
@ -654,8 +659,12 @@ namespace Avalonia.Skia
} }
else else
{ {
var transformOrigin = radialGradient.TransformOrigin.ToPixels(targetSize);
var offset = Matrix.CreateTranslation(transformOrigin);
var transform = (-offset) * radialGradient.Transform.Value * (offset);
using (var shader = using (var shader =
SKShader.CreateRadialGradient(center, radius, stopColors, stopOffsets, tileMode, radialGradient.Transform.Value.ToSKMatrix())) SKShader.CreateRadialGradient(center, radius, stopColors, stopOffsets, tileMode, transform.ToSKMatrix()))
{ {
paintWrapper.Paint.Shader = shader; paintWrapper.Paint.Shader = shader;
} }
@ -694,9 +703,14 @@ namespace Avalonia.Skia
} }
else else
{ {
var transformOrigin = radialGradient.TransformOrigin.ToPixels(targetSize);
var offset = Matrix.CreateTranslation(transformOrigin);
var transform = (-offset) * radialGradient.Transform.Value * (offset);
using (var shader = SKShader.CreateCompose( using (var shader = SKShader.CreateCompose(
SKShader.CreateColor(reversedColors[0]), SKShader.CreateColor(reversedColors[0]),
SKShader.CreateTwoPointConicalGradient(center, radius, origin, 0, reversedColors, reversedStops, tileMode, radialGradient.Transform.Value.ToSKMatrix()) SKShader.CreateTwoPointConicalGradient(center, radius, origin, 0, reversedColors, reversedStops, tileMode, transform.ToSKMatrix())
)) ))
{ {
paintWrapper.Paint.Shader = shader; paintWrapper.Paint.Shader = shader;
@ -717,7 +731,12 @@ namespace Avalonia.Skia
if (conicGradient.Transform is { }) if (conicGradient.Transform is { })
{ {
rotation = rotation.PreConcat(conicGradient.Transform.Value.ToSKMatrix());
var transformOrigin = conicGradient.TransformOrigin.ToPixels(targetSize);
var offset = Matrix.CreateTranslation(transformOrigin);
var transform = (-offset) * conicGradient.Transform.Value * (offset);
rotation = rotation.PreConcat(transform.ToSKMatrix());
} }
using (var shader = using (var shader =
@ -794,7 +813,11 @@ namespace Avalonia.Skia
if (tileBrush.Transform is { }) if (tileBrush.Transform is { })
{ {
paintTransform = paintTransform.PreConcat(tileBrush.Transform.Value.ToSKMatrix()); var origin = tileBrush.TransformOrigin.ToPixels(targetSize);
var offset = Matrix.CreateTranslation(origin);
var transform = (-offset) * tileBrush.Transform.Value * (offset);
paintTransform = paintTransform.PreConcat(transform.ToSKMatrix());
} }
using (var shader = image.ToShader(tileX, tileY, paintTransform)) using (var shader = image.ToShader(tileX, tileY, paintTransform))

Loading…
Cancel
Save