more pixel density fixes

This commit is contained in:
Ben Fry
2015-06-13 17:50:54 -04:00
parent f7d542b2a6
commit 13d019696c
5 changed files with 59 additions and 26 deletions
+25 -4
View File
@@ -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;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
+9 -6
View File
@@ -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);
+4 -2
View File
@@ -75,7 +75,8 @@ public class PSurfaceFX implements PSurface {
@Override
public void changed(ObservableValue<? extends Number> 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<? extends Number> 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);
}
+3 -2
View File
@@ -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);