IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
Opacity.cs
Go to the documentation of this file.
2
15public class Opacity
16{
17 private uint _value = Maximum;
18
23 public Opacity() : this(Maximum)
24 {
25 }
26
34 public Opacity(uint value)
35 {
36 Value = value; // validation handled in property setter
37 }
38
43 public static uint Minimum { get; } = 0;
44
49 public static uint Maximum { get; } = 100;
50
58 public uint Value
59 {
60 get => _value;
61 set
62 {
63 if (value > Maximum)
64 {
65 throw new IcvOutOfRangeException(
66 $"The given opacity {value} is out of range. The opacity value has to be within the range of {Minimum} and {Maximum}.");
67 }
68
69 _value = value;
70 }
71 }
72
77 public static IEqualityComparer<Opacity> Comparer { get; } = new OpacityEqualityComparer();
78
86 public override string ToString()
87 {
88 return Value.ToString();
89 }
90
91 private sealed class OpacityEqualityComparer : IEqualityComparer<Opacity>
92 {
93 public bool Equals(Opacity x, Opacity y)
94 {
95 if (ReferenceEquals(x, y))
96 {
97 return true;
98 }
99
100 if (ReferenceEquals(x, null))
101 {
102 return false;
103 }
104
105 if (ReferenceEquals(y, null))
106 {
107 return false;
108 }
109
110 return x._value.Equals(y._value);
111 }
112
113 public int GetHashCode(Opacity obj)
114 {
115 return obj._value.GetHashCode();
116 }
117 }
118}
Occurs when a provided value falls outside the allowed valid range.
Definition Exception.cs:128
Holds an opacity value representing the transparency level of an object or pixel.
Definition Opacity.cs:16
Opacity(uint value)
Constructs an Opacity object with the specified value.
Definition Opacity.cs:34
Opacity()
Constructs an Opacity object with full opacity (100).
Definition Opacity.cs:23
static IEqualityComparer< Opacity > Comparer
A default equality comparer for comparing Opacity data values.
Definition Opacity.cs:77
override string ToString()
Returns a string that represents the current opacity value.
Definition Opacity.cs:86
uint Value
The opacity value. Must be between 0 and 100.
Definition Opacity.cs:59
static uint Minimum
The minimum allowed opacity value.
Definition Opacity.cs:43
static uint Maximum
The maximum allowed opacity value.
Definition Opacity.cs:49