3 changed files with 135 additions and 12 deletions
@ -1,17 +1,67 @@ |
|||
namespace Avalonia.Media |
|||
{ |
|||
public class ExperimentalAcrylicBrush : IExperimentalAcrylicBrush |
|||
public class ExperimentalAcrylicBrush : Brush, IExperimentalAcrylicBrush |
|||
{ |
|||
public AcrylicBackgroundSource BackgroundSource { get; set; } |
|||
static ExperimentalAcrylicBrush() |
|||
{ |
|||
AffectsRender<ExperimentalAcrylicBrush>( |
|||
TintColorProperty, |
|||
BackgroundSourceProperty, |
|||
TintOpacityProperty, |
|||
TintLuminosityOpacityProperty); |
|||
} |
|||
|
|||
public Color TintColor { get; set; } |
|||
/// <summary>
|
|||
/// Defines the <see cref="TintColor"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<Color> TintColorProperty = |
|||
AvaloniaProperty.Register<ExperimentalAcrylicBrush, Color>(nameof(TintColor)); |
|||
|
|||
public double TintOpacity { get; set; } |
|||
public static readonly StyledProperty<AcrylicBackgroundSource> BackgroundSourceProperty = |
|||
AvaloniaProperty.Register<ExperimentalAcrylicBrush, AcrylicBackgroundSource>(nameof(BackgroundSource)); |
|||
|
|||
public Color FallbackColor { get; set; } |
|||
public static readonly StyledProperty<double> TintOpacityProperty = |
|||
AvaloniaProperty.Register<ExperimentalAcrylicBrush, double>(nameof(TintOpacity)); |
|||
|
|||
public double TintLuminosityOpacity { get; set; } |
|||
public static readonly StyledProperty<double> TintLuminosityOpacityProperty = |
|||
AvaloniaProperty.Register<ExperimentalAcrylicBrush, double>(nameof(TintLuminosityOpacity)); |
|||
|
|||
public double Opacity { get; set; } |
|||
public static readonly StyledProperty<Color> FallbackColorProperty = |
|||
AvaloniaProperty.Register<ExperimentalAcrylicBrush, Color>(nameof(FallbackColor)); |
|||
|
|||
public AcrylicBackgroundSource BackgroundSource |
|||
{ |
|||
get => GetValue(BackgroundSourceProperty); |
|||
set => SetValue(BackgroundSourceProperty, value); |
|||
} |
|||
|
|||
public Color TintColor |
|||
{ |
|||
get => GetValue(TintColorProperty); |
|||
set => SetValue(TintColorProperty, value); |
|||
} |
|||
|
|||
public double TintOpacity |
|||
{ |
|||
get => GetValue(TintOpacityProperty); |
|||
set => SetValue(TintOpacityProperty, value); |
|||
} |
|||
|
|||
public Color FallbackColor |
|||
{ |
|||
get => GetValue(FallbackColorProperty); |
|||
set => SetValue(FallbackColorProperty, value); |
|||
} |
|||
|
|||
public double TintLuminosityOpacity |
|||
{ |
|||
get => GetValue(TintLuminosityOpacityProperty); |
|||
set => SetValue(TintLuminosityOpacityProperty, value); |
|||
} |
|||
|
|||
public override IBrush ToImmutable() |
|||
{ |
|||
return new ImmutableExperimentalAcrylicBrush(this); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,73 @@ |
|||
using System; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
public readonly struct ImmutableExperimentalAcrylicBrush : IExperimentalAcrylicBrush, IEquatable<ImmutableExperimentalAcrylicBrush> |
|||
{ |
|||
public ImmutableExperimentalAcrylicBrush(IExperimentalAcrylicBrush brush) |
|||
{ |
|||
BackgroundSource = brush.BackgroundSource; |
|||
TintColor = brush.TintColor; |
|||
TintOpacity = brush.TintOpacity; |
|||
TintLuminosityOpacity = brush.TintLuminosityOpacity; |
|||
FallbackColor = brush.FallbackColor; |
|||
Opacity = brush.Opacity; |
|||
} |
|||
|
|||
public AcrylicBackgroundSource BackgroundSource { get; } |
|||
|
|||
public Color TintColor { get; } |
|||
|
|||
public double TintOpacity { get; } |
|||
|
|||
public double TintLuminosityOpacity { get; } |
|||
|
|||
public Color FallbackColor { get; } |
|||
|
|||
public double Opacity { get; } |
|||
|
|||
public bool Equals(ImmutableExperimentalAcrylicBrush other) |
|||
{ |
|||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
|||
return |
|||
TintColor == other.TintColor && |
|||
Opacity == other.Opacity && |
|||
TintOpacity == other.TintOpacity && |
|||
BackgroundSource == other.BackgroundSource && |
|||
TintLuminosityOpacity == other.TintLuminosityOpacity && |
|||
FallbackColor == other.FallbackColor; |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
return obj is ImmutableExperimentalAcrylicBrush other && Equals(other); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
unchecked |
|||
{ |
|||
int hash = 17; |
|||
|
|||
hash = (hash * 23) + TintColor.GetHashCode(); |
|||
hash = (hash * 23) + TintLuminosityOpacity.GetHashCode(); |
|||
hash = (hash * 23) + Opacity.GetHashCode(); |
|||
hash = (hash * 23) + TintOpacity.GetHashCode(); |
|||
hash = (hash * 23) + BackgroundSource.GetHashCode(); |
|||
hash = (hash * 23) + FallbackColor.GetHashCode(); |
|||
|
|||
return hash; |
|||
} |
|||
} |
|||
|
|||
public static bool operator ==(ImmutableExperimentalAcrylicBrush left, ImmutableExperimentalAcrylicBrush right) |
|||
{ |
|||
return left.Equals(right); |
|||
} |
|||
|
|||
public static bool operator !=(ImmutableExperimentalAcrylicBrush left, ImmutableExperimentalAcrylicBrush right) |
|||
{ |
|||
return !left.Equals(right); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue