PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/mt4j/components/clipping/FillPaint.java

http://mt4j.googlecode.com/
Java | 117 lines | 32 code | 18 blank | 67 comment | 0 complexity | 53cc79502ce1b88a514e17b25497fa96 MD5 | raw file
  1/***********************************************************************
  2 * mt4j Copyright (c) 2008 - 2009 Christopher Ruff, Fraunhofer-Gesellschaft All rights reserved.
  3 *  
  4 *   This program is free software: you can redistribute it and/or modify
  5 *   it under the terms of the GNU General Public License as published by
  6 *   the Free Software Foundation, either version 3 of the License, or
  7 *   (at your option) any later version.
  8 *
  9 *   This program is distributed in the hope that it will be useful,
 10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 *   GNU General Public License for more details.
 13 *
 14 *   You should have received a copy of the GNU General Public License
 15 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 16 *
 17 ***********************************************************************/
 18package org.mt4j.components.clipping;
 19
 20import javax.media.opengl.GL;
 21
 22import org.mt4j.components.MTComponent;
 23import org.mt4j.components.visibleComponents.AbstractVisibleComponent;
 24import org.mt4j.util.opengl.GLStencilUtil;
 25
 26import processing.core.PGraphics;
 27
 28
 29/**
 30 * The Class FillPaint. If added to a component, the specified fillpaint will be 
 31 * drawn where the original component would have been drawn.
 32 * <br><strong>NOTE:</strong> A fillpaint can only be used for a single component.
 33 * <br><strong>NOTE:</strong> This is only supported by the OpenGL renderer!
 34 * @author Christopher Ruff
 35 */
 36public class FillPaint { 
 37	/** The gradient shape. */
 38	protected MTComponent fillPaint;
 39	
 40	private GL gl;
 41
 42	private AbstractVisibleComponent clipShape;
 43	
 44	/**
 45	 * Instantiates a new fill paint. The specified fillpaint will be 
 46	 * drawn where the corresponding component would have been drawn.
 47	 * 
 48	 * @param gl the gl
 49	 * @param fillPaint the fill paint
 50	 */
 51	public FillPaint(GL gl, AbstractVisibleComponent fillPaint) {
 52		//super(gl);
 53		this.gl = gl;
 54		this.fillPaint = fillPaint;
 55//		this.clipShape = shape;
 56	}
 57
 58//	public FillPaint(GL gl, AbstractVisibleComponent shape, MTComponent fillPaint) {
 59//		//super(gl);
 60//		this.gl = gl;
 61//		this.fillPaint = fillPaint;
 62//		this.clipShape = shape;
 63//	}
 64	
 65
 66	/**
 67	 * Pre.
 68	 * 
 69	 * @param g the g
 70	 */
 71	public void pre(PGraphics g) {
 72		GLStencilUtil.getInstance().beginDrawClipShape(gl);
 73	}
 74
 75	
 76	/**
 77	 * Post.
 78	 * 
 79	 * @param g the g
 80	 */
 81	public void post(PGraphics g) {
 82		GLStencilUtil.getInstance().beginDrawClipped(gl);
 83		drawFillPaint(g);
 84		GLStencilUtil.getInstance().endClipping(g, gl, clipShape);
 85	}
 86	
 87	/**
 88	 * Draws the fill paint.
 89	 * 
 90	 * @param g the g
 91	 */
 92	protected void drawFillPaint(PGraphics g){
 93		//Draw the fill paint clipped to the area of the original shape
 94		fillPaint.drawComponent(g); 
 95	}
 96	
 97	/**
 98	 * Sets the shape to be fill painted. Usually this is called automatically
 99	 * when the paint is added to a shape. So this method should not be invoked directly.
100	 * 
101	 * @param shape the new shape
102	 */
103	public void setShape(AbstractVisibleComponent shape){
104		this.clipShape = shape;
105	}
106	
107	/**
108	 * Gets the fill painted shape.
109	 * 
110	 * @return the shape
111	 */
112	public AbstractVisibleComponent getShape(){
113		return this.clipShape;
114	}
115	
116	
117}