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