FileDocCategorySizeDatePackage
LinearGradientPaintDef.javaAPI DocphoneME MR2 API (J2ME)7584Wed May 02 18:00:34 BST 2007com.sun.perseus.j2d

LinearGradientPaintDef

public class LinearGradientPaintDef extends Object implements PaintDef
LinearGradientPaint support.
version
$Id: LinearGradientPaintDef.java,v 1.4 2006/04/21 06:35:26 st125089 Exp $

Fields Summary
public static final int
CYCLE_NONE
public static final int
CYCLE_REPEAT
public static final int
CYCLE_REFLECT
private com.sun.pisces.Transform6
IDENTITY
float
x0
The gradient starting point along the x-axis
float
y0
The gradient starting point along the y-axis
float
x1
The gradient end point along the x-axis
float
y1
The gradient end point along the y-axis.
float[]
fractions
The array of stop values.
int[]
frac
The array of stop values, as fixed point values.
int[]
rgba
The array of ARGB color values.
int[]
lrgba
The last used rgba array, accounting for operation opacity.
int
lastPaintOpacity
The last paintOpacity.
int
cycleMethod
One of the cycle methods (CYCLE_NONE, CYCLE_REPEAT, CYCLE_REFLECT
protected boolean
isObjectBBox
Set to true if this gradient is in objectBoundingBox space.
protected Transform
gradientTransform
An additional transform from the gradient space. This corresponds to a SVG gradientTransform attribute.
Constructors Summary
public LinearGradientPaintDef(float x0, float y0, float x1, float y1, float[] fractions, int[] rgba, int cycleMethod, boolean isObjectBBox, Transform gradientTransform)
Constructs an LinearGradientPaint.

param
x0 the gradient starting point along the x-axis
param
y0 the gradient starting point along the y-axis
param
x1 the gradient end point along the x-axis
param
y1 the gradient end point along the y-axis.
param
fractions the array of stop values.
param
rgba the array of ARGB color values
param
cycleMethod one of the cycle methods (CYCLE_NONE, CYCLE_REPEAT, CYCLE_REFLECT
param
isObjectBBox if set to true, the RenderGraphic's current paintTarget object bounding box should be used to append and additional transform to the gradientTransform. The objectBoundingBox transform is appended to the right of the gradientTransform.
param
gradientTransform an additional transform to add between the device coordinate space and the gradient's coordinate space.


                                                                                                                                                                 
        
                                     
                                     
                                     
                                     
                                     
                                     
                                     
                                      
        this.x0 = x0;
        this.y0 = y0;
        this.x1 = x1;
        this.y1 = y1;
        this.fractions = fractions;
        this.rgba = rgba;
        this.cycleMethod = cycleMethod;
        this.isObjectBBox = isObjectBBox;
        this.gradientTransform = gradientTransform;
    
Methods Summary
public voidsetPaint(PiscesRenderGraphics rg, com.sun.pisces.PiscesRenderer pr, int paintOpacity)
Sets the paint on a PiscesRender.

param
rg the RenderGraphics on requesting the paint to be set.
param
renderer the PiscesRender on which to set the paint.
param
paintOpacity additional paint opacity.

        // First, lazilly compute the fractions in fixed point.
        if (frac == null) {
            frac = new int[fractions.length];
            for (int i = 0; i < fractions.length; i++) {
                frac[i] = (int) (fractions[i] * 65536);
            }
        }

        // Now, lazilly compute the offset colors accounting for the current 
        // paint opacity.
        int[] c = rgba;
        if (paintOpacity != 255) {
            c = lrgba;
            if (paintOpacity != lastPaintOpacity) {
                if (lrgba == null) {
                    lrgba = new int[rgba.length];
                }
                int a = 0;
                for (int i = 0; i < rgba.length; i++) {
                    lrgba[i] = (rgba[i] & 0x00ffffff);
                    a = (paintOpacity * (0xff & (rgba[i] >> 24)) / 255);
                    lrgba[i] |= (a << 24);
                }
                lastPaintOpacity = paintOpacity;
            }
        }

        // Finally, compute the paint transform.

        // Start with the paintTarget's user space coordinate system.
        Transform txf = null;
        if (rg.paintTransform != null) {
            txf = new Transform(rg.paintTransform);
        } else {
            txf = new Transform(rg.transform.m00 / 65536f,
                                rg.transform.m10 / 65536f,
                                rg.transform.m01 / 65536f,
                                rg.transform.m11 / 65536f,
                                rg.transform.m02 / 65536f,
                                rg.transform.m12 / 65536f);
        }

        // Append the objectBoundingBox space to user space transform.
        if (isObjectBBox) {
            SVGRect bbox = rg.paintTarget.getBBox();
            txf.mTranslate(bbox.getX(), bbox.getY());
            txf.mScale(bbox.getWidth(), bbox.getHeight());
        } 

        // Now, append the gradient transform.
        if (gradientTransform != null) {
            txf.mMultiply(gradientTransform);
        }
        
        Transform6 t = new Transform6();
        t.m00 = (int) (txf.m0 * 65536);
        t.m10 = (int) (txf.m1 * 65536);
        t.m01 = (int) (txf.m2 * 65536);
        t.m11 = (int) (txf.m3 * 65536);
        t.m02 = (int) (txf.m4 * 65536);
        t.m12 = (int) (txf.m5 * 65536);
        
        pr.setLinearGradient((int) (x0 * 65536), 
                             (int) (y0 * 65536), 
                             (int) (x1 * 65536), 
                             (int) (y1 * 65536), 
                             frac, 
                             c, 
                             cycleMethod, 
                             t);