PageRenderTime 32ms CodeModel.GetById 17ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/src/org/mt4j/components/visibleComponents/widgets/MTClipRoundRect.java

http://mt4j.googlecode.com/
Java | 77 lines | 30 code | 12 blank | 35 comment | 5 complexity | 4a74c5d13b4e90ba67c1088eccce9009 MD5 | raw file
 1/***********************************************************************
 2 * mt4j Copyright (c) 2008 - 2009 C.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.visibleComponents.widgets;
19
20import javax.media.opengl.GL;
21
22import org.mt4j.components.clipping.Clip;
23import org.mt4j.components.visibleComponents.shapes.MTRectangle;
24import org.mt4j.components.visibleComponents.shapes.MTRoundRectangle;
25import org.mt4j.util.MT4jSettings;
26
27import processing.core.PApplet;
28import processing.opengl.PGraphicsOpenGL;
29
30/**
31 * The Class MTClipRoundRect.A round rectangle whos children are clipped at the borders
32 * of this round rectangle so they are only visible inside of it.
33 * @author Christopher Ruff
34 */
35public class MTClipRoundRect extends MTRoundRectangle {
36
37	/**
38	 * Instantiates a new mT clip round rect.
39	 * @param applet the applet
40	 * @param x the x
41	 * @param y the y
42	 * @param z the z
43	 * @param width the width
44	 * @param height the height
45	 * @param arcWidth the arc width
46	 * @param arcHeight the arc height
47	 */
48	public MTClipRoundRect(PApplet applet, float x, float y, float z, float width, float height, float arcWidth, float arcHeight) {
49		super(applet, x, y, z, width, height, arcWidth, arcHeight);
50		
51		this.setStrokeWeight(1);
52		
53		if (MT4jSettings.getInstance().isOpenGlMode()){
54//			MTRoundRectangle clipRect3 = new MTRoundRectangle(x+0.1f, y+0.1f, z, width - 0.8f, height - 0.8f, arcWidth, arcHeight, applet);
55			MTRoundRectangle clipRect = new MTRoundRectangle(applet, x, y, z, width, height, arcWidth, arcHeight);
56	        clipRect.setNoStroke(true);
57	        clipRect.setBoundsBehaviour(MTRectangle.BOUNDS_ONLY_CHECK);
58	        
59	        GL gl = ((PGraphicsOpenGL)applet.g).gl;
60	        Clip clipMask = new Clip(gl, clipRect);
61	        this.setChildClip(clipMask);
62		}
63        
64	}
65	
66	
67	@Override
68	public void setSizeLocal(float width, float height) {
69		super.setSizeLocal(width, height);
70		if (MT4jSettings.getInstance().isOpenGlMode() && this.getClip() != null && this.getClip().getClipShape() instanceof MTRectangle){ 
71			MTRectangle clipRect = (MTRectangle)this.getClip().getClipShape();
72			//clipRect.setVertices(Vertex.getDeepVertexArrayCopy(this.getVerticesLocal()));
73			clipRect.setVertices(this.getVerticesLocal());
74		}
75	}
76
77}