Path: blob/master/SLICK_HOME/src/org/newdawn/slick/svg/RadialGradientFill.java
1463 views
package org.newdawn.slick.svg;12import org.newdawn.slick.geom.Shape;3import org.newdawn.slick.geom.TexCoordGenerator;4import org.newdawn.slick.geom.Transform;5import org.newdawn.slick.geom.Vector2f;67/**8* A filler to apply a SVG radial gradient across a shape9*10* @author kevin11*/12public class RadialGradientFill implements TexCoordGenerator {13/** The centre of the gradient */14private Vector2f centre;15/** The radius before the gradient is complete */16private float radius;17/** The gradient to apply */18private Gradient gradient;19/** The shape being filled */20private Shape shape;2122/**23* Create a new fill for a radial gradient24*25* @param shape The shape being filled26* @param trans The transform given for the shape in the SVG27* @param gradient The gradient to apply across the shape28*/29public RadialGradientFill(Shape shape, Transform trans, Gradient gradient) {30this.gradient = gradient;3132radius = gradient.getR();33float x = gradient.getX1();34float y = gradient.getY1();3536float[] c = new float[] {x,y};37gradient.getTransform().transform(c, 0, c, 0, 1);38trans.transform(c, 0, c, 0, 1);39float[] rt = new float[] {x,y-radius};40gradient.getTransform().transform(rt, 0, rt, 0, 1);41trans.transform(rt, 0, rt, 0, 1);4243centre = new Vector2f(c[0],c[1]);44Vector2f dis = new Vector2f(rt[0],rt[1]);45radius = dis.distance(centre);46}4748/**49* @see org.newdawn.slick.geom.TexCoordGenerator#getCoordFor(float, float)50*/51public Vector2f getCoordFor(float x, float y) {52float u = centre.distance(new Vector2f(x,y));53u /= radius;5455if (u > 0.99f) {56u = 0.99f;57}5859return new Vector2f(u,0);60}6162}636465