Skip to content

Commit 647201c

Browse files
committed
more surface updates based on discussion in processing#3388
1 parent dd7ea4d commit 647201c

8 files changed

Lines changed: 124 additions & 37 deletions

File tree

core/src/processing/core/PApplet.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -772,18 +772,21 @@ public class PApplet implements PConstants {
772772
protected PSurface surface;
773773

774774

775-
/** The frame containing this sketch (if any) */
775+
/**
776+
* A dummy frame to keep compatibility with 2.x code
777+
* and encourage users to update.
778+
*/
776779
public Frame frame;
777780

778781

779-
public Frame getFrame() {
780-
return frame;
781-
}
782-
783-
784-
public void setFrame(Frame frame) {
785-
this.frame = frame;
786-
}
782+
// public Frame getFrame() {
783+
// return frame;
784+
// }
785+
//
786+
//
787+
// public void setFrame(Frame frame) {
788+
// this.frame = frame;
789+
// }
787790

788791

789792
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

core/src/processing/core/PGraphics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4934,7 +4934,7 @@ protected void textCharScreenImpl(PImage glyph,
49344934
*/
49354935
@SuppressWarnings("deprecation")
49364936
public FontMetrics getFontMetrics(Font font) { // ignore
4937-
Frame frame = parent.getFrame();
4937+
Frame frame = parent.frame;
49384938
if (frame != null) {
49394939
return frame.getToolkit().getFontMetrics(font);
49404940
}

core/src/processing/core/PSurface.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public interface PSurface {
4646
// int deviceIndex, boolean fullScreen, boolean spanDisplays);
4747
public void initFrame(PApplet sketch);
4848

49+
/**
50+
* Get the native window object associated with this drawing surface.
51+
* For Java2D, this will be an AWT Frame object. For OpenGL, the window.
52+
* The data returned here is subject to the whims of the renderer,
53+
* and using this method means you're willing to deal with underlying
54+
* implementation changes and that you won't throw a fit like a toddler
55+
* if your code breaks sometime in the future.
56+
*/
57+
public Object getNative();
58+
4959
//
5060

5161
// Just call these on an AWT Frame object stored in PApplet.
@@ -61,6 +71,8 @@ public interface PSurface {
6171
/** Set true if we want to resize things (default is not resizable) */
6272
public void setResizable(boolean resizable);
6373

74+
public void setIcon(PImage icon);
75+
6476
//
6577

6678
// public void placeWindow(int[] location);
@@ -78,6 +90,8 @@ public interface PSurface {
7890
// sets displayWidth/Height inside PApplet
7991
//public void checkDisplaySize();
8092

93+
public void setLocation(int x, int y);
94+
8195
public void setSize(int width, int height);
8296

8397
/**

core/src/processing/core/PSurfaceAWT.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ class SmoothCanvas extends Canvas {
149149
private Dimension newSize = new Dimension(0, 0);
150150

151151

152+
public Frame getFrame() {
153+
return frame;
154+
}
155+
156+
152157
@Override
153158
public Dimension getPreferredSize() {
154159
return new Dimension(sketchWidth, sketchHeight);
@@ -531,7 +536,13 @@ public void initFrame(PApplet sketch) {/*, int backgroundColor,
531536
// http://code.google.com/p/processing/issues/detail?id=467
532537
frame.setResizable(false);
533538

534-
sketch.setFrame(frame);
539+
// sketch.setFrame(frame);
540+
}
541+
542+
543+
@Override
544+
public Object getNative() {
545+
return canvas;
535546
}
536547

537548

@@ -833,9 +844,9 @@ public void initImage(PGraphics graphics) {
833844
// }
834845

835846

836-
@Override
837-
public void setSmooth(int level) {
838-
}
847+
// @Override
848+
// public void setSmooth(int level) {
849+
// }
839850

840851

841852
/*

core/src/processing/core/PSurfaceFX.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public PSurfaceFX(PGraphicsFX2D graphics) {
6868
}
6969

7070

71+
public Object getNative() {
72+
return canvas;
73+
}
74+
75+
7176
class ResizableCanvas extends Canvas {
7277

7378
public ResizableCanvas() {
@@ -141,6 +146,10 @@ public void changed(ObservableValue<? extends Boolean> value,
141146
});
142147
}
143148

149+
public Stage getStage() {
150+
return stage;
151+
}
152+
144153
@Override
145154
public boolean isResizable() {
146155
return true;
@@ -248,6 +257,11 @@ public void setResizable(boolean resizable) {
248257
}
249258

250259

260+
public void setIcon(PImage icon) {
261+
// TODO implement this in JavaFX
262+
}
263+
264+
251265
/*
252266
@Override
253267
public void placeWindow(int[] location) {
@@ -386,6 +400,12 @@ public void handle(WindowEvent we) {
386400
}
387401

388402

403+
public void setLocation(int x, int y) {
404+
stage.setX(x);
405+
stage.setY(y);
406+
}
407+
408+
389409
public void setSize(int width, int height) {
390410
//System.out.format("%s.setSize(%d, %d)%n", getClass().getSimpleName(), width, height);
391411
stage.setWidth(width);

core/src/processing/core/PSurfaceNone.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,38 @@ public void initFrame(PApplet sketch) {/*, int backgroundColor,
6767
}
6868

6969

70+
public Object getNative() {
71+
return null;
72+
}
73+
74+
7075
/** Set the window (and dock, or whatever necessary) title. */
76+
@Override
7177
public void setTitle(String title) {
72-
// TODO ignored?
78+
// You're in a utopian PSurface implementation where titles don't exist.
79+
}
80+
81+
82+
@Override
83+
public void setIcon(PImage image) {
84+
// I ain't visible, man.
7385
}
7486

7587

7688
/** Show or hide the window. */
89+
@Override
7790
public void setVisible(boolean visible) {
78-
// TODO ignored?
91+
// I'm always invisible. You can't catch me.
7992
}
8093

8194

8295
/** Set true if we want to resize things (default is not resizable) */
96+
@Override
8397
public void setResizable(boolean resizable) {
84-
// TODO ignored?
98+
// I don't need size to know my worth.
8599
}
86100

87101

88-
// public void placeWindow(int[] location) { }
89-
90102
@Override
91103
public void placeWindow(int[] location, int[] editorLocation) { }
92104

@@ -102,6 +114,12 @@ public void setupExternalMessages() { }
102114
//
103115

104116

117+
@Override
118+
public void setLocation(int x, int y) {
119+
// I'm everywhere, because I'm nowhere.
120+
}
121+
122+
105123
@Override
106124
public void setSize(int wide, int high) {
107125
if (PApplet.DEBUG) {
@@ -136,10 +154,9 @@ public void setSize(int wide, int high) {
136154
// }
137155

138156

139-
public void setSmooth(int level) {
140-
// TODO Auto-generated method stub
141-
142-
}
157+
// public void setSmooth(int level) {
158+
// // TODO Auto-generated method stub
159+
// }
143160

144161
// void requestFocus() {
145162
// }

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ public void initFrame(PApplet sketch) {/*, int backgroundColor,
111111
}
112112

113113

114+
public Object getNative() {
115+
System.err.println("PSurfaceJOGL.getNative() not implemented");
116+
return null;
117+
}
118+
119+
114120
protected void initScreen() {
115121
display = NewtFactory.createDisplay(null);
116122
display.addReference();
@@ -336,22 +342,40 @@ public void run() {
336342
}).start();
337343
}
338344

345+
339346
@Override
340347
public void setTitle(String title) {
341348
window.setTitle(title);
342349
}
343350

351+
344352
@Override
345353
public void setVisible(boolean visible) {
346354
window.setVisible(visible);
347355
}
348356

357+
349358
@Override
350359
public void setResizable(boolean resizable) {
351360
// TODO Auto-generated method stub
361+
}
352362

363+
364+
public void setIcon(PImage icon) {
365+
// TODO Auto-generated method stub
366+
}
367+
368+
369+
protected void initIcons() {
370+
final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
371+
String[] iconImages = new String[sizes.length];
372+
for (int i = 0; i < sizes.length; i++) {
373+
iconImages[i] = "/icon/icon-" + sizes[i] + ".png";
374+
}
375+
NewtFactory.setWindowIcons(new ClassResources(PApplet.class, iconImages));
353376
}
354377

378+
355379
// private void setFrameCentered() {
356380
// }
357381

@@ -460,16 +484,6 @@ public void placePresent(int stopColor) {
460484
}
461485

462486

463-
protected void initIcons() {
464-
final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
465-
String[] iconImages = new String[sizes.length];
466-
for (int i = 0; i < sizes.length; i++) {
467-
iconImages[i] = "/icon/icon-" + sizes[i] + ".png";
468-
}
469-
NewtFactory.setWindowIcons(new ClassResources(PApplet.class, iconImages));
470-
}
471-
472-
473487
public void setupExternalMessages() {
474488
// TODO Auto-generated method stub
475489

@@ -523,6 +537,13 @@ public boolean isStopped() {
523537
}
524538
}
525539

540+
541+
public void setLocation(int x, int y) {
542+
// TODO implement me!
543+
System.err.println("PSurfaceJOGL.setLocation() not yet implemented.");
544+
}
545+
546+
526547
public void setSize(int width, int height) {
527548
if (width == sketch.width && height == sketch.height) {
528549
return;

core/todo.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ beta
8181
_ pixelDensity(BEST)? (messes with pixels, but for most sketches, helpful)
8282
_ surface.setXxx() handling
8383
_ https://github.com/processing/processing/issues/3388
84-
_ setResizable, setVisible, setTitle
85-
_ setIconImage(java.awt.Image) -> take a PImage instead?
84+
X setResizable, setVisible, setTitle
85+
X setIconImage(java.awt.Image) -> take a PImage instead?
8686
_ removeNotify(), addNotify(), setUndecorated(boolean)
87-
_ setting menubar will be surface-specific
88-
_ setLocation(int, int) and setSize(int, int)
87+
X setting menubar will be surface-specific
88+
X setLocation(int, int) and setSize(int, int)
8989
_ add the "don't use this" warning to the JFrame in PSurfaceAWT
9090
_ draw() executes twice when noLoop() called in setup()
9191
_ https://github.com/processing/processing/issues/3310
@@ -126,6 +126,7 @@ _ move loadImage() into PGraphics, with AWT version the default?
126126
_ or pass createImage() through to renderer?
127127
_ implement frameRate()
128128
_ implement external messages (moving the window)
129+
_ implement PSurfaceFX.setIcon()
129130

130131

131132
opengl

0 commit comments

Comments
 (0)