public final class RadialGradient

  1. Object
  2. Gradient
  3. RadialGradient

ImplementsPaint

Multi-stop radial gradient with CSS shape / extent / center / radius support. Mirrors CSS radial-gradient([shape] [extent] [at <pos>], <stops>).

Fields

public static final byte SHAPE_CIRCLE = 0Radial shape: circular (single radius).
public static final byte SHAPE_ELLIPSE = 1Radial shape: elliptical (separate x/y radii).
public static final byte EXTENT_CLOSEST_SIDE = 0CSS radial extents.
public static final byte EXTENT_CLOSEST_CORNER = 1
public static final byte EXTENT_FARTHEST_SIDE = 2
public static final byte EXTENT_FARTHEST_CORNER = 3
public static final byte EXTENT_EXPLICIT = 4Use the configured relativeRadiusX/Y verbatim (times the rectangle’s larger dimension).

Constructors

public RadialGradient(int[] colors, float[] positions)

Methods

public byte getKind()Returns one of KIND_LINEAR, KIND_RADIAL, KIND_CONIC.
public byte getShape()
public RadialGradient setShape(byte shape)
public byte getExtent()
public RadialGradient setExtent(byte extent)
public float getRelativeCenterX()
public RadialGradient setRelativeCenterX(float relativeCenterX)
public float getRelativeCenterY()
public RadialGradient setRelativeCenterY(float relativeCenterY)
public float getRelativeRadiusX()
public RadialGradient setRelativeRadiusX(float relativeRadiusX)
public float getRelativeRadiusY()
public RadialGradient setRelativeRadiusY(float relativeRadiusY)
public void computeRadii(int width, int height, float[] out)Computes (cx, cy, rx, ry) in pixel coordinates for a rectangle of the given width / height, applying the configured CSS extent.
public void computeShaderRadii(int width, int height, float[] out)Computes shader-ready (cx, cy, rx, ry) for native APIs like Android’s RadialGradient and Java2D’s RadialGradientPaint.
public float[] getNormalizedPositions()Returns stop positions rescaled to [0, 1] within the [first_stop, last_stop] range.
public int sampleArgb(int px, int py, int width, int height)Software-rasterizer hook used by the default port implementation when no native gradient shader is available.
public RadialGradient copy()Returns a defensive deep copy.

Inherited fields

Inherited methods

Field details

SHAPE_CIRCLE

public static final byte SHAPE_CIRCLE = 0
Radial shape: circular (single radius).

SHAPE_ELLIPSE

public static final byte SHAPE_ELLIPSE = 1
Radial shape: elliptical (separate x/y radii).

EXTENT_CLOSEST_SIDE

public static final byte EXTENT_CLOSEST_SIDE = 0
CSS radial extents.

EXTENT_CLOSEST_CORNER

public static final byte EXTENT_CLOSEST_CORNER = 1

EXTENT_FARTHEST_SIDE

public static final byte EXTENT_FARTHEST_SIDE = 2

EXTENT_FARTHEST_CORNER

public static final byte EXTENT_FARTHEST_CORNER = 3

EXTENT_EXPLICIT

public static final byte EXTENT_EXPLICIT = 4
Use the configured relativeRadiusX/Y verbatim (times the rectangle’s larger dimension).

Constructor details

RadialGradient

public RadialGradient(int[] colors, float[] positions)

Method details

getKind

public byte getKind()
Returns one of KIND_LINEAR, KIND_RADIAL, KIND_CONIC.

getShape

public byte getShape()

setShape

public RadialGradient setShape(byte shape)

getExtent

public byte getExtent()

setExtent

public RadialGradient setExtent(byte extent)

getRelativeCenterX

public float getRelativeCenterX()

setRelativeCenterX

public RadialGradient setRelativeCenterX(float relativeCenterX)

getRelativeCenterY

public float getRelativeCenterY()

setRelativeCenterY

public RadialGradient setRelativeCenterY(float relativeCenterY)

getRelativeRadiusX

public float getRelativeRadiusX()

setRelativeRadiusX

public RadialGradient setRelativeRadiusX(float relativeRadiusX)

getRelativeRadiusY

public float getRelativeRadiusY()

setRelativeRadiusY

public RadialGradient setRelativeRadiusY(float relativeRadiusY)

computeRadii

public void computeRadii(int width, int height, float[] out)
Computes (cx, cy, rx, ry) in pixel coordinates for a rectangle of the given width / height, applying the configured CSS extent.

computeShaderRadii

public void computeShaderRadii(int width, int height, float[] out)

Computes shader-ready (cx, cy, rx, ry) for native APIs like Android’s RadialGradient and Java2D’s RadialGradientPaint. For NO_CYCLE this is the same as computeRadii. For REPEAT / REFLECT it scales the radii so the [0, 1] shader range corresponds to exactly one stop-list period (getPositions()[0] to getPositions()[N-1]), matching the CSS repeating-radial-gradient semantic.

Use getNormalizedPositions() for the matching stop array when using these radii with REPEAT/REFLECT.

getNormalizedPositions

public float[] getNormalizedPositions()
Returns stop positions rescaled to [0, 1] within the [first_stop, last_stop] range. Use alongside computeShaderRadii when feeding the native shader API.

sampleArgb

public int sampleArgb(int px, int py, int width, int height)
Software-rasterizer hook used by the default port implementation when no native gradient shader is available. Samples an ARGB color for the pixel at (px, py) within a rectangle of the given width / height. Ports overriding fillGradient directly do not call this.

copy

public RadialGradient copy()
Returns a defensive deep copy. Implemented by each concrete subclass so async-paint queues can capture an immutable snapshot.