From 3fb66fc3505fea4424c5ad1e4fe010eb2419005e Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 3 Feb 2022 17:23:58 -0500 Subject: [PATCH] working on windowXxxx() methods to replace surface.xxx() --- core/src/processing/awt/PSurfaceAWT.java | 11 +++++---- core/src/processing/core/PApplet.java | 24 +++++++++++++------- core/src/processing/opengl/PSurfaceJOGL.java | 4 ++-- core/todo.txt | 19 +++++++++------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/core/src/processing/awt/PSurfaceAWT.java b/core/src/processing/awt/PSurfaceAWT.java index 54f3a5705..b9a934248 100644 --- a/core/src/processing/awt/PSurfaceAWT.java +++ b/core/src/processing/awt/PSurfaceAWT.java @@ -823,6 +823,8 @@ public class PSurfaceAWT extends PSurfaceNone { // closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508 frame.setLocation(frameLoc.x, 30); } + // make sure that windowX and windowY are set on startup + sketch.postWindowMoved(frame.getX(), frame.getY()); } canvas.setBounds((contentW - sketchWidth)/2, @@ -1065,12 +1067,13 @@ public class PSurfaceAWT extends PSurfaceNone { int w = windowSize.width - currentInsets.left - currentInsets.right; int h = windowSize.height - currentInsets.top - currentInsets.bottom; setSize(w / windowScaleFactor, h / windowScaleFactor); + // notify the sketch that the window has been resized + sketch.postWindowResized(w / windowScaleFactor, h / windowScaleFactor); // correct the location when inset size changes setLocation(x - currentInsets.left, y - currentInsets.top); - - // notify the sketch that the window has been resized - sketch.postWindowResize(w / windowScaleFactor, h / windowScaleFactor); + //sketch.postWindowMoved(x - currentInsets.left, y - currentInsets.top); + sketch.postWindowMoved(x, y); // presumably user wants drawing area } } } @@ -1078,7 +1081,7 @@ public class PSurfaceAWT extends PSurfaceNone { @Override public void componentMoved(ComponentEvent e) { Point where = ((Frame) e.getSource()).getLocation(); - sketch.postWindowPosition(where.x, where.y); + sketch.postWindowMoved(where.x, where.y); } }); } diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index f23973d1c..3853238ad 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -164,6 +164,9 @@ public class PApplet implements PConstants { */ public int displayHeight; + public int windowX; + public int windowY; + /** A leech graphics object that is echoing all events. */ public PGraphics recorder; @@ -9983,14 +9986,14 @@ public class PApplet implements PConstants { * the beginDraw() call and before the draw(). Note that this is * only the notification that the resize has happened. */ - public void postWindowResize(int newWidth, int newHeight) { + public void postWindowResized(int newWidth, int newHeight) { windowEventQueue.put("w", newWidth); windowEventQueue.put("h", newHeight); } /** Called when window is resized. */ - public void windowResized(int newWidth, int newHeight) { } + public void windowResized() { } public void windowResizable(boolean resizable) { @@ -10009,7 +10012,7 @@ public class PApplet implements PConstants { * the beginDraw() call and before the draw(). Note that this is * only the notification that the window is in a new position. */ - public void postWindowPosition(int newX, int newY) { + public void postWindowMoved(int newX, int newY) { if (external && !fullScreen) { // When running from the PDE, this saves the window position // for next time the sketch is run. @@ -10023,17 +10026,22 @@ public class PApplet implements PConstants { /** Called when the window is moved */ - public void windowPositioned(int x, int y) { } + public void windowMoved() { } private void dequeueWindowEvents() { if (windowEventQueue.containsKey("x")) { - windowPositioned(windowEventQueue.remove("x"), - windowEventQueue.remove("y")); + windowX = windowEventQueue.remove("x"); + windowY = windowEventQueue.remove("y"); + windowMoved(); } if (windowEventQueue.containsKey("w")) { - windowResized(windowEventQueue.remove("w"), - windowEventQueue.remove("h")); + // these should already match width/height + //windowResized(windowEventQueue.remove("w"), + // windowEventQueue.remove("h")); + windowEventQueue.remove("w"); + windowEventQueue.remove("h"); + windowResized(); } } diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index 08c085a71..2d0bd5e7c 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -912,7 +912,7 @@ public class PSurfaceJOGL implements PSurface { sketch.frameMoved(window.getX(), window.getY()); } */ - sketch.postWindowPosition(window.getX(), window.getY()); + sketch.postWindowMoved(window.getX(), window.getY()); } @Override @@ -921,7 +921,7 @@ public class PSurfaceJOGL implements PSurface { @Override public void windowResized(com.jogamp.newt.event.WindowEvent arg0) { - sketch.postWindowResize(window.getWidth(), window.getHeight()); + sketch.postWindowResized(window.getWidth(), window.getHeight()); } } diff --git a/core/todo.txt b/core/todo.txt index 8772f701e..7fa086b2e 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -22,20 +22,19 @@ X this was mostly already in place X 'ArrayIndexOutOfBoundsException: Coordinate out of bounds!' X when resizing sketch while also saving frame in Java2D (default renderer) X https://github.com/processing/processing4/issues/186 -_ Better solution for frame/surface methods -_ https://github.com/processing/processing4/issues/53 +X working on better methods for surface.setXxxx() but incomplete o should it be requestSize() because the change is not immediate? X nope, too confusing for folks anyway X windowTitle(), windowSize(), windowResizable() X windowLocation() or maybe windowPosition() and windowPositioned() X or windowMove()? X do we need a windowResized() event? -_ windowMove(d) would go with windowResize(d) -_ windowResized and windowPositioned ok but imperfect -_ but windowSize() is awkward with size() -_ moveWindow better than windowMove -_ but breaks alphabetical -_ and then titleWindow()? ugh +X windowMove(d) would go with windowResize(d) +X windowResized and windowPositioned ok but imperfect +X but windowSize() is awkward with size() +o moveWindow better than windowMove +o but breaks alphabetical +o and then titleWindow()? ugh images X rework saveImpl() for images and how it interacts with the ShimAWT default @@ -47,6 +46,10 @@ X core/src/icon-NN.png should be the exported application icon X currently it's the p5 icon since the export just looks black +_ finish the solution for frame/surface methods +_ https://github.com/processing/processing4/issues/53 +_ need to update windowX/Y on first open +_ finalize naming/behavior _ windowRatio() _ size() function that scales to screen, keeps aspect, re-scales mouse coords