twaver.shader
Class Gradient

java.lang.Object
  extended by twaver.shader.Gradient
All Implemented Interfaces:
ISerializable, IShader

public class Gradient
extends java.lang.Object
implements IShader, ISerializable

渐变着色器


Field Summary
protected  float angle
          渐变旋转角度
protected  int[] colors
          渐变颜色数组
static java.lang.String LINEAR
          线性渐变类型
static Gradient LINEAR_GRADIENT_HORIZONTAL
          线性水平方向渐变
static Gradient LINEAR_GRADIENT_VERTICAL
          线性垂直方向渐变
static Gradient NONE
          空渐变
protected  float[] positions
          渐变颜色位置数组
static java.lang.String RADIAL
          径向渐变类型
protected  float scaleX
          x缩放比例
protected  float scaleY
          y缩放比例
static java.lang.String SWEEP
          sweep渐变类型
protected  TileMode tile
          渐变图块模式,默认为:TileMode#CLAMP
protected  float translateX
          x偏移量
protected  float translateY
          y偏移量
protected  java.lang.String type
          渐变类型
 
Constructor Summary
Gradient()
          构造函数,渐变
Gradient(java.lang.String type, int[] colors)
          构造函数,指定渐变类型,渐变颜色,渐变位置将平均分布
Gradient(java.lang.String type, int[] colors, float[] positions)
          构造函数,指定渐变类型,颜色以及位置
Gradient(java.lang.String type, int[] colors, float[] positions, float angle)
          构造函数,指定渐变类型,颜色,位置以及角度
Gradient(java.lang.String type, int[] colors, float[] positions, float angle, float xscale, float yscale)
          构造函数,指定渐变类型,颜色,位置,角度以及缩放比例
 
Method Summary
 void deserialize(java.lang.String s)
          反序列化属性,根据字符串生成对象的属性
 boolean equals(java.lang.Object o)
           
 Shader getShader(float tx, float ty, Size size)
          生成指定偏移量和大小区域的着色器
 Shader getShader(Size size)
          生成指定大小区域的着色器,比如渐变的作用范围
 boolean isEmpty()
          空渐变
 java.lang.String serialize()
          序列化该对象
 void setAngle(float angle)
          设置旋转角度
 void setColors(int[] colors)
          设置渐变颜色
 void setPositions(float[] positions)
          设置渐变颜色位置,数量应该与渐变颜色数量一致
 void setScaleX(float scaleX)
          设置x缩放比例
 void setScaleY(float scaleY)
          设置y方向缩放比例
 void setTranslateX(float translateX)
          设置x偏移量
 void setTranslateY(float translateY)
          设置y偏移量
 void setType(java.lang.String type)
          设置渐变类型
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final Gradient NONE
空渐变


LINEAR_GRADIENT_VERTICAL

public static final Gradient LINEAR_GRADIENT_VERTICAL
线性垂直方向渐变


LINEAR_GRADIENT_HORIZONTAL

public static final Gradient LINEAR_GRADIENT_HORIZONTAL
线性水平方向渐变


RADIAL

public static final java.lang.String RADIAL
径向渐变类型

See Also:
Constant Field Values

LINEAR

public static final java.lang.String LINEAR
线性渐变类型

See Also:
Constant Field Values

SWEEP

public static final java.lang.String SWEEP
sweep渐变类型

See Also:
Constant Field Values

type

protected java.lang.String type
渐变类型


angle

protected float angle
渐变旋转角度


scaleX

protected float scaleX
x缩放比例


scaleY

protected float scaleY
y缩放比例


translateX

protected float translateX
x偏移量


translateY

protected float translateY
y偏移量


colors

protected int[] colors
渐变颜色数组


positions

protected float[] positions
渐变颜色位置数组


tile

protected TileMode tile
渐变图块模式,默认为:TileMode#CLAMP

Constructor Detail

Gradient

public Gradient()
构造函数,渐变


Gradient

public Gradient(java.lang.String type,
                int[] colors)
构造函数,指定渐变类型,渐变颜色,渐变位置将平均分布

Parameters:
type - 渐变类型
colors - 渐变颜色,渐变位置将平均分布

Gradient

public Gradient(java.lang.String type,
                int[] colors,
                float[] positions)
构造函数,指定渐变类型,颜色以及位置

Parameters:
type - 渐变类型
colors - 渐变颜色
positions - 渐变位置,数组与渐变颜色数组保持相同个数

Gradient

public Gradient(java.lang.String type,
                int[] colors,
                float[] positions,
                float angle)
构造函数,指定渐变类型,颜色,位置以及角度

Parameters:
type - 渐变类型
colors - 渐变颜色
positions - 渐变位置,数组与渐变颜色数组保持相同个数
angle - 渐变旋转角度

Gradient

public Gradient(java.lang.String type,
                int[] colors,
                float[] positions,
                float angle,
                float xscale,
                float yscale)
构造函数,指定渐变类型,颜色,位置,角度以及缩放比例

Parameters:
type - 渐变类型
colors - 渐变颜色
positions - 渐变位置,数组与渐变颜色数组保持相同个数
angle - 渐变旋转角度
xscale - x方向缩放比例
yscale - y方向缩放比例
Method Detail

setType

public void setType(java.lang.String type)
设置渐变类型

Parameters:
type -

setColors

public void setColors(int[] colors)
设置渐变颜色

Parameters:
colors - 渐变颜色

setPositions

public void setPositions(float[] positions)
设置渐变颜色位置,数量应该与渐变颜色数量一致

Parameters:
positions - 渐变颜色位置

setAngle

public void setAngle(float angle)
设置旋转角度

Parameters:
angle - 旋转角度

setScaleX

public void setScaleX(float scaleX)
设置x缩放比例

Parameters:
scaleX - x缩放比例

setScaleY

public void setScaleY(float scaleY)
设置y方向缩放比例

Parameters:
scaleY - y方向缩放比例

setTranslateX

public void setTranslateX(float translateX)
设置x偏移量

Parameters:
translateX - x偏移量

setTranslateY

public void setTranslateY(float translateY)
设置y偏移量

Parameters:
translateY - y偏移量

getShader

public Shader getShader(float tx,
                        float ty,
                        Size size)
Description copied from interface: IShader
生成指定偏移量和大小区域的着色器

Specified by:
getShader in interface IShader
Parameters:
tx - 着色器偏移量
ty - 着色器偏移量
size - 着色器作用范围
Returns:
着色器
See Also:
Gradient, Shader, Shader#setLocalMatrix(android.graphics.Matrix)

getShader

public Shader getShader(Size size)
Description copied from interface: IShader
生成指定大小区域的着色器,比如渐变的作用范围

Specified by:
getShader in interface IShader
Parameters:
size - 着色器作用范围
Returns:
着色器
See Also:
Gradient, Shader

isEmpty

public boolean isEmpty()
空渐变

Specified by:
isEmpty in interface IShader
Returns:
是否是空渐变

serialize

public java.lang.String serialize()
Description copied from interface: ISerializable
序列化该对象

Specified by:
serialize in interface ISerializable
Returns:
字符串

deserialize

public void deserialize(java.lang.String s)
Description copied from interface: ISerializable
反序列化属性,根据字符串生成对象的属性

Specified by:
deserialize in interface ISerializable
Parameters:
s - 字符串

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object