propane 3.1.0.pre-java → 3.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/CHANGELOG.md +1 -5
- data/README.md +23 -12
- data/Rakefile +23 -12
- data/lib/propane/helpers/version_error.rb +6 -0
- data/lib/propane/runner.rb +12 -0
- data/lib/propane/version.rb +1 -1
- data/library/slider/slider.rb +1 -1
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.xml +28 -27
- data/propane.gemspec +2 -2
- data/src/main/java/japplemenubar/JAppleMenuBar.java +41 -47
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/MathToolModule.java +12 -11
- data/src/main/java/monkstone/PropaneLibrary.java +9 -10
- data/src/main/java/monkstone/core/LibraryProxy.java +124 -113
- data/src/main/java/monkstone/fastmath/Deglut.java +86 -89
- data/src/main/java/monkstone/filechooser/Chooser.java +7 -13
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -1
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +4 -4
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +9 -9
- data/src/main/java/monkstone/slider/SimpleSlider.java +0 -9
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +11 -13
- data/src/main/java/monkstone/slider/Slider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +8 -9
- data/src/main/java/monkstone/vecmath/AppRender.java +2 -2
- data/src/main/java/monkstone/vecmath/ShapeRender.java +2 -2
- data/src/main/java/monkstone/vecmath/package-info.java +2 -2
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/VideoInterface.java +11 -5
- data/src/main/java/monkstone/videoevent/package-info.java +2 -2
- data/src/main/java/processing/awt/PGraphicsJava2D.java +1742 -2243
- data/src/main/java/processing/awt/PShapeJava2D.java +268 -270
- data/src/main/java/processing/awt/PSurfaceAWT.java +821 -920
- data/src/main/java/processing/core/DesktopHandler.java +94 -0
- data/src/main/java/processing/core/PApplet.java +14170 -14082
- data/src/main/java/processing/core/PConstants.java +447 -473
- data/src/main/java/processing/core/PFont.java +867 -873
- data/src/main/java/processing/core/PGraphics.java +7193 -7428
- data/src/main/java/processing/core/PImage.java +3051 -3117
- data/src/main/java/processing/core/PMatrix.java +159 -172
- data/src/main/java/processing/core/PMatrix2D.java +403 -444
- data/src/main/java/processing/core/PMatrix3D.java +735 -749
- data/src/main/java/processing/core/PShape.java +2651 -2793
- data/src/main/java/processing/core/PShapeOBJ.java +415 -422
- data/src/main/java/processing/core/PShapeSVG.java +1466 -1475
- data/src/main/java/processing/core/PStyle.java +37 -40
- data/src/main/java/processing/core/PSurface.java +98 -103
- data/src/main/java/processing/core/PSurfaceNone.java +208 -236
- data/src/main/java/processing/core/PVector.java +961 -990
- data/src/main/java/processing/data/DoubleDict.java +709 -753
- data/src/main/java/processing/data/DoubleList.java +695 -748
- data/src/main/java/processing/data/FloatDict.java +702 -746
- data/src/main/java/processing/data/FloatList.java +697 -751
- data/src/main/java/processing/data/IntDict.java +673 -718
- data/src/main/java/processing/data/IntList.java +633 -699
- data/src/main/java/processing/data/JSONArray.java +873 -931
- data/src/main/java/processing/data/JSONObject.java +1165 -1262
- data/src/main/java/processing/data/JSONTokener.java +341 -351
- data/src/main/java/processing/data/LongDict.java +662 -707
- data/src/main/java/processing/data/LongList.java +634 -700
- data/src/main/java/processing/data/Sort.java +41 -37
- data/src/main/java/processing/data/StringDict.java +486 -522
- data/src/main/java/processing/data/StringList.java +580 -624
- data/src/main/java/processing/data/Table.java +3508 -3686
- data/src/main/java/processing/data/TableRow.java +183 -182
- data/src/main/java/processing/data/XML.java +883 -957
- data/src/main/java/processing/event/Event.java +66 -87
- data/src/main/java/processing/event/KeyEvent.java +41 -48
- data/src/main/java/processing/event/MouseEvent.java +93 -103
- data/src/main/java/processing/event/TouchEvent.java +6 -10
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +5 -69
- data/src/main/java/processing/javafx/PSurfaceFX.java +2 -7
- data/src/main/java/processing/opengl/FontTexture.java +270 -290
- data/src/main/java/processing/opengl/FrameBuffer.java +363 -375
- data/src/main/java/processing/opengl/LinePath.java +500 -543
- data/src/main/java/processing/opengl/LineStroker.java +582 -593
- data/src/main/java/processing/opengl/PGL.java +2881 -2904
- data/src/main/java/processing/opengl/PGraphics2D.java +315 -408
- data/src/main/java/processing/opengl/PGraphics3D.java +72 -107
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12043 -12230
- data/src/main/java/processing/opengl/PJOGL.java +1681 -1745
- data/src/main/java/processing/opengl/PShader.java +1257 -1260
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4599 -4662
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1030 -1047
- data/src/main/java/processing/opengl/Texture.java +1397 -1462
- data/src/main/java/processing/opengl/VertexBuffer.java +55 -57
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/vendors/Rakefile +1 -1
- metadata +12 -8
- data/src/main/java/processing/core/ThinkDifferent.java +0 -70
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
2
|
-
|
|
3
1
|
/*
|
|
4
2
|
Part of the Processing project - http://processing.org
|
|
5
3
|
|
|
@@ -18,8 +16,7 @@
|
|
|
18
16
|
Public License along with this library; if not, write to the
|
|
19
17
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
20
18
|
Boston, MA 02111-1307 USA
|
|
21
|
-
*/
|
|
22
|
-
|
|
19
|
+
*/
|
|
23
20
|
package processing.awt;
|
|
24
21
|
|
|
25
22
|
import java.awt.Canvas;
|
|
@@ -42,12 +39,14 @@ import java.awt.event.*;
|
|
|
42
39
|
import java.awt.geom.Rectangle2D;
|
|
43
40
|
import java.awt.image.*;
|
|
44
41
|
import java.lang.management.ManagementFactory;
|
|
42
|
+
import java.lang.reflect.InvocationTargetException;
|
|
45
43
|
import java.lang.reflect.Method;
|
|
46
44
|
import java.net.URL;
|
|
47
45
|
import java.util.ArrayList;
|
|
48
46
|
import java.util.List;
|
|
49
47
|
|
|
50
48
|
import javax.swing.JFrame;
|
|
49
|
+
import processing.core.DesktopHandler;
|
|
51
50
|
|
|
52
51
|
import processing.core.PApplet;
|
|
53
52
|
import processing.core.PConstants;
|
|
@@ -57,47 +56,43 @@ import processing.core.PSurfaceNone;
|
|
|
57
56
|
import processing.event.KeyEvent;
|
|
58
57
|
import processing.event.MouseEvent;
|
|
59
58
|
|
|
60
|
-
|
|
61
59
|
public class PSurfaceAWT extends PSurfaceNone {
|
|
62
|
-
GraphicsDevice displayDevice;
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
// boolean resizable; // default is false
|
|
61
|
+
GraphicsDevice displayDevice;
|
|
66
62
|
|
|
67
|
-
|
|
63
|
+
// used for canvas to determine whether resizable or not
|
|
64
|
+
// boolean resizable; // default is false
|
|
65
|
+
// Internally, we know it's always a JFrame (not just a Frame)
|
|
68
66
|
// JFrame frame;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
// Trying Frame again with a11 to see if this avoids some Swing nastiness.
|
|
68
|
+
// In the past, AWT Frames caused some problems on Windows and Linux,
|
|
69
|
+
// but those may not be a problem for our reworked PSurfaceAWT class.
|
|
70
|
+
Frame frame;
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
// Note that x and y may not be zero, depending on the display configuration
|
|
73
|
+
Rectangle screenRect;
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
// Used for resizing, at least on Windows insets size changes when
|
|
76
|
+
// frame.setResizable() is called, and in resize listener we need
|
|
77
|
+
// to know what size the window was before.
|
|
78
|
+
Insets currentInsets = new Insets(0, 0, 0, 0);
|
|
81
79
|
|
|
82
|
-
|
|
80
|
+
// 3.0a5 didn't use strategy, and active was shut off during init() w/ retina
|
|
83
81
|
// boolean useStrategy = true;
|
|
84
|
-
|
|
85
|
-
Canvas canvas;
|
|
82
|
+
Canvas canvas;
|
|
86
83
|
// Component canvas;
|
|
87
84
|
|
|
88
85
|
// PGraphics graphics; // moved to PSurfaceNone
|
|
86
|
+
int sketchWidth;
|
|
87
|
+
int sketchHeight;
|
|
89
88
|
|
|
90
|
-
|
|
91
|
-
int sketchHeight;
|
|
89
|
+
int windowScaleFactor;
|
|
92
90
|
|
|
93
|
-
|
|
91
|
+
public PSurfaceAWT(PGraphics graphics) {
|
|
92
|
+
//this.graphics = graphics;
|
|
93
|
+
super(graphics);
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
public PSurfaceAWT(PGraphics graphics) {
|
|
97
|
-
//this.graphics = graphics;
|
|
98
|
-
super(graphics);
|
|
99
|
-
|
|
100
|
-
/*
|
|
95
|
+
/*
|
|
101
96
|
if (checkRetina()) {
|
|
102
97
|
// System.out.println("retina in use");
|
|
103
98
|
|
|
@@ -118,32 +113,31 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
118
113
|
// flicker--pushing pixels out before the screen has finished rendering.
|
|
119
114
|
// useStrategy = false;
|
|
120
115
|
}
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
*/
|
|
117
|
+
canvas = new SmoothCanvas();
|
|
123
118
|
// if (useStrategy) {
|
|
124
|
-
|
|
119
|
+
//canvas.setIgnoreRepaint(true);
|
|
125
120
|
// }
|
|
126
121
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
122
|
+
// Pass tab key to the sketch, rather than moving between components
|
|
123
|
+
canvas.setFocusTraversalKeysEnabled(false);
|
|
124
|
+
|
|
125
|
+
canvas.addComponentListener(new ComponentAdapter() {
|
|
126
|
+
@Override
|
|
127
|
+
public void componentResized(ComponentEvent e) {
|
|
128
|
+
if (!sketch.isLooping()) {
|
|
129
|
+
// make sure this is a real resize event, not just initial setup
|
|
130
|
+
// https://github.com/processing/processing/issues/3310
|
|
131
|
+
Dimension canvasSize = canvas.getSize();
|
|
132
|
+
if (canvasSize.width != sketch.sketchWidth()
|
|
133
|
+
|| canvasSize.height != sketch.sketchHeight()) {
|
|
134
|
+
sketch.redraw();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
addListeners();
|
|
140
|
+
}
|
|
147
141
|
|
|
148
142
|
// /**
|
|
149
143
|
// * Handle grabbing the focus on startup. Other renderers can override this
|
|
@@ -179,81 +173,71 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
179
173
|
// }
|
|
180
174
|
// });
|
|
181
175
|
// }
|
|
176
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
|
177
|
+
public class SmoothCanvas extends Canvas {
|
|
182
178
|
|
|
179
|
+
private Dimension oldSize = new Dimension(0, 0);
|
|
180
|
+
private Dimension newSize = new Dimension(0, 0);
|
|
183
181
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
private Dimension oldSize = new Dimension(0, 0);
|
|
189
|
-
private Dimension newSize = new Dimension(0, 0);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
// Turns out getParent() returns a JPanel on a JFrame. Yech.
|
|
193
|
-
public Frame getFrame() {
|
|
194
|
-
return frame;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
@Override
|
|
199
|
-
public Dimension getPreferredSize() {
|
|
200
|
-
return new Dimension(sketchWidth, sketchHeight);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
@Override
|
|
205
|
-
public Dimension getMinimumSize() {
|
|
206
|
-
return getPreferredSize();
|
|
207
|
-
}
|
|
182
|
+
// Turns out getParent() returns a JPanel on a JFrame. Yech.
|
|
183
|
+
public Frame getFrame() {
|
|
184
|
+
return frame;
|
|
185
|
+
}
|
|
208
186
|
|
|
187
|
+
@Override
|
|
188
|
+
public Dimension getPreferredSize() {
|
|
189
|
+
return new Dimension(sketchWidth, sketchHeight);
|
|
190
|
+
}
|
|
209
191
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
192
|
+
@Override
|
|
193
|
+
public Dimension getMinimumSize() {
|
|
194
|
+
return getPreferredSize();
|
|
195
|
+
}
|
|
215
196
|
|
|
197
|
+
@Override
|
|
198
|
+
public Dimension getMaximumSize() {
|
|
199
|
+
//return resizable ? super.getMaximumSize() : getPreferredSize();
|
|
200
|
+
return frame.isResizable() ? super.getMaximumSize() : getPreferredSize();
|
|
201
|
+
}
|
|
216
202
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
203
|
+
@Override
|
|
204
|
+
public void validate() {
|
|
205
|
+
super.validate();
|
|
206
|
+
newSize.width = getWidth();
|
|
207
|
+
newSize.height = getHeight();
|
|
222
208
|
// if (oldSize.equals(newSize)) {
|
|
223
209
|
//// System.out.println("validate() return " + oldSize);
|
|
224
210
|
// return;
|
|
225
211
|
// } else {
|
|
226
|
-
|
|
212
|
+
if (!oldSize.equals(newSize)) {
|
|
227
213
|
// System.out.println("validate() render old=" + oldSize + " -> new=" + newSize);
|
|
228
|
-
|
|
229
|
-
|
|
214
|
+
oldSize = newSize;
|
|
215
|
+
sketch.setSize(newSize.width / windowScaleFactor, newSize.height / windowScaleFactor);
|
|
230
216
|
// try {
|
|
231
|
-
|
|
217
|
+
render();
|
|
232
218
|
// } catch (IllegalStateException ise) {
|
|
233
219
|
// System.out.println(ise.getMessage());
|
|
234
220
|
// }
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
221
|
+
}
|
|
222
|
+
}
|
|
238
223
|
|
|
239
|
-
|
|
240
|
-
|
|
224
|
+
@Override
|
|
225
|
+
public void update(Graphics g) {
|
|
241
226
|
// System.out.println("updating");
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
227
|
+
paint(g);
|
|
228
|
+
}
|
|
245
229
|
|
|
246
|
-
|
|
247
|
-
|
|
230
|
+
@Override
|
|
231
|
+
public void paint(Graphics screen) {
|
|
248
232
|
// System.out.println("painting");
|
|
249
233
|
// if (useStrategy) {
|
|
250
|
-
|
|
251
|
-
|
|
234
|
+
render();
|
|
235
|
+
/*
|
|
252
236
|
if (graphics != null) {
|
|
253
237
|
System.out.println("drawing to screen " + canvas);
|
|
254
238
|
screen.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
|
|
255
239
|
}
|
|
256
|
-
|
|
240
|
+
*/
|
|
257
241
|
|
|
258
242
|
// } else {
|
|
259
243
|
//// new Exception("painting").printStackTrace(System.out);
|
|
@@ -267,8 +251,8 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
267
251
|
// }
|
|
268
252
|
// }
|
|
269
253
|
// }
|
|
254
|
+
}
|
|
270
255
|
}
|
|
271
|
-
}
|
|
272
256
|
|
|
273
257
|
/*
|
|
274
258
|
@Override
|
|
@@ -278,40 +262,38 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
278
262
|
// prior to Java 7 on OS X, this no longer works [121222]
|
|
279
263
|
// createBufferStrategy(2);
|
|
280
264
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (strategy != null) {
|
|
292
|
-
// Render single frame
|
|
265
|
+
*/
|
|
266
|
+
synchronized protected void render() {
|
|
267
|
+
if (canvas.isDisplayable()
|
|
268
|
+
&& graphics.image != null) {
|
|
269
|
+
if (canvas.getBufferStrategy() == null) {
|
|
270
|
+
canvas.createBufferStrategy(2);
|
|
271
|
+
}
|
|
272
|
+
BufferStrategy strategy = canvas.getBufferStrategy();
|
|
273
|
+
if (strategy != null) {
|
|
274
|
+
// Render single frame
|
|
293
275
|
// try {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
276
|
+
do {
|
|
277
|
+
// The following loop ensures that the contents of the drawing buffer
|
|
278
|
+
// are consistent in case the underlying surface was recreated
|
|
279
|
+
do {
|
|
280
|
+
Graphics2D draw = (Graphics2D) strategy.getDrawGraphics();
|
|
281
|
+
// draw to width/height, since this may be a 2x image
|
|
282
|
+
draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
|
|
283
|
+
draw.dispose();
|
|
284
|
+
} while (strategy.contentsRestored());
|
|
285
|
+
|
|
286
|
+
// Display the buffer
|
|
287
|
+
strategy.show();
|
|
288
|
+
|
|
289
|
+
// Repeat the rendering if the drawing buffer was lost
|
|
290
|
+
} while (strategy.contentsLost());
|
|
291
|
+
}
|
|
292
|
+
}
|
|
310
293
|
}
|
|
311
|
-
}
|
|
312
294
|
|
|
313
295
|
|
|
314
|
-
|
|
296
|
+
/*
|
|
315
297
|
protected void blit() {
|
|
316
298
|
// Other folks that call render() (i.e. paint()) are already on the EDT.
|
|
317
299
|
// We need to be using the EDT since we're messing with the Canvas
|
|
@@ -353,25 +335,23 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
353
335
|
}
|
|
354
336
|
}
|
|
355
337
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
this.sketch = sketch;
|
|
363
|
-
}
|
|
338
|
+
*/
|
|
339
|
+
// what needs to happen here?
|
|
340
|
+
@Override
|
|
341
|
+
public void initOffscreen(PApplet sketch) {
|
|
342
|
+
this.sketch = sketch;
|
|
343
|
+
}
|
|
364
344
|
|
|
365
|
-
|
|
345
|
+
/*
|
|
366
346
|
public Frame initOffscreen() {
|
|
367
347
|
Frame dummy = new Frame();
|
|
368
348
|
dummy.pack(); // get legit AWT graphics
|
|
369
349
|
// but don't show it
|
|
370
350
|
return dummy;
|
|
371
351
|
}
|
|
372
|
-
|
|
352
|
+
*/
|
|
373
353
|
|
|
374
|
-
|
|
354
|
+
/*
|
|
375
355
|
@Override
|
|
376
356
|
public Component initComponent(PApplet sketch) {
|
|
377
357
|
this.sketch = sketch;
|
|
@@ -382,61 +362,59 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
382
362
|
|
|
383
363
|
return canvas;
|
|
384
364
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
@Override
|
|
389
|
-
public void initFrame(final PApplet sketch) {/*, int backgroundColor,
|
|
365
|
+
*/
|
|
366
|
+
@Override
|
|
367
|
+
public void initFrame(final PApplet sketch) {/*, int backgroundColor,
|
|
390
368
|
int deviceIndex, boolean fullScreen, boolean spanDisplays) {*/
|
|
391
|
-
|
|
369
|
+
this.sketch = sketch;
|
|
392
370
|
|
|
393
|
-
|
|
394
|
-
|
|
371
|
+
GraphicsEnvironment environment
|
|
372
|
+
= GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
395
373
|
|
|
396
|
-
|
|
374
|
+
int displayNum = sketch.sketchDisplay();
|
|
397
375
|
// System.out.println("display from sketch is " + displayNum);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
376
|
+
if (displayNum > 0) { // if -1, use the default device
|
|
377
|
+
GraphicsDevice[] devices = environment.getScreenDevices();
|
|
378
|
+
if (displayNum <= devices.length) {
|
|
379
|
+
displayDevice = devices[displayNum - 1];
|
|
380
|
+
} else {
|
|
381
|
+
System.err.format("Display %d does not exist, "
|
|
382
|
+
+ "using the default display instead.%n", displayNum);
|
|
383
|
+
for (int i = 0; i < devices.length; i++) {
|
|
384
|
+
System.err.format("Display %d is %s%n", (i + 1), devices[i]);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (displayDevice == null) {
|
|
389
|
+
displayDevice = environment.getDefaultScreenDevice();
|
|
407
390
|
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (displayDevice == null) {
|
|
411
|
-
displayDevice = environment.getDefaultScreenDevice();
|
|
412
|
-
}
|
|
413
391
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
392
|
+
// Need to save the window bounds at full screen,
|
|
393
|
+
// because pack() will cause the bounds to go to zero.
|
|
394
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=923
|
|
395
|
+
boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
|
|
396
|
+
screenRect = spanDisplays ? getDisplaySpan()
|
|
397
|
+
: displayDevice.getDefaultConfiguration().getBounds();
|
|
398
|
+
// DisplayMode doesn't work here, because we can't get the upper-left
|
|
399
|
+
// corner of the display, which is important for multi-display setups.
|
|
400
|
+
|
|
401
|
+
// Set the displayWidth/Height variables inside PApplet, so that they're
|
|
402
|
+
// usable and can even be returned by the sketchWidth()/Height() methods.
|
|
403
|
+
sketch.displayWidth = screenRect.width;
|
|
404
|
+
sketch.displayHeight = screenRect.height;
|
|
405
|
+
|
|
406
|
+
windowScaleFactor = PApplet.platform == PConstants.MACOSX
|
|
407
|
+
? 1 : sketch.pixelDensity;
|
|
408
|
+
|
|
409
|
+
sketchWidth = sketch.sketchWidth() * windowScaleFactor;
|
|
410
|
+
sketchHeight = sketch.sketchHeight() * windowScaleFactor;
|
|
411
|
+
|
|
412
|
+
boolean fullScreen = sketch.sketchFullScreen();
|
|
413
|
+
// Removing the section below because sometimes people want to do the
|
|
414
|
+
// full screen size in a window, and it also breaks insideSettings().
|
|
415
|
+
// With 3.x, fullScreen() is so easy, that it's just better that way.
|
|
416
|
+
// https://github.com/processing/processing/issues/3545
|
|
417
|
+
/*
|
|
440
418
|
// Sketch has already requested to be the same as the screen's
|
|
441
419
|
// width and height, so let's roll with full screen mode.
|
|
442
420
|
if (screenRect.width == sketchWidth &&
|
|
@@ -444,18 +422,18 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
444
422
|
fullScreen = true;
|
|
445
423
|
sketch.fullScreen(); // won't change the renderer
|
|
446
424
|
}
|
|
447
|
-
|
|
425
|
+
*/
|
|
448
426
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
427
|
+
if (fullScreen || spanDisplays) {
|
|
428
|
+
sketchWidth = screenRect.width;
|
|
429
|
+
sketchHeight = screenRect.height;
|
|
430
|
+
}
|
|
453
431
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
432
|
+
// Using a JFrame fixes a Windows problem with Present mode. This might
|
|
433
|
+
// be our error, but usually this is the sort of crap we usually get from
|
|
434
|
+
// OS X. It's time for a turnaround: Redmond is thinking different too!
|
|
435
|
+
// https://github.com/processing/processing/issues/1955
|
|
436
|
+
frame = new JFrame(displayDevice.getDefaultConfiguration());
|
|
459
437
|
// frame = new Frame(displayDevice.getDefaultConfiguration());
|
|
460
438
|
// // Default Processing gray, which will be replaced below if another
|
|
461
439
|
// // color is specified on the command line (i.e. in the prefs).
|
|
@@ -467,28 +445,27 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
467
445
|
// if (backgroundColor == 0) {
|
|
468
446
|
// backgroundColor = WINDOW_BGCOLOR;
|
|
469
447
|
// }
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
// Put the p5 logo in the Frame's corner to override the Java coffee cup.
|
|
478
|
-
setProcessingIcon(frame);
|
|
448
|
+
final Color windowColor = new Color(sketch.sketchWindowColor(), false);
|
|
449
|
+
if (frame instanceof JFrame) {
|
|
450
|
+
((JFrame) frame).getContentPane().setBackground(windowColor);
|
|
451
|
+
} else {
|
|
452
|
+
frame.setBackground(windowColor);
|
|
453
|
+
}
|
|
479
454
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
// needed before a GLDrawable can be created. So pack() needs to be
|
|
483
|
-
// called on the Frame before applet.init(), which itself calls size(),
|
|
484
|
-
// and launches the Thread that will kick off setup().
|
|
485
|
-
// http://dev.processing.org/bugs/show_bug.cgi?id=891
|
|
486
|
-
// http://dev.processing.org/bugs/show_bug.cgi?id=908
|
|
455
|
+
// Put the p5 logo in the Frame's corner to override the Java coffee cup.
|
|
456
|
+
setProcessingIcon(frame);
|
|
487
457
|
|
|
488
|
-
|
|
489
|
-
|
|
458
|
+
// For 0149, moving this code (up to the pack() method) before init().
|
|
459
|
+
// For OpenGL (and perhaps other renderers in the future), a peer is
|
|
460
|
+
// needed before a GLDrawable can be created. So pack() needs to be
|
|
461
|
+
// called on the Frame before applet.init(), which itself calls size(),
|
|
462
|
+
// and launches the Thread that will kick off setup().
|
|
463
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=891
|
|
464
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=908
|
|
465
|
+
frame.add(canvas);
|
|
466
|
+
setSize(sketchWidth / windowScaleFactor, sketchHeight / windowScaleFactor);
|
|
490
467
|
|
|
491
|
-
|
|
468
|
+
/*
|
|
492
469
|
if (fullScreen) {
|
|
493
470
|
// Called here because the graphics device is needed before we can
|
|
494
471
|
// determine whether the sketch wants size(displayWidth, displayHeight),
|
|
@@ -511,189 +488,162 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
511
488
|
// will be set visible in placeWindow() [3.0a10]
|
|
512
489
|
//frame.setVisible(true); // re-add native resources
|
|
513
490
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
491
|
+
*/
|
|
492
|
+
frame.setLayout(null);
|
|
493
|
+
//frame.add(applet);
|
|
517
494
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
495
|
+
// Need to pass back our new sketchWidth/Height here, because it may have
|
|
496
|
+
// been overridden by numbers we calculated above if fullScreen and/or
|
|
497
|
+
// spanScreens was in use.
|
|
521
498
|
// pg = sketch.makePrimaryGraphics(sketchWidth, sketchHeight);
|
|
522
499
|
// pg = sketch.makePrimaryGraphics();
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
frame.invalidate();
|
|
528
|
-
} else {
|
|
500
|
+
// resize sketch to sketchWidth/sketchHeight here
|
|
501
|
+
if (fullScreen) {
|
|
502
|
+
frame.invalidate();
|
|
503
|
+
} else {
|
|
529
504
|
// frame.pack();
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
// insufficient, places the 100x100 sketches offset strangely
|
|
533
|
-
//frame.validate();
|
|
505
|
+
}
|
|
534
506
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
507
|
+
// insufficient, places the 100x100 sketches offset strangely
|
|
508
|
+
//frame.validate();
|
|
509
|
+
// disabling resize has to happen after pack() to avoid apparent Apple bug
|
|
510
|
+
// http://code.google.com/p/processing/issues/detail?id=467
|
|
511
|
+
frame.setResizable(false);
|
|
538
512
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
513
|
+
frame.addWindowListener(new WindowAdapter() {
|
|
514
|
+
@Override
|
|
515
|
+
public void windowClosing(WindowEvent e) {
|
|
516
|
+
sketch.exit(); // don't quit, need to just shut everything down (0133)
|
|
517
|
+
}
|
|
518
|
+
});
|
|
545
519
|
|
|
546
520
|
// sketch.setFrame(frame);
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
@Override
|
|
551
|
-
public Object getNative() {
|
|
552
|
-
return canvas;
|
|
553
|
-
}
|
|
521
|
+
}
|
|
554
522
|
|
|
523
|
+
@Override
|
|
524
|
+
public Object getNative() {
|
|
525
|
+
return canvas;
|
|
526
|
+
}
|
|
555
527
|
|
|
556
528
|
// public Toolkit getToolkit() {
|
|
557
529
|
// return canvas.getToolkit();
|
|
558
530
|
// }
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
(
|
|
570
|
-
|
|
571
|
-
|
|
531
|
+
/**
|
|
532
|
+
* Set the window (and dock, or whatever necessary) title.
|
|
533
|
+
*
|
|
534
|
+
* @param title
|
|
535
|
+
*/
|
|
536
|
+
@Override
|
|
537
|
+
public void setTitle(String title) {
|
|
538
|
+
frame.setTitle(title);
|
|
539
|
+
// Workaround for apparent Java bug on OS X?
|
|
540
|
+
// https://github.com/processing/processing/issues/3472
|
|
541
|
+
if (cursorVisible
|
|
542
|
+
&& (PApplet.platform == PConstants.MACOSX)
|
|
543
|
+
&& (cursorType != PConstants.ARROW)) {
|
|
544
|
+
hideCursor();
|
|
545
|
+
showCursor();
|
|
546
|
+
}
|
|
572
547
|
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
548
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
549
|
+
/**
|
|
550
|
+
* Set true if we want to resize things (default is not resizable)
|
|
551
|
+
*/
|
|
552
|
+
@Override
|
|
553
|
+
public void setResizable(boolean resizable) {
|
|
554
|
+
//this.resizable = resizable; // really only used for canvas
|
|
580
555
|
|
|
581
|
-
|
|
582
|
-
|
|
556
|
+
if (frame != null) {
|
|
557
|
+
frame.setResizable(resizable);
|
|
558
|
+
}
|
|
583
559
|
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
@Override
|
|
588
|
-
public void setIcon(PImage image) {
|
|
589
|
-
Image awtImage = (Image) image.getNative();
|
|
590
|
-
|
|
591
|
-
if (PApplet.platform != PConstants.MACOSX) {
|
|
592
|
-
frame.setIconImage(awtImage);
|
|
593
560
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
Method method =
|
|
600
|
-
thinkDifferent.getMethod("setIconImage", new Class[] { java.awt.Image.class });
|
|
601
|
-
method.invoke(null, new Object[] { awtImage });
|
|
602
|
-
} catch (Exception e) {
|
|
603
|
-
e.printStackTrace(); // That's unfortunate
|
|
604
|
-
}
|
|
561
|
+
@Override
|
|
562
|
+
public void setIcon(PImage image) {
|
|
563
|
+
Image awtImage = (Image) image.getNative();
|
|
564
|
+
DesktopHandler.init(sketch);
|
|
565
|
+
DesktopHandler.setIconImage(awtImage);
|
|
605
566
|
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
@Override
|
|
610
|
-
public void setAlwaysOnTop(boolean always) {
|
|
611
|
-
frame.setAlwaysOnTop(always);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
@Override
|
|
616
|
-
public void setLocation(int x, int y) {
|
|
617
|
-
frame.setLocation(x, y);
|
|
618
|
-
}
|
|
619
567
|
|
|
568
|
+
@Override
|
|
569
|
+
public void setAlwaysOnTop(boolean always) {
|
|
570
|
+
frame.setAlwaysOnTop(always);
|
|
571
|
+
}
|
|
620
572
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
// So replacing it is actually a step backwards. Brilliant.
|
|
626
|
-
if (PApplet.platform != PConstants.MACOSX) {
|
|
627
|
-
//Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
|
|
628
|
-
//frame.setIconImage(image);
|
|
629
|
-
try {
|
|
630
|
-
if (iconImages == null) {
|
|
631
|
-
iconImages = new ArrayList<Image>();
|
|
632
|
-
final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
|
|
633
|
-
|
|
634
|
-
for (int sz : sizes) {
|
|
635
|
-
//URL url = getClass().getResource("/icon/icon-" + sz + ".png");
|
|
636
|
-
URL url = PApplet.class.getResource("/icon/icon-" + sz + ".png");
|
|
637
|
-
Image image = Toolkit.getDefaultToolkit().getImage(url);
|
|
638
|
-
iconImages.add(image);
|
|
639
|
-
//iconImages.add(Toolkit.getLibImage("icons/pde-" + sz + ".png", frame));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
frame.setIconImages(iconImages);
|
|
643
|
-
|
|
644
|
-
} catch (Exception e) { } // harmless; keep this to ourselves
|
|
573
|
+
@Override
|
|
574
|
+
public void setLocation(int x, int y) {
|
|
575
|
+
frame.setLocation(x, y);
|
|
576
|
+
}
|
|
645
577
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
//
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
578
|
+
List<Image> iconImages;
|
|
579
|
+
|
|
580
|
+
protected void setProcessingIcon(Frame frame) {
|
|
581
|
+
// On OS X, this only affects what shows up in the dock when minimized.
|
|
582
|
+
// So replacing it is actually a step backwards. Brilliant.
|
|
583
|
+
if (PApplet.platform != PConstants.MACOSX) {
|
|
584
|
+
//Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
|
|
585
|
+
//frame.setIconImage(image);
|
|
586
|
+
// try {
|
|
587
|
+
if (iconImages == null) {
|
|
588
|
+
iconImages = new ArrayList<>();
|
|
589
|
+
final int[] sizes = {16, 32, 48, 64, 128, 256, 512};
|
|
590
|
+
|
|
591
|
+
for (int sz : sizes) {
|
|
592
|
+
//URL url = getClass().getResource("/icon/icon-" + sz + ".png");
|
|
593
|
+
URL url = PApplet.class.getResource("/icon/icon-" + sz + ".png");
|
|
594
|
+
Image image = Toolkit.getDefaultToolkit().getImage(url);
|
|
595
|
+
iconImages.add(image);
|
|
596
|
+
//iconImages.add(Toolkit.getLibImage("icons/pde-" + sz + ".png", frame));
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
frame.setIconImages(iconImages);
|
|
600
|
+
|
|
601
|
+
// } catch (Exception e) {
|
|
602
|
+
// } // harmless; keep this to ourselves
|
|
603
|
+
} else { // handle OS X differently
|
|
604
|
+
if (!dockIconSpecified()) { // don't override existing -Xdock param
|
|
605
|
+
// On OS X, set this for AWT surfaces, which handles the dock image
|
|
606
|
+
// as well as the cmd-tab image that's shown. Just one size, I guess.
|
|
607
|
+
URL url = PApplet.class.getResource("/icon/icon-512.png");
|
|
608
|
+
// Seems dangerous to have this in code instead of using reflection, no?
|
|
609
|
+
//DesktopHandler.setIconImage(Toolkit.getDefaultToolkit().getImage(url));
|
|
610
|
+
try {
|
|
611
|
+
final String td = "processing.core.DesktopHandler";
|
|
612
|
+
Class<?> thinkDifferent
|
|
613
|
+
= Thread.currentThread().getContextClassLoader().loadClass(td);
|
|
614
|
+
Method method
|
|
615
|
+
= thinkDifferent.getMethod("setIconImage", new Class[]{java.awt.Image.class});
|
|
616
|
+
method.invoke(null, new Object[]{Toolkit.getDefaultToolkit().getImage(url)});
|
|
617
|
+
} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
|
|
618
|
+
e.printStackTrace(); // That's unfortunate
|
|
619
|
+
}
|
|
620
|
+
}
|
|
662
621
|
}
|
|
663
|
-
}
|
|
664
622
|
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
623
|
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
if (arg.startsWith("-Xdock:icon")) {
|
|
678
|
-
return true; // dock image already set
|
|
679
|
-
}
|
|
624
|
+
/**
|
|
625
|
+
* @return true if -Xdock:icon was specified on the command line
|
|
626
|
+
*/
|
|
627
|
+
private boolean dockIconSpecified() {
|
|
628
|
+
// TODO This is incomplete... Haven't yet found a way to figure out if
|
|
629
|
+
// the app has an icns file specified already. Help?
|
|
630
|
+
List<String> jvmArgs
|
|
631
|
+
= ManagementFactory.getRuntimeMXBean().getInputArguments();
|
|
632
|
+
return (jvmArgs.stream().anyMatch((arg) -> (arg.startsWith("-Xdock:icon"))));
|
|
680
633
|
}
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
634
|
|
|
635
|
+
@Override
|
|
636
|
+
public void setVisible(boolean visible) {
|
|
637
|
+
frame.setVisible(visible);
|
|
684
638
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
if (canvas != null) {
|
|
691
|
-
//canvas.requestFocusInWindow();
|
|
692
|
-
canvas.requestFocus();
|
|
693
|
-
}
|
|
639
|
+
// Generally useful whenever setting the frame visible
|
|
640
|
+
if (canvas != null) {
|
|
641
|
+
//canvas.requestFocusInWindow();
|
|
642
|
+
canvas.requestFocus();
|
|
643
|
+
}
|
|
694
644
|
|
|
695
|
-
|
|
696
|
-
|
|
645
|
+
// removing per https://github.com/processing/processing/pull/3162
|
|
646
|
+
// can remove the code below once 3.0a6 is tested and behaving
|
|
697
647
|
/*
|
|
698
648
|
if (visible && PApplet.platform == PConstants.LINUX) {
|
|
699
649
|
// Linux doesn't deal with insets the same way. We get fake insets
|
|
@@ -707,52 +657,50 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
707
657
|
insets.top + insets.bottom);
|
|
708
658
|
}
|
|
709
659
|
}
|
|
710
|
-
*/
|
|
711
|
-
|
|
712
|
-
|
|
660
|
+
*/
|
|
661
|
+
}
|
|
713
662
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
663
|
+
//public void placeFullScreen(boolean hideStop) {
|
|
664
|
+
@Override
|
|
665
|
+
public void placePresent(int stopColor) {
|
|
666
|
+
setFullFrame();
|
|
718
667
|
|
|
719
|
-
|
|
668
|
+
// After the pack(), the screen bounds are gonna be 0s
|
|
720
669
|
// frame.setBounds(screenRect); // already called in setFullFrame()
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
670
|
+
canvas.setBounds((screenRect.width - sketchWidth) / 2,
|
|
671
|
+
(screenRect.height - sketchHeight) / 2,
|
|
672
|
+
sketchWidth, sketchHeight);
|
|
724
673
|
|
|
725
674
|
// if (PApplet.platform == PConstants.MACOSX) {
|
|
726
675
|
// macosxFullScreenEnable(frame);
|
|
727
676
|
// macosxFullScreenToggle(frame);
|
|
728
677
|
// }
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
678
|
+
if (stopColor != 0) {
|
|
679
|
+
Label label = new Label("stop");
|
|
680
|
+
label.setForeground(new Color(stopColor, false));
|
|
681
|
+
label.addMouseListener(new MouseAdapter() {
|
|
682
|
+
@Override
|
|
683
|
+
public void mousePressed(java.awt.event.MouseEvent e) {
|
|
684
|
+
sketch.exit();
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
frame.add(label);
|
|
688
|
+
|
|
689
|
+
Dimension labelSize = label.getPreferredSize();
|
|
690
|
+
// sometimes shows up truncated on mac
|
|
691
|
+
//System.out.println("label width is " + labelSize.width);
|
|
692
|
+
labelSize = new Dimension(100, labelSize.height);
|
|
693
|
+
label.setSize(labelSize);
|
|
694
|
+
label.setLocation(20, screenRect.height - labelSize.height - 20);
|
|
737
695
|
}
|
|
738
|
-
});
|
|
739
|
-
frame.add(label);
|
|
740
|
-
|
|
741
|
-
Dimension labelSize = label.getPreferredSize();
|
|
742
|
-
// sometimes shows up truncated on mac
|
|
743
|
-
//System.out.println("label width is " + labelSize.width);
|
|
744
|
-
labelSize = new Dimension(100, labelSize.height);
|
|
745
|
-
label.setSize(labelSize);
|
|
746
|
-
label.setLocation(20, screenRect.height - labelSize.height - 20);
|
|
747
|
-
}
|
|
748
696
|
|
|
749
697
|
// if (sketch.getGraphics().displayable()) {
|
|
750
698
|
// setVisible(true);
|
|
751
699
|
// }
|
|
752
|
-
|
|
700
|
+
}
|
|
753
701
|
|
|
754
702
|
|
|
755
|
-
|
|
703
|
+
/*
|
|
756
704
|
@Override
|
|
757
705
|
public void placeWindow(int[] location) {
|
|
758
706
|
setFrameSize(); //sketchWidth, sketchHeight);
|
|
@@ -796,135 +744,132 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
796
744
|
frame.setVisible(true);
|
|
797
745
|
}
|
|
798
746
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
private void setCanvasSize() {
|
|
747
|
+
*/
|
|
748
|
+
private void setCanvasSize() {
|
|
803
749
|
// System.out.format("setting canvas size %d %d%n", sketchWidth, sketchHeight);
|
|
804
750
|
// new Exception().printStackTrace(System.out);
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
canvas.setBounds((contentW - sketchWidth)/2,
|
|
809
|
-
(contentH - sketchHeight)/2,
|
|
810
|
-
sketchWidth, sketchHeight);
|
|
811
|
-
}
|
|
751
|
+
int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
|
|
752
|
+
int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
|
|
812
753
|
|
|
754
|
+
canvas.setBounds((contentW - sketchWidth) / 2,
|
|
755
|
+
(contentH - sketchHeight) / 2,
|
|
756
|
+
sketchWidth, sketchHeight);
|
|
757
|
+
}
|
|
813
758
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
759
|
+
/**
|
|
760
|
+
* Resize frame for these sketch (canvas) dimensions.
|
|
761
|
+
*/
|
|
762
|
+
private Dimension setFrameSize() { //int sketchWidth, int sketchHeight) {
|
|
763
|
+
// https://github.com/processing/processing/pull/3162
|
|
764
|
+
frame.addNotify(); // using instead of show() to add the peer [fry]
|
|
818
765
|
|
|
819
766
|
// System.out.format("setting frame size %d %d %n", sketchWidth, sketchHeight);
|
|
820
767
|
// new Exception().printStackTrace(System.out);
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
private void setFrameCentered() {
|
|
832
|
-
// Can't use frame.setLocationRelativeTo(null) because it sends the
|
|
833
|
-
// frame to the main display, which undermines the --display setting.
|
|
834
|
-
frame.setLocation(screenRect.x + (screenRect.width - sketchWidth) / 2,
|
|
835
|
-
screenRect.y + (screenRect.height - sketchHeight) / 2);
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
/** Hide the menu bar, make the Frame undecorated, set it to screenRect. */
|
|
840
|
-
private void setFullFrame() {
|
|
841
|
-
// Called here because the graphics device is needed before we can
|
|
842
|
-
// determine whether the sketch wants size(displayWidth, displayHeight),
|
|
843
|
-
// and getting the graphics device will be PSurface-specific.
|
|
844
|
-
PApplet.hideMenuBar();
|
|
845
|
-
|
|
846
|
-
// Tried to use this to fix the 'present' mode issue.
|
|
847
|
-
// Did not help, and the screenRect setup seems to work fine.
|
|
848
|
-
//frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
|
849
|
-
|
|
850
|
-
// https://github.com/processing/processing/pull/3162
|
|
851
|
-
//frame.dispose(); // release native resources, allows setUndecorated()
|
|
852
|
-
frame.removeNotify();
|
|
853
|
-
frame.setUndecorated(true);
|
|
854
|
-
frame.addNotify();
|
|
768
|
+
currentInsets = frame.getInsets();
|
|
769
|
+
int windowW = Math.max(sketchWidth, MIN_WINDOW_WIDTH)
|
|
770
|
+
+ currentInsets.left + currentInsets.right;
|
|
771
|
+
int windowH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT)
|
|
772
|
+
+ currentInsets.top + currentInsets.bottom;
|
|
773
|
+
frame.setSize(windowW, windowH);
|
|
774
|
+
return new Dimension(windowW, windowH);
|
|
775
|
+
}
|
|
855
776
|
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
777
|
+
private void setFrameCentered() {
|
|
778
|
+
// Can't use frame.setLocationRelativeTo(null) because it sends the
|
|
779
|
+
// frame to the main display, which undermines the --display setting.
|
|
780
|
+
frame.setLocation(screenRect.x + (screenRect.width - sketchWidth) / 2,
|
|
781
|
+
screenRect.y + (screenRect.height - sketchHeight) / 2);
|
|
782
|
+
}
|
|
861
783
|
|
|
784
|
+
/**
|
|
785
|
+
* Hide the menu bar, make the Frame undecorated, set it to screenRect.
|
|
786
|
+
*/
|
|
787
|
+
private void setFullFrame() {
|
|
788
|
+
// Called here because the graphics device is needed before we can
|
|
789
|
+
// determine whether the sketch wants size(displayWidth, displayHeight),
|
|
790
|
+
// and getting the graphics device will be PSurface-specific.
|
|
791
|
+
PApplet.hideMenuBar();
|
|
792
|
+
|
|
793
|
+
// Tried to use this to fix the 'present' mode issue.
|
|
794
|
+
// Did not help, and the screenRect setup seems to work fine.
|
|
795
|
+
//frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
|
796
|
+
// https://github.com/processing/processing/pull/3162
|
|
797
|
+
//frame.dispose(); // release native resources, allows setUndecorated()
|
|
798
|
+
frame.removeNotify();
|
|
799
|
+
frame.setUndecorated(true);
|
|
800
|
+
frame.addNotify();
|
|
801
|
+
|
|
802
|
+
// this may be the bounds of all screens
|
|
803
|
+
frame.setBounds(screenRect);
|
|
804
|
+
// will be set visible in placeWindow() [3.0a10]
|
|
805
|
+
//frame.setVisible(true); // re-add native resources
|
|
806
|
+
}
|
|
862
807
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
808
|
+
@Override
|
|
809
|
+
public void placeWindow(int[] location, int[] editorLocation) {
|
|
810
|
+
//Dimension window = setFrameSize(sketchWidth, sketchHeight);
|
|
811
|
+
Dimension window = setFrameSize(); //sketchWidth, sketchHeight);
|
|
867
812
|
|
|
868
|
-
|
|
869
|
-
|
|
813
|
+
int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
|
|
814
|
+
int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
|
|
870
815
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
816
|
+
if (sketch.sketchFullScreen()) {
|
|
817
|
+
setFullFrame();
|
|
818
|
+
}
|
|
874
819
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
820
|
+
// Ignore placement of previous window and editor when full screen
|
|
821
|
+
if (!sketch.sketchFullScreen()) {
|
|
822
|
+
if (location != null) {
|
|
823
|
+
// a specific location was received from the Runner
|
|
824
|
+
// (applet has been run more than once, user placed window)
|
|
825
|
+
frame.setLocation(location[0], location[1]);
|
|
826
|
+
|
|
827
|
+
} else if (editorLocation != null) {
|
|
828
|
+
int locationX = editorLocation[0] - 20;
|
|
829
|
+
int locationY = editorLocation[1];
|
|
830
|
+
|
|
831
|
+
if (locationX - window.width > 10) {
|
|
832
|
+
// if it fits to the left of the window
|
|
833
|
+
frame.setLocation(locationX - window.width, locationY);
|
|
834
|
+
|
|
835
|
+
} else { // doesn't fit
|
|
836
|
+
// if it fits inside the editor window,
|
|
837
|
+
// offset slightly from upper lefthand corner
|
|
838
|
+
// so that it's plunked inside the text area
|
|
839
|
+
//locationX = editorLocation[0] + 66;
|
|
840
|
+
//locationY = editorLocation[1] + 66;
|
|
841
|
+
locationX = (sketch.displayWidth - window.width) / 2;
|
|
842
|
+
locationY = (sketch.displayHeight - window.height) / 2;
|
|
843
|
+
|
|
844
|
+
/*
|
|
900
845
|
if ((locationX + window.width > sketch.displayWidth - 33) ||
|
|
901
846
|
(locationY + window.height > sketch.displayHeight - 33)) {
|
|
902
847
|
// otherwise center on screen
|
|
903
848
|
locationX = (sketch.displayWidth - window.width) / 2;
|
|
904
849
|
locationY = (sketch.displayHeight - window.height) / 2;
|
|
905
850
|
}
|
|
906
|
-
|
|
907
|
-
|
|
851
|
+
*/
|
|
852
|
+
frame.setLocation(locationX, locationY);
|
|
853
|
+
}
|
|
854
|
+
} else { // just center on screen
|
|
855
|
+
setFrameCentered();
|
|
856
|
+
}
|
|
857
|
+
Point frameLoc = frame.getLocation();
|
|
858
|
+
if (frameLoc.y < 0) {
|
|
859
|
+
// Windows actually allows you to place frames where they can't be
|
|
860
|
+
// closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508
|
|
861
|
+
frame.setLocation(frameLoc.x, 30);
|
|
862
|
+
}
|
|
908
863
|
}
|
|
909
|
-
} else { // just center on screen
|
|
910
|
-
setFrameCentered();
|
|
911
|
-
}
|
|
912
|
-
Point frameLoc = frame.getLocation();
|
|
913
|
-
if (frameLoc.y < 0) {
|
|
914
|
-
// Windows actually allows you to place frames where they can't be
|
|
915
|
-
// closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508
|
|
916
|
-
frame.setLocation(frameLoc.x, 30);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
864
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
865
|
+
canvas.setBounds((contentW - sketchWidth) / 2,
|
|
866
|
+
(contentH - sketchHeight) / 2,
|
|
867
|
+
sketchWidth, sketchHeight);
|
|
923
868
|
|
|
924
|
-
|
|
925
|
-
|
|
869
|
+
// handle frame resizing events
|
|
870
|
+
setupFrameResizeListener();
|
|
926
871
|
|
|
927
|
-
|
|
872
|
+
/*
|
|
928
873
|
// If displayable() is false, then PSurfaceNone should be used, but...
|
|
929
874
|
if (sketch.getGraphics().displayable()) {
|
|
930
875
|
frame.setVisible(true);
|
|
@@ -935,68 +880,64 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
935
880
|
// canvas.requestFocus();
|
|
936
881
|
// }
|
|
937
882
|
}
|
|
938
|
-
|
|
883
|
+
*/
|
|
939
884
|
// if (sketch.getGraphics().displayable()) {
|
|
940
885
|
// setVisible(true);
|
|
941
886
|
// }
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
// needs to resize the frame, which will resize the canvas, and so on...
|
|
946
|
-
@Override
|
|
947
|
-
public void setSize(int wide, int high) {
|
|
948
|
-
// When the surface is set to resizable via surface.setResizable(true),
|
|
949
|
-
// a crash may occur if the user sets the window to size zero.
|
|
950
|
-
// https://github.com/processing/processing/issues/5052
|
|
951
|
-
if (high <= 0) {
|
|
952
|
-
high = 1;
|
|
953
|
-
}
|
|
954
|
-
if (wide <= 0) {
|
|
955
|
-
wide = 1;
|
|
956
887
|
}
|
|
957
888
|
|
|
889
|
+
// needs to resize the frame, which will resize the canvas, and so on...
|
|
890
|
+
@Override
|
|
891
|
+
public void setSize(int wide, int high) {
|
|
892
|
+
// When the surface is set to resizable via surface.setResizable(true),
|
|
893
|
+
// a crash may occur if the user sets the window to size zero.
|
|
894
|
+
// https://github.com/processing/processing/issues/5052
|
|
895
|
+
if (high <= 0) {
|
|
896
|
+
high = 1;
|
|
897
|
+
}
|
|
898
|
+
if (wide <= 0) {
|
|
899
|
+
wide = 1;
|
|
900
|
+
}
|
|
901
|
+
|
|
958
902
|
// if (PApplet.DEBUG) {
|
|
959
903
|
// //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
|
|
960
904
|
// new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
|
|
961
905
|
// }
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
(frame == null || currentInsets.equals(frame.getInsets()))) {
|
|
906
|
+
//if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
|
|
907
|
+
if (wide == sketch.width && high == sketch.height
|
|
908
|
+
&& (frame == null || currentInsets.equals(frame.getInsets()))) {
|
|
966
909
|
// if (PApplet.DEBUG) {
|
|
967
910
|
// new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
|
|
968
911
|
// }
|
|
969
|
-
|
|
970
|
-
|
|
912
|
+
return; // unchanged, don't rebuild everything
|
|
913
|
+
}
|
|
971
914
|
|
|
972
|
-
|
|
973
|
-
|
|
915
|
+
sketchWidth = wide * windowScaleFactor;
|
|
916
|
+
sketchHeight = high * windowScaleFactor;
|
|
974
917
|
|
|
975
918
|
// canvas.setSize(wide, high);
|
|
976
919
|
// frame.setSize(wide, high);
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
920
|
+
if (frame != null) { // skip if just a canvas
|
|
921
|
+
setFrameSize(); //wide, high);
|
|
922
|
+
}
|
|
923
|
+
setCanvasSize();
|
|
981
924
|
// if (frame != null) {
|
|
982
925
|
// frame.setLocationRelativeTo(null);
|
|
983
926
|
// }
|
|
984
927
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
sketch.setSize(wide, high);
|
|
928
|
+
//initImage(graphics, wide, high);
|
|
929
|
+
//throw new RuntimeException("implement me, see readme.md");
|
|
930
|
+
sketch.setSize(wide, high);
|
|
989
931
|
// sketch.width = wide;
|
|
990
932
|
// sketch.height = high;
|
|
991
933
|
|
|
992
|
-
|
|
993
|
-
|
|
934
|
+
// set PGraphics variables for width/height/pixelWidth/pixelHeight
|
|
935
|
+
graphics.setSize(wide, high);
|
|
994
936
|
// System.out.println("out of setSize()");
|
|
995
|
-
|
|
996
|
-
|
|
937
|
+
}
|
|
997
938
|
|
|
998
|
-
|
|
999
|
-
|
|
939
|
+
//public void initImage(PGraphics gr, int wide, int high) {
|
|
940
|
+
/*
|
|
1000
941
|
@Override
|
|
1001
942
|
public void initImage(PGraphics graphics) {
|
|
1002
943
|
GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
|
|
@@ -1013,21 +954,15 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1013
954
|
int high = graphics.height * graphics.pixelFactor;
|
|
1014
955
|
graphics.image = gc.createCompatibleImage(wide, high);
|
|
1015
956
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
957
|
+
*/
|
|
1019
958
|
// @Override
|
|
1020
959
|
// public Component getComponent() {
|
|
1021
960
|
// return canvas;
|
|
1022
961
|
// }
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
962
|
// @Override
|
|
1026
963
|
// public void setSmooth(int level) {
|
|
1027
964
|
// }
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
/*
|
|
965
|
+
/*
|
|
1031
966
|
private boolean checkRetina() {
|
|
1032
967
|
if (PApplet.platform == PConstants.MACOSX) {
|
|
1033
968
|
// This should probably be reset each time there's a display change.
|
|
@@ -1053,24 +988,24 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1053
988
|
}
|
|
1054
989
|
return false;
|
|
1055
990
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
991
|
+
*/
|
|
992
|
+
/**
|
|
993
|
+
* Get the bounds rectangle for all displays.
|
|
994
|
+
*/
|
|
995
|
+
static Rectangle getDisplaySpan() {
|
|
996
|
+
Rectangle bounds = new Rectangle();
|
|
997
|
+
GraphicsEnvironment environment
|
|
998
|
+
= GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
999
|
+
for (GraphicsDevice device : environment.getScreenDevices()) {
|
|
1000
|
+
for (GraphicsConfiguration config : device.getConfigurations()) {
|
|
1001
|
+
Rectangle2D.union(bounds, config.getBounds(), bounds);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return bounds;
|
|
1068
1005
|
}
|
|
1069
|
-
return bounds;
|
|
1070
|
-
}
|
|
1071
1006
|
|
|
1072
1007
|
|
|
1073
|
-
|
|
1008
|
+
/*
|
|
1074
1009
|
private void checkDisplaySize() {
|
|
1075
1010
|
if (canvas.getGraphicsConfiguration() != null) {
|
|
1076
1011
|
GraphicsDevice displayDevice = getGraphicsConfiguration().getDevice();
|
|
@@ -1084,91 +1019,81 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1084
1019
|
}
|
|
1085
1020
|
}
|
|
1086
1021
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
/**
|
|
1110
|
-
* Set up a listener that will fire proper component resize events
|
|
1111
|
-
* in cases where frame.setResizable(true) is called.
|
|
1112
|
-
*/
|
|
1113
|
-
private void setupFrameResizeListener() {
|
|
1114
|
-
frame.addWindowStateListener(new WindowStateListener() {
|
|
1115
|
-
@Override
|
|
1116
|
-
// Detecting when the frame is resized in order to handle the frame
|
|
1117
|
-
// maximization bug in OSX:
|
|
1118
|
-
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8036935
|
|
1119
|
-
public void windowStateChanged(WindowEvent e) {
|
|
1120
|
-
// This seems to be firing when dragging the window on OS X
|
|
1121
|
-
// https://github.com/processing/processing/issues/3092
|
|
1122
|
-
if (Frame.MAXIMIZED_BOTH == e.getNewState()) {
|
|
1123
|
-
// Supposedly, sending the frame to back and then front is a
|
|
1124
|
-
// workaround for this bug:
|
|
1125
|
-
// http://stackoverflow.com/a/23897602
|
|
1126
|
-
// but is not working for me...
|
|
1127
|
-
//frame.toBack();
|
|
1128
|
-
//frame.toFront();
|
|
1129
|
-
// Packing the frame works, but that causes the window to collapse
|
|
1130
|
-
// on OS X when the window is dragged. Changing to addNotify() for
|
|
1131
|
-
// https://github.com/processing/processing/issues/3092
|
|
1132
|
-
//frame.pack();
|
|
1133
|
-
frame.addNotify();
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
});
|
|
1137
|
-
|
|
1138
|
-
frame.addComponentListener(new ComponentAdapter() {
|
|
1139
|
-
@Override
|
|
1140
|
-
public void componentResized(ComponentEvent e) {
|
|
1141
|
-
// Ignore bad resize events fired during setup to fix
|
|
1142
|
-
// http://dev.processing.org/bugs/show_bug.cgi?id=341
|
|
1143
|
-
// This should also fix the blank screen on Linux bug
|
|
1144
|
-
// http://dev.processing.org/bugs/show_bug.cgi?id=282
|
|
1145
|
-
if (frame.isResizable()) {
|
|
1146
|
-
// might be multiple resize calls before visible (i.e. first
|
|
1147
|
-
// when pack() is called, then when it's resized for use).
|
|
1148
|
-
// ignore them because it's not the user resizing things.
|
|
1149
|
-
Frame farm = (Frame) e.getComponent();
|
|
1150
|
-
if (farm.isVisible()) {
|
|
1151
|
-
Dimension windowSize = farm.getSize();
|
|
1152
|
-
int x = farm.getX() + currentInsets.left;
|
|
1153
|
-
int y = farm.getY() + currentInsets.top;
|
|
1154
|
-
|
|
1155
|
-
// JFrame (unlike java.awt.Frame) doesn't include the left/top
|
|
1156
|
-
// insets for placement (though it does seem to need them for
|
|
1157
|
-
// overall size of the window. Perhaps JFrame sets its coord
|
|
1158
|
-
// system so that (0, 0) is always the upper-left of the content
|
|
1159
|
-
// area. Which seems nice, but breaks any f*ing AWT-based code.
|
|
1160
|
-
int w = windowSize.width - currentInsets.left - currentInsets.right;
|
|
1161
|
-
int h = windowSize.height - currentInsets.top - currentInsets.bottom;
|
|
1162
|
-
setSize(w / windowScaleFactor, h / windowScaleFactor);
|
|
1163
|
-
|
|
1164
|
-
// correct the location when inset size changes
|
|
1165
|
-
setLocation(x - currentInsets.left, y - currentInsets.top);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
1022
|
+
*/
|
|
1023
|
+
/**
|
|
1024
|
+
* Set this sketch to communicate its state back to the PDE.
|
|
1025
|
+
* <p/>
|
|
1026
|
+
* This uses the stderr stream to write positions of the window (so that it
|
|
1027
|
+
* will be saved by the PDE for the next run) and notify on quit. See more
|
|
1028
|
+
* notes in the Worker class.
|
|
1029
|
+
*/
|
|
1030
|
+
@Override
|
|
1031
|
+
public void setupExternalMessages() {
|
|
1032
|
+
frame.addComponentListener(new ComponentAdapter() {
|
|
1033
|
+
@Override
|
|
1034
|
+
public void componentMoved(ComponentEvent e) {
|
|
1035
|
+
Point where = ((Frame) e.getSource()).getLocation();
|
|
1036
|
+
sketch.frameMoved(where.x, where.y);
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1171
1040
|
|
|
1041
|
+
/**
|
|
1042
|
+
* Set up a listener that will fire proper component resize events in cases
|
|
1043
|
+
* where frame.setResizable(true) is called.
|
|
1044
|
+
*/
|
|
1045
|
+
private void setupFrameResizeListener() {
|
|
1046
|
+
frame.addWindowStateListener((WindowEvent e) -> {
|
|
1047
|
+
// This seems to be firing when dragging the window on OS X
|
|
1048
|
+
// https://github.com/processing/processing/issues/3092
|
|
1049
|
+
if (Frame.MAXIMIZED_BOTH == e.getNewState()) {
|
|
1050
|
+
// Supposedly, sending the frame to back and then front is a
|
|
1051
|
+
// workaround for this bug:
|
|
1052
|
+
// http://stackoverflow.com/a/23897602
|
|
1053
|
+
// but is not working for me...
|
|
1054
|
+
//frame.toBack();
|
|
1055
|
+
//frame.toFront();
|
|
1056
|
+
// Packing the frame works, but that causes the window to collapse
|
|
1057
|
+
// on OS X when the window is dragged. Changing to addNotify() for
|
|
1058
|
+
// https://github.com/processing/processing/issues/3092
|
|
1059
|
+
//frame.pack();
|
|
1060
|
+
frame.addNotify();
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
frame.addComponentListener(new ComponentAdapter() {
|
|
1065
|
+
@Override
|
|
1066
|
+
public void componentResized(ComponentEvent e) {
|
|
1067
|
+
// Ignore bad resize events fired during setup to fix
|
|
1068
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=341
|
|
1069
|
+
// This should also fix the blank screen on Linux bug
|
|
1070
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=282
|
|
1071
|
+
if (frame.isResizable()) {
|
|
1072
|
+
// might be multiple resize calls before visible (i.e. first
|
|
1073
|
+
// when pack() is called, then when it's resized for use).
|
|
1074
|
+
// ignore them because it's not the user resizing things.
|
|
1075
|
+
Frame farm = (Frame) e.getComponent();
|
|
1076
|
+
if (farm.isVisible()) {
|
|
1077
|
+
Dimension windowSize = farm.getSize();
|
|
1078
|
+
int x = farm.getX() + currentInsets.left;
|
|
1079
|
+
int y = farm.getY() + currentInsets.top;
|
|
1080
|
+
|
|
1081
|
+
// JFrame (unlike java.awt.Frame) doesn't include the left/top
|
|
1082
|
+
// insets for placement (though it does seem to need them for
|
|
1083
|
+
// overall size of the window. Perhaps JFrame sets its coord
|
|
1084
|
+
// system so that (0, 0) is always the upper-left of the content
|
|
1085
|
+
// area. Which seems nice, but breaks any f*ing AWT-based code.
|
|
1086
|
+
int w = windowSize.width - currentInsets.left - currentInsets.right;
|
|
1087
|
+
int h = windowSize.height - currentInsets.top - currentInsets.bottom;
|
|
1088
|
+
setSize(w / windowScaleFactor, h / windowScaleFactor);
|
|
1089
|
+
|
|
1090
|
+
// correct the location when inset size changes
|
|
1091
|
+
setLocation(x - currentInsets.left, y - currentInsets.top);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1172
1097
|
|
|
1173
1098
|
// /**
|
|
1174
1099
|
// * (No longer in use) Use reflection to call
|
|
@@ -1210,12 +1135,8 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1210
1135
|
// e.printStackTrace();
|
|
1211
1136
|
// }
|
|
1212
1137
|
// }
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
//////////////////////////////////////////////////////////////
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
/*
|
|
1138
|
+
//////////////////////////////////////////////////////////////
|
|
1139
|
+
/*
|
|
1219
1140
|
// disabling for now; requires Java 1.7 and "precise" semantics are odd...
|
|
1220
1141
|
// returns 0.1 for tick-by-tick scrolling on OS X, but it's not a matter of
|
|
1221
1142
|
// calling ceil() on the value: 1.5 goes to 1, but 2.3 goes to 2.
|
|
@@ -1228,46 +1149,46 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1228
1149
|
// ignored, the method will just be set to null
|
|
1229
1150
|
}
|
|
1230
1151
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1152
|
+
*/
|
|
1153
|
+
/**
|
|
1154
|
+
* Figure out how to process a mouse event.When loop() has been called, the
|
|
1155
|
+
* events will be queued up until drawing is complete. If noLoop() has been
|
|
1156
|
+
* called, then events will happen immediately.
|
|
1157
|
+
*
|
|
1158
|
+
* @param nativeEvent
|
|
1159
|
+
*/
|
|
1160
|
+
protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
|
|
1161
|
+
// the 'amount' is the number of button clicks for a click event,
|
|
1162
|
+
// or the number of steps/clicks on the wheel for a mouse wheel event.
|
|
1163
|
+
int peCount = nativeEvent.getClickCount();
|
|
1164
|
+
|
|
1165
|
+
int peAction = 0;
|
|
1166
|
+
switch (nativeEvent.getID()) {
|
|
1167
|
+
case java.awt.event.MouseEvent.MOUSE_PRESSED:
|
|
1168
|
+
peAction = MouseEvent.PRESS;
|
|
1169
|
+
break;
|
|
1170
|
+
case java.awt.event.MouseEvent.MOUSE_RELEASED:
|
|
1171
|
+
peAction = MouseEvent.RELEASE;
|
|
1172
|
+
break;
|
|
1173
|
+
case java.awt.event.MouseEvent.MOUSE_CLICKED:
|
|
1174
|
+
peAction = MouseEvent.CLICK;
|
|
1175
|
+
break;
|
|
1176
|
+
case java.awt.event.MouseEvent.MOUSE_DRAGGED:
|
|
1177
|
+
peAction = MouseEvent.DRAG;
|
|
1178
|
+
break;
|
|
1179
|
+
case java.awt.event.MouseEvent.MOUSE_MOVED:
|
|
1180
|
+
peAction = MouseEvent.MOVE;
|
|
1181
|
+
break;
|
|
1182
|
+
case java.awt.event.MouseEvent.MOUSE_ENTERED:
|
|
1183
|
+
peAction = MouseEvent.ENTER;
|
|
1184
|
+
break;
|
|
1185
|
+
case java.awt.event.MouseEvent.MOUSE_EXITED:
|
|
1186
|
+
peAction = MouseEvent.EXIT;
|
|
1187
|
+
break;
|
|
1188
|
+
//case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
|
|
1189
|
+
case java.awt.event.MouseEvent.MOUSE_WHEEL:
|
|
1190
|
+
peAction = MouseEvent.WHEEL;
|
|
1191
|
+
/*
|
|
1271
1192
|
if (preciseWheelMethod != null) {
|
|
1272
1193
|
try {
|
|
1273
1194
|
peAmount = ((Double) preciseWheelMethod.invoke(nativeEvent, (Object[]) null)).floatValue();
|
|
@@ -1275,29 +1196,29 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1275
1196
|
preciseWheelMethod = null;
|
|
1276
1197
|
}
|
|
1277
1198
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1199
|
+
*/
|
|
1200
|
+
peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1282
1203
|
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1204
|
+
//System.out.println(nativeEvent);
|
|
1205
|
+
//int modifiers = nativeEvent.getModifiersEx();
|
|
1206
|
+
// If using getModifiersEx(), the regular modifiers don't set properly.
|
|
1207
|
+
int modifiers = nativeEvent.getModifiers();
|
|
1208
|
+
|
|
1209
|
+
int peModifiers = modifiers
|
|
1210
|
+
& (InputEvent.SHIFT_MASK
|
|
1211
|
+
| InputEvent.CTRL_MASK
|
|
1212
|
+
| InputEvent.META_MASK
|
|
1213
|
+
| InputEvent.ALT_MASK);
|
|
1214
|
+
|
|
1215
|
+
// Windows and OS X seem to disagree on how to handle this. Windows only
|
|
1216
|
+
// sets BUTTON1_DOWN_MASK, while OS X seems to set BUTTON1_MASK.
|
|
1217
|
+
// This is an issue in particular with mouse release events:
|
|
1218
|
+
// http://code.google.com/p/processing/issues/detail?id=1294
|
|
1219
|
+
// The fix for which led to a regression (fixed here by checking both):
|
|
1220
|
+
// http://code.google.com/p/processing/issues/detail?id=1332
|
|
1221
|
+
int peButton = 0;
|
|
1301
1222
|
// if ((modifiers & InputEvent.BUTTON1_MASK) != 0 ||
|
|
1302
1223
|
// (modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
|
|
1303
1224
|
// peButton = LEFT;
|
|
@@ -1308,141 +1229,134 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1308
1229
|
// (modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
|
|
1309
1230
|
// peButton = RIGHT;
|
|
1310
1231
|
// }
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
// If running on Mac OS, allow ctrl-click as right mouse. Prior to 0215,
|
|
1320
|
-
// this used isPopupTrigger() on the native event, but that doesn't work
|
|
1321
|
-
// for mouseClicked and mouseReleased (or others).
|
|
1322
|
-
if (PApplet.platform == PConstants.MACOSX) {
|
|
1323
|
-
//if (nativeEvent.isPopupTrigger()) {
|
|
1324
|
-
if ((modifiers & InputEvent.CTRL_MASK) != 0) {
|
|
1325
|
-
peButton = PConstants.RIGHT;
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
|
|
1330
|
-
peAction, peModifiers,
|
|
1331
|
-
nativeEvent.getX() / windowScaleFactor,
|
|
1332
|
-
nativeEvent.getY() / windowScaleFactor,
|
|
1333
|
-
peButton,
|
|
1334
|
-
peCount));
|
|
1335
|
-
}
|
|
1232
|
+
if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
|
|
1233
|
+
peButton = PConstants.LEFT;
|
|
1234
|
+
} else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
|
|
1235
|
+
peButton = PConstants.CENTER;
|
|
1236
|
+
} else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
|
|
1237
|
+
peButton = PConstants.RIGHT;
|
|
1238
|
+
}
|
|
1336
1239
|
|
|
1240
|
+
// If running on Mac OS, allow ctrl-click as right mouse. Prior to 0215,
|
|
1241
|
+
// this used isPopupTrigger() on the native event, but that doesn't work
|
|
1242
|
+
// for mouseClicked and mouseReleased (or others).
|
|
1243
|
+
if (PApplet.platform == PConstants.MACOSX) {
|
|
1244
|
+
//if (nativeEvent.isPopupTrigger()) {
|
|
1245
|
+
if ((modifiers & InputEvent.CTRL_MASK) != 0) {
|
|
1246
|
+
peButton = PConstants.RIGHT;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1337
1249
|
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
case java.awt.event.KeyEvent.KEY_RELEASED:
|
|
1345
|
-
peAction = KeyEvent.RELEASE;
|
|
1346
|
-
break;
|
|
1347
|
-
case java.awt.event.KeyEvent.KEY_TYPED:
|
|
1348
|
-
peAction = KeyEvent.TYPE;
|
|
1349
|
-
break;
|
|
1250
|
+
sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
|
|
1251
|
+
peAction, peModifiers,
|
|
1252
|
+
nativeEvent.getX() / windowScaleFactor,
|
|
1253
|
+
nativeEvent.getY() / windowScaleFactor,
|
|
1254
|
+
peButton,
|
|
1255
|
+
peCount));
|
|
1350
1256
|
}
|
|
1351
1257
|
|
|
1258
|
+
protected void nativeKeyEvent(java.awt.event.KeyEvent event) {
|
|
1259
|
+
int peAction = 0;
|
|
1260
|
+
switch (event.getID()) {
|
|
1261
|
+
case java.awt.event.KeyEvent.KEY_PRESSED:
|
|
1262
|
+
peAction = KeyEvent.PRESS;
|
|
1263
|
+
break;
|
|
1264
|
+
case java.awt.event.KeyEvent.KEY_RELEASED:
|
|
1265
|
+
peAction = KeyEvent.RELEASE;
|
|
1266
|
+
break;
|
|
1267
|
+
case java.awt.event.KeyEvent.KEY_TYPED:
|
|
1268
|
+
peAction = KeyEvent.TYPE;
|
|
1269
|
+
break;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1352
1272
|
// int peModifiers = event.getModifiersEx() &
|
|
1353
1273
|
// (InputEvent.SHIFT_DOWN_MASK |
|
|
1354
1274
|
// InputEvent.CTRL_DOWN_MASK |
|
|
1355
1275
|
// InputEvent.META_DOWN_MASK |
|
|
1356
1276
|
// InputEvent.ALT_DOWN_MASK);
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
// listeners, for all my men!
|
|
1370
|
-
protected void addListeners() {
|
|
1371
|
-
|
|
1372
|
-
canvas.addMouseListener(new MouseListener() {
|
|
1277
|
+
int peModifiers = event.getModifiers()
|
|
1278
|
+
& (InputEvent.SHIFT_MASK
|
|
1279
|
+
| InputEvent.CTRL_MASK
|
|
1280
|
+
| InputEvent.META_MASK
|
|
1281
|
+
| InputEvent.ALT_MASK);
|
|
1282
|
+
|
|
1283
|
+
sketch.postEvent(new KeyEvent(event, event.getWhen(),
|
|
1284
|
+
peAction, peModifiers,
|
|
1285
|
+
event.getKeyChar(), event.getKeyCode()));
|
|
1286
|
+
}
|
|
1373
1287
|
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
}
|
|
1288
|
+
// listeners, for all my men!
|
|
1289
|
+
protected void addListeners() {
|
|
1377
1290
|
|
|
1378
|
-
|
|
1379
|
-
nativeMouseEvent(e);
|
|
1380
|
-
}
|
|
1291
|
+
canvas.addMouseListener(new MouseListener() {
|
|
1381
1292
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
public void mouseEntered(java.awt.event.MouseEvent e) {
|
|
1387
|
-
nativeMouseEvent(e);
|
|
1388
|
-
}
|
|
1293
|
+
public void mousePressed(java.awt.event.MouseEvent e) {
|
|
1294
|
+
nativeMouseEvent(e);
|
|
1295
|
+
}
|
|
1389
1296
|
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
});
|
|
1297
|
+
public void mouseReleased(java.awt.event.MouseEvent e) {
|
|
1298
|
+
nativeMouseEvent(e);
|
|
1299
|
+
}
|
|
1394
1300
|
|
|
1395
|
-
|
|
1301
|
+
public void mouseClicked(java.awt.event.MouseEvent e) {
|
|
1302
|
+
nativeMouseEvent(e);
|
|
1303
|
+
}
|
|
1396
1304
|
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1305
|
+
public void mouseEntered(java.awt.event.MouseEvent e) {
|
|
1306
|
+
nativeMouseEvent(e);
|
|
1307
|
+
}
|
|
1400
1308
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1309
|
+
public void mouseExited(java.awt.event.MouseEvent e) {
|
|
1310
|
+
nativeMouseEvent(e);
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1405
1313
|
|
|
1406
|
-
|
|
1314
|
+
canvas.addMouseMotionListener(new MouseMotionListener() {
|
|
1407
1315
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
});
|
|
1316
|
+
public void mouseDragged(java.awt.event.MouseEvent e) {
|
|
1317
|
+
nativeMouseEvent(e);
|
|
1318
|
+
}
|
|
1412
1319
|
|
|
1413
|
-
|
|
1320
|
+
public void mouseMoved(java.awt.event.MouseEvent e) {
|
|
1321
|
+
nativeMouseEvent(e);
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1414
1324
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1325
|
+
canvas.addMouseWheelListener((MouseWheelEvent e) -> {
|
|
1326
|
+
nativeMouseEvent(e);
|
|
1327
|
+
});
|
|
1418
1328
|
|
|
1329
|
+
canvas.addKeyListener(new KeyListener() {
|
|
1419
1330
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1331
|
+
public void keyPressed(java.awt.event.KeyEvent e) {
|
|
1332
|
+
nativeKeyEvent(e);
|
|
1333
|
+
}
|
|
1423
1334
|
|
|
1335
|
+
public void keyReleased(java.awt.event.KeyEvent e) {
|
|
1336
|
+
nativeKeyEvent(e);
|
|
1337
|
+
}
|
|
1424
1338
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1339
|
+
public void keyTyped(java.awt.event.KeyEvent e) {
|
|
1340
|
+
nativeKeyEvent(e);
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1429
1343
|
|
|
1430
|
-
|
|
1344
|
+
canvas.addFocusListener(new FocusListener() {
|
|
1431
1345
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1346
|
+
public void focusGained(FocusEvent e) {
|
|
1347
|
+
sketch.focused = true;
|
|
1348
|
+
sketch.focusGained();
|
|
1349
|
+
}
|
|
1436
1350
|
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1351
|
+
public void focusLost(FocusEvent e) {
|
|
1352
|
+
sketch.focused = false;
|
|
1353
|
+
sketch.focusLost();
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1443
1357
|
|
|
1444
1358
|
|
|
1445
|
-
|
|
1359
|
+
/*
|
|
1446
1360
|
public void addListeners(Component comp) {
|
|
1447
1361
|
comp.addMouseListener(this);
|
|
1448
1362
|
comp.addMouseWheelListener(this);
|
|
@@ -1459,9 +1373,7 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1459
1373
|
comp.removeKeyListener(this);
|
|
1460
1374
|
comp.removeFocusListener(this);
|
|
1461
1375
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1376
|
+
*/
|
|
1465
1377
|
// /**
|
|
1466
1378
|
// * Call to remove, then add, listeners to a component.
|
|
1467
1379
|
// * Avoids issues with double-adding.
|
|
@@ -1470,98 +1382,87 @@ public class PSurfaceAWT extends PSurfaceNone {
|
|
|
1470
1382
|
// removeListeners(comp);
|
|
1471
1383
|
// addListeners(comp);
|
|
1472
1384
|
// }
|
|
1385
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
|
1386
|
+
int cursorType = PConstants.ARROW;
|
|
1387
|
+
boolean cursorVisible = true;
|
|
1388
|
+
Cursor invisibleCursor;
|
|
1473
1389
|
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
@Override
|
|
1485
|
-
public void setCursor(int kind) {
|
|
1486
|
-
// Swap the HAND cursor because MOVE doesn't seem to be available on OS X
|
|
1487
|
-
// https://github.com/processing/processing/issues/2358
|
|
1488
|
-
if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) {
|
|
1489
|
-
kind = PConstants.HAND;
|
|
1390
|
+
@Override
|
|
1391
|
+
public void setCursor(int kind) {
|
|
1392
|
+
// Swap the HAND cursor because MOVE doesn't seem to be available on OS X
|
|
1393
|
+
// https://github.com/processing/processing/issues/2358
|
|
1394
|
+
if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) {
|
|
1395
|
+
kind = PConstants.HAND;
|
|
1396
|
+
}
|
|
1397
|
+
canvas.setCursor(Cursor.getPredefinedCursor(kind));
|
|
1398
|
+
cursorVisible = true;
|
|
1399
|
+
this.cursorType = kind;
|
|
1490
1400
|
}
|
|
1491
|
-
canvas.setCursor(Cursor.getPredefinedCursor(kind));
|
|
1492
|
-
cursorVisible = true;
|
|
1493
|
-
this.cursorType = kind;
|
|
1494
|
-
}
|
|
1495
1401
|
|
|
1402
|
+
@Override
|
|
1403
|
+
public void setCursor(PImage img, int x, int y) {
|
|
1404
|
+
// Don't set cursorType, instead use cursorType to save the last
|
|
1405
|
+
// regular cursor type used for when cursor() is called.
|
|
1406
|
+
//cursor_type = Cursor.CUSTOM_CURSOR;
|
|
1407
|
+
|
|
1408
|
+
// this is a temporary workaround for the CHIP, will be removed
|
|
1409
|
+
Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(img.width, img.height);
|
|
1410
|
+
if (cursorSize.width == 0 || cursorSize.height == 0) {
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1496
1413
|
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
// this is a temporary workaround for the CHIP, will be removed
|
|
1504
|
-
Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(img.width, img.height);
|
|
1505
|
-
if (cursorSize.width == 0 || cursorSize.height == 0) {
|
|
1506
|
-
return;
|
|
1414
|
+
Cursor cursor
|
|
1415
|
+
= canvas.getToolkit().createCustomCursor((Image) img.getNative(),
|
|
1416
|
+
new Point(x, y),
|
|
1417
|
+
"custom");
|
|
1418
|
+
canvas.setCursor(cursor);
|
|
1419
|
+
cursorVisible = true;
|
|
1507
1420
|
}
|
|
1508
1421
|
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
@Override
|
|
1519
|
-
public void showCursor() {
|
|
1520
|
-
// Maybe should always set here? Seems dangerous, since it's likely that
|
|
1521
|
-
// Java will set the cursor to something else on its own, and the sketch
|
|
1522
|
-
// will be stuck b/c p5 thinks the cursor is set to one particular thing.
|
|
1523
|
-
if (!cursorVisible) {
|
|
1524
|
-
cursorVisible = true;
|
|
1525
|
-
canvas.setCursor(Cursor.getPredefinedCursor(cursorType));
|
|
1422
|
+
@Override
|
|
1423
|
+
public void showCursor() {
|
|
1424
|
+
// Maybe should always set here? Seems dangerous, since it's likely that
|
|
1425
|
+
// Java will set the cursor to something else on its own, and the sketch
|
|
1426
|
+
// will be stuck b/c p5 thinks the cursor is set to one particular thing.
|
|
1427
|
+
if (!cursorVisible) {
|
|
1428
|
+
cursorVisible = true;
|
|
1429
|
+
canvas.setCursor(Cursor.getPredefinedCursor(cursorType));
|
|
1430
|
+
}
|
|
1526
1431
|
}
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
1432
|
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1433
|
+
@Override
|
|
1434
|
+
public void hideCursor() {
|
|
1435
|
+
// Because the OS may have shown the cursor on its own,
|
|
1436
|
+
// don't return if 'cursorVisible' is set to true. [rev 0216]
|
|
1437
|
+
|
|
1438
|
+
if (invisibleCursor == null) {
|
|
1439
|
+
BufferedImage cursorImg
|
|
1440
|
+
= new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
|
1441
|
+
// this is a temporary workaround for the CHIP, will be removed
|
|
1442
|
+
Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
|
|
1443
|
+
if (cursorSize.width == 0 || cursorSize.height == 0) {
|
|
1444
|
+
invisibleCursor = Cursor.getDefaultCursor();
|
|
1445
|
+
} else {
|
|
1446
|
+
invisibleCursor
|
|
1447
|
+
= canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
canvas.setCursor(invisibleCursor);
|
|
1451
|
+
cursorVisible = false;
|
|
1546
1452
|
}
|
|
1547
|
-
canvas.setCursor(invisibleCursor);
|
|
1548
|
-
cursorVisible = false;
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
@Override
|
|
1553
|
-
public Thread createThread() {
|
|
1554
|
-
return new AnimationThread() {
|
|
1555
|
-
@Override
|
|
1556
|
-
public void callDraw() {
|
|
1557
|
-
sketch.handleDraw();
|
|
1558
|
-
render();
|
|
1559
|
-
}
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1562
1453
|
|
|
1454
|
+
@Override
|
|
1455
|
+
public Thread createThread() {
|
|
1456
|
+
return new AnimationThread() {
|
|
1457
|
+
@Override
|
|
1458
|
+
public void callDraw() {
|
|
1459
|
+
sketch.handleDraw();
|
|
1460
|
+
render();
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1563
1464
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1465
|
+
void debug(String format, Object... args) {
|
|
1466
|
+
System.out.format(format + "%n", args);
|
|
1467
|
+
}
|
|
1567
1468
|
}
|