Browse Source

Merge branch 'master' into update-obsolete-api-usages

pull/3461/head
Dariusz Komosiński 7 years ago
committed by GitHub
parent
commit
2f4c63ccc2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      src/Avalonia.Visuals/Media/Color.cs

38
src/Avalonia.Visuals/Media/Color.cs

@ -3,7 +3,6 @@
using System;
using System.Globalization;
using Avalonia.Animation;
using Avalonia.Animation.Animators;
namespace Avalonia.Media
@ -11,7 +10,7 @@ namespace Avalonia.Media
/// <summary>
/// An ARGB color.
/// </summary>
public readonly struct Color
public readonly struct Color : IEquatable<Color>
{
static Color()
{
@ -144,5 +143,40 @@ namespace Avalonia.Media
{
return ((uint)A << 24) | ((uint)R << 16) | ((uint)G << 8) | (uint)B;
}
/// <summary>
/// Check if two colors are equal.
/// </summary>
public bool Equals(Color other)
{
return A == other.A && R == other.R && G == other.G && B == other.B;
}
public override bool Equals(object obj)
{
return obj is Color other && Equals(other);
}
public override int GetHashCode()
{
unchecked
{
int hashCode = A.GetHashCode();
hashCode = (hashCode * 397) ^ R.GetHashCode();
hashCode = (hashCode * 397) ^ G.GetHashCode();
hashCode = (hashCode * 397) ^ B.GetHashCode();
return hashCode;
}
}
public static bool operator ==(Color left, Color right)
{
return left.Equals(right);
}
public static bool operator !=(Color left, Color right)
{
return !left.Equals(right);
}
}
}

Loading…
Cancel
Save