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