picrate 0.7.0-java → 0.8.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/.gitignore +1 -1
- data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
- data/.mvn/wrapper/maven-wrapper.properties +2 -1
- data/.travis.yml +2 -5
- data/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/Rakefile +15 -27
- data/docs/_config.yml +1 -1
- data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -1
- data/docs/_posts/2018-11-18-building-gem.md +1 -1
- data/lib/picrate/app.rb +1 -1
- data/lib/picrate/native_folder.rb +1 -1
- data/lib/picrate/version.rb +1 -1
- data/mvnw +127 -51
- data/mvnw.cmd +182 -0
- data/pom.rb +39 -30
- data/pom.xml +50 -37
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/core/LibraryProxy.java +0 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +1 -1
- data/src/main/java/monkstone/vecmath/GfxRender.java +87 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +48 -50
- data/src/main/java/processing/awt/PShapeJava2D.java +10 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +315 -371
- data/src/main/java/processing/core/PApplet.java +15424 -15495
- data/src/main/java/processing/core/PConstants.java +4 -4
- data/src/main/java/processing/core/PFont.java +394 -369
- data/src/main/java/processing/core/PGraphics.java +11 -10
- data/src/main/java/processing/core/PImage.java +1389 -1435
- data/src/main/java/processing/core/PMatrix2D.java +297 -294
- data/src/main/java/processing/core/PMatrix3D.java +641 -594
- data/src/main/java/processing/core/PShape.java +1755 -1784
- data/src/main/java/processing/core/PShapeOBJ.java +145 -133
- data/src/main/java/processing/core/PShapeSVG.java +808 -801
- data/src/main/java/processing/core/PStyle.java +141 -149
- data/src/main/java/processing/core/PSurface.java +111 -117
- data/src/main/java/processing/core/PSurfaceNone.java +178 -187
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +349 -346
- data/src/main/java/processing/opengl/FontTexture.java +40 -59
- data/src/main/java/processing/opengl/FrameBuffer.java +28 -18
- data/src/main/java/processing/opengl/LinePath.java +7 -7
- data/src/main/java/processing/opengl/LineStroker.java +6 -10
- data/src/main/java/processing/opengl/PGL.java +56 -44
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +909 -2338
- data/src/main/java/processing/opengl/PJOGL.java +1722 -1763
- data/src/main/java/processing/opengl/PShader.java +1308 -1192
- data/src/main/java/processing/opengl/PShapeOpenGL.java +487 -1811
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +482 -497
- data/src/main/java/processing/opengl/Texture.java +99 -76
- data/src/main/java/processing/opengl/VertexBuffer.java +41 -43
- data/vendors/Rakefile +1 -1
- metadata +7 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
2
|
|
3
|
-
/*
|
3
|
+
/*
|
4
4
|
Part of the Processing project - http://processing.org
|
5
5
|
|
6
6
|
Copyright (c) 2012-15 The Processing Foundation
|
@@ -20,8 +20,7 @@
|
|
20
20
|
Public License along with this library; if not, write to the
|
21
21
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
22
22
|
Boston, MA 02111-1307 USA
|
23
|
-
*/
|
24
|
-
|
23
|
+
*/
|
25
24
|
package processing.opengl;
|
26
25
|
|
27
26
|
import java.awt.Component;
|
@@ -65,7 +64,6 @@ import com.jogamp.newt.event.InputEvent;
|
|
65
64
|
import com.jogamp.newt.opengl.GLWindow;
|
66
65
|
import com.jogamp.opengl.util.FPSAnimator;
|
67
66
|
|
68
|
-
|
69
67
|
import processing.core.PApplet;
|
70
68
|
import processing.core.PConstants;
|
71
69
|
import processing.core.PGraphics;
|
@@ -79,112 +77,115 @@ import processing.event.MouseEvent;
|
|
79
77
|
* @author Martin Prout
|
80
78
|
*/
|
81
79
|
public class PSurfaceJOGL implements PSurface {
|
82
|
-
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Selected GL profile
|
83
|
+
*/
|
83
84
|
public static GLProfile profile;
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
/**
|
87
|
+
*
|
88
|
+
*/
|
89
|
+
public PJOGL pgl;
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
/**
|
92
|
+
*
|
93
|
+
*/
|
94
|
+
protected GLWindow window;
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
/**
|
97
|
+
*
|
98
|
+
*/
|
99
|
+
protected FPSAnimator animator;
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
/**
|
102
|
+
*
|
103
|
+
*/
|
104
|
+
protected Rectangle screenRect;
|
104
105
|
|
105
106
|
private Thread drawExceptionHandler;
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
108
|
+
/**
|
109
|
+
*
|
110
|
+
*/
|
111
|
+
protected PApplet sketch;
|
112
|
+
|
113
|
+
/**
|
114
|
+
*
|
115
|
+
*/
|
116
|
+
protected PGraphics graphics;
|
117
|
+
|
118
|
+
/**
|
119
|
+
*
|
120
|
+
*/
|
121
|
+
protected int sketchWidth0;
|
122
|
+
|
123
|
+
/**
|
124
|
+
*
|
125
|
+
*/
|
126
|
+
protected int sketchHeight0;
|
127
|
+
|
128
|
+
/**
|
129
|
+
*
|
130
|
+
*/
|
131
|
+
protected int sketchWidth;
|
132
|
+
|
133
|
+
/**
|
134
|
+
*
|
135
|
+
*/
|
136
|
+
protected int sketchHeight;
|
137
|
+
|
138
|
+
/**
|
139
|
+
*
|
140
|
+
*/
|
141
|
+
protected Display display;
|
142
|
+
|
143
|
+
/**
|
144
|
+
*
|
145
|
+
*/
|
146
|
+
protected Screen screen;
|
147
|
+
|
148
|
+
/**
|
149
|
+
*
|
150
|
+
*/
|
151
|
+
protected Rectangle displayRect;
|
152
|
+
|
153
|
+
/**
|
154
|
+
*
|
155
|
+
*/
|
156
|
+
protected Throwable drawException;
|
156
157
|
private final Object drawExceptionMutex = new Object();
|
157
158
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
159
|
+
/**
|
160
|
+
*
|
161
|
+
*/
|
162
|
+
protected NewtCanvasAWT canvas;
|
163
|
+
|
164
|
+
/**
|
165
|
+
*
|
166
|
+
*/
|
167
|
+
protected int windowScaleFactor;
|
168
|
+
|
169
|
+
/**
|
170
|
+
*
|
171
|
+
*/
|
172
|
+
protected float[] currentPixelScale = {0, 0};
|
173
|
+
|
174
|
+
/**
|
175
|
+
*
|
176
|
+
*/
|
177
|
+
protected boolean external = false;
|
178
|
+
|
179
|
+
/**
|
180
|
+
*
|
181
|
+
* @param graphics
|
182
|
+
*/
|
183
|
+
public PSurfaceJOGL(PGraphics graphics) {
|
183
184
|
this.graphics = graphics;
|
184
|
-
this.pgl = (PJOGL) ((PGraphicsOpenGL)graphics).pgl;
|
185
|
+
this.pgl = (PJOGL) ((PGraphicsOpenGL) graphics).pgl;
|
185
186
|
}
|
186
187
|
|
187
|
-
|
188
|
+
@Override
|
188
189
|
public void initOffscreen(PApplet sketch) {
|
189
190
|
this.sketch = sketch;
|
190
191
|
|
@@ -198,7 +199,7 @@ public class PSurfaceJOGL implements PSurface {
|
|
198
199
|
}
|
199
200
|
}
|
200
201
|
|
201
|
-
|
202
|
+
@Override
|
202
203
|
public void initFrame(PApplet sketch) {
|
203
204
|
this.sketch = sketch;
|
204
205
|
initIcons();
|
@@ -209,15 +210,15 @@ public class PSurfaceJOGL implements PSurface {
|
|
209
210
|
initAnimator();
|
210
211
|
}
|
211
212
|
|
212
|
-
|
213
|
+
@Override
|
213
214
|
public Object getNative() {
|
214
215
|
return window;
|
215
216
|
}
|
216
217
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
218
|
+
/**
|
219
|
+
*
|
220
|
+
*/
|
221
|
+
protected void initDisplay() {
|
221
222
|
display = NewtFactory.createDisplay(null);
|
222
223
|
display.addReference();
|
223
224
|
screen = NewtFactory.createScreen(display, 0);
|
@@ -230,12 +231,12 @@ public class PSurfaceJOGL implements PSurface {
|
|
230
231
|
int displayNum = sketch.sketchDisplay();
|
231
232
|
if (displayNum > 0) { // if -1, use the default device
|
232
233
|
if (displayNum <= awtDevices.length) {
|
233
|
-
awtDisplayDevice = awtDevices[displayNum-1];
|
234
|
+
awtDisplayDevice = awtDevices[displayNum - 1];
|
234
235
|
} else {
|
235
|
-
System.err.format("Display %d does not exist, "
|
236
|
-
"using the default display instead.%n", displayNum);
|
236
|
+
System.err.format("Display %d does not exist, "
|
237
|
+
+ "using the default display instead.%n", displayNum);
|
237
238
|
for (int i = 0; i < awtDevices.length; i++) {
|
238
|
-
System.err.format("Display %d is %s%n", i+1, awtDevices[i]);
|
239
|
+
System.err.format("Display %d is %s%n", i + 1, awtDevices[i]);
|
239
240
|
}
|
240
241
|
}
|
241
242
|
} else if (0 < awtDevices.length) {
|
@@ -249,52 +250,59 @@ public class PSurfaceJOGL implements PSurface {
|
|
249
250
|
displayRect = awtDisplayDevice.getDefaultConfiguration().getBounds();
|
250
251
|
}
|
251
252
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
253
|
+
/**
|
254
|
+
*
|
255
|
+
*/
|
256
|
+
protected void initGL() {
|
256
257
|
// System.out.println("*******************************");
|
257
258
|
if (profile == null) {
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
259
|
+
switch (PJOGL.profile) {
|
260
|
+
case 1:
|
261
|
+
try {
|
262
|
+
profile = GLProfile.getGL2ES1();
|
263
|
+
} catch (GLException ex) {
|
264
|
+
profile = GLProfile.getMaxFixedFunc(true);
|
265
|
+
}
|
266
|
+
break;
|
267
|
+
case 2:
|
268
|
+
try {
|
269
|
+
profile = GLProfile.getGL2ES2();
|
267
270
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
271
|
+
// workaround for https://jogamp.org/bugzilla/show_bug.cgi?id=1347
|
272
|
+
if (!profile.isHardwareRasterizer()) {
|
273
|
+
GLProfile hardware = GLProfile.getMaxProgrammable(true);
|
274
|
+
if (hardware.isGL2ES2()) {
|
275
|
+
profile = hardware;
|
276
|
+
}
|
273
277
|
}
|
274
|
-
}
|
275
278
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
279
|
+
} catch (GLException ex) {
|
280
|
+
profile = GLProfile.getMaxProgrammable(true);
|
281
|
+
}
|
282
|
+
break;
|
283
|
+
case 3:
|
284
|
+
try {
|
285
|
+
profile = GLProfile.getGL2GL3();
|
286
|
+
} catch (GLException ex) {
|
287
|
+
profile = GLProfile.getMaxProgrammable(true);
|
288
|
+
}
|
289
|
+
if (!profile.isGL3()) {
|
290
|
+
PGraphics.showWarning("Requested profile GL3 but is not available, got: " + profile);
|
291
|
+
}
|
292
|
+
break;
|
293
|
+
case 4:
|
294
|
+
try {
|
295
|
+
profile = GLProfile.getGL4ES3();
|
296
|
+
} catch (GLException ex) {
|
297
|
+
profile = GLProfile.getMaxProgrammable(true);
|
298
|
+
}
|
299
|
+
if (!profile.isGL4()) {
|
300
|
+
PGraphics.showWarning("Requested profile GL4 but is not available, got: " + profile);
|
301
|
+
}
|
302
|
+
break;
|
303
|
+
default:
|
304
|
+
throw new RuntimeException(PGL.UNSUPPORTED_GLPROF_ERROR);
|
305
|
+
}
|
298
306
|
}
|
299
307
|
|
300
308
|
// Setting up the desired capabilities;
|
@@ -305,7 +313,6 @@ public class PSurfaceJOGL implements PSurface {
|
|
305
313
|
|
306
314
|
// caps.setPBuffer(false);
|
307
315
|
// caps.setFBO(false);
|
308
|
-
|
309
316
|
// pgl.reqNumSamples = PGL.smoothToSamples(graphics.smooth);
|
310
317
|
caps.setSampleBuffers(true);
|
311
318
|
caps.setNumSamples(PGL.smoothToSamples(graphics.smooth));
|
@@ -314,10 +321,10 @@ public class PSurfaceJOGL implements PSurface {
|
|
314
321
|
pgl.setCaps(caps);
|
315
322
|
}
|
316
323
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
324
|
+
/**
|
325
|
+
*
|
326
|
+
*/
|
327
|
+
protected void initWindow() {
|
321
328
|
window = GLWindow.create(screen, pgl.getCaps());
|
322
329
|
|
323
330
|
// Make sure that we pass the window close through to exit(), otherwise
|
@@ -332,16 +339,15 @@ public class PSurfaceJOGL implements PSurface {
|
|
332
339
|
// } else {
|
333
340
|
// window = GLWindow.create(displayDevice.getScreen(), pgl.getCaps());
|
334
341
|
// }
|
335
|
-
|
336
|
-
|
337
|
-
1 : sketch.pixelDensity;
|
342
|
+
windowScaleFactor = PApplet.platform == PConstants.MACOSX
|
343
|
+
? 1 : sketch.pixelDensity;
|
338
344
|
|
339
345
|
boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
|
340
|
-
screenRect = spanDisplays
|
341
|
-
new Rectangle(screen.getX(), screen.getY(), screen.getWidth(), screen.getHeight())
|
342
|
-
new Rectangle((int) displayRect.getX(), (int) displayRect.getY(),
|
343
|
-
|
344
|
-
|
346
|
+
screenRect = spanDisplays
|
347
|
+
? new Rectangle(screen.getX(), screen.getY(), screen.getWidth(), screen.getHeight())
|
348
|
+
: new Rectangle((int) displayRect.getX(), (int) displayRect.getY(),
|
349
|
+
(int) displayRect.getWidth(),
|
350
|
+
(int) displayRect.getHeight());
|
345
351
|
|
346
352
|
// Set the displayWidth/Height variables inside PApplet, so that they're
|
347
353
|
// usable and can even be returned by the sketchWidth()/Height() methods.
|
@@ -368,8 +374,7 @@ public class PSurfaceJOGL implements PSurface {
|
|
368
374
|
// graphics.setSize(w, h - 22 - 22);
|
369
375
|
System.err.println("setting width/height to " + w + " " + h);
|
370
376
|
}
|
371
|
-
|
372
|
-
|
377
|
+
*/
|
373
378
|
sketchWidth = sketch.sketchWidth();
|
374
379
|
sketchHeight = sketch.sketchHeight();
|
375
380
|
// System.out.println("init: " + sketchWidth + " " + sketchHeight);
|
@@ -387,7 +392,7 @@ public class PSurfaceJOGL implements PSurface {
|
|
387
392
|
fullScreen = true;
|
388
393
|
sketch.fullScreen();
|
389
394
|
}
|
390
|
-
|
395
|
+
*/
|
391
396
|
|
392
397
|
if (fullScreen || spanDisplays) {
|
393
398
|
sketchWidth = screenRect.width / windowScaleFactor;
|
@@ -398,13 +403,13 @@ public class PSurfaceJOGL implements PSurface {
|
|
398
403
|
|
399
404
|
float[] reqSurfacePixelScale;
|
400
405
|
if (graphics.is2X() && PApplet.platform == PConstants.MACOSX) {
|
401
|
-
|
402
|
-
|
403
|
-
|
406
|
+
// Retina
|
407
|
+
reqSurfacePixelScale = new float[]{ScalableSurface.AUTOMAX_PIXELSCALE,
|
408
|
+
ScalableSurface.AUTOMAX_PIXELSCALE};
|
404
409
|
} else {
|
405
410
|
// Non-retina
|
406
|
-
reqSurfacePixelScale = new float[]
|
407
|
-
|
411
|
+
reqSurfacePixelScale = new float[]{ScalableSurface.IDENTITY_PIXELSCALE,
|
412
|
+
ScalableSurface.IDENTITY_PIXELSCALE};
|
408
413
|
}
|
409
414
|
window.setSurfaceScale(reqSurfacePixelScale);
|
410
415
|
window.setSize(sketchWidth * windowScaleFactor, sketchHeight * windowScaleFactor);
|
@@ -422,10 +427,10 @@ public class PSurfaceJOGL implements PSurface {
|
|
422
427
|
}
|
423
428
|
}
|
424
429
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
430
|
+
/**
|
431
|
+
*
|
432
|
+
*/
|
433
|
+
protected void initListeners() {
|
429
434
|
NEWTMouseListener mouseListener = new NEWTMouseListener();
|
430
435
|
window.addMouseListener(mouseListener);
|
431
436
|
NEWTKeyListener keyListener = new NEWTKeyListener();
|
@@ -437,10 +442,10 @@ public class PSurfaceJOGL implements PSurface {
|
|
437
442
|
window.addGLEventListener(drawlistener);
|
438
443
|
}
|
439
444
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
445
|
+
/**
|
446
|
+
*
|
447
|
+
*/
|
448
|
+
protected void initAnimator() {
|
444
449
|
if (PApplet.platform == PConstants.WINDOWS) {
|
445
450
|
// Force Windows to keep timer resolution high by
|
446
451
|
// sleeping for time which is not a multiple of 10 ms.
|
@@ -449,7 +454,8 @@ public class PSurfaceJOGL implements PSurface {
|
|
449
454
|
Thread highResTimerThread = new Thread(() -> {
|
450
455
|
try {
|
451
456
|
Thread.sleep(Long.MAX_VALUE);
|
452
|
-
} catch (InterruptedException ignore) {
|
457
|
+
} catch (InterruptedException ignore) {
|
458
|
+
}
|
453
459
|
}, "HighResTimerThread");
|
454
460
|
highResTimerThread.setDaemon(true);
|
455
461
|
highResTimerThread.start();
|
@@ -457,19 +463,15 @@ public class PSurfaceJOGL implements PSurface {
|
|
457
463
|
|
458
464
|
animator = new FPSAnimator(window, 60);
|
459
465
|
drawException = null;
|
460
|
-
animator.setUncaughtExceptionHandler(
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
final Throwable cause) {
|
465
|
-
synchronized (drawExceptionMutex) {
|
466
|
-
drawException = cause;
|
467
|
-
drawExceptionMutex.notify();
|
468
|
-
}
|
466
|
+
animator.setUncaughtExceptionHandler((final GLAnimatorControl animator1, final GLAutoDrawable drawable, final Throwable cause) -> {
|
467
|
+
synchronized (drawExceptionMutex) {
|
468
|
+
drawException = cause;
|
469
|
+
drawExceptionMutex.notify();
|
469
470
|
}
|
470
471
|
});
|
471
472
|
|
472
473
|
drawExceptionHandler = new Thread(new Runnable() {
|
474
|
+
@Override
|
473
475
|
public void run() {
|
474
476
|
synchronized (drawExceptionMutex) {
|
475
477
|
try {
|
@@ -493,7 +495,6 @@ public class PSurfaceJOGL implements PSurface {
|
|
493
495
|
}
|
494
496
|
}
|
495
497
|
} catch (InterruptedException e) {
|
496
|
-
return;
|
497
498
|
}
|
498
499
|
}
|
499
500
|
}
|
@@ -501,71 +502,55 @@ public class PSurfaceJOGL implements PSurface {
|
|
501
502
|
drawExceptionHandler.start();
|
502
503
|
}
|
503
504
|
|
504
|
-
|
505
505
|
@Override
|
506
506
|
public void setTitle(final String title) {
|
507
|
-
display.getEDTUtil().invoke(false,
|
508
|
-
|
509
|
-
public void run() {
|
510
|
-
window.setTitle(title);
|
511
|
-
}
|
507
|
+
display.getEDTUtil().invoke(false, () -> {
|
508
|
+
window.setTitle(title);
|
512
509
|
});
|
513
510
|
}
|
514
511
|
|
515
|
-
|
516
512
|
@Override
|
517
513
|
public void setVisible(final boolean visible) {
|
518
|
-
display.getEDTUtil().invoke(false,
|
519
|
-
|
520
|
-
public void run() {
|
521
|
-
window.setVisible(visible);
|
522
|
-
}
|
514
|
+
display.getEDTUtil().invoke(false, () -> {
|
515
|
+
window.setVisible(visible);
|
523
516
|
});
|
524
517
|
}
|
525
518
|
|
526
|
-
|
527
519
|
@Override
|
528
520
|
public void setResizable(final boolean resizable) {
|
529
|
-
display.getEDTUtil().invoke(false,
|
530
|
-
|
531
|
-
public void run() {
|
532
|
-
window.setResizable(resizable);
|
533
|
-
}
|
521
|
+
display.getEDTUtil().invoke(false, () -> {
|
522
|
+
window.setResizable(resizable);
|
534
523
|
});
|
535
524
|
}
|
536
525
|
|
537
|
-
|
526
|
+
@Override
|
538
527
|
public void setIcon(PImage icon) {
|
539
|
-
PGraphics.showWarning("Window icons for OpenGL sketches can only be set in settings()\n"
|
540
|
-
|
528
|
+
PGraphics.showWarning("Window icons for OpenGL sketches can only be set in settings()\n"
|
529
|
+
+ "using PJOGL.setIcon(filename).");
|
541
530
|
}
|
542
531
|
|
543
|
-
|
544
532
|
@Override
|
545
533
|
public void setAlwaysOnTop(final boolean always) {
|
546
|
-
display.getEDTUtil().invoke(false,
|
547
|
-
|
548
|
-
public void run() {
|
549
|
-
window.setAlwaysOnTop(always);
|
550
|
-
}
|
534
|
+
display.getEDTUtil().invoke(false, () -> {
|
535
|
+
window.setAlwaysOnTop(always);
|
551
536
|
});
|
552
537
|
}
|
553
538
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
539
|
+
/**
|
540
|
+
*
|
541
|
+
*/
|
542
|
+
protected void initIcons() {
|
558
543
|
IOUtil.ClassResources res = null;
|
559
544
|
if (PJOGL.icons == null || PJOGL.icons.length == 0) {
|
560
545
|
// Default Processing icons
|
561
|
-
final int[] sizes = {
|
546
|
+
final int[] sizes = {16, 32, 48, 64, 128, 256, 512};
|
562
547
|
String[] iconImages = new String[sizes.length];
|
563
548
|
for (int i = 0; i < sizes.length; i++) {
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
549
|
+
iconImages[i] = "/icon/icon-" + sizes[i] + ".png";
|
550
|
+
}
|
551
|
+
res = new ClassResources(iconImages,
|
552
|
+
PApplet.class.getClassLoader(),
|
553
|
+
PApplet.class);
|
569
554
|
} else {
|
570
555
|
// Loading custom icons from user-provided files.
|
571
556
|
String[] iconImages = new String[PJOGL.icons.length];
|
@@ -574,13 +559,12 @@ public class PSurfaceJOGL implements PSurface {
|
|
574
559
|
}
|
575
560
|
|
576
561
|
res = new ClassResources(iconImages,
|
577
|
-
|
578
|
-
|
562
|
+
sketch.getClass().getClassLoader(),
|
563
|
+
sketch.getClass());
|
579
564
|
}
|
580
565
|
NewtFactory.setWindowIcons(res);
|
581
566
|
}
|
582
567
|
|
583
|
-
|
584
568
|
@SuppressWarnings("resource")
|
585
569
|
private String resourceFilename(String filename) {
|
586
570
|
// The code below comes from PApplet.createInputRaw() with a few adaptations
|
@@ -606,12 +590,13 @@ public class PSurfaceJOGL implements PSurface {
|
|
606
590
|
//if (filenameActual.equalsIgnoreCase(filenameShort) &&
|
607
591
|
//!filenameActual.equals(filenameShort)) {
|
608
592
|
if (!filenameActual.equals(filenameShort)) {
|
609
|
-
throw new RuntimeException("This file is named "
|
610
|
-
|
611
|
-
|
612
|
-
|
593
|
+
throw new RuntimeException("This file is named "
|
594
|
+
+ filenameActual + " not "
|
595
|
+
+ filename + ". Rename the file "
|
596
|
+
+ "or change your code.");
|
613
597
|
}
|
614
|
-
} catch (IOException e) {
|
598
|
+
} catch (IOException e) {
|
599
|
+
}
|
615
600
|
}
|
616
601
|
|
617
602
|
stream = new FileInputStream(file);
|
@@ -622,8 +607,8 @@ public class PSurfaceJOGL implements PSurface {
|
|
622
607
|
|
623
608
|
// have to break these out because a general Exception might
|
624
609
|
// catch the RuntimeException being thrown above
|
625
|
-
} catch (IOException ioe) {
|
626
|
-
}
|
610
|
+
} catch (IOException | SecurityException ioe) {
|
611
|
+
}
|
627
612
|
|
628
613
|
ClassLoader cl = sketch.getClass().getClassLoader();
|
629
614
|
|
@@ -654,7 +639,8 @@ public class PSurfaceJOGL implements PSurface {
|
|
654
639
|
return filename;
|
655
640
|
}
|
656
641
|
}
|
657
|
-
} catch (IOException e) {
|
642
|
+
} catch (IOException e) {
|
643
|
+
}
|
658
644
|
|
659
645
|
try {
|
660
646
|
// attempt to load from a local file, used when running as
|
@@ -667,7 +653,8 @@ public class PSurfaceJOGL implements PSurface {
|
|
667
653
|
stream.close();
|
668
654
|
return path;
|
669
655
|
}
|
670
|
-
} catch (IOException e2) {
|
656
|
+
} catch (IOException e2) {
|
657
|
+
}
|
671
658
|
|
672
659
|
try {
|
673
660
|
String path = sketch.sketchPath(filename);
|
@@ -676,7 +663,8 @@ public class PSurfaceJOGL implements PSurface {
|
|
676
663
|
stream.close();
|
677
664
|
return path;
|
678
665
|
}
|
679
|
-
} catch (
|
666
|
+
} catch (IOException e) {
|
667
|
+
} // ignored
|
680
668
|
|
681
669
|
try {
|
682
670
|
stream = new FileInputStream(filename);
|
@@ -684,19 +672,19 @@ public class PSurfaceJOGL implements PSurface {
|
|
684
672
|
stream.close();
|
685
673
|
return filename;
|
686
674
|
}
|
687
|
-
} catch (IOException e1) {
|
675
|
+
} catch (IOException e1) {
|
676
|
+
}
|
688
677
|
|
689
|
-
} catch (SecurityException se) {
|
678
|
+
} catch (SecurityException se) {
|
679
|
+
} // online, whups
|
690
680
|
|
691
681
|
} catch (Exception e) {
|
692
682
|
//die(e.getMessage(), e);
|
693
|
-
e.printStackTrace();
|
694
683
|
}
|
695
684
|
|
696
685
|
return "";
|
697
686
|
}
|
698
687
|
|
699
|
-
|
700
688
|
@Override
|
701
689
|
public void placeWindow(int[] location, int[] editorLocation) {
|
702
690
|
|
@@ -733,19 +721,19 @@ public class PSurfaceJOGL implements PSurface {
|
|
733
721
|
if ((locationX + w > sketch.displayWidth - 33) ||
|
734
722
|
(locationY + h > sketch.displayHeight - 33)) {
|
735
723
|
// otherwise center on screen
|
736
|
-
|
724
|
+
*/
|
737
725
|
locationX = (sketch.displayWidth - w) / 2;
|
738
726
|
locationY = (sketch.displayHeight - h) / 2;
|
739
727
|
/*
|
740
728
|
}
|
741
|
-
|
729
|
+
*/
|
742
730
|
window.setTopLevelPosition(locationX, locationY);
|
743
731
|
}
|
744
732
|
} else { // just center on screen
|
745
733
|
// Can't use frame.setLocationRelativeTo(null) because it sends the
|
746
734
|
// frame to the main display, which undermines the --display setting.
|
747
735
|
window.setTopLevelPosition(screenRect.x + (screenRect.width - sketchWidth) / 2,
|
748
|
-
|
736
|
+
screenRect.y + (screenRect.height - sketchHeight) / 2);
|
749
737
|
}
|
750
738
|
|
751
739
|
Point frameLoc = new Point(x, y);
|
@@ -756,11 +744,11 @@ public class PSurfaceJOGL implements PSurface {
|
|
756
744
|
}
|
757
745
|
}
|
758
746
|
|
759
|
-
|
747
|
+
@Override
|
760
748
|
public void placePresent(int stopColor) {
|
761
749
|
float scale = getPixelScale();
|
762
|
-
pgl.initPresentMode(0.5f * (screenRect.width/scale - sketchWidth),
|
763
|
-
|
750
|
+
pgl.initPresentMode(0.5f * (screenRect.width / scale - sketchWidth),
|
751
|
+
0.5f * (screenRect.height / scale - sketchHeight), stopColor);
|
764
752
|
PApplet.hideMenuBar();
|
765
753
|
|
766
754
|
window.setUndecorated(true);
|
@@ -768,33 +756,33 @@ public class PSurfaceJOGL implements PSurface {
|
|
768
756
|
window.setTopLevelSize((int) displayRect.getWidth(), (int) displayRect.getHeight());
|
769
757
|
}
|
770
758
|
|
771
|
-
|
759
|
+
@Override
|
772
760
|
public void setupExternalMessages() {
|
773
761
|
external = true;
|
774
762
|
}
|
775
763
|
|
776
|
-
|
764
|
+
@Override
|
777
765
|
public void startThread() {
|
778
766
|
if (animator != null) {
|
779
767
|
animator.start();
|
780
768
|
}
|
781
769
|
}
|
782
770
|
|
783
|
-
|
771
|
+
@Override
|
784
772
|
public void pauseThread() {
|
785
773
|
if (animator != null) {
|
786
774
|
animator.pause();
|
787
775
|
}
|
788
776
|
}
|
789
777
|
|
790
|
-
|
778
|
+
@Override
|
791
779
|
public void resumeThread() {
|
792
780
|
if (animator != null) {
|
793
781
|
animator.resume();
|
794
782
|
}
|
795
783
|
}
|
796
784
|
|
797
|
-
|
785
|
+
@Override
|
798
786
|
public boolean stopThread() {
|
799
787
|
if (drawExceptionHandler != null) {
|
800
788
|
drawExceptionHandler.interrupt();
|
@@ -807,7 +795,11 @@ public class PSurfaceJOGL implements PSurface {
|
|
807
795
|
}
|
808
796
|
}
|
809
797
|
|
810
|
-
|
798
|
+
/**
|
799
|
+
*
|
800
|
+
* @return
|
801
|
+
*/
|
802
|
+
@Override
|
811
803
|
public boolean isStopped() {
|
812
804
|
if (animator != null) {
|
813
805
|
return !animator.isAnimating();
|
@@ -816,19 +808,18 @@ public class PSurfaceJOGL implements PSurface {
|
|
816
808
|
}
|
817
809
|
}
|
818
810
|
|
819
|
-
|
811
|
+
@Override
|
820
812
|
public void setLocation(final int x, final int y) {
|
821
|
-
display.getEDTUtil().invoke(false,
|
822
|
-
|
823
|
-
public void run() {
|
824
|
-
window.setTopLevelPosition(x, y);
|
825
|
-
}
|
813
|
+
display.getEDTUtil().invoke(false, () -> {
|
814
|
+
window.setTopLevelPosition(x, y);
|
826
815
|
});
|
827
816
|
}
|
828
817
|
|
829
|
-
|
818
|
+
@Override
|
830
819
|
public void setSize(int wide, int high) {
|
831
|
-
if (pgl.presentMode())
|
820
|
+
if (pgl.presentMode()) {
|
821
|
+
return;
|
822
|
+
}
|
832
823
|
|
833
824
|
// When the surface is set to resizable via surface.setResizable(true),
|
834
825
|
// a crash may occur if the user sets the window to size zero.
|
@@ -853,11 +844,11 @@ public class PSurfaceJOGL implements PSurface {
|
|
853
844
|
}
|
854
845
|
}
|
855
846
|
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
847
|
+
/**
|
848
|
+
*
|
849
|
+
* @return
|
850
|
+
*/
|
851
|
+
public float getPixelScale() {
|
861
852
|
if (graphics.pixelDensity == 1) {
|
862
853
|
return 1;
|
863
854
|
}
|
@@ -876,19 +867,19 @@ public class PSurfaceJOGL implements PSurface {
|
|
876
867
|
return currentPixelScale[0];
|
877
868
|
}
|
878
869
|
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
870
|
+
/**
|
871
|
+
*
|
872
|
+
* @return
|
873
|
+
*/
|
874
|
+
public Component getComponent() {
|
884
875
|
return canvas;
|
885
876
|
}
|
886
877
|
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
878
|
+
/**
|
879
|
+
*
|
880
|
+
* @param level
|
881
|
+
*/
|
882
|
+
public void setSmooth(int level) {
|
892
883
|
pgl.reqNumSamples = level;
|
893
884
|
GLCapabilities caps = new GLCapabilities(profile);
|
894
885
|
caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS);
|
@@ -903,41 +894,39 @@ public class PSurfaceJOGL implements PSurface {
|
|
903
894
|
config.setChosenCapabilities(caps);
|
904
895
|
}
|
905
896
|
|
906
|
-
|
897
|
+
@Override
|
907
898
|
public void setFrameRate(float fps) {
|
908
899
|
if (fps < 1) {
|
909
900
|
PGraphics.showWarning(
|
910
|
-
"The OpenGL renderer cannot have a frame rate lower than 1.\n"
|
911
|
-
"Your sketch will run at 1 frame per second.");
|
901
|
+
"The OpenGL renderer cannot have a frame rate lower than 1.\n"
|
902
|
+
+ "Your sketch will run at 1 frame per second.");
|
912
903
|
fps = 1;
|
913
904
|
} else if (fps > 1000) {
|
914
905
|
PGraphics.showWarning(
|
915
|
-
"The OpenGL renderer cannot have a frame rate higher than 1000.\n"
|
916
|
-
"Your sketch will run at 1000 frames per second.");
|
906
|
+
"The OpenGL renderer cannot have a frame rate higher than 1000.\n"
|
907
|
+
+ "Your sketch will run at 1000 frames per second.");
|
917
908
|
fps = 1000;
|
918
909
|
}
|
919
910
|
if (animator != null) {
|
920
911
|
animator.stop();
|
921
|
-
animator.setFPS((int)fps);
|
912
|
+
animator.setFPS((int) fps);
|
922
913
|
pgl.setFps(fps);
|
923
914
|
animator.start();
|
924
915
|
}
|
925
916
|
}
|
926
917
|
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
display.getEDTUtil().invoke(false,
|
932
|
-
|
933
|
-
public void run() {
|
934
|
-
window.requestFocus();
|
935
|
-
}
|
918
|
+
/**
|
919
|
+
*
|
920
|
+
*/
|
921
|
+
public void requestFocus() {
|
922
|
+
display.getEDTUtil().invoke(false, () -> {
|
923
|
+
window.requestFocus();
|
936
924
|
});
|
937
925
|
}
|
938
926
|
|
939
|
-
|
940
927
|
class DrawListener implements GLEventListener {
|
928
|
+
|
929
|
+
@Override
|
941
930
|
public void display(GLAutoDrawable drawable) {
|
942
931
|
if (display.getEDTUtil().isCurrentThreadEDT()) {
|
943
932
|
// For some reason, the first two frames of the animator are run on the
|
@@ -974,9 +963,13 @@ public class PSurfaceJOGL implements PSurface {
|
|
974
963
|
sketch.exitActual();
|
975
964
|
}
|
976
965
|
}
|
966
|
+
|
967
|
+
@Override
|
977
968
|
public void dispose(GLAutoDrawable drawable) {
|
978
969
|
// sketch.dispose();
|
979
970
|
}
|
971
|
+
|
972
|
+
@Override
|
980
973
|
public void init(GLAutoDrawable drawable) {
|
981
974
|
pgl.getGL(drawable);
|
982
975
|
pgl.init(drawable);
|
@@ -984,244 +977,241 @@ public class PSurfaceJOGL implements PSurface {
|
|
984
977
|
|
985
978
|
int c = graphics.backgroundColor;
|
986
979
|
pgl.clearColor(((c >> 16) & 0xff) / 255f,
|
987
|
-
|
988
|
-
|
989
|
-
|
980
|
+
((c >> 8) & 0xff) / 255f,
|
981
|
+
((c) & 0xff) / 255f,
|
982
|
+
((c >> 24) & 0xff) / 255f);
|
990
983
|
pgl.clear(PGL.COLOR_BUFFER_BIT);
|
991
984
|
}
|
992
985
|
|
986
|
+
@Override
|
993
987
|
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
|
994
988
|
pgl.resetFBOLayer();
|
995
989
|
pgl.getGL(drawable);
|
996
|
-
float scale = PApplet.platform == PConstants.MACOSX
|
997
|
-
|
990
|
+
float scale = PApplet.platform == PConstants.MACOSX
|
991
|
+
? getCurrentPixelScale() : getPixelScale();
|
998
992
|
setSize((int) (w / scale), (int) (h / scale));
|
999
993
|
}
|
1000
994
|
}
|
1001
995
|
|
996
|
+
/**
|
997
|
+
*
|
998
|
+
*/
|
999
|
+
protected class NEWTWindowListener implements com.jogamp.newt.event.WindowListener {
|
1000
|
+
|
1002
1001
|
/**
|
1003
1002
|
*
|
1004
1003
|
*/
|
1005
|
-
|
1006
|
-
|
1007
|
-
/**
|
1008
|
-
*
|
1009
|
-
*/
|
1010
|
-
public NEWTWindowListener() {
|
1004
|
+
public NEWTWindowListener() {
|
1011
1005
|
super();
|
1012
1006
|
}
|
1013
1007
|
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1008
|
+
/**
|
1009
|
+
*
|
1010
|
+
* @param arg0
|
1011
|
+
*/
|
1012
|
+
@Override
|
1019
1013
|
public void windowGainedFocus(com.jogamp.newt.event.WindowEvent arg0) {
|
1020
1014
|
sketch.focused = true;
|
1021
1015
|
sketch.focusGained();
|
1022
1016
|
}
|
1023
1017
|
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1018
|
+
/**
|
1019
|
+
*
|
1020
|
+
* @param arg0
|
1021
|
+
*/
|
1022
|
+
@Override
|
1029
1023
|
public void windowLostFocus(com.jogamp.newt.event.WindowEvent arg0) {
|
1030
1024
|
sketch.focused = false;
|
1031
1025
|
sketch.focusLost();
|
1032
1026
|
}
|
1033
1027
|
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1028
|
+
/**
|
1029
|
+
*
|
1030
|
+
* @param arg0
|
1031
|
+
*/
|
1032
|
+
@Override
|
1039
1033
|
public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent arg0) {
|
1040
1034
|
sketch.exit();
|
1041
1035
|
}
|
1042
1036
|
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1037
|
+
/**
|
1038
|
+
*
|
1039
|
+
* @param arg0
|
1040
|
+
*/
|
1041
|
+
@Override
|
1048
1042
|
public void windowDestroyed(com.jogamp.newt.event.WindowEvent arg0) {
|
1049
1043
|
sketch.exit();
|
1050
1044
|
}
|
1051
1045
|
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1046
|
+
/**
|
1047
|
+
*
|
1048
|
+
* @param arg0
|
1049
|
+
*/
|
1050
|
+
@Override
|
1057
1051
|
public void windowMoved(com.jogamp.newt.event.WindowEvent arg0) {
|
1058
1052
|
if (external) {
|
1059
1053
|
sketch.frameMoved(window.getX(), window.getY());
|
1060
1054
|
}
|
1061
1055
|
}
|
1062
1056
|
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1057
|
+
/**
|
1058
|
+
*
|
1059
|
+
* @param arg0
|
1060
|
+
*/
|
1061
|
+
@Override
|
1068
1062
|
public void windowRepaint(com.jogamp.newt.event.WindowUpdateEvent arg0) {
|
1069
1063
|
}
|
1070
1064
|
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1065
|
+
/**
|
1066
|
+
*
|
1067
|
+
* @param arg0
|
1068
|
+
*/
|
1069
|
+
@Override
|
1076
1070
|
public void windowResized(com.jogamp.newt.event.WindowEvent arg0) {
|
1077
1071
|
}
|
1078
1072
|
}
|
1079
1073
|
|
1080
|
-
|
1081
1074
|
// NEWT mouse listener
|
1075
|
+
/**
|
1076
|
+
*
|
1077
|
+
*/
|
1078
|
+
protected class NEWTMouseListener extends com.jogamp.newt.event.MouseAdapter {
|
1082
1079
|
|
1083
1080
|
/**
|
1084
1081
|
*
|
1085
1082
|
*/
|
1086
|
-
|
1087
|
-
|
1088
|
-
/**
|
1089
|
-
*
|
1090
|
-
*/
|
1091
|
-
public NEWTMouseListener() {
|
1083
|
+
public NEWTMouseListener() {
|
1092
1084
|
super();
|
1093
1085
|
}
|
1094
1086
|
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1087
|
+
/**
|
1088
|
+
*
|
1089
|
+
* @param e
|
1090
|
+
*/
|
1091
|
+
@Override
|
1100
1092
|
public void mousePressed(com.jogamp.newt.event.MouseEvent e) {
|
1101
1093
|
nativeMouseEvent(e, MouseEvent.PRESS);
|
1102
1094
|
}
|
1103
1095
|
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1096
|
+
/**
|
1097
|
+
*
|
1098
|
+
* @param e
|
1099
|
+
*/
|
1100
|
+
@Override
|
1109
1101
|
public void mouseReleased(com.jogamp.newt.event.MouseEvent e) {
|
1110
1102
|
nativeMouseEvent(e, MouseEvent.RELEASE);
|
1111
1103
|
}
|
1112
1104
|
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1105
|
+
/**
|
1106
|
+
*
|
1107
|
+
* @param e
|
1108
|
+
*/
|
1109
|
+
@Override
|
1118
1110
|
public void mouseClicked(com.jogamp.newt.event.MouseEvent e) {
|
1119
1111
|
nativeMouseEvent(e, MouseEvent.CLICK);
|
1120
1112
|
}
|
1121
1113
|
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1114
|
+
/**
|
1115
|
+
*
|
1116
|
+
* @param e
|
1117
|
+
*/
|
1118
|
+
@Override
|
1127
1119
|
public void mouseDragged(com.jogamp.newt.event.MouseEvent e) {
|
1128
1120
|
nativeMouseEvent(e, MouseEvent.DRAG);
|
1129
1121
|
}
|
1130
1122
|
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1123
|
+
/**
|
1124
|
+
*
|
1125
|
+
* @param e
|
1126
|
+
*/
|
1127
|
+
@Override
|
1136
1128
|
public void mouseMoved(com.jogamp.newt.event.MouseEvent e) {
|
1137
1129
|
nativeMouseEvent(e, MouseEvent.MOVE);
|
1138
1130
|
}
|
1139
1131
|
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1132
|
+
/**
|
1133
|
+
*
|
1134
|
+
* @param e
|
1135
|
+
*/
|
1136
|
+
@Override
|
1145
1137
|
public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent e) {
|
1146
1138
|
nativeMouseEvent(e, MouseEvent.WHEEL);
|
1147
1139
|
}
|
1148
1140
|
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1141
|
+
/**
|
1142
|
+
*
|
1143
|
+
* @param e
|
1144
|
+
*/
|
1145
|
+
@Override
|
1154
1146
|
public void mouseEntered(com.jogamp.newt.event.MouseEvent e) {
|
1155
1147
|
// System.out.println("enter");
|
1156
1148
|
nativeMouseEvent(e, MouseEvent.ENTER);
|
1157
1149
|
}
|
1158
1150
|
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1151
|
+
/**
|
1152
|
+
*
|
1153
|
+
* @param e
|
1154
|
+
*/
|
1155
|
+
@Override
|
1164
1156
|
public void mouseExited(com.jogamp.newt.event.MouseEvent e) {
|
1165
1157
|
// System.out.println("exit");
|
1166
1158
|
nativeMouseEvent(e, MouseEvent.EXIT);
|
1167
1159
|
}
|
1168
1160
|
}
|
1169
1161
|
|
1170
|
-
|
1171
1162
|
// NEWT key listener
|
1163
|
+
/**
|
1164
|
+
*
|
1165
|
+
*/
|
1166
|
+
protected class NEWTKeyListener extends com.jogamp.newt.event.KeyAdapter {
|
1172
1167
|
|
1173
1168
|
/**
|
1174
1169
|
*
|
1175
1170
|
*/
|
1176
|
-
|
1177
|
-
|
1178
|
-
/**
|
1179
|
-
*
|
1180
|
-
*/
|
1181
|
-
public NEWTKeyListener() {
|
1171
|
+
public NEWTKeyListener() {
|
1182
1172
|
super();
|
1183
1173
|
}
|
1184
1174
|
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1175
|
+
/**
|
1176
|
+
*
|
1177
|
+
* @param e
|
1178
|
+
*/
|
1179
|
+
@Override
|
1190
1180
|
public void keyPressed(com.jogamp.newt.event.KeyEvent e) {
|
1191
1181
|
nativeKeyEvent(e, KeyEvent.PRESS);
|
1192
1182
|
}
|
1193
1183
|
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1184
|
+
/**
|
1185
|
+
*
|
1186
|
+
* @param e
|
1187
|
+
*/
|
1188
|
+
@Override
|
1199
1189
|
public void keyReleased(com.jogamp.newt.event.KeyEvent e) {
|
1200
1190
|
nativeKeyEvent(e, KeyEvent.RELEASE);
|
1201
1191
|
}
|
1202
1192
|
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1193
|
+
/**
|
1194
|
+
*
|
1195
|
+
* @param e
|
1196
|
+
*/
|
1197
|
+
public void keyTyped(com.jogamp.newt.event.KeyEvent e) {
|
1208
1198
|
nativeKeyEvent(e, KeyEvent.TYPE);
|
1209
1199
|
}
|
1210
1200
|
}
|
1211
1201
|
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1202
|
+
/**
|
1203
|
+
*
|
1204
|
+
* @param nativeEvent
|
1205
|
+
* @param peAction
|
1206
|
+
*/
|
1207
|
+
protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
|
1208
|
+
int peAction) {
|
1219
1209
|
int modifiers = nativeEvent.getModifiers();
|
1220
|
-
int peModifiers = modifiers
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1210
|
+
int peModifiers = modifiers
|
1211
|
+
& (InputEvent.SHIFT_MASK
|
1212
|
+
| InputEvent.CTRL_MASK
|
1213
|
+
| InputEvent.META_MASK
|
1214
|
+
| InputEvent.ALT_MASK);
|
1225
1215
|
|
1226
1216
|
int peButton = 0;
|
1227
1217
|
switch (nativeEvent.getButton()) {
|
@@ -1247,8 +1237,8 @@ public class PSurfaceJOGL implements PSurface {
|
|
1247
1237
|
if (peAction == MouseEvent.WHEEL) {
|
1248
1238
|
// Invert wheel rotation count so it matches JAVA2D's
|
1249
1239
|
// https://github.com/processing/processing/issues/3840
|
1250
|
-
peCount = -(nativeEvent.isShiftDown() ? (int)nativeEvent.getRotation()[0]
|
1251
|
-
|
1240
|
+
peCount = -(nativeEvent.isShiftDown() ? (int) nativeEvent.getRotation()[0]
|
1241
|
+
: (int) nativeEvent.getRotation()[1]);
|
1252
1242
|
} else {
|
1253
1243
|
peCount = nativeEvent.getClickCount();
|
1254
1244
|
}
|
@@ -1265,10 +1255,10 @@ public class PSurfaceJOGL implements PSurface {
|
|
1265
1255
|
int my = sy;
|
1266
1256
|
|
1267
1257
|
if (pgl.presentMode()) {
|
1268
|
-
mx -= (int)pgl.presentX;
|
1269
|
-
my -= (int)pgl.presentY;
|
1270
|
-
if (peAction == KeyEvent.RELEASE
|
1271
|
-
|
1258
|
+
mx -= (int) pgl.presentX;
|
1259
|
+
my -= (int) pgl.presentY;
|
1260
|
+
if (peAction == KeyEvent.RELEASE
|
1261
|
+
&& pgl.insideStopButton(sx, sy - screenRect.height / windowScaleFactor)) {
|
1272
1262
|
sketch.exit();
|
1273
1263
|
}
|
1274
1264
|
if (mx < 0 || sketchWidth < mx || my < 0 || sketchHeight < my) {
|
@@ -1277,26 +1267,26 @@ public class PSurfaceJOGL implements PSurface {
|
|
1277
1267
|
}
|
1278
1268
|
|
1279
1269
|
MouseEvent me = new MouseEvent(nativeEvent, nativeEvent.getWhen(),
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1270
|
+
peAction, peModifiers,
|
1271
|
+
mx, my,
|
1272
|
+
peButton,
|
1273
|
+
peCount);
|
1284
1274
|
|
1285
1275
|
sketch.postEvent(me);
|
1286
1276
|
}
|
1287
1277
|
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
int peModifiers = nativeEvent.getModifiers()
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1278
|
+
/**
|
1279
|
+
*
|
1280
|
+
* @param nativeEvent
|
1281
|
+
* @param peAction
|
1282
|
+
*/
|
1283
|
+
protected void nativeKeyEvent(com.jogamp.newt.event.KeyEvent nativeEvent,
|
1284
|
+
int peAction) {
|
1285
|
+
int peModifiers = nativeEvent.getModifiers()
|
1286
|
+
& (InputEvent.SHIFT_MASK
|
1287
|
+
| InputEvent.CTRL_MASK
|
1288
|
+
| InputEvent.META_MASK
|
1289
|
+
| InputEvent.ALT_MASK);
|
1300
1290
|
|
1301
1291
|
short code = nativeEvent.getKeyCode();
|
1302
1292
|
char keyChar;
|
@@ -1306,8 +1296,8 @@ public class PSurfaceJOGL implements PSurface {
|
|
1306
1296
|
keyChar = PConstants.CODED;
|
1307
1297
|
} else if (isHackyKey(code)) {
|
1308
1298
|
// we can return only one char for ENTER, let it be \n everywhere
|
1309
|
-
keyCode = code == com.jogamp.newt.event.KeyEvent.VK_ENTER
|
1310
|
-
|
1299
|
+
keyCode = code == com.jogamp.newt.event.KeyEvent.VK_ENTER
|
1300
|
+
? PConstants.ENTER : code;
|
1311
1301
|
keyChar = hackToChar(code, nativeEvent.getKeyChar());
|
1312
1302
|
} else {
|
1313
1303
|
keyCode = code;
|
@@ -1322,10 +1312,10 @@ public class PSurfaceJOGL implements PSurface {
|
|
1322
1312
|
// In contrast to key symbol, key code uses a fixed US keyboard layout and therefore is keyboard layout independent.
|
1323
1313
|
// E.g. virtual key code VK_Y denotes the same physical key regardless whether keyboard layout QWERTY or QWERTZ is active. The key symbol of the former is VK_Y, where the latter produces VK_Y.
|
1324
1314
|
KeyEvent ke = new KeyEvent(nativeEvent, nativeEvent.getWhen(),
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1315
|
+
peAction, peModifiers,
|
1316
|
+
keyChar,
|
1317
|
+
keyCode,
|
1318
|
+
nativeEvent.isAutoRepeat());
|
1329
1319
|
|
1330
1320
|
sketch.postEvent(ke);
|
1331
1321
|
|
@@ -1334,29 +1324,27 @@ public class PSurfaceJOGL implements PSurface {
|
|
1334
1324
|
// Create key typed event
|
1335
1325
|
// TODO: combine dead keys with the following key
|
1336
1326
|
KeyEvent tke = new KeyEvent(nativeEvent, nativeEvent.getWhen(),
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1327
|
+
KeyEvent.TYPE, peModifiers,
|
1328
|
+
keyChar,
|
1329
|
+
0,
|
1330
|
+
nativeEvent.isAutoRepeat());
|
1341
1331
|
|
1342
1332
|
sketch.postEvent(tke);
|
1343
1333
|
}
|
1344
1334
|
}
|
1345
1335
|
}
|
1346
1336
|
|
1347
|
-
|
1348
1337
|
private static boolean isPCodedKey(short code) {
|
1349
|
-
return code == com.jogamp.newt.event.KeyEvent.VK_UP
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1338
|
+
return code == com.jogamp.newt.event.KeyEvent.VK_UP
|
1339
|
+
|| code == com.jogamp.newt.event.KeyEvent.VK_DOWN
|
1340
|
+
|| code == com.jogamp.newt.event.KeyEvent.VK_LEFT
|
1341
|
+
|| code == com.jogamp.newt.event.KeyEvent.VK_RIGHT
|
1342
|
+
|| code == com.jogamp.newt.event.KeyEvent.VK_ALT
|
1343
|
+
|| code == com.jogamp.newt.event.KeyEvent.VK_CONTROL
|
1344
|
+
|| code == com.jogamp.newt.event.KeyEvent.VK_SHIFT
|
1345
|
+
|| code == com.jogamp.newt.event.KeyEvent.VK_WINDOWS;
|
1357
1346
|
}
|
1358
1347
|
|
1359
|
-
|
1360
1348
|
// Why do we need this mapping?
|
1361
1349
|
// Relevant discussion and links here:
|
1362
1350
|
// http://forum.jogamp.org/Newt-wrong-keycode-for-key-td4033690.html#a4033697
|
@@ -1384,7 +1372,6 @@ public class PSurfaceJOGL implements PSurface {
|
|
1384
1372
|
}
|
1385
1373
|
}
|
1386
1374
|
|
1387
|
-
|
1388
1375
|
private static boolean isHackyKey(short code) {
|
1389
1376
|
switch (code) {
|
1390
1377
|
case com.jogamp.newt.event.KeyEvent.VK_BACK_SPACE:
|
@@ -1397,7 +1384,6 @@ public class PSurfaceJOGL implements PSurface {
|
|
1397
1384
|
return false;
|
1398
1385
|
}
|
1399
1386
|
|
1400
|
-
|
1401
1387
|
private static char hackToChar(short code, char def) {
|
1402
1388
|
switch (code) {
|
1403
1389
|
case com.jogamp.newt.event.KeyEvent.VK_BACK_SPACE:
|
@@ -1414,11 +1400,9 @@ public class PSurfaceJOGL implements PSurface {
|
|
1414
1400
|
return def;
|
1415
1401
|
}
|
1416
1402
|
|
1417
|
-
|
1418
1403
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
1419
|
-
|
1420
|
-
|
1421
1404
|
class CursorInfo {
|
1405
|
+
|
1422
1406
|
PImage image;
|
1423
1407
|
int x, y;
|
1424
1408
|
|
@@ -1435,6 +1419,7 @@ public class PSurfaceJOGL implements PSurface {
|
|
1435
1419
|
|
1436
1420
|
static Map<Integer, CursorInfo> cursors = new HashMap<>();
|
1437
1421
|
static Map<Integer, String> cursorNames = new HashMap<>();
|
1422
|
+
|
1438
1423
|
static {
|
1439
1424
|
cursorNames.put(PConstants.ARROW, "arrow");
|
1440
1425
|
cursorNames.put(PConstants.CROSS, "cross");
|
@@ -1444,7 +1429,7 @@ public class PSurfaceJOGL implements PSurface {
|
|
1444
1429
|
cursorNames.put(PConstants.TEXT, "text");
|
1445
1430
|
}
|
1446
1431
|
|
1447
|
-
|
1432
|
+
@Override
|
1448
1433
|
public void setCursor(int kind) {
|
1449
1434
|
if (!cursorNames.containsKey(kind)) {
|
1450
1435
|
PGraphics.showWarning("Unknown cursor type: " + kind);
|
@@ -1454,19 +1439,28 @@ public class PSurfaceJOGL implements PSurface {
|
|
1454
1439
|
if (cursor == null) {
|
1455
1440
|
String name = cursorNames.get(kind);
|
1456
1441
|
if (name != null) {
|
1457
|
-
ImageIcon icon
|
1458
|
-
new ImageIcon(getClass().getResource("cursors/" + name + ".png"));
|
1442
|
+
ImageIcon icon
|
1443
|
+
= new ImageIcon(getClass().getResource("cursors/" + name + ".png"));
|
1459
1444
|
PImage img = new PImage(icon.getImage());
|
1460
1445
|
// Most cursors just use the center as the hotspot...
|
1461
1446
|
int x = img.width / 2;
|
1462
1447
|
int y = img.height / 2;
|
1463
1448
|
// ...others are more specific
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1449
|
+
switch (kind) {
|
1450
|
+
case PConstants.ARROW:
|
1451
|
+
x = 10;
|
1452
|
+
y = 7;
|
1453
|
+
break;
|
1454
|
+
case PConstants.HAND:
|
1455
|
+
x = 12;
|
1456
|
+
y = 8;
|
1457
|
+
break;
|
1458
|
+
case PConstants.TEXT:
|
1459
|
+
x = 16;
|
1460
|
+
y = 22;
|
1461
|
+
break;
|
1462
|
+
default:
|
1463
|
+
break;
|
1470
1464
|
}
|
1471
1465
|
cursor = new CursorInfo(img, x, y);
|
1472
1466
|
cursors.put(kind, cursor);
|
@@ -1479,11 +1473,11 @@ public class PSurfaceJOGL implements PSurface {
|
|
1479
1473
|
}
|
1480
1474
|
}
|
1481
1475
|
|
1482
|
-
|
1476
|
+
@Override
|
1483
1477
|
public void setCursor(PImage image, int hotspotX, int hotspotY) {
|
1484
1478
|
Display disp = window.getScreen().getDisplay();
|
1485
|
-
BufferedImage bimg = (BufferedImage)image.getNative();
|
1486
|
-
DataBufferInt dbuf = (DataBufferInt)bimg.getData().getDataBuffer();
|
1479
|
+
BufferedImage bimg = (BufferedImage) image.getNative();
|
1480
|
+
DataBufferInt dbuf = (DataBufferInt) bimg.getData().getDataBuffer();
|
1487
1481
|
int[] ipix = dbuf.getData();
|
1488
1482
|
ByteBuffer pixels = ByteBuffer.allocate(ipix.length * 4);
|
1489
1483
|
pixels.asIntBuffer().put(ipix);
|
@@ -1491,32 +1485,23 @@ public class PSurfaceJOGL implements PSurface {
|
|
1491
1485
|
final Dimension size = new Dimension(bimg.getWidth(), bimg.getHeight());
|
1492
1486
|
PixelRectangle pixelrect = new PixelRectangle.GenericPixelRect(format, size, 0, false, pixels);
|
1493
1487
|
final PointerIcon pi = disp.createPointerIcon(pixelrect, hotspotX, hotspotY);
|
1494
|
-
display.getEDTUtil().invoke(false,
|
1495
|
-
|
1496
|
-
|
1497
|
-
window.setPointerVisible(true);
|
1498
|
-
window.setPointerIcon(pi);
|
1499
|
-
}
|
1488
|
+
display.getEDTUtil().invoke(false, () -> {
|
1489
|
+
window.setPointerVisible(true);
|
1490
|
+
window.setPointerIcon(pi);
|
1500
1491
|
});
|
1501
1492
|
}
|
1502
1493
|
|
1503
|
-
|
1494
|
+
@Override
|
1504
1495
|
public void showCursor() {
|
1505
|
-
display.getEDTUtil().invoke(false,
|
1506
|
-
|
1507
|
-
public void run() {
|
1508
|
-
window.setPointerVisible(true);
|
1509
|
-
}
|
1496
|
+
display.getEDTUtil().invoke(false, () -> {
|
1497
|
+
window.setPointerVisible(true);
|
1510
1498
|
});
|
1511
1499
|
}
|
1512
1500
|
|
1513
|
-
|
1501
|
+
@Override
|
1514
1502
|
public void hideCursor() {
|
1515
|
-
display.getEDTUtil().invoke(false,
|
1516
|
-
|
1517
|
-
public void run() {
|
1518
|
-
window.setPointerVisible(false);
|
1519
|
-
}
|
1503
|
+
display.getEDTUtil().invoke(false, () -> {
|
1504
|
+
window.setPointerVisible(false);
|
1520
1505
|
});
|
1521
1506
|
}
|
1522
1507
|
}
|