/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. ***********************************************************************/
  18. package org.mt4j.components.clipping;
  19. import javax.media.opengl.GL;
  20. import org.mt4j.components.MTComponent;
  21. import org.mt4j.components.visibleComponents.AbstractVisibleComponent;
  22. import org.mt4j.util.opengl.GLStencilUtil;
  23. import processing.core.PGraphics;
  24. /**
  25. * The Class FillPaint. If added to a component, the specified fillpaint will be
  26. * drawn where the original component would have been drawn.
  27. * <br><strong>NOTE:</strong> A fillpaint can only be used for a single component.
  28. * <br><strong>NOTE:</strong> This is only supported by the OpenGL renderer!
  29. * @author Christopher Ruff
  30. */
  31. public class FillPaint {
  32. /** The gradient shape. */
  33. protected MTComponent fillPaint;
  34. private GL gl;
  35. private AbstractVisibleComponent clipShape;
  36. /**
  37. * Instantiates a new fill paint. The specified fillpaint will be
  38. * drawn where the corresponding component would have been drawn.
  39. *
  40. * @param gl the gl
  41. * @param fillPaint the fill paint
  42. */
  43. public FillPaint(GL gl, AbstractVisibleComponent fillPaint) {
  44. //super(gl);
  45. this.gl = gl;
  46. this.fillPaint = fillPaint;
  47. // this.clipShape = shape;
  48. }
  49. // public FillPaint(GL gl, AbstractVisibleComponent shape, MTComponent fillPaint) {
  50. // //super(gl);
  51. // this.gl = gl;
  52. // this.fillPaint = fillPaint;
  53. // this.clipShape = shape;
  54. // }
  55. /**
  56. * Pre.
  57. *
  58. * @param g the g
  59. */
  60. public void pre(PGraphics g) {
  61. GLStencilUtil.getInstance().beginDrawClipShape(gl);
  62. }
  63. /**
  64. * Post.
  65. *
  66. * @param g the g
  67. */
  68. public void post(PGraphics g) {
  69. GLStencilUtil.getInstance().beginDrawClipped(gl);
  70. drawFillPaint(g);
  71. GLStencilUtil.getInstance().endClipping(g, gl, clipShape);
  72. }
  73. /**
  74. * Draws the fill paint.
  75. *
  76. * @param g the g
  77. */
  78. protected void drawFillPaint(PGraphics g){
  79. //Draw the fill paint clipped to the area of the original shape
  80. fillPaint.drawComponent(g);
  81. }
  82. /**
  83. * Sets the shape to be fill painted. Usually this is called automatically
  84. * when the paint is added to a shape. So this method should not be invoked directly.
  85. *
  86. * @param shape the new shape
  87. */
  88. public void setShape(AbstractVisibleComponent shape){
  89. this.clipShape = shape;
  90. }
  91. /**
  92. * Gets the fill painted shape.
  93. *
  94. * @return the shape
  95. */
  96. public AbstractVisibleComponent getShape(){
  97. return this.clipShape;
  98. }
  99. }