Class MutableColorGradient
An editable color gradient that can be modified at runtime. Supports adding, removing, and modifying stops. Call Build() to produce an immutable ColorGradient snapshot.
Inherited Members
Namespace: Scylla.Core.Util.Palette
Assembly: ScyllaCore.dll
Syntax
public sealed class MutableColorGradient
Remarks
Sort invariant. Stops are always kept sorted by offset internally. AddStop(float, Color, ColorGradientStopInterpolation, float) inserts at the correct sorted position. SetStopOffset(int, float) removes and re-inserts to maintain sort order.
Changed event. The Changed event fires after every mutation that actually modifies state. This enables editor tooling to react to gradient edits in real time.
Constructors
MutableColorGradient(ColorGradient)
Creates a mutable copy of an existing immutable gradient.
Declaration
public MutableColorGradient(ColorGradient source)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorGradient | source | The gradient to copy. |
MutableColorGradient(string, string, ColorGradientMode, ColorGradientColorSpace)
Creates a new empty mutable gradient.
Declaration
public MutableColorGradient(string name, string description, ColorGradientMode mode = ColorGradientMode.Smooth, ColorGradientColorSpace colorSpace = ColorGradientColorSpace.RGB)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Human-readable name. Must not be null or empty. |
| string | description | Short description. Null is treated as empty string. |
| ColorGradientMode | mode | Interpolation mode. Defaults to smooth. |
| ColorGradientColorSpace | colorSpace | Color space. Defaults to RGB. |
Properties
AlphaStopCount
The number of alpha stops currently in the gradient.
Declaration
public int AlphaStopCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
ColorSpace
The color space for smooth interpolation.
Declaration
public ColorGradientColorSpace ColorSpace { get; set; }
Property Value
| Type | Description |
|---|---|
| ColorGradientColorSpace |
Description
A short description of this gradient's purpose.
Declaration
public string Description { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
HasAlphaStops
Whether this gradient has any alpha stops.
Declaration
public bool HasAlphaStops { get; }
Property Value
| Type | Description |
|---|---|
| bool |
this[int]
Gets the color at the specified stop index.
Declaration
public Color this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index into the sorted stops. |
Property Value
| Type | Description |
|---|---|
| Color | The color at the given index. |
Mode
The interpolation mode (smooth or stepped).
Declaration
public ColorGradientMode Mode { get; set; }
Property Value
| Type | Description |
|---|---|
| ColorGradientMode |
Name
The human-readable name of this gradient.
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Reduction
Smooth-mode reduction-slider value [0, 1]. Preserved through copy constructor and Build() so editor round-trips don't silently zero the Reduction state.
Declaration
public float Reduction { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
SteppedReduction
Stepped-mode reduction-slider value [0, 1]. Independent of Reduction; preserved through copy constructor and Build().
Declaration
public float SteppedReduction { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
StopCount
The number of color stops currently in the gradient.
Declaration
public int StopCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Tags
Asset-level tags associated with this gradient. Preserved through copy constructor and Build(). Null is treated as no tags.
Declaration
public string[] Tags { get; set; }
Property Value
| Type | Description |
|---|---|
| string[] |
Methods
AddAlphaStop(float, float, ColorGradientStopInterpolation, float)
Adds a new alpha stop at the specified offset with a per-segment easing curve. The stop is inserted at the correct sorted position.
Declaration
public void AddAlphaStop(float offset, float alpha, ColorGradientStopInterpolation interpolation, float midpoint = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| float | offset | Normalized position [0, 1]. |
| float | alpha | Alpha value [0, 1]. |
| ColorGradientStopInterpolation | interpolation | Per-segment easing curve override. |
| float | midpoint | Interpolation midpoint (0, 1). Defaults to 0.5. |
AddAlphaStop(float, float, float)
Adds a new alpha stop at the specified offset. The stop is inserted at the correct sorted position.
Declaration
public void AddAlphaStop(float offset, float alpha, float midpoint = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| float | offset | Normalized position [0, 1]. |
| float | alpha | Alpha value [0, 1]. |
| float | midpoint | Interpolation midpoint (0, 1). Defaults to 0.5. |
AddStop(float, Color, ColorGradientStopInterpolation, float)
Adds a new color stop at the specified offset. The stop is inserted at the correct sorted position.
Declaration
public void AddStop(float offset, Color color, ColorGradientStopInterpolation interpolation = ColorGradientStopInterpolation.None, float midpoint = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| float | offset | Normalized position [0, 1]. |
| Color | color | RGBA color at this stop. |
| ColorGradientStopInterpolation | interpolation | Per-stop interpolation override. Defaults to None (inherit). |
| float | midpoint | Interpolation midpoint (0, 1). Defaults to 0.5. |
AddStop(float, Color, ColorGradientStopInterpolation, float, ColorStopBlendMode)
Adds a new color stop at the specified offset with a per-segment blend operator. The stop is inserted at the correct sorted position.
Declaration
public void AddStop(float offset, Color color, ColorGradientStopInterpolation interpolation, float midpoint, ColorStopBlendMode blendMode)
Parameters
| Type | Name | Description |
|---|---|---|
| float | offset | Normalized position [0, 1]. |
| Color | color | RGBA color at this stop. |
| ColorGradientStopInterpolation | interpolation | Per-stop interpolation override. |
| float | midpoint | Interpolation midpoint (0, 1). |
| ColorStopBlendMode | blendMode | Per-segment color blend operator override. |
Build()
Creates an immutable ColorGradient snapshot of the current state.
Declaration
public ColorGradient Build()
Returns
| Type | Description |
|---|---|
| ColorGradient | A new immutable ColorGradient. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if the gradient has fewer than 2 stops. |
Clear()
Removes all color stops and alpha stops from the gradient.
Declaration
public void Clear()
ClearAlphaStops()
Removes all alpha stops, reverting to using alpha values from color stops.
Declaration
public void ClearAlphaStops()
Evaluate(float)
Evaluates the current gradient at the specified position. Builds a temporary immutable gradient internally.
Declaration
public Color Evaluate(float t)
Parameters
| Type | Name | Description |
|---|---|---|
| float | t | Position along the gradient, clamped to [0, 1]. |
Returns
| Type | Description |
|---|---|
| Color | The interpolated color. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if the gradient has fewer than 2 stops. |
GetAlphaStop(int)
Gets the alpha stop at the specified index.
Declaration
public ColorGradientAlphaStop GetAlphaStop(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index into the sorted alpha stops. |
Returns
| Type | Description |
|---|---|
| ColorGradientAlphaStop | The ColorGradientAlphaStop at the given index. |
GetStop(int)
Gets the stop at the specified index.
Declaration
public ColorGradientStop GetStop(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index into the sorted stops. |
Returns
| Type | Description |
|---|---|
| ColorGradientStop | The ColorGradientStop at the given index. |
RemoveAlphaStop(int)
Removes the alpha stop at the specified index.
Declaration
public void RemoveAlphaStop(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the alpha stop to remove. |
RemoveStop(int)
Removes the stop at the specified index.
Declaration
public void RemoveStop(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the stop to remove. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
SetAlphaStopAlpha(int, float)
Changes the alpha value of the alpha stop at the specified index.
Declaration
public void SetAlphaStopAlpha(int index, float alpha)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the alpha stop to modify. |
| float | alpha | New alpha value [0, 1]. |
SetAlphaStopInterpolation(int, ColorGradientStopInterpolation)
Changes the per-segment easing curve of the alpha stop at the specified index.
Declaration
public void SetAlphaStopInterpolation(int index, ColorGradientStopInterpolation interpolation)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the alpha stop to modify. |
| ColorGradientStopInterpolation | interpolation | New easing curve. |
SetAlphaStopOffset(int, float)
Changes the offset of the alpha stop at the specified index. The stop is removed and re-inserted at the correct sorted position.
Declaration
public void SetAlphaStopOffset(int index, float offset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the alpha stop to modify. |
| float | offset | New normalized offset [0, 1]. |
SetStopBlendMode(int, ColorStopBlendMode)
Sets the per-segment color blend operator for the stop at the given index.
Declaration
public void SetStopBlendMode(int index, ColorStopBlendMode blendMode)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the stop to modify. |
| ColorStopBlendMode | blendMode | The blend operator to apply. |
SetStopColor(int, Color)
Changes the color of the stop at the specified index.
Declaration
public void SetStopColor(int index, Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the stop to modify. |
| Color | color | New RGBA color. |
SetStopInterpolation(int, ColorGradientStopInterpolation)
Sets the per-stop interpolation override for the stop at the given index.
Declaration
public void SetStopInterpolation(int index, ColorGradientStopInterpolation interpolation)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the stop to modify. |
| ColorGradientStopInterpolation | interpolation | The interpolation override to apply. |
SetStopMidpoint(int, float)
Sets the midpoint for the stop at the given index.
Declaration
public void SetStopMidpoint(int index, float midpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the stop to modify. |
| float | midpoint | The midpoint value in (0, 1). |
SetStopOffset(int, float)
Changes the offset of the stop at the specified index. The stop is removed and re-inserted at the correct sorted position.
Declaration
public void SetStopOffset(int index, float offset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero-based index of the stop to modify. |
| float | offset | New normalized offset [0, 1]. |
Events
Changed
Raised after any mutation that modifies the gradient state.
Declaration
public event Action<MutableColorGradient> Changed
Event Type
| Type | Description |
|---|---|
| Action<MutableColorGradient> |