Class LinearGradient
java.lang.Object
com.codename1.ui.Gradient
com.codename1.ui.LinearGradient
- All Implemented Interfaces:
Paint
Multi-stop linear gradient at an arbitrary angle. Mirrors CSS
linear-gradient(<angle>, <stops>). Angle is in CSS degrees: 0 points
up (toward the top edge), 90 right, 180 down, 270 left.-
Field Summary
Fields inherited from class Gradient
CYCLE_NONE, CYCLE_REFLECT, CYCLE_REPEAT, KIND_CONIC, KIND_LINEAR, KIND_RADIAL -
Constructor Summary
ConstructorsConstructorDescriptionLinearGradient(float angleDegrees, int[] colors, float[] positions) Creates a linear gradient at the given angle with the given stops. -
Method Summary
Modifier and TypeMethodDescriptionvoidcomputeEndpoints(int width, int height, float[] out) Computes the endpoints of the gradient line for a rectangle of the given width / height (rect origin at (0,0)).voidcomputeShaderEndpoints(int width, int height, float[] out) Computes shader-ready endpoints for native APIs like Android'sLinearGradientand Java2D'sLinearGradientPaint.copy()Returns a defensive deep copy.floatbytegetKind()Returns one ofKIND_LINEAR,KIND_RADIAL,KIND_CONIC.float[]Returns stop positions rescaled to[0, 1]within the[first_stop, last_stop]range of the original positions.intsampleArgb(int px, int py, int width, int height) Software-rasterizer hook used by the default port implementation when no native gradient shader is available.setAngleDegrees(float angleDegrees) Methods inherited from class Gradient
getCachedRaster, getColors, getCycleMethod, getPositions, invalidateRasterCache, paint, paint, parseCss, sampleStops, setCycleMethod
-
Constructor Details
-
LinearGradient
public LinearGradient(float angleDegrees, int[] colors, float[] positions) Creates a linear gradient at the given angle with the given stops.
-
-
Method Details
-
getKind
-
getAngleDegrees
public float getAngleDegrees() -
setAngleDegrees
-
computeEndpoints
public void computeEndpoints(int width, int height, float[] out) Computes the endpoints of the gradient line for a rectangle of the given width / height (rect origin at (0,0)). Output is x0,y0,x1,y1. These endpoints span the full bounding box; stop positions are interpreted relative to them. -
computeShaderEndpoints
public void computeShaderEndpoints(int width, int height, float[] out) Computes shader-ready endpoints for native APIs like Android's
LinearGradientand Java2D'sLinearGradientPaint. For NO_CYCLE this is the same ascomputeEndpoints. For REPEAT / REFLECT it clips the endpoint range to span exactly one stop-list period (fromgetPositions()[0]togetPositions()[N-1]of the original line) so the native shader's tile mode wraps the period across the rest of the bounding box - matching the CSSrepeating-linear-gradientsemantic.Use
getNormalizedPositions()for the matching stop array when using these endpoints with REPEAT/REFLECT. -
getNormalizedPositions
public float[] getNormalizedPositions()Returns stop positions rescaled to[0, 1]within the[first_stop, last_stop]range of the original positions. For NO_CYCLE this is the same asgetPositions(); for REPEAT/REFLECT it is the array to pass alongsidecomputeShaderEndpoints. -
sampleArgb
public int sampleArgb(int px, int py, int width, int height) Description copied from class:GradientSoftware-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 overridingfillGradientdirectly do not call this.- Specified by:
sampleArgbin classGradient
-
copy
Description copied from class:GradientReturns a defensive deep copy. Implemented by each concrete subclass so async-paint queues can capture an immutable snapshot.
-