package org.newdawn.slick.svg; import java.util.ArrayList; import org.newdawn.slick.Color; import org.newdawn.slick.Image; import org.newdawn.slick.ImageBuffer; import org.newdawn.slick.geom.Transform; /** * A gradient definition from an SVG file, includes the stops, name and transform. * * @author kevin */ public class Gradient { /** The name/id given to the gradient */ private String name; /** The steps in colour of the gradient */ private ArrayList steps = new ArrayList(); /** The first x coordiante given in the gradient (cx in radial) */ private float x1; /** The second x coordiante given in the gradient (fx in radial) */ private float x2; /** The first y coordiante given in the gradient (cy in radial) */ private float y1; /** The first y coordiante given in the gradient (fy in radial) */ private float y2; /** The radius given if any */ private float r; /** The texture representing this gradient */ private Image image; /** True if this gradient is radial in nature */ private boolean radial; /** The transform specified for the gradient */ private Transform transform; /** The name of the referenced gradient */ private String ref; /** * Create a new gradient definition * * @param name The name of the gradient * @param radial True if the gradient is radial */ public Gradient(String name, boolean radial) { this.name = name; this.radial = radial; } /** * Check if the gradient is radial * * @return True if the gradient is radial */ public boolean isRadial() { return radial; } /** * Set the transform given for this definition * * @param trans The transform given for this definition */ public void setTransform(Transform trans) { this.transform = trans; } /** * Get the transform to apply during this gradient application * * @return The transform given for this gradient */ public Transform getTransform() { return transform; } /** * Reference another gradient, i.e. use it's colour stops * * @param ref The name of the other gradient to reference */ public void reference(String ref) { this.ref = ref; } /** * Resolve the gradient reference * * @param diagram The diagram to resolve against */ public void resolve(Diagram diagram) { if (ref == null) { return; } Gradient other = diagram.getGradient(ref); for (int i=0;i= n >= 1) * @return The interpolated colour at the given location */ public Color getColorAt(float p) { if (p <= 0) { return ((Step) steps.get(0)).col; } if (p > 1) { return ((Step) steps.get(steps.size()-1)).col; } for (int i=1;i