Package icyllis.modernui.graphics
Class LinearGradient.Builder
java.lang.Object
icyllis.modernui.graphics.GradientShader.Builder
icyllis.modernui.graphics.LinearGradient.Builder
- Enclosing class:
LinearGradient
Builder pattern of
LinearGradient
.-
Constructor Summary
ConstructorDescriptionBuilder
(float startX, float startY, float endX, float endY, Shader.TileMode tileMode) Builder
(float startX, float startY, float endX, float endY, Shader.TileMode tileMode, ColorSpace colorSpace) Builder
(float startX, float startY, float endX, float endY, Shader.TileMode tileMode, ColorSpace colorSpace, int colorCount) -
Method Summary
Modifier and TypeMethodDescriptionaddColor
(float r, float g, float b, float a) Add a color representing the color of the i-th stop.addColor
(int color) Add a color representing the color of the i-th stop.addColorStop
(float offset, int color) Helper version ofaddColor(int)
andaddPosition(float)
.addPosition
(float position) Add a number between 0 and 1, inclusive, representing the position of the i-th color stop.build()
Create the linear gradient, this builder cannot be reused anymore.int
Returns the initial number of color stops.setHueInterpolationMethod
(GradientShader.HueInterpolationMethod hueInterpolationMethod) For color functions with a hue angle (LCH, HSL, HWB etc.), this specifies a way to interpolate hue values.setInterpolationColorSpace
(GradientShader.InterpolationColorSpace interpolationColorSpace) Set the color space for interpolation.setInterpolationInPremul
(boolean interpolationInPremul) If false, gradients will interpolate their colors in unpremul space and then premultiply each of the results.setLocalMatrix
(Matrix localMatrix) This specifies an additional local matrix for the gradient, it transforms gradient's local coordinates to geometry's local coordinates, null means identity.Methods inherited from class icyllis.modernui.graphics.GradientShader.Builder
getHueInterpolationMethod, getInterpolationColorSpace, isInterpolationInPremul
-
Constructor Details
-
Builder
public Builder(float startX, float startY, float endX, float endY, @NonNull Shader.TileMode tileMode) -
Builder
public Builder(float startX, float startY, float endX, float endY, @NonNull Shader.TileMode tileMode, @Nullable ColorSpace colorSpace) -
Builder
public Builder(float startX, float startY, float endX, float endY, @NonNull Shader.TileMode tileMode, @Nullable ColorSpace colorSpace, int colorCount)
-
-
Method Details
-
addColor
Add a color representing the color of the i-th stop. -
addColor
Add a color representing the color of the i-th stop. -
addPosition
Add a number between 0 and 1, inclusive, representing the position of the i-th color stop. 0 represents the start of the gradient and 1 represents the end.A gradient can be created with implicit positions (by assuming they are uniformly distributed). Once you call this method, the number of colors must be equal to the number of positions.
-
addColorStop
Helper version ofaddColor(int)
andaddPosition(float)
. -
getColorCount
public int getColorCount()Returns the initial number of color stops. -
setInterpolationInPremul
If false, gradients will interpolate their colors in unpremul space and then premultiply each of the results. If true, gradients will premultiply their colors first, and then interpolate between them.Interpolating colors using the premultiplied representations tends to produce more attractive transitions than the non-premultiplied representations, particularly when transitioning from a fully opaque color to fully transparent.
The default is true to match CSS requirements.
- Overrides:
setInterpolationInPremul
in classGradientShader.Builder
- Parameters:
interpolationInPremul
- whether interpolate colors in premul space
-
setInterpolationColorSpace
public LinearGradient.Builder setInterpolationColorSpace(@NonNull GradientShader.InterpolationColorSpace interpolationColorSpace) Set the color space for interpolation.The default is
GradientShader.InterpolationColorSpace.DESTINATION
.- Overrides:
setInterpolationColorSpace
in classGradientShader.Builder
-
setHueInterpolationMethod
public LinearGradient.Builder setHueInterpolationMethod(@NonNull GradientShader.HueInterpolationMethod hueInterpolationMethod) For color functions with a hue angle (LCH, HSL, HWB etc.), this specifies a way to interpolate hue values.The default is
GradientShader.HueInterpolationMethod.SHORTER
.- Overrides:
setHueInterpolationMethod
in classGradientShader.Builder
-
setLocalMatrix
This specifies an additional local matrix for the gradient, it transforms gradient's local coordinates to geometry's local coordinates, null means identity.- Parameters:
localMatrix
- the local matrix to set
-
build
Create the linear gradient, this builder cannot be reused anymore.- Specified by:
build
in classGradientShader.Builder
- Throws:
IllegalArgumentException
- no color, NaN, infinity, non-invertible matrix, etc.
-