Class ColorGradient
A gradient containing a list of ColorGradientStops
public class ColorGradient : IList<ColorGradientStop>, ICollection<ColorGradientStop>, IEnumerable<ColorGradientStop>, IList, ICollection, IEnumerable, INotifyCollectionChanged
- Inheritance
-
objectColorGradient
- Implements
Constructors
ColorGradient()
Creates a new instance of the ColorGradient class
public ColorGradient()
ColorGradient(ColorGradient?)
Creates a new instance of the ColorGradient class
public ColorGradient(ColorGradient? colorGradient)
Parameters
colorGradientColorGradientThe color gradient to copy
ColorGradient(List<ColorGradientStop>)
Creates a new instance of the ColorGradient class
public ColorGradient(List<ColorGradientStop> stops)
Parameters
stopsList<ColorGradientStop>The stops to copy
Properties
Colors
Gets an array containing the colors of the color gradient.
Note: Making changes to this array will not be reflected on the gradient, is is essentially read-only.public SKColor[] Colors { get; }
Property Value
- SKColor[]
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
IsFixedSize
Gets a value indicating whether the IList has a fixed size.
public bool IsFixedSize { get; }
Property Value
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
public bool IsReadOnly { get; }
Property Value
- bool
true if the ICollection<T> is read-only; otherwise, false.
IsSynchronized
Gets a value indicating whether access to the ICollection is synchronized (thread safe).
public bool IsSynchronized { get; }
Property Value
- bool
true if access to the ICollection is synchronized (thread safe); otherwise, false.
this[int]
Gets or sets the element at the specified index.
public ColorGradientStop this[int index] { get; set; }
Parameters
indexintThe zero-based index of the element to get or set.
Property Value
- ColorGradientStop
The element at the specified index.
Exceptions
- ArgumentOutOfRangeException
indexis not a valid index in the IList<T>.- NotSupportedException
The property is set and the IList<T> is read-only.
Positions
Gets an array containing the positions of colors of the color gradient.
Note: Making changes to this array will not be reflected on the gradient, is is essentially read-only.public float[] Positions { get; }
Property Value
- float[]
SyncRoot
Gets an object that can be used to synchronize access to the ICollection.
public object SyncRoot { get; }
Property Value
- object
An object that can be used to synchronize access to the ICollection.
Methods
Add(ColorGradientStop)
Adds an item to the ICollection<T>.
public void Add(ColorGradientStop item)
Parameters
itemColorGradientStopThe object to add to the ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Add(object?)
Adds an item to the IList.
public int Add(object? value)
Parameters
valueobjectThe object to add to the IList.
Returns
- int
The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection.
Exceptions
- NotSupportedException
The IList is read-only.
-or-
The IList has a fixed size.
Clear()
Removes all items from the IList.
public void Clear()
Exceptions
- NotSupportedException
The IList is read-only.
Contains(ColorGradientStop)
Determines whether the ICollection<T> contains a specific value.
public bool Contains(ColorGradientStop item)
Parameters
itemColorGradientStopThe object to locate in the ICollection<T>.
Returns
- bool
true if
itemis found in the ICollection<T>; otherwise, false.
Contains(object?)
Determines whether the IList contains a specific value.
public bool Contains(object? value)
Parameters
valueobjectThe object to locate in the IList.
Returns
CopyTo(ColorGradientStop[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
public void CopyTo(ColorGradientStop[] array, int arrayIndex)
Parameters
arrayColorGradientStop[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndexintThe zero-based index in
arrayat which copying begins.
Exceptions
- ArgumentNullException
arrayis null.- ArgumentOutOfRangeException
arrayIndexis less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndexto the end of the destinationarray.
CopyTo(Array, int)
Copies the elements of the ICollection to an Array, starting at a particular Array index.
public void CopyTo(Array array, int index)
Parameters
arrayArrayThe one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.
indexintThe zero-based index in
arrayat which copying begins.
Exceptions
- ArgumentNullException
arrayis null.- ArgumentOutOfRangeException
indexis less than zero.- ArgumentException
<code class="paramref">array</code> is multidimensional.-or-
The number of elements in the source ICollection is greater than the available space from
indexto the end of the destinationarray.-or-
The type of the source ICollection cannot be cast automatically to the type of the destination
array.
Equals(ColorGradient)
Determines whether all the stops in this gradient are equal to the stops in the given other
gradient.
protected bool Equals(ColorGradient other)
Parameters
otherColorGradientThe other gradient to compare to
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
FlipStops()
Flips the stops of the gradient.
public void FlipStops()
GetColor(float)
Gets a color at any position between 0.0 and 1.0 using interpolation
public SKColor GetColor(float position)
Parameters
positionfloatA position between 0.0 and 1.0
Returns
GetColor(float, int, bool)
Gets a color at any position between 0.0 and 1.0 using interpolation
[Obsolete("Use GetColor(float position) instead.", true)]
public SKColor GetColor(float position, int timesToRepeat = 0, bool seamless = false)
Parameters
positionfloatA position between 0.0 and 1.0
timesToRepeatintThe amount of times to repeat the positions
seamlessboolA boolean indicating whether to make the gradient seamless by adding the first color behind the last color
Returns
GetColorsArray(int, bool)
Gets all the colors in the color gradient
[Obsolete("Use the Colors property instead", true)]
public SKColor[] GetColorsArray(int timesToRepeat = 0, bool seamless = false)
Parameters
timesToRepeatintThe amount of times to repeat the colors
seamlessboolA boolean indicating whether to make the gradient seamless by adding the first color behind the last color
Returns
- SKColor[]
An array containing each color in the gradient
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<ColorGradientStop> GetEnumerator()
Returns
- IEnumerator<ColorGradientStop>
An enumerator that can be used to iterate through the collection.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
GetPositionsArray(int, bool)
Gets all the positions in the color gradient
[Obsolete("Use the Positions property instead", true)]
public float[] GetPositionsArray(int timesToRepeat = 0, bool seamless = false)
Parameters
timesToRepeatintThe amount of times to repeat the positions
seamlessboolA boolean indicating whether to make the gradient seamless by adding the first color behind the last color
Returns
- float[]
An array containing a position for each color between 0.0 and 1.0
GetRandom(int)
Gets a new ColorGradient with random colors from the HSV-spectrum
public static ColorGradient GetRandom(int stops)
Parameters
stopsintThe amount of stops to add
Returns
GetUnicornBarf()
Gets a new ColorGradient with colors looping through the HSV-spectrum
public static ColorGradient GetUnicornBarf()
Returns
IndexOf(ColorGradientStop)
Determines the index of a specific item in the IList<T>.
public int IndexOf(ColorGradientStop item)
Parameters
itemColorGradientStopThe object to locate in the IList<T>.
Returns
- int
The index of
itemif found in the list; otherwise, -1.
IndexOf(object?)
Determines the index of a specific item in the IList.
public int IndexOf(object? value)
Parameters
valueobjectThe object to locate in the IList.
Returns
- int
The index of
valueif found in the list; otherwise, -1.
Insert(int, ColorGradientStop)
Inserts an item to the IList<T> at the specified index.
public void Insert(int index, ColorGradientStop item)
Parameters
indexintThe zero-based index at which
itemshould be inserted.itemColorGradientStopThe object to insert into the IList<T>.
Exceptions
- ArgumentOutOfRangeException
indexis not a valid index in the IList<T>.- NotSupportedException
The IList<T> is read-only.
Insert(int, object?)
Inserts an item to the IList at the specified index.
public void Insert(int index, object? value)
Parameters
indexintThe zero-based index at which
valueshould be inserted.valueobjectThe object to insert into the IList.
Exceptions
- ArgumentOutOfRangeException
indexis not a valid index in the IList.- NotSupportedException
The IList is read-only.
-or-
The IList has a fixed size.
- NullReferenceException
valueis null reference in the IList.
Interpolate(ColorGradient, float)
Interpolates a color gradient between the this gradient and the provided targetValue.
public ColorGradient Interpolate(ColorGradient targetValue, float progress)
Parameters
targetValueColorGradientThe second color gradient.
progressfloatA value between 0 and 1.
Returns
- ColorGradient
The interpolated color gradient.
IsSeamless()
Determines whether the gradient is seamless
public bool IsSeamless()
Returns
Randomize(int)
Randomizes the color gradient with the given amount of stops.
public void Randomize(int stops)
Parameters
stopsintThe amount of stops to put into the gradient.
Remove(ColorGradientStop)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(ColorGradientStop item)
Parameters
itemColorGradientStopThe object to remove from the ICollection<T>.
Returns
- bool
true if
itemwas successfully removed from the ICollection<T>; otherwise, false. This method also returns false ifitemis not found in the original ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Remove(object?)
Removes the first occurrence of a specific object from the IList.
public void Remove(object? value)
Parameters
valueobjectThe object to remove from the IList.
Exceptions
- NotSupportedException
The IList is read-only.
-or-
The IList has a fixed size.
RemoveAt(int)
Removes the IList<T> item at the specified index.
public void RemoveAt(int index)
Parameters
indexintThe zero-based index of the item to remove.
Exceptions
- ArgumentOutOfRangeException
indexis not a valid index in the IList<T>.- NotSupportedException
The IList<T> is read-only.
RotateStops(bool)
Rotates the stops of the gradient shifting every stop over to the position of it's neighbor and wrapping around at the end of the gradient.
public void RotateStops(bool inverse)
Parameters
inverseboolA boolean indicating whether or not the invert the rotation.
SpreadStops()
Spreads the color stops equally across the gradient.
public void SpreadStops()
ToggleSeamless()
If not already the case, makes the gradient seamless by adding the first color to the end of the gradient and compressing the other stops.
If the gradient is already seamless, removes the last color and spreads the remaining stops to fill the freed space.
public void ToggleSeamless()
Events
CollectionChanged
Occurs when the collection changes.
public event NotifyCollectionChangedEventHandler? CollectionChanged
Event Type
StopChanged
Occurs when any of the stops has changed in some way
public event EventHandler? StopChanged