Class LinearGradient

java.lang.Object
com.codename1.ui.Gradient
com.codename1.ui.LinearGradient
All Implemented Interfaces:
Paint

public final class LinearGradient extends Gradient
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.
  • 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

      public byte getKind()
      Description copied from class: Gradient
      Returns one of KIND_LINEAR, KIND_RADIAL, KIND_CONIC.
      Specified by:
      getKind in class Gradient
    • getAngleDegrees

      public float getAngleDegrees()
    • setAngleDegrees

      public LinearGradient setAngleDegrees(float angleDegrees)
    • 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 LinearGradient and Java2D's LinearGradientPaint. For NO_CYCLE this is the same as computeEndpoints. For REPEAT / REFLECT it clips the endpoint range to span exactly one stop-list period (from getPositions()[0] to getPositions()[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 CSS repeating-linear-gradient semantic.

      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 as getPositions(); for REPEAT/REFLECT it is the array to pass alongside computeShaderEndpoints.
    • sampleArgb

      public int sampleArgb(int px, int py, int width, int height)
      Description copied from class: Gradient
      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.
      Specified by:
      sampleArgb in class Gradient
    • copy

      public LinearGradient copy()
      Description copied from class: Gradient
      Returns a defensive deep copy. Implemented by each concrete subclass so async-paint queues can capture an immutable snapshot.
      Specified by:
      copy in class Gradient