Browse Source

Fix RadialGradientBrush.Radius obsolete usages (#14774)

pull/14782/head
Julien Lebosquain 3 years ago
committed by GitHub
parent
commit
a63474300b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs
  2. 8
      src/Avalonia.Base/Media/RadialGradientBrush.cs
  3. 1
      src/Avalonia.Base/RelativePoint.cs
  4. 6
      tests/Avalonia.RenderTests/Media/RadialGradientBrushTests.cs

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

@ -129,7 +129,8 @@ namespace Avalonia.Animation.Animators
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.TransformOrigin,
oldRadial.SpreadMethod, oldRadial.Center, oldRadial.GradientOrigin, oldRadial.Radius); oldRadial.SpreadMethod, oldRadial.Center, oldRadial.GradientOrigin,
oldRadial.RadiusX, oldRadial.RadiusY);
case IConicGradientBrush oldConic: case IConicGradientBrush oldConic:
return new ImmutableConicGradientBrush( return new ImmutableConicGradientBrush(

8
src/Avalonia.Base/Media/RadialGradientBrush.cs

@ -31,6 +31,7 @@ namespace Avalonia.Media
/// <summary> /// <summary>
/// Defines the <see cref="Radius"/> property. /// Defines the <see cref="Radius"/> property.
/// </summary> /// </summary>
[Obsolete("Use RadiusX/RadiusY, note that those properties use _relative_ values, so Radius=0.55 would become RadiusX=55% RadiusY=55%. Radius property is always relative even if the rest of the brush uses absolute values.")]
public static readonly StyledProperty<double> RadiusProperty = public static readonly StyledProperty<double> RadiusProperty =
AvaloniaProperty.Register<RadialGradientBrush, double>( AvaloniaProperty.Register<RadialGradientBrush, double>(
nameof(Radius), nameof(Radius),
@ -73,7 +74,9 @@ namespace Avalonia.Media
/// Gets or sets the horizontal radius of the outermost circle of the radial /// Gets or sets the horizontal radius of the outermost circle of the radial
/// gradient. /// gradient.
/// </summary> /// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
[DependsOn(nameof(Radius))] [DependsOn(nameof(Radius))]
#pragma warning restore CS0618 // Type or member is obsolete
public RelativeScalar RadiusX public RelativeScalar RadiusX
{ {
get { return GetValue(RadiusXProperty); } get { return GetValue(RadiusXProperty); }
@ -84,7 +87,9 @@ namespace Avalonia.Media
/// Gets or sets the vertical radius of the outermost circle of the radial /// Gets or sets the vertical radius of the outermost circle of the radial
/// gradient. /// gradient.
/// </summary> /// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
[DependsOn(nameof(Radius))] [DependsOn(nameof(Radius))]
#pragma warning restore CS0618 // Type or member is obsolete
public RelativeScalar RadiusY public RelativeScalar RadiusY
{ {
get { return GetValue(RadiusYProperty); } get { return GetValue(RadiusYProperty); }
@ -119,12 +124,15 @@ namespace Avalonia.Media
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{ {
#pragma warning disable CS0618 // Type or member is obsolete: compatibility code for Radius
if (change.IsEffectiveValueChange && change.Property == RadiusProperty) if (change.IsEffectiveValueChange && change.Property == RadiusProperty)
{ {
var compatibilityValue = new RelativeScalar(Radius, RelativeUnit.Relative); var compatibilityValue = new RelativeScalar(Radius, RelativeUnit.Relative);
SetCurrentValue(RadiusXProperty, compatibilityValue); SetCurrentValue(RadiusXProperty, compatibilityValue);
SetCurrentValue(RadiusYProperty, compatibilityValue); SetCurrentValue(RadiusYProperty, compatibilityValue);
} }
#pragma warning restore CS0618 // Type or member is obsolete
base.OnPropertyChanged(change); base.OnPropertyChanged(change);
} }
} }

1
src/Avalonia.Base/RelativePoint.cs

@ -142,7 +142,6 @@ namespace Avalonia
/// </summary> /// </summary>
/// <param name="size">The size of the visual.</param> /// <param name="size">The size of the visual.</param>
/// <returns>The origin point in pixels.</returns> /// <returns>The origin point in pixels.</returns>
[Obsolete("Use ToPixels(Rect) overload to properly map relative points")]
public Point ToPixels(Size size) public Point ToPixels(Size size)
{ {
return _unit == RelativeUnit.Absolute ? return _unit == RelativeUnit.Absolute ?

6
tests/Avalonia.RenderTests/Media/RadialGradientBrushTests.cs

@ -125,7 +125,8 @@ namespace Avalonia.Direct2D1.RenderTests.Media
}, },
GradientOrigin = new RelativePoint(0.25, 0.25, RelativeUnit.Relative), GradientOrigin = new RelativePoint(0.25, 0.25, RelativeUnit.Relative),
Center = new RelativePoint(0.5, 0.5, RelativeUnit.Relative), Center = new RelativePoint(0.5, 0.5, RelativeUnit.Relative),
Radius = 0.5 RadiusX = RelativeScalar.Middle,
RadiusY = RelativeScalar.Middle
} }
} }
}; };
@ -157,7 +158,8 @@ namespace Avalonia.Direct2D1.RenderTests.Media
}, },
GradientOrigin = new RelativePoint(0.1, 0.1, RelativeUnit.Relative), GradientOrigin = new RelativePoint(0.1, 0.1, RelativeUnit.Relative),
Center = new RelativePoint(0.5, 0.5, RelativeUnit.Relative), Center = new RelativePoint(0.5, 0.5, RelativeUnit.Relative),
Radius = 0.5 RadiusX = RelativeScalar.Middle,
RadiusY = RelativeScalar.Middle
} }
} }
}; };

Loading…
Cancel
Save