From 13d019696c82a458264359bbe13029e37d35eef7 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 13 Jun 2015 17:50:54 -0400 Subject: [PATCH] more pixel density fixes --- core/src/processing/core/PApplet.java | 29 ++++++++++++++++--- core/src/processing/core/PSurfaceAWT.java | 15 ++++++---- core/src/processing/core/PSurfaceFX.java | 6 ++-- core/src/processing/opengl/PSurfaceJOGL.java | 5 ++-- core/todo.txt | 30 ++++++++++++-------- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 38f37e346..d17d8fb79 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -293,6 +293,18 @@ public class PApplet implements PConstants { */ public int height = DEFAULT_HEIGHT; + /** + * Width of the pixels in this drawing surface + * (takes pixelDensity into account). + */ + public int pixelWidth; + + /** + * Height of the pixels in this drawing surface + * (takes pixelDensity into account). + */ + public int pixelHeight; + /** * ( begin auto-generated from mouseX.xml ) * @@ -811,7 +823,7 @@ public class PApplet implements PConstants { boolean fullScreen; int display = -1; // use default GraphicsDevice[] displayDevices; - int pixelDensity = 1; + public int pixelDensity = 1; String outputPath; OutputStream outputStream; @@ -897,19 +909,16 @@ public class PApplet implements PConstants { final public int sketchWidth() { - //return DEFAULT_WIDTH; return width; } final public int sketchHeight() { - //return DEFAULT_HEIGHT; return height; } final public String sketchRenderer() { - //return JAVA2D; return renderer; } @@ -1061,6 +1070,18 @@ public class PApplet implements PConstants { } + /** + * Called by PSurface objects to set the width and height variables, + * and update the pixelWidth and pixelHeight variables. + */ + public void setSize(int width, int height) { + this.width = width; + this.height = height; + pixelWidth = width * pixelDensity; + pixelHeight = height * pixelDensity; + } + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . diff --git a/core/src/processing/core/PSurfaceAWT.java b/core/src/processing/core/PSurfaceAWT.java index eb4ea8403..d5e274ca2 100644 --- a/core/src/processing/core/PSurfaceAWT.java +++ b/core/src/processing/core/PSurfaceAWT.java @@ -168,12 +168,14 @@ public class PSurfaceAWT extends PSurfaceNone { super.validate(); newSize.width = getWidth(); newSize.height = getHeight(); - if (oldSize.equals(newSize)) { -// System.out.println("validate() return " + oldSize); - return; - } else { +// if (oldSize.equals(newSize)) { +//// System.out.println("validate() return " + oldSize); +// return; +// } else { + if (!oldSize.equals(newSize)) { // System.out.println("validate() render old=" + oldSize + " -> new=" + newSize); oldSize = newSize; + sketch.setSize(newSize.width, newSize.height); render(); } } @@ -783,8 +785,9 @@ public class PSurfaceAWT extends PSurfaceNone { //initImage(graphics, wide, high); //throw new RuntimeException("implement me, see readme.md"); - sketch.width = wide; - sketch.height = high; + sketch.setSize(wide, high); +// sketch.width = wide; +// sketch.height = high; // set PGraphics variables for width/height/pixelWidth/pixelHeight graphics.setSize(wide, high); diff --git a/core/src/processing/core/PSurfaceFX.java b/core/src/processing/core/PSurfaceFX.java index 249f41625..e7a61fc9e 100644 --- a/core/src/processing/core/PSurfaceFX.java +++ b/core/src/processing/core/PSurfaceFX.java @@ -75,7 +75,8 @@ public class PSurfaceFX implements PSurface { @Override public void changed(ObservableValue value, Number oldWidth, Number newWidth) { - sketch.width = newWidth.intValue(); +// sketch.width = newWidth.intValue(); + sketch.setSize(newWidth.intValue(), sketch.height); // draw(); fx.setSize(sketch.width, sketch.height); } @@ -84,7 +85,8 @@ public class PSurfaceFX implements PSurface { @Override public void changed(ObservableValue value, Number oldHeight, Number newHeight) { - sketch.height = newHeight.intValue(); +// sketch.height = newHeight.intValue(); + sketch.setSize(sketch.width, newHeight.intValue()); // draw(); fx.setSize(sketch.width, sketch.height); } diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index 7df3d34d6..34723ce25 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -522,8 +522,9 @@ public class PSurfaceJOGL implements PSurface { // System.err.println("3. set size"); if (!presentMode) { - sketch.width = width; - sketch.height = height; +// sketch.width = width; +// sketch.height = height; + sketch.setSize(width, height); sketchWidth = width; sketchHeight = height; graphics.setSize(width, height); diff --git a/core/todo.txt b/core/todo.txt index c7bfc484c..4ea8addf8 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,10 +1,20 @@ 0238 (3.0b1) +retina fixes +X make g.pixelDensity public inside PApplet (so accessible by sketches) +o or is it akin to g.fill and the rest? +X it's in PApplet, but not public.. will be the same as g.pixelDensity +X add pixelWidth/Height to PApplet +X add setSize() method for surfaces +X tricky cuz we'll need a getter/setter when surface messes w/ things + text/fonts X Text looks blurry in GL Retina X https://github.com/processing/processing/issues/2739 X text not getting the correct font in Retina2D X https://github.com/processing/processing/issues/2617 +X Text is half size in PGraphicsRetina2D +X https://github.com/processing/processing/issues/2738 andres X ortho function is broken @@ -14,6 +24,14 @@ X https://github.com/processing/processing/issues/3379 beta +_ need to be able to call pixelDensity(2) before beginDraw() +_ add pixelDensity() method to PImage/PGraphics +_ pixelDensity(2) does: pixelWidth = width; width /= 2; pixelDensity = 2; +_ this works for both PGraphics and images (though they're a little backwards) +_ for PGraphics it comes early enough +_ pixelDensity(BEST)? (messes with pixels, but for most sketches, helpful) +_ NPE when using image() created with createGraphics(PGraphicsRetina2D) +_ https://github.com/processing/processing/issues/2510 _ replace sketchXxxx() methods with another mechanism? _ and an internal dictionary that stores them all? _ intParam(), stringParam() and setParam()? @@ -22,13 +40,6 @@ _ surface.size(), surface.noSmooth()... just like PGraphics methods? _ make final to move folks away from these? _ or is this a bad move until we've sorted out Android? _ update wiki/docs to say "don't override sketchXxxx() methods" -_ pixelDensity(BEST)? (messes with pixels, but for most sketches, helpful) -_ add pixelDensity() method to PImage/PGraphics -_ pixelDensity(2) does: pixelWidth = width; width /= 2; pixelDensity = 2; -_ this works for both PGraphics and images (though they're a little backwards) -_ for PGraphics it comes early enough -_ g.pixelDensity should prolly move to PApplet? -_ or is it akin to g.fill and the rest? high priority @@ -194,11 +205,6 @@ _ retina sketches slow to start _ https://github.com/processing/processing/issues/2357 _ zero alpha values still a problem with retina renderer _ https://github.com/processing/processing/issues/2030 -_ NPE when using image() created with createGraphics(PGraphicsRetina2D) -_ https://github.com/processing/processing/issues/2510 -_ check retina with PGraphicsRetina2D -_ Text is half size in PGraphicsRetina2D -_ https://github.com/processing/processing/issues/2738 decisions/misc