Path: blob/master/SLICK_HOME/src/org/newdawn/slick/svg/SimpleDiagramRenderer.java
1463 views
package org.newdawn.slick.svg;12import org.newdawn.slick.Color;3import org.newdawn.slick.Graphics;4import org.newdawn.slick.geom.Shape;5import org.newdawn.slick.geom.ShapeRenderer;6import org.newdawn.slick.geom.TexCoordGenerator;7import org.newdawn.slick.opengl.TextureImpl;8import org.newdawn.slick.opengl.renderer.Renderer;9import org.newdawn.slick.opengl.renderer.SGL;1011/**12* A very primtive implementation for rendering a diagram. This simply13* sticks the shapes on the screen in the right fill and stroke colours14*15* @author kevin16*/17public class SimpleDiagramRenderer {18/** The renderer to use for all GL operations */19protected static SGL GL = Renderer.get();2021/** The diagram to be rendered */22public Diagram diagram;23/** The display list representing the diagram */24public int list = -1;2526/**27* Create a new simple renderer28*29* @param diagram The diagram to be rendered30*/31public SimpleDiagramRenderer(Diagram diagram) {32this.diagram = diagram;33}3435/**36* Render the diagram to the given graphics context37*38* @param g The graphics context to which we should render the diagram39*/40public void render(Graphics g) {41// last list generation42if (list == -1) {43list = GL.glGenLists(1);44GL.glNewList(list, SGL.GL_COMPILE);45render(g, diagram);46GL.glEndList();47}4849GL.glCallList(list);5051TextureImpl.bindNone();52}5354/**55* Utility method to render a diagram in immediate mode56*57* @param g The graphics context to render to58* @param diagram The diagram to render59*/60public static void render(Graphics g, Diagram diagram) {61for (int i=0;i<diagram.getFigureCount();i++) {62Figure figure = diagram.getFigure(i);6364if (figure.getData().isFilled()) {65if (figure.getData().isColor(NonGeometricData.FILL)) {66g.setColor(figure.getData().getAsColor(NonGeometricData.FILL));67g.fill(diagram.getFigure(i).getShape());68g.setAntiAlias(true);69g.draw(diagram.getFigure(i).getShape());70g.setAntiAlias(false);71}7273String fill = figure.getData().getAsReference(NonGeometricData.FILL);74if (diagram.getPatternDef(fill) != null){75System.out.println("PATTERN");76}77if (diagram.getGradient(fill) != null) {78Gradient gradient = diagram.getGradient(fill);79Shape shape = diagram.getFigure(i).getShape();80TexCoordGenerator fg = null;81if (gradient.isRadial()) {82fg = new RadialGradientFill(shape, diagram.getFigure(i).getTransform(), gradient);83} else {84fg = new LinearGradientFill(shape, diagram.getFigure(i).getTransform(), gradient);85}8687Color.white.bind();88ShapeRenderer.texture(shape, gradient.getImage(), fg);89}90}9192if (figure.getData().isStroked()) {93if (figure.getData().isColor(NonGeometricData.STROKE)) {94g.setColor(figure.getData().getAsColor(NonGeometricData.STROKE));95g.setLineWidth(figure.getData().getAsFloat(NonGeometricData.STROKE_WIDTH));96g.setAntiAlias(true);97g.draw(diagram.getFigure(i).getShape());98g.setAntiAlias(false);99g.resetLineWidth();100}101}102103// DEBUG VERSION104// g.setColor(Color.black);105// g.draw(diagram.getFigure(i).getShape());106// g.setColor(Color.red);107// g.fill(diagram.getFigure(i).getShape());108}109}110}111112113