diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 388ea6530..44bed52d9 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -3069,10 +3069,19 @@ public class PApplet extends Applet mouseExited(); } - + /** + * @nowebref + */ public void mouseWheel() { } - + /** + * The event.getAmount() method returns negative values if the mouse wheel + * if rotated up or away from the user and positive in the other direction. + * On OS X with "natural" scrolling enabled, the values are opposite. + * + * @webref input:mouse + * @param event the MouseEvent + */ public void mouseWheel(MouseEvent event) { mouseWheel(); } diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 026d3214c..e5eaa28fd 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -1647,6 +1647,10 @@ public class PShape implements PConstants { return parent; } + /** + * @webref + * @brief Returns the number of children + */ public int getChildCount() { return childCount; } diff --git a/core/src/processing/data/XML.java b/core/src/processing/data/XML.java index bc1fd7fac..656f6ede5 100644 --- a/core/src/processing/data/XML.java +++ b/core/src/processing/data/XML.java @@ -61,7 +61,9 @@ public class XML implements Serializable { /** Child elements, once loaded. */ protected XML[] children; - + /** + * @nowebref + */ protected XML() { } @@ -81,6 +83,8 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(File file) throws IOException, ParserConfigurationException, SAXException { this(file, null); @@ -89,12 +93,16 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(File file, String options) throws IOException, ParserConfigurationException, SAXException { this(PApplet.createReader(file), options); } - + /** + * @nowebref + */ public XML(InputStream input) throws IOException, ParserConfigurationException, SAXException { this(input, null); } @@ -104,6 +112,8 @@ public class XML implements Serializable { * Shouldn't be part of main p5 reference, this is for advanced users. * Note that while it doesn't accept anything but UTF-8, this is preserved * so that we have some chance of implementing that in the future. + * + * @nowebref */ public XML(InputStream input, String options) throws IOException, ParserConfigurationException, SAXException { this(PApplet.createReader(input), options); @@ -112,6 +122,8 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(Reader reader) throws IOException, ParserConfigurationException, SAXException { this(reader, null); @@ -120,6 +132,8 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(Reader reader, String options) throws IOException, ParserConfigurationException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -166,6 +180,8 @@ public class XML implements Serializable { /** * @param name description TBD + * + * @nowebref */ public XML(String name) { try { @@ -181,7 +197,9 @@ public class XML implements Serializable { } } - + /** + * @nowebref + */ protected XML(XML parent, Node node) { this.node = node; this.parent = parent; @@ -197,12 +215,15 @@ public class XML implements Serializable { * @throws SAXException * @throws ParserConfigurationException * @throws IOException + * @nowebref */ static public XML parse(String data) throws IOException, ParserConfigurationException, SAXException { return XML.parse(data, null); } - + /** + * @nowebref + */ static public XML parse(String data, String options) throws IOException, ParserConfigurationException, SAXException { return new XML(new StringReader(data), null); } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 9d0475a41..e58d3d598 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -182,15 +182,6 @@ public class PShapeOpenGL extends PShape { // ........................................................ - // Modes inherited from renderer - - protected int rectMode; - protected int ellipseMode; - protected int shapeMode; - protected int imageMode; - - // ........................................................ - // Bezier and Catmull-Rom curves protected int bezierDetail = 20; @@ -307,12 +298,8 @@ public class PShapeOpenGL extends PShape { inGeo = pg.newInGeometry(PGraphicsOpenGL.RETAINED); } - // Modes are retrieved from the current values in the renderer. + // Style parameters are retrieved from the current values in the renderer. textureMode = pg.textureMode; - rectMode = pg.rectMode; - ellipseMode = pg.ellipseMode; - shapeMode = pg.shapeMode; - imageMode = pg.imageMode; colorMode(pg.colorMode, pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA); @@ -757,10 +744,25 @@ public class PShapeOpenGL extends PShape { if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; - child.textureMode(mode); + child.setTextureMode(mode); } } else { - textureMode = mode; + setTextureModeImpl(mode); + } + } + + + protected void setTextureModeImpl(int mode) { + if (textureMode == mode) return; + textureMode = mode; + if (image != null) { + float uFactor = image.width; + float vFactor = image.height; + if (textureMode == NORMAL) { + uFactor = 1.0f / uFactor; + vFactor = 1.0f / vFactor; + } + scaleTextureUV(uFactor, vFactor); } } @@ -778,17 +780,69 @@ public class PShapeOpenGL extends PShape { child.texture(tex); } } else { - PImage tex0 = image; - image = tex; - if (tex0 != tex && parent != null) { - ((PShapeOpenGL)parent).removeTexture(tex); + setTextureImpl(tex); + } + } + + + protected void setTextureImpl(PImage tex) { + PImage image0 = image; + image = tex; + + if (textureMode == IMAGE && image0 != image) { + // Need to rescale the texture coordinates + float uFactor = 1; + float vFactor = 1; + if (image != null) { + uFactor /= image.width; + vFactor /= image.height; } - if (parent != null) { - ((PShapeOpenGL)parent).addTexture(image); - if (is2D() && stroke) { - ((PShapeOpenGL)parent).strokedTexture(true); - } + if (image0 != null) { + uFactor *= image0.width; + vFactor *= image0.height; } + scaleTextureUV(uFactor, vFactor); + } + + if (image0 != tex && parent != null) { + ((PShapeOpenGL)parent).removeTexture(tex); + } + if (parent != null) { + ((PShapeOpenGL)parent).addTexture(image); + if (is2D() && stroke) { + ((PShapeOpenGL)parent).strokedTexture(true); + } + } + } + + + protected void scaleTextureUV(float uFactor, float vFactor) { + if (PGraphicsOpenGL.same(uFactor, 1) && + PGraphicsOpenGL.same(vFactor, 1)) return; + + for (int i = 0; i < inGeo.vertexCount; i++) { + float u = inGeo.texcoords[2 * i + 0]; + float v = inGeo.texcoords[2 * i + 1]; + inGeo.texcoords[2 * i + 0] = PApplet.min(1, u * uFactor); + inGeo.texcoords[2 * i + 1] = PApplet.min(1, v * uFactor); + } + + if (shapeCreated && tessellated && hasPolys) { + int last1 = 0; + if (is3D()) { + last1 = lastPolyVertex + 1; + } else if (is2D()) { + last1 = lastPolyVertex + 1; + if (-1 < firstLineVertex) last1 = firstLineVertex; + if (-1 < firstPointVertex) last1 = firstPointVertex; + } + for (int i = firstLineVertex; i < last1; i++) { + float u = tessGeo.polyTexCoords[2 * i + 0]; + float v = tessGeo.polyTexCoords[2 * i + 1]; + tessGeo.polyTexCoords[2 * i + 0] = PApplet.min(1, u * uFactor); + tessGeo.polyTexCoords[2 * i + 1] = PApplet.min(1, v * uFactor); + } + root.setModifiedPolyTexCoords(firstPolyVertex, last1 - 1); } } @@ -1524,8 +1578,13 @@ public class PShapeOpenGL extends PShape { return; } + if (image != null && textureMode == IMAGE) { + u = PApplet.min(1, u / image.width); + v = PApplet.min(1, v / image.height); + } inGeo.texcoords[2 * index + 0] = u; inGeo.texcoords[2 * index + 1] = v; + markForTessellation(); } @@ -2629,18 +2688,17 @@ public class PShapeOpenGL extends PShape { rounded = true; } - rectMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); if (rounded) { inGeo.addRect(a, b, c, d, tl, tr, br, bl, - fill, stroke, bezierDetail, rectMode); + fill, stroke, bezierDetail, CORNER); tessellator.tessellatePolygon(false, true, true); } else { inGeo.addRect(a, b, c, d, - fill, stroke, rectMode); + fill, stroke, CORNER); tessellator.tessellateQuads(); } } @@ -2655,11 +2713,10 @@ public class PShapeOpenGL extends PShape { d = params[3]; } -// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addEllipse(a, b, c, d, fill, stroke, ellipseMode); + inGeo.addEllipse(a, b, c, d, fill, stroke, CORNER); tessellator.tessellateTriangleFan(); } @@ -2667,7 +2724,7 @@ public class PShapeOpenGL extends PShape { protected void tessellateArc() { float a = 0, b = 0, c = 0, d = 0; float start = 0, stop = 0; - int mode = 0; +// int mode = 0; if (params.length == 6 || params.length == 7) { a = params[0]; b = params[1]; @@ -2675,16 +2732,16 @@ public class PShapeOpenGL extends PShape { d = params[3]; start = params[4]; stop = params[5]; - if (params.length == 7) { - mode = (int)(params[6]); - } + // Not using arc mode since PShape only uses CORNER +// if (params.length == 7) { +// mode = (int)(params[6]); +// } } -// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addArc(a, b, c, d, start, stop, fill, stroke, mode); + inGeo.addArc(a, b, c, d, start, stop, fill, stroke, CORNER); tessellator.tessellateTriangleFan(); } @@ -3960,31 +4017,36 @@ public class PShapeOpenGL extends PShape { @Override protected void styles(PGraphics g) { if (g instanceof PGraphicsOpenGL) { - if (stroke) { + if (g.stroke) { + setStroke(true); setStroke(g.strokeColor); setStrokeWeight(g.strokeWeight); - - // These two don't to nothing probably: setStrokeCap(g.strokeCap); setStrokeJoin(g.strokeJoin); } else { setStroke(false); } - if (fill) { + if (g.fill) { + setFill(true); setFill(g.fillColor); } else { setFill(false); } + if (g.tint) { + setTint(true); + setTint(g.tintColor); + } + setAmbient(g.ambientColor); setSpecular(g.specularColor); setEmissive(g.emissiveColor); setShininess(g.shininess); - // What about other style parameters, such as rectMode, etc? - // These should force a tessellation update, same as stroke - // cap and weight... right? + if (image != null) { + setTextureMode(g.textureMode); + } } else { super.styles(g); } diff --git a/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde b/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde index f0554ab93..e08079140 100644 --- a/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde +++ b/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde @@ -54,8 +54,8 @@ void draw() void keyPressed() { - // If the key is between 'A'(65) and 'z'(122) - if( key >= 'A' && key <= 'z') { + // If the key is between 'A'(65) to 'Z' and 'a' to 'z'(122) + if((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')) { int keyIndex; if(key <= 'Z') { keyIndex = key-'A'; diff --git a/java/examples/Basics/Typography/Letters/Letters.pde b/java/examples/Basics/Typography/Letters/Letters.pde index 6f0314c73..781d2aac7 100644 --- a/java/examples/Basics/Typography/Letters/Letters.pde +++ b/java/examples/Basics/Typography/Letters/Letters.pde @@ -5,9 +5,6 @@ * setting the font, and then drawing the letters. */ -// The next line is needed if running in JavaScript Mode with Processing.js -/* @pjs font="Courier.ttf"; */ - PFont f; void setup() { @@ -16,7 +13,7 @@ void setup() { // Create the font println(PFont.list()); - f = createFont("Monospaced", 24); + f = createFont("Georgia", 24); textFont(f); textAlign(CENTER, CENTER); } diff --git a/java/examples/Basics/Typography/Words/Words.pde b/java/examples/Basics/Typography/Words/Words.pde index 445a6fef9..c86bdcbb6 100644 --- a/java/examples/Basics/Typography/Words/Words.pde +++ b/java/examples/Basics/Typography/Words/Words.pde @@ -5,9 +5,6 @@ * The letters can be aligned left, center, or right with the * textAlign() function. */ - -// The next line is needed if running in JavaScript Mode with Processing.js -/* @pjs font="Georgia.ttf"; */ PFont f; @@ -16,7 +13,7 @@ void setup() { // Create the font println(PFont.list()); - f = createFont("Serif", 24); + f = createFont("Georgia", 24); textFont(f); }