blob: 1677ee46ec48fb4cd06c31954d7893e2c7c0a1f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Xamarin.PropertyEditing.Drawing
{
/// <summary>
/// An abstract description of a gradient brush, composed of gradient stops.
/// </summary>
[Serializable]
public abstract class CommonGradientBrush : CommonBrush, IEquatable<CommonGradientBrush>
{
protected CommonGradientBrush (
IEnumerable<CommonGradientStop> stops,
CommonColorInterpolationMode colorInterpolationMode = CommonColorInterpolationMode.SRgbLinearInterpolation,
CommonBrushMappingMode mappingMode = CommonBrushMappingMode.RelativeToBoundingBox,
CommonGradientSpreadMethod spreadMethod = CommonGradientSpreadMethod.Pad,
double opacity = 1.0)
: base(opacity)
{
if (stops == null) {
throw new ArgumentNullException (nameof (stops));
}
GradientStops = stops.ToArray ();
ColorInterpolationMode = colorInterpolationMode;
MappingMode = mappingMode;
SpreadMethod = spreadMethod;
}
/// <summary>
/// The brush's gradient stops.
/// </summary>
public IReadOnlyList<CommonGradientStop> GradientStops { get; }
/// <summary>
/// How the gradient's colors are interpolated.
/// </summary>
public CommonColorInterpolationMode ColorInterpolationMode { get; }
/// <summary>
/// Specifies whether the gradient brush's positioning coordinates are
/// absolute or relative to the output area.
/// </summary>
public CommonBrushMappingMode MappingMode { get; }
/// <summary>
/// Specifies how to draw a gradient that starts or ends inside the
/// bounds of the object to be painted.
/// </summary>
public CommonGradientSpreadMethod SpreadMethod { get; }
public override bool Equals (object obj)
{
var brush = obj as CommonGradientBrush;
if (brush == null) return false;
return Equals (brush);
}
public bool Equals (CommonGradientBrush other)
{
if (other == null) return false;
if (GradientStops.Count != other.GradientStops.Count) return false;
for(var i = 0; i < GradientStops.Count; i++) {
if (GradientStops[i] != other.GradientStops[i]) return false;
}
return base.Equals (other) &&
ColorInterpolationMode == other.ColorInterpolationMode &&
MappingMode == other.MappingMode &&
SpreadMethod == other.SpreadMethod;
}
public static bool operator == (CommonGradientBrush left, CommonGradientBrush right) => Equals (left, right);
public static bool operator != (CommonGradientBrush left, CommonGradientBrush right) => !Equals (left, right);
public override int GetHashCode ()
{
var hashCode = base.GetHashCode ();
unchecked {
foreach(var stop in GradientStops) {
hashCode = hashCode * -1521134295 + stop.GetHashCode();
}
hashCode = hashCode * -1521134295 + ColorInterpolationMode.GetHashCode ();
hashCode = hashCode * -1521134295 + MappingMode.GetHashCode ();
hashCode = hashCode * -1521134295 + SpreadMethod.GetHashCode ();
}
return hashCode;
}
}
}
|