From 57f3797bb8b7a37eb347fc487803f0b56a2ad7f3 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 31 Dec 2012 00:40:47 +0000 Subject: [PATCH] added PShape.setTexture(), PShape.setTextureMode() --- core/src/processing/core/PShape.java | 43 ++++++++++++++++++++ core/src/processing/opengl/PShapeOpenGL.java | 36 ++++++---------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 26019280f..2fa801684 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -97,6 +97,8 @@ public class PShape implements PConstants { protected PMatrix matrix; + protected int textureMode; + /** Texture or image data associated with this shape. */ protected PImage image; @@ -481,10 +483,31 @@ public class PShape implements PConstants { // Drawing methods + public void textureMode(int mode) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "textureMode()"); + return; + } + + textureMode = mode; + } + public void texture(PImage tex) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "texture()"); + return; + } + + image = tex; } public void noTexture() { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noTexture()"); + return; + } + + image = null; } // TODO unapproved @@ -1985,6 +2008,26 @@ public class PShape implements PConstants { } + public void setTextureMode(int mode) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureMode()"); + return; + } + + textureMode = mode; + } + + + public void setTexture(PImage tex) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTexture()"); + return; + } + + image = tex; + } + + public int getFill(int index) { if (image == null) { int a = (int) (vertices[index][PGraphics.A] * 255); diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index ac5bb3367..a13a34b2c 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -184,7 +184,6 @@ public class PShapeOpenGL extends PShape { // Modes inherited from renderer - protected int textureMode; protected int rectMode; protected int ellipseMode; protected int shapeMode; @@ -725,7 +724,13 @@ public class PShapeOpenGL extends PShape { // Drawing methods - public void textureMode(int mode) { + @Override + public void setTextureMode(int mode) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureMode()"); + return; + } + if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; @@ -738,7 +743,12 @@ public class PShapeOpenGL extends PShape { @Override - public void texture(PImage tex) { + public void setTexture(PImage tex) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTexture()"); + return; + } + if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; @@ -760,26 +770,6 @@ public class PShapeOpenGL extends PShape { } - @Override - public void noTexture() { - if (family == GROUP) { - for (int i = 0; i < childCount; i++) { - PShapeOpenGL child = (PShapeOpenGL) children[i]; - child.noTexture(); - } - } else { - PImage tex0 = image; - image = null; - if (tex0 != null && parent != null) { - ((PShapeOpenGL)parent).removeTexture(tex0); - if (is2D()) { - ((PShapeOpenGL)parent).strokedTexture(false); - } - } - } - } - - protected void addTexture(PImage tex) { if (textures == null) { textures = new HashSet();