Skip to content

Commit 3fb66fc

Browse files
committed
working on windowXxxx() methods to replace surface.xxx()
1 parent 62c3dcc commit 3fb66fc

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

core/src/processing/awt/PSurfaceAWT.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ public void placeWindow(int[] location, int[] editorLocation) {
823823
// closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508
824824
frame.setLocation(frameLoc.x, 30);
825825
}
826+
// make sure that windowX and windowY are set on startup
827+
sketch.postWindowMoved(frame.getX(), frame.getY());
826828
}
827829

828830
canvas.setBounds((contentW - sketchWidth)/2,
@@ -1065,20 +1067,21 @@ public void componentResized(ComponentEvent e) {
10651067
int w = windowSize.width - currentInsets.left - currentInsets.right;
10661068
int h = windowSize.height - currentInsets.top - currentInsets.bottom;
10671069
setSize(w / windowScaleFactor, h / windowScaleFactor);
1070+
// notify the sketch that the window has been resized
1071+
sketch.postWindowResized(w / windowScaleFactor, h / windowScaleFactor);
10681072

10691073
// correct the location when inset size changes
10701074
setLocation(x - currentInsets.left, y - currentInsets.top);
1071-
1072-
// notify the sketch that the window has been resized
1073-
sketch.postWindowResize(w / windowScaleFactor, h / windowScaleFactor);
1075+
//sketch.postWindowMoved(x - currentInsets.left, y - currentInsets.top);
1076+
sketch.postWindowMoved(x, y); // presumably user wants drawing area
10741077
}
10751078
}
10761079
}
10771080

10781081
@Override
10791082
public void componentMoved(ComponentEvent e) {
10801083
Point where = ((Frame) e.getSource()).getLocation();
1081-
sketch.postWindowPosition(where.x, where.y);
1084+
sketch.postWindowMoved(where.x, where.y);
10821085
}
10831086
});
10841087
}

core/src/processing/core/PApplet.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public class PApplet implements PConstants {
164164
*/
165165
public int displayHeight;
166166

167+
public int windowX;
168+
public int windowY;
169+
167170
/** A leech graphics object that is echoing all events. */
168171
public PGraphics recorder;
169172

@@ -9983,14 +9986,14 @@ public void windowSize(int newWidth, int newHeight) {
99839986
* the beginDraw() call and before the draw(). Note that this is
99849987
* only the notification that the resize has happened.
99859988
*/
9986-
public void postWindowResize(int newWidth, int newHeight) {
9989+
public void postWindowResized(int newWidth, int newHeight) {
99879990
windowEventQueue.put("w", newWidth);
99889991
windowEventQueue.put("h", newHeight);
99899992
}
99909993

99919994

99929995
/** Called when window is resized. */
9993-
public void windowResized(int newWidth, int newHeight) { }
9996+
public void windowResized() { }
99949997

99959998

99969999
public void windowResizable(boolean resizable) {
@@ -10009,7 +10012,7 @@ public void windowPosition(int x, int y) {
1000910012
* the beginDraw() call and before the draw(). Note that this is
1001010013
* only the notification that the window is in a new position.
1001110014
*/
10012-
public void postWindowPosition(int newX, int newY) {
10015+
public void postWindowMoved(int newX, int newY) {
1001310016
if (external && !fullScreen) {
1001410017
// When running from the PDE, this saves the window position
1001510018
// for next time the sketch is run.
@@ -10023,17 +10026,22 @@ public void postWindowPosition(int newX, int newY) {
1002310026

1002410027

1002510028
/** Called when the window is moved */
10026-
public void windowPositioned(int x, int y) { }
10029+
public void windowMoved() { }
1002710030

1002810031

1002910032
private void dequeueWindowEvents() {
1003010033
if (windowEventQueue.containsKey("x")) {
10031-
windowPositioned(windowEventQueue.remove("x"),
10032-
windowEventQueue.remove("y"));
10034+
windowX = windowEventQueue.remove("x");
10035+
windowY = windowEventQueue.remove("y");
10036+
windowMoved();
1003310037
}
1003410038
if (windowEventQueue.containsKey("w")) {
10035-
windowResized(windowEventQueue.remove("w"),
10036-
windowEventQueue.remove("h"));
10039+
// these should already match width/height
10040+
//windowResized(windowEventQueue.remove("w"),
10041+
// windowEventQueue.remove("h"));
10042+
windowEventQueue.remove("w");
10043+
windowEventQueue.remove("h");
10044+
windowResized();
1003710045
}
1003810046
}
1003910047

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ public void windowMoved(com.jogamp.newt.event.WindowEvent arg0) {
912912
sketch.frameMoved(window.getX(), window.getY());
913913
}
914914
*/
915-
sketch.postWindowPosition(window.getX(), window.getY());
915+
sketch.postWindowMoved(window.getX(), window.getY());
916916
}
917917

918918
@Override
@@ -921,7 +921,7 @@ public void windowRepaint(com.jogamp.newt.event.WindowUpdateEvent arg0) {
921921

922922
@Override
923923
public void windowResized(com.jogamp.newt.event.WindowEvent arg0) {
924-
sketch.postWindowResize(window.getWidth(), window.getHeight());
924+
sketch.postWindowResized(window.getWidth(), window.getHeight());
925925
}
926926
}
927927

core/todo.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,19 @@ X this was mostly already in place
2222
X 'ArrayIndexOutOfBoundsException: Coordinate out of bounds!'
2323
X when resizing sketch while also saving frame in Java2D (default renderer)
2424
X https://github.com/processing/processing4/issues/186
25-
_ Better solution for frame/surface methods
26-
_ https://github.com/processing/processing4/issues/53
25+
X working on better methods for surface.setXxxx() but incomplete
2726
o should it be requestSize() because the change is not immediate?
2827
X nope, too confusing for folks anyway
2928
X windowTitle(), windowSize(), windowResizable()
3029
X windowLocation() or maybe windowPosition() and windowPositioned()
3130
X or windowMove()?
3231
X do we need a windowResized() event?
33-
_ windowMove(d) would go with windowResize(d)
34-
_ windowResized and windowPositioned ok but imperfect
35-
_ but windowSize() is awkward with size()
36-
_ moveWindow better than windowMove
37-
_ but breaks alphabetical
38-
_ and then titleWindow()? ugh
32+
X windowMove(d) would go with windowResize(d)
33+
X windowResized and windowPositioned ok but imperfect
34+
X but windowSize() is awkward with size()
35+
o moveWindow better than windowMove
36+
o but breaks alphabetical
37+
o and then titleWindow()? ugh
3938

4039
images
4140
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
4746
X currently it's the p5 icon since the export just looks black
4847

4948

49+
_ finish the solution for frame/surface methods
50+
_ https://github.com/processing/processing4/issues/53
51+
_ need to update windowX/Y on first open
52+
_ finalize naming/behavior
5053
_ windowRatio()
5154
_ size() function that scales to screen, keeps aspect, re-scales mouse coords
5255

0 commit comments

Comments
 (0)