propane 3.3.1-java → 3.6.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -3
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +17 -5
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +16 -30
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +23 -24
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +21 -15
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +7 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +4 -1
  37. data/mvnw +127 -51
  38. data/mvnw.cmd +182 -145
  39. data/pom.rb +53 -50
  40. data/pom.xml +17 -8
  41. data/propane.gemspec +13 -11
  42. data/src/main/java/monkstone/ColorUtil.java +13 -1
  43. data/src/main/java/monkstone/MathToolModule.java +253 -203
  44. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  45. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  46. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  47. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  48. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  53. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  54. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  55. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  57. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  58. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  59. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  60. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  61. data/src/main/java/processing/awt/PGraphicsJava2D.java +2164 -1661
  62. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  63. data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
  64. data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
  65. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  66. data/src/main/java/processing/core/PApplet.java +831 -824
  67. data/src/main/java/processing/core/PConstants.java +477 -447
  68. data/src/main/java/processing/core/PFont.java +914 -880
  69. data/src/main/java/processing/core/PGraphics.java +229 -213
  70. data/src/main/java/processing/core/PImage.java +620 -318
  71. data/src/main/java/processing/core/PMatrix.java +172 -159
  72. data/src/main/java/processing/core/PMatrix2D.java +478 -409
  73. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  74. data/src/main/java/processing/core/PShape.java +2888 -2652
  75. data/src/main/java/processing/core/PShapeOBJ.java +436 -415
  76. data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
  77. data/src/main/java/processing/core/PStyle.java +40 -37
  78. data/src/main/java/processing/core/PSurface.java +139 -97
  79. data/src/main/java/processing/core/PSurfaceNone.java +296 -208
  80. data/src/main/java/processing/core/PVector.java +997 -965
  81. data/src/main/java/processing/core/ThinkDifferent.java +12 -17
  82. data/src/main/java/processing/data/DoubleDict.java +756 -710
  83. data/src/main/java/processing/data/DoubleList.java +749 -696
  84. data/src/main/java/processing/data/FloatDict.java +748 -702
  85. data/src/main/java/processing/data/FloatList.java +751 -697
  86. data/src/main/java/processing/data/IntDict.java +720 -673
  87. data/src/main/java/processing/data/IntList.java +699 -633
  88. data/src/main/java/processing/data/JSONArray.java +931 -873
  89. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  90. data/src/main/java/processing/data/JSONTokener.java +351 -341
  91. data/src/main/java/processing/data/LongDict.java +710 -663
  92. data/src/main/java/processing/data/LongList.java +701 -635
  93. data/src/main/java/processing/data/Sort.java +37 -41
  94. data/src/main/java/processing/data/StringDict.java +525 -486
  95. data/src/main/java/processing/data/StringList.java +626 -580
  96. data/src/main/java/processing/data/Table.java +3690 -3510
  97. data/src/main/java/processing/data/TableRow.java +182 -183
  98. data/src/main/java/processing/data/XML.java +957 -883
  99. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  100. data/src/main/java/processing/event/Event.java +87 -66
  101. data/src/main/java/processing/event/KeyEvent.java +48 -41
  102. data/src/main/java/processing/event/MouseEvent.java +88 -113
  103. data/src/main/java/processing/event/TouchEvent.java +10 -6
  104. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  105. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  106. data/src/main/java/processing/net/Client.java +744 -0
  107. data/src/main/java/processing/net/Server.java +388 -0
  108. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  109. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  110. data/src/main/java/processing/opengl/LinePath.java +547 -500
  111. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  112. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  113. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  114. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  115. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  116. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  117. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  118. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  119. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  120. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  121. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  122. data/test/create_test.rb +21 -20
  123. data/test/deglut_spec_test.rb +4 -2
  124. data/test/helper_methods_test.rb +49 -20
  125. data/test/math_tool_test.rb +39 -32
  126. data/test/native_folder.rb +47 -0
  127. data/test/respond_to_test.rb +3 -2
  128. data/test/sketches/key_event.rb +2 -2
  129. data/test/sketches/library/my_library/my_library.rb +3 -0
  130. data/test/test_helper.rb +2 -0
  131. data/test/vecmath_spec_test.rb +35 -22
  132. data/vendors/Rakefile +33 -62
  133. metadata +54 -45
  134. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  135. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  136. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  137. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  138. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  139. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  140. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  141. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  142. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  143. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  144. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  145. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  146. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  147. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  148. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  149. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  150. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  151. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  152. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  153. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  154. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  155. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  156. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  157. 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
 
@@ -17,44 +19,45 @@
17
19
  Public License along with this library; if not, write to the
18
20
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19
21
  Boston, MA 02111-1307 USA
20
- */
22
+ */
23
+
21
24
  package processing.core;
22
25
 
23
- public class PStyle implements PConstants {
24
26
 
25
- public int imageMode;
26
- public int rectMode;
27
- public int ellipseMode;
28
- public int shapeMode;
29
-
30
- public int blendMode;
31
-
32
- public int colorMode;
33
- public float colorModeX;
34
- public float colorModeY;
35
- public float colorModeZ;
36
- public float colorModeA;
37
-
38
- public boolean tint;
39
- public int tintColor;
40
- public boolean fill;
41
- public int fillColor;
42
- public boolean stroke;
43
- public int strokeColor;
44
- public float strokeWeight;
45
- public int strokeCap;
46
- public int strokeJoin;
47
-
48
- // TODO these fellas are inconsistent, and may need to go elsewhere
49
- public float ambientR, ambientG, ambientB;
50
- public float specularR, specularG, specularB;
51
- public float emissiveR, emissiveG, emissiveB;
52
- public float shininess;
53
-
54
- public PFont textFont;
55
- public int textAlign;
56
- public int textAlignY;
57
- public int textMode;
58
- public float textSize;
59
- public float textLeading;
27
+ public class PStyle implements PConstants {
28
+ public int imageMode;
29
+ public int rectMode;
30
+ public int ellipseMode;
31
+ public int shapeMode;
32
+
33
+ public int blendMode;
34
+
35
+ public int colorMode;
36
+ public float colorModeX;
37
+ public float colorModeY;
38
+ public float colorModeZ;
39
+ public float colorModeA;
40
+
41
+ public boolean tint;
42
+ public int tintColor;
43
+ public boolean fill;
44
+ public int fillColor;
45
+ public boolean stroke;
46
+ public int strokeColor;
47
+ public float strokeWeight;
48
+ public int strokeCap;
49
+ public int strokeJoin;
50
+
51
+ // TODO these fellas are inconsistent, and may need to go elsewhere
52
+ public float ambientR, ambientG, ambientB;
53
+ public float specularR, specularG, specularB;
54
+ public float emissiveR, emissiveG, emissiveB;
55
+ public float shininess;
56
+
57
+ public PFont textFont;
58
+ public int textAlign;
59
+ public int textAlignY;
60
+ public int textMode;
61
+ public float textSize;
62
+ public float textLeading;
60
63
  }
@@ -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,84 +18,113 @@
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.core;
21
24
 
25
+ import java.io.File;
26
+
22
27
  public interface PSurface {
28
+ /**
29
+ * Minimum dimensions for the window holding an applet. This varies between
30
+ * platforms, Mac OS X 10.3 (confirmed with 10.7 and Java 6) can do any
31
+ * height but requires at least 128 pixels width. Windows XP has another
32
+ * set of limitations. And for all I know, Linux probably allows window
33
+ * sizes to be negative numbers.
34
+ */
35
+ static public final int MIN_WINDOW_WIDTH = 128;
36
+ static public final int MIN_WINDOW_HEIGHT = 128;
37
+
38
+ //public int displayDensity();
39
+
40
+ //public int displayDensity(int display);
23
41
 
24
- /**
25
- * Minimum dimensions for the window holding an applet. This varies between
26
- * platforms, Mac OS X 10.3 (confirmed with 10.7 and Java 6) can do any
27
- * height but requires at least 128 pixels width. Windows XP has another set
28
- * of limitations. And for all I know, Linux probably allows window sizes to
29
- * be negative numbers.
30
- */
31
- static public final int MIN_WINDOW_WIDTH = 128;
32
- static public final int MIN_WINDOW_HEIGHT = 128;
33
-
34
- // renderer that doesn't draw to the screen
35
- public void initOffscreen(PApplet sketch);
36
-
37
- // considering removal in favor of separate Component classes for appropriate renderers
38
- // (i.e. for Java2D or a generic Image surface, but not PDF, debatable for GL or )
39
- //public Component initComponent(PApplet sketch);
40
- //public Frame initFrame(PApplet sketch, Color backgroundColor,
42
+ //
43
+
44
+ // renderer that doesn't draw to the screen
45
+ public void initOffscreen(PApplet sketch);
46
+
47
+ // considering removal in favor of separate Component classes for appropriate renderers
48
+ // (i.e. for Java2D or a generic Image surface, but not PDF, debatable for GL or FX)
49
+ //public Component initComponent(PApplet sketch);
50
+
51
+ //public Frame initFrame(PApplet sketch, Color backgroundColor,
41
52
  // public void initFrame(PApplet sketch, int backgroundColor,
42
53
  // int deviceIndex, boolean fullScreen, boolean spanDisplays);
43
- public void initFrame(PApplet sketch);
44
-
45
- /**
46
- * Get the native window object associated with this drawing surface. For
47
- * Java2D, this will be an AWT Frame object. For OpenGL, the window. The
48
- * data returned here is subject to the whims of the renderer, and using
49
- * this method means you're willing to deal with underlying implementation
50
- * changes and that you won't throw a fit like a toddler if your code breaks
51
- * sometime in the future.
52
- */
53
- public Object getNative();
54
-
55
- //
56
- // Just call these on an AWT Frame object stored in PApplet.
57
- // Silly, but prevents a lot of rewrite and extra methods for little benefit.
58
- // However, maybe prevents us from having to document the 'frame' variable?
59
- /**
60
- * Set the window (and dock, or whatever necessary) title.
61
- */
62
- public void setTitle(String title);
63
-
64
- /**
65
- * Show or hide the window.
66
- */
67
- public void setVisible(boolean visible);
68
-
69
- /**
70
- * Set true if we want to resize things (default is not resizable)
71
- */
72
- public void setResizable(boolean resizable);
73
-
74
- /**
75
- * Dumb name, but inherited from Frame and no better ideas.
76
- */
77
- public void setAlwaysOnTop(boolean always);
78
-
79
- public void setIcon(PImage icon);
80
-
81
- //
54
+ public void initFrame(PApplet sketch);
55
+
56
+ //
57
+
58
+ public PImage loadImage(String path, Object... args);
59
+
60
+ //
61
+
62
+ public void selectInput(String prompt, String callback,
63
+ File file, Object callbackObject);
64
+
65
+ public void selectOutput(String prompt, String callback,
66
+ File file, Object callbackObject);
67
+
68
+ public void selectFolder(String prompt, String callback,
69
+ File file, Object callbackObject);
70
+
71
+ //
72
+
73
+ /**
74
+ * Get the native window object associated with this drawing surface.For Java2D, this will be an AWT Frame object.
75
+ * For OpenGL, the window.
76
+ The data returned here is subject to the whims of the renderer,
77
+ and using this method means you're willing to deal with underlying
78
+ implementation changes and that you won't throw a fit like a toddler
79
+ if your code breaks sometime in the future.
80
+ * @return
81
+ */
82
+ public Object getNative();
83
+
84
+ //
85
+
86
+ // Just call these on an AWT Frame object stored in PApplet.
87
+ // Silly, but prevents a lot of rewrite and extra methods for little benefit.
88
+ // However, maybe prevents us from having to document the 'frame' variable?
89
+
90
+ /** Set the window (and dock, or whatever necessary) title.
91
+ * @param title */
92
+ public void setTitle(String title);
93
+
94
+ /** Show or hide the window.
95
+ * @param visible */
96
+ public void setVisible(boolean visible);
97
+
98
+ /** Set true if we want to resize things (default is not resizable)
99
+ * @param resizable */
100
+ public void setResizable(boolean resizable);
101
+
102
+ /** Dumb name, but inherited from Frame and no better ideas.
103
+ * @param always */
104
+ public void setAlwaysOnTop(boolean always);
105
+
106
+ public void setIcon(PImage icon);
107
+
108
+ //
109
+
82
110
  // public void placeWindow(int[] location);
83
- public void placeWindow(int[] location, int[] editorLocation);
84
111
 
85
- //public void placeFullScreen(boolean hideStop);
86
- public void placePresent(int stopColor);
112
+ public void placeWindow(int[] location, int[] editorLocation);
113
+
114
+ //public void placeFullScreen(boolean hideStop);
115
+ public void placePresent(int stopColor);
116
+
117
+ // Sketch is running from the PDE, set up messaging back to the PDE
118
+ public void setupExternalMessages();
119
+
120
+ //
87
121
 
88
- // Sketch is running from the PDE, set up messaging back to the PDE
89
- public void setupExternalMessages();
122
+ // sets displayWidth/Height inside PApplet
123
+ //public void checkDisplaySize();
90
124
 
91
- //
92
- // sets displayWidth/Height inside PApplet
93
- //public void checkDisplaySize();
94
- public void setLocation(int x, int y);
125
+ public void setLocation(int x, int y);
95
126
 
96
- public void setSize(int width, int height);
127
+ public void setSize(int width, int height);
97
128
 
98
129
  // /**
99
130
  // * Called by {@link PApplet#createGraphics} to initialize the
@@ -103,54 +134,65 @@ public interface PSurface {
103
134
  // * @param wide
104
135
  // * @param high
105
136
  // */
106
- // create pixel buffer (pulled out for offscreen graphics)
107
- //public void initImage(PGraphics gr, int wide, int high);
108
- // create pixel buffer, called from allocate() to produce a compatible image for rendering efficiently
137
+ // create pixel buffer (pulled out for offscreen graphics)
138
+ //public void initImage(PGraphics gr, int wide, int high);
139
+ // create pixel buffer, called from allocate() to produce a compatible image for rendering efficiently
109
140
  // public void initImage(PGraphics gr);
110
- //public Component getComponent();
141
+
142
+ //public Component getComponent();
143
+
111
144
  // /**
112
145
  // * Sometimes smoothing must be set at the drawing surface level
113
146
  // * not just inside the renderer itself.
114
147
  // */
115
148
  // public void setSmooth(int level);
116
- public void setFrameRate(float fps);
149
+
150
+ public void setFrameRate(float fps);
117
151
 
118
152
  // // called on the first frame so that the now-visible drawing surface can
119
153
  // // receive key and mouse events
120
154
  // public void requestFocus();
155
+
121
156
  // // finish rendering to the screen (called by PApplet)
122
157
  // public void blit();
123
- //
124
- public void setCursor(int kind);
125
158
 
126
- public void setCursor(PImage image, int hotspotX, int hotspotY);
159
+ //
160
+
161
+ public void setCursor(int kind);
162
+
163
+ public void setCursor(PImage image, int hotspotX, int hotspotY);
164
+
165
+ public void showCursor();
166
+
167
+ public void hideCursor();
168
+
169
+ //
127
170
 
128
- public void showCursor();
171
+ /**
172
+ * @param url the link to open
173
+ * @return false if unable to find a viable way to open
174
+ */
175
+ public boolean openLink(String url);
129
176
 
130
- public void hideCursor();
177
+ //
131
178
 
132
- //
133
- /**
134
- * Start the animation thread
135
- */
136
- public void startThread();
179
+ /** Start the animation thread */
180
+ public void startThread();
137
181
 
138
- /**
139
- * On the next trip through the animation thread, things should go
140
- * sleepy-bye. Does not pause the thread immediately because that needs to
141
- * happen on the animation thread itself, so fires on the next trip through
142
- * draw().
143
- */
144
- public void pauseThread();
182
+ /**
183
+ * On the next trip through the animation thread, things should go sleepy-bye.
184
+ * Does not pause the thread immediately because that needs to happen on the
185
+ * animation thread itself, so fires on the next trip through draw().
186
+ */
187
+ public void pauseThread();
145
188
 
146
- public void resumeThread();
189
+ public void resumeThread();
147
190
 
148
- /**
149
- * Stop the animation thread (set it null)
150
- *
151
- * @return false if already stopped
152
- */
153
- public boolean stopThread();
191
+ /**
192
+ * Stop the animation thread (set it null)
193
+ * @return false if already stopped
194
+ */
195
+ public boolean stopThread();
154
196
 
155
- public boolean isStopped();
197
+ public boolean isStopped();
156
198
  }
@@ -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,238 +18,320 @@
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.core;
21
24
 
25
+ import java.io.File;
26
+
27
+ import processing.awt.ShimAWT;
28
+
22
29
  /**
23
30
  * Surface that's not really visible. Used for PDF and friends, or as a base
24
31
  * class for other drawing surfaces. It includes the standard rendering loop.
25
32
  */
26
33
  public class PSurfaceNone implements PSurface {
34
+ protected PApplet sketch;
35
+ protected PGraphics graphics;
27
36
 
28
- protected PApplet sketch;
29
- protected PGraphics graphics;
37
+ protected Thread thread;
38
+ protected boolean paused;
39
+ protected Object pauseObject = new Object();
30
40
 
31
- protected Thread thread;
32
- protected boolean paused;
33
- protected Object pauseObject = new Object();
41
+ protected float frameRateTarget = 60;
42
+ protected long frameRatePeriod = 1000000000L / 60L;
34
43
 
35
- protected float frameRateTarget = 60;
36
- protected long frameRatePeriod = 1000000000L / 60L;
37
44
 
38
- public PSurfaceNone(PGraphics graphics) {
39
- this.graphics = graphics;
40
- }
45
+ public PSurfaceNone(PGraphics graphics) {
46
+ this.graphics = graphics;
47
+ }
41
48
 
42
- @Override
43
- public void initOffscreen(PApplet sketch) {
44
- this.sketch = sketch;
45
49
 
46
- setSize(sketch.sketchWidth(), sketch.sketchHeight());
47
- }
50
+ public int displayDensity() {
51
+ return 1;
52
+ }
53
+
54
+
55
+ public int displayDensity(int display) {
56
+ return 1;
57
+ }
58
+
59
+
60
+ @Override
61
+ public PImage loadImage(String path, Object... args) {
62
+ return ShimAWT.loadImage(sketch, path, args);
63
+ }
64
+
65
+
66
+ @Override
67
+ public void selectInput(String prompt, String callback, File file,
68
+ Object callbackObject) {
69
+ }
70
+
71
+
72
+ @Override
73
+ public void selectOutput(String prompt, String callback, File file,
74
+ Object callbackObject) {
75
+ }
76
+
77
+
78
+ @Override
79
+ public void selectFolder(String prompt, String callback, File file,
80
+ Object callbackObject) {
81
+ }
82
+
83
+
84
+ @Override
85
+ public void initOffscreen(PApplet sketch) {
86
+ this.sketch = sketch;
87
+
88
+ setSize(sketch.sketchWidth(), sketch.sketchHeight());
89
+ }
90
+
48
91
 
49
92
  // public Component initComponent(PApplet sketch) {
50
93
  // return null;
51
94
  // }
52
- @Override
53
- public void initFrame(PApplet sketch) {
54
- throw new IllegalStateException("initFrame() not available with "
55
- + getClass().getSimpleName());
56
- }
57
95
 
58
- public Object getNative() {
59
- return null;
60
- }
61
96
 
62
- /**
63
- * Set the window (and dock, or whatever necessary) title.
64
- */
65
- @Override
66
- public void setTitle(String title) {
67
- // You're in a utopian PSurface implementation where titles don't exist.
68
- }
97
+ @Override
98
+ public void initFrame(PApplet sketch) {
99
+ throw new IllegalStateException("initFrame() not available with " +
100
+ getClass().getSimpleName());
101
+ }
69
102
 
70
- @Override
71
- public void setIcon(PImage image) {
72
- // I ain't visible, man.
73
- }
74
103
 
75
- /**
76
- * Show or hide the window.
77
- */
78
- @Override
79
- public void setVisible(boolean visible) {
80
- // I'm always invisible. You can't catch me.
81
- }
104
+ @Override
105
+ public Object getNative() {
106
+ return null;
107
+ }
82
108
 
83
- /**
84
- * Set true if we want to resize things (default is not resizable)
85
- */
86
- @Override
87
- public void setResizable(boolean resizable) {
88
- // I don't need size to know my worth.
89
- }
90
109
 
91
- @Override
92
- public void placeWindow(int[] location, int[] editorLocation) {
93
- }
110
+ /** Set the window (and dock, or whatever necessary) title.
111
+ * @param title */
112
+ @Override
113
+ public void setTitle(String title) {
114
+ // You're in a utopian PSurface implementation where titles don't exist.
115
+ }
94
116
 
95
- @Override
96
- public void placePresent(int stopColor) {
97
- }
98
117
 
99
- @Override
100
- public void setupExternalMessages() {
101
- }
118
+ @Override
119
+ public void setIcon(PImage image) {
120
+ // I ain't visible, man.
121
+ }
102
122
 
103
- @Override
104
- public void setAlwaysOnTop(boolean always) {
105
- }
106
123
 
107
- //
108
- @Override
109
- public void setLocation(int x, int y) {
110
- // I'm everywhere, because I'm nowhere.
111
- }
124
+ /** Show or hide the window.
125
+ * @param visible */
126
+ @Override
127
+ public void setVisible(boolean visible) {
128
+ // I'm always invisible. You can't catch me.
129
+ }
112
130
 
113
- @Override
114
- public void setSize(int wide, int high) {
115
- if (PApplet.DEBUG) {
116
- //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
117
- new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
118
- }
119
131
 
120
- //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
121
- if (wide == sketch.width && high == sketch.height) {
122
- if (PApplet.DEBUG) {
123
- new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
124
- }
125
- return; // unchanged, don't rebuild everything
126
- }
132
+ /** Set true if we want to resize things (default is not resizable)
133
+ * @param resizable */
134
+ @Override
135
+ public void setResizable(boolean resizable) {
136
+ // I don't need size to know my worth.
137
+ }
138
+
139
+
140
+ @Override
141
+ public void placeWindow(int[] location, int[] editorLocation) { }
142
+
143
+
144
+ @Override
145
+ public void placePresent(int stopColor) { }
146
+
147
+
148
+ @Override
149
+ public void setupExternalMessages() { }
150
+
151
+
152
+ @Override
153
+ public void setAlwaysOnTop(boolean always) { }
154
+
155
+
156
+ //
157
+
158
+
159
+ @Override
160
+ public void setLocation(int x, int y) {
161
+ // I'm everywhere, because I'm nowhere.
162
+ }
127
163
 
128
- //throw new RuntimeException("implement me, see readme.md");
129
- sketch.width = wide;
130
- sketch.height = high;
131
164
 
132
- // set PGraphics variables for width/height/pixelWidth/pixelHeight
133
- graphics.setSize(wide, high);
165
+ @Override
166
+ public void setSize(int wide, int high) {
167
+ if (PApplet.DEBUG) {
168
+ //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
169
+ new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
134
170
  }
135
171
 
172
+ //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
173
+ if (wide == sketch.width && high == sketch.height) {
174
+ if (PApplet.DEBUG) {
175
+ new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
176
+ }
177
+ return; // unchanged, don't rebuild everything
178
+ }
179
+
180
+ //throw new RuntimeException("implement me, see readme.md");
181
+ sketch.width = wide;
182
+ sketch.height = high;
183
+
184
+ // set PGraphics variables for width/height/pixelWidth/pixelHeight
185
+ graphics.setSize(wide, high);
186
+ }
187
+
188
+
136
189
  // public void initImage(PGraphics graphics) {
137
190
  // // TODO Auto-generated method stub
138
191
  //
139
192
  // }
193
+
140
194
  // public Component getComponent() {
141
195
  // return null;
142
196
  // }
197
+
198
+
143
199
  // public void setSmooth(int level) {
144
200
  // // TODO Auto-generated method stub
145
201
  // }
202
+
146
203
  // void requestFocus() {
147
204
  // }
205
+
148
206
  // public void blit() {
149
207
  // // TODO Auto-generated method stub
150
208
  // }
151
- public void setCursor(int kind) {
152
- }
153
209
 
154
- public void setCursor(PImage image, int hotspotX, int hotspotY) {
155
- }
210
+ @Override
211
+ public void setCursor(int kind) { }
156
212
 
157
- public void showCursor() {
158
- }
213
+ @Override
214
+ public void setCursor(PImage image, int hotspotX, int hotspotY) { }
159
215
 
160
- public void hideCursor() {
161
- }
216
+ @Override
217
+ public void showCursor() { }
162
218
 
163
- //
164
- public Thread createThread() {
165
- return new AnimationThread();
166
- }
219
+ @Override
220
+ public void hideCursor() { }
167
221
 
168
- public void startThread() {
169
- if (thread == null) {
170
- thread = createThread();
171
- thread.start();
172
- } else {
173
- throw new IllegalStateException("Thread already started in "
174
- + getClass().getSimpleName());
175
- }
176
- }
177
222
 
178
- public boolean stopThread() {
179
- if (thread == null) {
180
- return false;
181
- }
182
- thread = null;
183
- return true;
184
- }
223
+ //
224
+
225
+
226
+ @Override
227
+ public boolean openLink(String url) {
228
+ return false;
229
+ }
230
+
231
+
232
+ //
185
233
 
186
- public boolean isStopped() {
187
- return thread == null || !thread.isAlive();
234
+
235
+ public Thread createThread() {
236
+ return new AnimationThread();
237
+ }
238
+
239
+
240
+ @Override
241
+ public void startThread() {
242
+ if (thread == null) {
243
+ thread = createThread();
244
+ thread.start();
245
+ } else {
246
+ throw new IllegalStateException("Thread already started in " +
247
+ getClass().getSimpleName());
188
248
  }
249
+ }
250
+
189
251
 
190
- // sets a flag to pause the thread when ready
191
- public void pauseThread() {
192
- PApplet.debug("PApplet.run() paused, calling object wait...");
193
- paused = true;
252
+ @Override
253
+ public boolean stopThread() {
254
+ if (thread == null) {
255
+ return false;
194
256
  }
257
+ thread = null;
258
+ return true;
259
+ }
260
+
261
+
262
+ @Override
263
+ public boolean isStopped() {
264
+ return thread == null || !thread.isAlive();
265
+ }
266
+
267
+
268
+ // sets a flag to pause the thread when ready
269
+ @Override
270
+ public void pauseThread() {
271
+ PApplet.debug("PApplet.run() paused, calling object wait...");
272
+ paused = true;
273
+ }
195
274
 
196
- // halts the animation thread if the pause flag is set
197
- protected void checkPause() {
198
- if (paused) {
199
- synchronized (pauseObject) {
200
- try {
201
- pauseObject.wait();
275
+
276
+ // halts the animation thread if the pause flag is set
277
+ protected void checkPause() {
278
+ if (paused) {
279
+ synchronized (pauseObject) {
280
+ try {
281
+ pauseObject.wait();
202
282
  // PApplet.debug("out of wait");
203
- } catch (InterruptedException e) {
204
- // waiting for this interrupt on a start() (resume) call
205
- }
206
- }
283
+ } catch (InterruptedException e) {
284
+ // waiting for this interrupt on a start() (resume) call
207
285
  }
208
- // PApplet.debug("done with pause");
286
+ }
209
287
  }
288
+ // PApplet.debug("done with pause");
289
+ }
210
290
 
211
- public void resumeThread() {
212
- paused = false;
213
- synchronized (pauseObject) {
214
- pauseObject.notifyAll(); // wake up the animation thread
215
- }
291
+
292
+ @Override
293
+ public void resumeThread() {
294
+ paused = false;
295
+ synchronized (pauseObject) {
296
+ pauseObject.notifyAll(); // wake up the animation thread
216
297
  }
298
+ }
217
299
 
218
- public void setFrameRate(float fps) {
219
- frameRateTarget = fps;
220
- frameRatePeriod = (long) (1000000000.0 / frameRateTarget);
221
- //g.setFrameRate(fps);
300
+
301
+ @Override
302
+ public void setFrameRate(float fps) {
303
+ frameRateTarget = fps;
304
+ frameRatePeriod = (long) (1000000000.0 / frameRateTarget);
305
+ //g.setFrameRate(fps);
306
+ }
307
+
308
+
309
+ public class AnimationThread extends Thread {
310
+
311
+ public AnimationThread() {
312
+ super("Animation Thread");
222
313
  }
223
314
 
224
- public class AnimationThread extends Thread {
315
+ // broken out so it can be overridden by Danger et al
316
+ public void callDraw() {
317
+ sketch.handleDraw();
318
+ }
225
319
 
226
- public AnimationThread() {
227
- super("Animation Thread");
228
- }
320
+ /**
321
+ * Main method for the primary animation thread.
322
+ * <A HREF="http://java.sun.com/products/jfc/tsc/articles/painting/">Painting in AWT and Swing</A>
323
+ */
324
+ @Override
325
+ public void run() { // not good to make this synchronized, locks things up
326
+ long beforeTime = System.nanoTime();
327
+ long overSleepTime = 0L;
229
328
 
230
- // broken out so it can be overridden by Danger et al
231
- public void callDraw() {
232
- sketch.handleDraw();
233
- }
329
+ int noDelays = 0;
330
+ // Number of frames with a delay of 0 ms before the
331
+ // animation thread yields to other running threads.
332
+ final int NO_DELAYS_PER_YIELD = 15;
234
333
 
235
- /**
236
- * Main method for the primary animation thread.
237
- * <A HREF="http://java.sun.com/products/jfc/tsc/articles/painting/">Painting
238
- * in AWT and Swing</A>
239
- */
240
- @Override
241
- public void run() { // not good to make this synchronized, locks things up
242
- long beforeTime = System.nanoTime();
243
- long overSleepTime = 0L;
244
-
245
- int noDelays = 0;
246
- // Number of frames with a delay of 0 ms before the
247
- // animation thread yields to other running threads.
248
- final int NO_DELAYS_PER_YIELD = 15;
249
-
250
- /*
334
+ /*
251
335
  // If size un-initialized, might be a Canvas. Call setSize() here since
252
336
  // we now have a parent object that this Canvas can use as a peer.
253
337
  if (graphics.image == null) {
@@ -265,26 +349,28 @@ public class PSurfaceNone implements PSurface {
265
349
  }
266
350
  // System.out.format(" but now, sketchW/H changed to %d %d%n", sketchWidth, sketchHeight);
267
351
  }
268
- */
269
- // un-pause the sketch and get rolling
270
- sketch.start();
352
+ */
271
353
 
272
- while ((Thread.currentThread() == thread) && !sketch.finished) {
273
- checkPause();
354
+ // un-pause the sketch and get rolling
355
+ sketch.start();
274
356
 
275
- // Don't resize the renderer from the EDT (i.e. from a ComponentEvent),
276
- // otherwise it may attempt a resize mid-render.
357
+ while ((Thread.currentThread() == thread) && !sketch.finished) {
358
+ checkPause();
359
+
360
+ // Don't resize the renderer from the EDT (i.e. from a ComponentEvent),
361
+ // otherwise it may attempt a resize mid-render.
277
362
  // Dimension currentSize = canvas.getSize();
278
363
  // if (currentSize.width != sketchWidth || currentSize.height != sketchHeight) {
279
364
  // System.err.format("need to resize from %s to %d, %d%n", currentSize, sketchWidth, sketchHeight);
280
365
  // }
281
- // render a single frame
366
+
367
+ // render a single frame
282
368
  // try {
283
369
  // EventQueue.invokeAndWait(new Runnable() {
284
370
  // public void run() {
285
371
  // System.out.println("calling draw, finished = " + sketch.finished);
286
- //System.out.println("calling draw, looping = " + sketch.looping + ", frameCount = " + sketch.frameCount);
287
- callDraw();
372
+ //System.out.println("calling draw, looping = " + sketch.looping + ", frameCount = " + sketch.frameCount);
373
+ callDraw();
288
374
 
289
375
  // EventQueue.invokeLater(new Runnable() {
290
376
  // public void run() {
@@ -293,6 +379,7 @@ public class PSurfaceNone implements PSurface {
293
379
  // }
294
380
  // }
295
381
  // });
382
+
296
383
  // }
297
384
  // });
298
385
  // } catch (InterruptedException ie) {
@@ -300,44 +387,45 @@ public class PSurfaceNone implements PSurface {
300
387
  // } catch (InvocationTargetException ite) {
301
388
  // ite.getTargetException().printStackTrace();
302
389
  // }
303
- // wait for update & paint to happen before drawing next frame
304
- // this is necessary since the drawing is sometimes in a
305
- // separate thread, meaning that the next frame will start
306
- // before the update/paint is completed
307
- long afterTime = System.nanoTime();
308
- long timeDiff = afterTime - beforeTime;
309
- //System.out.println("time diff is " + timeDiff);
310
- long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime;
311
-
312
- if (sleepTime > 0) { // some time left in this cycle
313
- try {
314
- Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L));
315
- noDelays = 0; // Got some sleep, not delaying anymore
316
- } catch (InterruptedException ex) {
317
- }
318
-
319
- overSleepTime = (System.nanoTime() - afterTime) - sleepTime;
320
-
321
- } else { // sleepTime <= 0; the frame took longer than the period
322
- overSleepTime = 0L;
323
- noDelays++;
324
-
325
- if (noDelays > NO_DELAYS_PER_YIELD) {
326
- Thread.yield(); // give another thread a chance to run
327
- noDelays = 0;
328
- }
329
- }
330
-
331
- beforeTime = System.nanoTime();
332
- }
333
390
 
334
- sketch.dispose(); // call to shutdown libs?
391
+ // wait for update & paint to happen before drawing next frame
392
+ // this is necessary since the drawing is sometimes in a
393
+ // separate thread, meaning that the next frame will start
394
+ // before the update/paint is completed
335
395
 
336
- // If the user called the exit() function, the window should close,
337
- // rather than the sketch just halting.
338
- if (sketch.exitCalled) {
339
- sketch.exitActual();
340
- }
396
+ long afterTime = System.nanoTime();
397
+ long timeDiff = afterTime - beforeTime;
398
+ //System.out.println("time diff is " + timeDiff);
399
+ long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime;
400
+
401
+ if (sleepTime > 0) { // some time left in this cycle
402
+ try {
403
+ Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L));
404
+ noDelays = 0; // Got some sleep, not delaying anymore
405
+ } catch (InterruptedException ex) { }
406
+
407
+ overSleepTime = (System.nanoTime() - afterTime) - sleepTime;
408
+
409
+ } else { // sleepTime <= 0; the frame took longer than the period
410
+ overSleepTime = 0L;
411
+ noDelays++;
412
+
413
+ if (noDelays > NO_DELAYS_PER_YIELD) {
414
+ Thread.yield(); // give another thread a chance to run
415
+ noDelays = 0;
416
+ }
341
417
  }
418
+
419
+ beforeTime = System.nanoTime();
420
+ }
421
+
422
+ sketch.dispose(); // call to shutdown libs?
423
+
424
+ // If the user called the exit() function, the window should close,
425
+ // rather than the sketch just halting.
426
+ if (sketch.exitCalled) {
427
+ sketch.exitActual();
428
+ }
342
429
  }
430
+ }
343
431
  }