propane 3.4.0-java → 3.7.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +2 -2
  6. data/CHANGELOG.md +12 -0
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +10 -11
  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 +10 -9
  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/pom.rb +37 -36
  38. data/pom.xml +7 -7
  39. data/propane.gemspec +16 -12
  40. data/src/main/java/monkstone/ColorUtil.java +13 -1
  41. data/src/main/java/monkstone/MathToolModule.java +253 -203
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  44. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  45. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  46. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  51. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  52. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  53. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  54. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  55. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -3
  56. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  57. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  58. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  59. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  60. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  61. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  62. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -209
  63. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  64. data/src/main/java/processing/core/PApplet.java +4510 -4503
  65. data/src/main/java/processing/core/PConstants.java +477 -447
  66. data/src/main/java/processing/core/PFont.java +914 -880
  67. data/src/main/java/processing/core/PGraphics.java +193 -177
  68. data/src/main/java/processing/core/PImage.java +611 -309
  69. data/src/main/java/processing/core/PMatrix.java +172 -159
  70. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  71. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  72. data/src/main/java/processing/core/PShape.java +2888 -2652
  73. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  74. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  75. data/src/main/java/processing/core/PStyle.java +40 -37
  76. data/src/main/java/processing/core/PSurface.java +139 -97
  77. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  78. data/src/main/java/processing/core/PVector.java +997 -965
  79. data/src/main/java/processing/core/ThinkDifferent.java +15 -13
  80. data/src/main/java/processing/data/DoubleDict.java +756 -710
  81. data/src/main/java/processing/data/DoubleList.java +749 -696
  82. data/src/main/java/processing/data/FloatDict.java +748 -702
  83. data/src/main/java/processing/data/FloatList.java +751 -697
  84. data/src/main/java/processing/data/IntDict.java +720 -673
  85. data/src/main/java/processing/data/IntList.java +699 -633
  86. data/src/main/java/processing/data/JSONArray.java +931 -873
  87. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  88. data/src/main/java/processing/data/JSONTokener.java +351 -341
  89. data/src/main/java/processing/data/LongDict.java +710 -663
  90. data/src/main/java/processing/data/LongList.java +701 -635
  91. data/src/main/java/processing/data/Sort.java +37 -41
  92. data/src/main/java/processing/data/StringDict.java +525 -486
  93. data/src/main/java/processing/data/StringList.java +626 -580
  94. data/src/main/java/processing/data/Table.java +3690 -3510
  95. data/src/main/java/processing/data/TableRow.java +182 -183
  96. data/src/main/java/processing/data/XML.java +957 -883
  97. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  98. data/src/main/java/processing/event/Event.java +87 -67
  99. data/src/main/java/processing/event/KeyEvent.java +48 -41
  100. data/src/main/java/processing/event/MouseEvent.java +88 -113
  101. data/src/main/java/processing/event/TouchEvent.java +10 -6
  102. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  103. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  104. data/src/main/java/processing/net/Client.java +744 -0
  105. data/src/main/java/processing/net/Server.java +388 -0
  106. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  107. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  108. data/src/main/java/processing/opengl/LinePath.java +547 -500
  109. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  110. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  111. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  112. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  113. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  114. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  115. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  116. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  117. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  118. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  119. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  120. data/test/create_test.rb +21 -20
  121. data/test/deglut_spec_test.rb +4 -2
  122. data/test/helper_methods_test.rb +49 -20
  123. data/test/math_tool_test.rb +39 -32
  124. data/test/native_folder.rb +47 -0
  125. data/test/respond_to_test.rb +3 -2
  126. data/test/sketches/key_event.rb +2 -2
  127. data/test/sketches/library/my_library/my_library.rb +3 -0
  128. data/test/test_helper.rb +2 -0
  129. data/test/vecmath_spec_test.rb +35 -22
  130. data/vendors/Rakefile +33 -62
  131. metadata +56 -48
  132. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  133. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  134. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  135. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  136. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  137. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  138. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  139. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  140. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  141. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  142. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  143. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  144. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  145. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  146. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  147. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  148. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  149. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  150. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  151. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  152. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  153. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  154. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  155. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The purpose of this class is to load the MathTool into ruby-processing runtime
3
- * Copyright (C) 2015-19 Martin Prout. This code is free software; you can
3
+ * Copyright (C) 2015-20 Martin Prout. This code is free software; you can
4
4
  * redistribute it and/or modify it under the terms of the GNU Lesser General
5
5
  * Public License as published by the Free Software Foundation; either version
6
6
  * 2.1 of the License, or (at your option) any later version.
@@ -41,6 +41,6 @@ public class PropaneLibrary implements Library {
41
41
  */
42
42
  @Override
43
43
  public void load(final Ruby runtime, boolean wrap) throws IOException {
44
- load(runtime);
44
+ PropaneLibrary.load(runtime);
45
45
  }
46
46
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -32,6 +32,7 @@ import java.io.File;
32
32
  *
33
33
  * @author Martin Prout
34
34
  */
35
+ @FunctionalInterface
35
36
  public interface Chooser {
36
37
 
37
38
  public void file_selected(File selection);
@@ -31,7 +31,7 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
31
31
  new Grad(1, 1, 1, 0), new Grad(1, 1, -1, 0), new Grad(1, -1, 1, 0), new Grad(1, -1, -1, 0),
32
32
  new Grad(-1, 1, 1, 0), new Grad(-1, 1, -1, 0), new Grad(-1, -1, 1, 0), new Grad(-1, -1, -1, 0)};
33
33
 
34
- private static short p[] = {151, 160, 137, 91, 90, 15,
34
+ private final static short p[] = {151, 160, 137, 91, 90, 15,
35
35
  131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
36
36
  190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
37
37
  88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
@@ -45,7 +45,7 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
45
45
  49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
46
46
  138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
47
47
  // To remove the need for index wrapping, double the permutation table length
48
- static short[] PERM = new short[512];
48
+ final static short[] PERM = new short[512];
49
49
  static short[] PERM_MOD_12 = new short[512];
50
50
 
51
51
  static {
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,18 +1,18 @@
1
- /*
2
- * Copyright (c) 2016-19 Martin Prout
3
- *
1
+ /*
2
+ * Copyright (c) 2015-20 Martin Prout
3
+ *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
6
6
  * License as published by the Free Software Foundation; either
7
7
  * version 2.1 of the License, or (at your option) any later version.
8
- *
8
+ *
9
9
  * http://creativecommons.org/licenses/LGPL/2.1/
10
- *
10
+ *
11
11
  * This library is distributed in the hope that it will be useful,
12
12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
14
  * Lesser General Public License for more details.
15
- *
15
+ *
16
16
  * You should have received a copy of the GNU Lesser General Public
17
17
  * License along with this library; if not, write to the Free Software
18
18
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -24,6 +24,7 @@ package monkstone.slider;
24
24
  * Peasycam when I was struggling with non functioning browser applet, probably
25
25
  * superfluous here.
26
26
  */
27
+ @FunctionalInterface
27
28
  public interface WheelHandler {
28
29
 
29
30
  /**
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,7 +1,7 @@
1
1
  package monkstone.vecmath.vec2;
2
2
 
3
3
  /*
4
- * Copyright (c) 2015-19 Martin Prout
4
+ * Copyright (c) 2015-20 Martin Prout
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
7
7
  * modify it under the terms of the GNU Lesser General Public
@@ -1,7 +1,7 @@
1
1
  package monkstone.vecmath.vec3;
2
2
 
3
3
  /*
4
- * Copyright (c) 2015-19 Martin Prout
4
+ * Copyright (c) 2015-20 Martin Prout
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
7
7
  * modify it under the terms of the GNU Lesser General Public
@@ -385,7 +385,7 @@ public final class Vec3 extends RubyObject {
385
385
  @JRubyMethod(name = "/", required = 1)
386
386
  public IRubyObject op_div(ThreadContext context, IRubyObject scalar) {
387
387
  Ruby runtime = context.runtime;
388
- var divisor = (scalar instanceof RubyFloat)
388
+ double divisor = (scalar instanceof RubyFloat)
389
389
  ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
390
390
  if (Math.abs(divisor) < Vec3.EPSILON) {
391
391
  return this;
@@ -432,7 +432,7 @@ public final class Vec3 extends RubyObject {
432
432
  return this;
433
433
  }
434
434
  }
435
- var new_mag = (scalar instanceof RubyFloat)
435
+ double new_mag = (scalar instanceof RubyFloat)
436
436
  ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
437
437
  double current = Math.sqrt(jx * jx + jy * jy + jz * jz);
438
438
  if (current > EPSILON) {
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) 2015-20 Martin Prout
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * http://creativecommons.org/licenses/LGPL/2.1/
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+ package monkstone.videoevent;
22
+ import processing.video.Capture;
23
+
24
+ @FunctionalInterface
25
+ public interface CaptureEvent{
26
+ public void captureEvent(Capture capture);
27
+ }
@@ -1,48 +1,32 @@
1
- /*
2
- * Copyright (c) 2015-19 Martin Prout
3
- *
1
+ /*
2
+ * Copyright (c) 2015-20 Martin Prout
3
+ *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
6
6
  * License as published by the Free Software Foundation; either
7
7
  * version 2.1 of the License, or (at your option) any later version.
8
- *
8
+ *
9
9
  * http://creativecommons.org/licenses/LGPL/2.1/
10
- *
10
+ *
11
11
  * This library is distributed in the hope that it will be useful,
12
12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
14
  * Lesser General Public License for more details.
15
- *
15
+ *
16
16
  * You should have received a copy of the GNU Lesser General Public
17
17
  * License along with this library; if not, write to the Free Software
18
18
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  */
20
- package monkstone.videoevent;
21
20
 
21
+ package monkstone.videoevent;
22
22
  import processing.video.Movie;
23
- import processing.video.Capture;
24
23
 
25
24
  /**
26
- * This interface makes it easier/possible to use the reflection methods from
27
- * Movie and Capture classes in Propane::App in propane
28
- *
25
+ * This interface makes it easier/possible to use the reflection methods
26
+ * from Movie and Capture classes in Processing::App in JRubyArt
29
27
  * @author Martin Prout
30
28
  */
31
- public interface VideoInterface {
32
-
33
- /**
34
- * Used to implement reflection method in PApplet
35
- *
36
- * @see processing.video.Movie
37
- * @param movie Movie
38
- */
29
+ @FunctionalInterface
30
+ public interface MovieEvent {
39
31
  public void movieEvent(Movie movie);
40
-
41
- /**
42
- * Used to implement reflection method in PApplet
43
- *
44
- * @see processing.video.Capture
45
- * @param capture Capture
46
- */
47
- public void captureEvent(Capture capture);
48
32
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -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
 
@@ -18,7 +20,8 @@
18
20
  Public License along with this library; if not, write to the
19
21
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
22
  Boston, MA 02111-1307 USA
21
- */
23
+ */
24
+
22
25
  package processing.awt;
23
26
 
24
27
  import java.awt.*;
@@ -31,20 +34,20 @@ import java.util.Map;
31
34
 
32
35
  import processing.core.*;
33
36
 
37
+
34
38
  /**
35
39
  * Subclass for PGraphics that implements the graphics API using Java2D.
36
40
  * <p>
37
- * To get access to the Java 2D "Graphics2D" object for the default renderer,
38
- * use:
41
+ * To get access to the Java 2D "Graphics2D" object for the default
42
+ * renderer, use:
39
43
  * <PRE>
40
44
  * Graphics2D g2 = (Graphics2D) g.getNative();
41
- * </PRE> This will let you do Graphics2D calls directly, but is not supported
42
- * in any way shape or form. Which just means "have fun, but don't complain if
43
- * it breaks."
45
+ * </PRE>
46
+ * This will let you do Graphics2D calls directly, but is not supported
47
+ * in any way shape or form. Which just means "have fun, but don't complain
48
+ * if it breaks."
44
49
  * <p>
45
- * Advanced
46
- * <a href="http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/java2d.html">debugging
47
- * notes</a> for Java2D.
50
+ * Advanced <a href="http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/java2d.html">debugging notes</a> for Java2D.
48
51
  */
49
52
  public class PGraphicsJava2D extends PGraphics {
50
53
  //// BufferStrategy strategy;
@@ -79,8 +82,8 @@ public class PGraphicsJava2D extends PGraphics {
79
82
  float[] curveDrawY;
80
83
 
81
84
  int transformCount;
82
- AffineTransform transformStack[]
83
- = new AffineTransform[MATRIX_STACK_DEPTH];
85
+ AffineTransform[] transformStack =
86
+ new AffineTransform[MATRIX_STACK_DEPTH];
84
87
  double[] transform = new double[6];
85
88
 
86
89
  Line2D.Float line = new Line2D.Float();
@@ -101,14 +104,25 @@ public class PGraphicsJava2D extends PGraphics {
101
104
 
102
105
  Font fontObject;
103
106
 
107
+
108
+
104
109
  //////////////////////////////////////////////////////////////
110
+
105
111
  // INTERNAL
106
- public PGraphicsJava2D() {
107
- }
112
+
113
+
114
+ public PGraphicsJava2D() { }
115
+
108
116
 
109
117
  //public void setParent(PApplet parent)
118
+
119
+
110
120
  //public void setPrimary(boolean primary)
121
+
122
+
111
123
  //public void setPath(String path)
124
+
125
+
112
126
  // /**
113
127
  // * Called in response to a resize event, handles setting the
114
128
  // * new width and height internally, as well as re-allocating
@@ -124,11 +138,15 @@ public class PGraphicsJava2D extends PGraphics {
124
138
  // allocate();
125
139
  // reapplySettings();
126
140
  // }
141
+
142
+
127
143
  // @Override
128
144
  // protected void allocate() {
129
145
  // //surface.initImage(this, width, height);
130
146
  // surface.initImage(this);
131
147
  // }
148
+
149
+
132
150
  /*
133
151
  @Override
134
152
  protected void allocate() {
@@ -201,9 +219,9 @@ public class PGraphicsJava2D extends PGraphics {
201
219
  image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
202
220
  g2 = (Graphics2D) image.getGraphics();
203
221
  }
204
- */
222
+ */
205
223
 
206
- /*
224
+ /*
207
225
  if (primarySurface) {
208
226
  Canvas canvas = ((PSurfaceAWT) surface).canvas;
209
227
 
@@ -223,40 +241,47 @@ public class PGraphicsJava2D extends PGraphics {
223
241
  }
224
242
  g2 = (Graphics2D) image.getGraphics();
225
243
  }
226
- */
244
+ */
245
+
246
+
227
247
  //public void dispose()
248
+
249
+
228
250
  @Override
229
251
  public PSurface createSurface() {
230
252
  return surface = new PSurfaceAWT(this);
231
253
  }
232
254
 
233
- /**
234
- * Still need a means to get the java.awt.Image object, since getNative() is
235
- * going to return the {@link Graphics2D} object.
236
- *
237
- * @return
238
- */
239
- @Override
240
- public Image getImage() {
241
- return image;
242
- }
243
255
 
244
- /**
245
- * Returns the java.awt.Graphics2D object used by this renderer.
246
- *
247
- * @return
248
- */
256
+ // /**
257
+ // * Still need a means to get the java.awt.Image object, since getNative()
258
+ // * is going to return the {@link Graphics2D} object.
259
+ // */
260
+ // @Override
261
+ // public Image getImage() {
262
+ // return image;
263
+ // }
264
+
265
+
266
+ /** Returns the java.awt.Graphics2D object used by this renderer.
267
+ * @return */
249
268
  @Override
250
269
  public Object getNative() {
251
270
  return g2;
252
271
  }
253
272
 
273
+
254
274
  //////////////////////////////////////////////////////////////
275
+
255
276
  // FRAME
277
+
278
+
256
279
  // @Override
257
280
  // public boolean canDraw() {
258
281
  // return true;
259
282
  // }
283
+
284
+
260
285
  // @Override
261
286
  // public void requestDraw() {
262
287
  //// EventQueue.invokeLater(new Runnable() {
@@ -265,11 +290,14 @@ public class PGraphicsJava2D extends PGraphics {
265
290
  //// }
266
291
  //// });
267
292
  // }
293
+
294
+
268
295
  // Graphics2D g2old;
296
+
269
297
  public Graphics2D checkImage() {
270
- if (image == null
271
- || ((BufferedImage) image).getWidth() != width * pixelDensity
272
- || ((BufferedImage) image).getHeight() != height * pixelDensity) {
298
+ if (image == null ||
299
+ ((BufferedImage) image).getWidth() != width*pixelDensity ||
300
+ ((BufferedImage) image).getHeight() != height*pixelDensity) {
273
301
  // ((VolatileImage) image).getWidth() != width ||
274
302
  // ((VolatileImage) image).getHeight() != height) {
275
303
  // image = new BufferedImage(width * pixelFactor, height * pixelFactor
@@ -294,6 +322,7 @@ public class PGraphicsJava2D extends PGraphics {
294
322
  // GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
295
323
  // gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
296
324
  // }
325
+
297
326
  // Formerly this was broken into separate versions based on offscreen or
298
327
  // not, but we may as well create a compatible image; it won't hurt, right?
299
328
  // P.S.: Three years later, I'm happy to report it did in fact hurt [jv 2018-06-01]
@@ -313,6 +342,7 @@ public class PGraphicsJava2D extends PGraphics {
313
342
  return (Graphics2D) image.getGraphics();
314
343
  }
315
344
 
345
+
316
346
  @Override
317
347
  public void beginDraw() {
318
348
  g2 = checkImage();
@@ -384,12 +414,14 @@ public class PGraphicsJava2D extends PGraphics {
384
414
  reapplySettings = true;
385
415
  }
386
416
  }
387
- */
417
+ */
418
+
388
419
  checkSettings();
389
420
  resetMatrix(); // reset model matrix
390
421
  vertexCount = 0;
391
422
  }
392
423
 
424
+
393
425
  /**
394
426
  * Smoothing for Java2D is 2 for bilinear, and 3 for bicubic (the default).
395
427
  * Internally, smooth(1) is the default, smooth(0) is noSmooth().
@@ -397,33 +429,33 @@ public class PGraphicsJava2D extends PGraphics {
397
429
  protected void handleSmooth() {
398
430
  if (smooth == 0) {
399
431
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
400
- RenderingHints.VALUE_ANTIALIAS_OFF);
432
+ RenderingHints.VALUE_ANTIALIAS_OFF);
401
433
  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
402
- RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
434
+ RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
403
435
  g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
404
- RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
436
+ RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
405
437
 
406
438
  } else {
407
439
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
408
- RenderingHints.VALUE_ANTIALIAS_ON);
440
+ RenderingHints.VALUE_ANTIALIAS_ON);
409
441
 
410
442
  if (smooth == 1 || smooth == 3) { // default is bicubic
411
443
  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
412
- RenderingHints.VALUE_INTERPOLATION_BICUBIC);
444
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC);
413
445
  } else if (smooth == 2) {
414
446
  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
415
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
447
+ RenderingHints.VALUE_INTERPOLATION_BILINEAR);
416
448
  }
417
449
 
418
450
  // http://docs.oracle.com/javase/tutorial/2d/text/renderinghints.html
419
451
  // Oracle Java text anti-aliasing on OS X looks like s*t compared to the
420
452
  // text rendering with Apple's old Java 6. Below, several attempts to fix:
421
453
  g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
422
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
454
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
423
455
  // Turns out this is the one that actually makes things work.
424
456
  // Kerning is still screwed up, however.
425
457
  g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
426
- RenderingHints.VALUE_FRACTIONALMETRICS_ON);
458
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
427
459
  // g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
428
460
  // RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
429
461
  // g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
@@ -434,6 +466,7 @@ public class PGraphicsJava2D extends PGraphics {
434
466
  }
435
467
  }
436
468
 
469
+
437
470
  @Override
438
471
  public void endDraw() {
439
472
  // hm, mark pixels as changed, because this will instantly do a full
@@ -469,7 +502,7 @@ public class PGraphicsJava2D extends PGraphics {
469
502
  // g2.dispose();
470
503
  // System.out.println("not doing anything special in endDraw()");
471
504
  }
472
- */
505
+ */
473
506
  } else {
474
507
  // TODO this is probably overkill for most tasks...
475
508
  loadPixels();
@@ -481,6 +514,7 @@ public class PGraphicsJava2D extends PGraphics {
481
514
  // // full copy of the pixels to the surface in this.updatePixels().
482
515
  // setModified();
483
516
  // super.updatePixels();
517
+
484
518
  // Marks pixels as modified so that the pixels will be updated.
485
519
  // Also sets mx1/y1/x2/y2 so that OpenGL will pick it up.
486
520
  setModified();
@@ -532,10 +566,18 @@ public class PGraphicsJava2D extends PGraphics {
532
566
  } while (strategy.contentsLost());
533
567
  PApplet.debug("PGraphicsJava2D.redraw() out of do { } block");
534
568
  }
535
- */
569
+ */
570
+
571
+
572
+
536
573
  //////////////////////////////////////////////////////////////
574
+
537
575
  // SETTINGS
576
+
577
+
538
578
  //protected void checkSettings()
579
+
580
+
539
581
  @Override
540
582
  protected void defaultSettings() {
541
583
  // if (!useCanvas) {
@@ -552,9 +594,16 @@ public class PGraphicsJava2D extends PGraphics {
552
594
  super.defaultSettings();
553
595
  }
554
596
 
597
+
555
598
  //protected void reapplySettings()
599
+
600
+
601
+
556
602
  //////////////////////////////////////////////////////////////
603
+
557
604
  // HINT
605
+
606
+
558
607
  @Override
559
608
  public void hint(int which) {
560
609
  // take care of setting the hint
@@ -566,29 +615,38 @@ public class PGraphicsJava2D extends PGraphics {
566
615
  // stroke in many standard Processing examples really gross.
567
616
  if (which == ENABLE_STROKE_PURE) {
568
617
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
569
- RenderingHints.VALUE_STROKE_PURE);
618
+ RenderingHints.VALUE_STROKE_PURE);
570
619
  } else if (which == DISABLE_STROKE_PURE) {
571
620
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
572
- RenderingHints.VALUE_STROKE_DEFAULT);
621
+ RenderingHints.VALUE_STROKE_DEFAULT);
573
622
  }
574
623
  }
575
624
 
625
+
626
+
576
627
  //////////////////////////////////////////////////////////////
628
+
577
629
  // SHAPE CREATION
630
+
631
+
578
632
  @Override
579
633
  protected PShape createShapeFamily(int type) {
580
634
  return new PShape(this, type);
581
635
  }
582
636
 
637
+
583
638
  @Override
584
639
  protected PShape createShapePrimitive(int kind, float... p) {
585
640
  return new PShape(this, kind, p);
586
641
  }
587
642
 
643
+
588
644
  // @Override
589
645
  // public PShape createShape(PShape source) {
590
646
  // return PShapeOpenGL.createShape2D(this, source);
591
647
  // }
648
+
649
+
592
650
  /*
593
651
  protected PShape createShapeImpl(PGraphicsJava2D pg, int type) {
594
652
  PShape shape = null;
@@ -604,7 +662,9 @@ public class PGraphicsJava2D extends PGraphics {
604
662
  return shape;
605
663
  }
606
664
  */
607
- /*
665
+
666
+
667
+ /*
608
668
  static protected PShape createShapeImpl(PGraphicsJava2D pg,
609
669
  int kind, float... p) {
610
670
  PShape shape = null;
@@ -676,9 +736,15 @@ public class PGraphicsJava2D extends PGraphics {
676
736
 
677
737
  return shape;
678
738
  }
679
- */
739
+ */
740
+
741
+
742
+
680
743
  //////////////////////////////////////////////////////////////
744
+
681
745
  // SHAPES
746
+
747
+
682
748
  @Override
683
749
  public void beginShape(int kind) {
684
750
  //super.beginShape(kind);
@@ -695,21 +761,29 @@ public class PGraphicsJava2D extends PGraphics {
695
761
  auxPath = null;
696
762
  }
697
763
 
764
+
698
765
  //public boolean edge(boolean e)
766
+
767
+
699
768
  //public void normal(float nx, float ny, float nz) {
769
+
770
+
700
771
  //public void textureMode(int mode)
772
+
773
+
701
774
  @Override
702
775
  public void texture(PImage image) {
703
776
  showMethodWarning("texture");
704
777
  }
705
778
 
779
+
706
780
  @Override
707
781
  public void vertex(float x, float y) {
708
782
  curveVertexCount = 0;
709
783
  //float vertex[];
710
784
 
711
785
  if (vertexCount == vertices.length) {
712
- float temp[][] = new float[vertexCount << 1][VERTEX_FIELD_COUNT];
786
+ float[][] temp = new float[vertexCount<<1][VERTEX_FIELD_COUNT];
713
787
  System.arraycopy(vertices, 0, temp, 0, vertexCount);
714
788
  vertices = temp;
715
789
  //message(CHATTER, "allocating more vertices " + vertices.length);
@@ -722,98 +796,99 @@ public class PGraphicsJava2D extends PGraphics {
722
796
 
723
797
  switch (shape) {
724
798
 
725
- case POINTS:
726
- point(x, y);
727
- break;
728
-
729
- case LINES:
730
- if ((vertexCount % 2) == 0) {
731
- line(vertices[vertexCount - 2][X],
732
- vertices[vertexCount - 2][Y], x, y);
733
- }
734
- break;
735
-
736
- case TRIANGLES:
737
- if ((vertexCount % 3) == 0) {
738
- triangle(vertices[vertexCount - 3][X],
739
- vertices[vertexCount - 3][Y],
740
- vertices[vertexCount - 2][X],
741
- vertices[vertexCount - 2][Y],
742
- x, y);
743
- }
744
- break;
745
-
746
- case TRIANGLE_STRIP:
747
- if (vertexCount >= 3) {
748
- triangle(vertices[vertexCount - 2][X],
749
- vertices[vertexCount - 2][Y],
750
- vertices[vertexCount - 1][X],
751
- vertices[vertexCount - 1][Y],
752
- vertices[vertexCount - 3][X],
753
- vertices[vertexCount - 3][Y]);
754
- }
755
- break;
756
-
757
- case TRIANGLE_FAN:
758
- if (vertexCount >= 3) {
759
- // This is an unfortunate implementation because the stroke for an
760
- // adjacent triangle will be repeated. However, if the stroke is not
761
- // redrawn, it will replace the adjacent line (when it lines up
762
- // perfectly) or show a faint line (when off by a small amount).
763
- // The alternative would be to wait, then draw the shape as a
764
- // polygon fill, followed by a series of vertices. But that's a
765
- // poor method when used with PDF, DXF, or other recording objects,
766
- // since discrete triangles would likely be preferred.
767
- triangle(vertices[0][X],
768
- vertices[0][Y],
769
- vertices[vertexCount - 2][X],
770
- vertices[vertexCount - 2][Y],
771
- x, y);
772
- }
773
- break;
774
-
775
- case QUAD:
776
- case QUADS:
777
- if ((vertexCount % 4) == 0) {
778
- quad(vertices[vertexCount - 4][X],
779
- vertices[vertexCount - 4][Y],
780
- vertices[vertexCount - 3][X],
781
- vertices[vertexCount - 3][Y],
782
- vertices[vertexCount - 2][X],
783
- vertices[vertexCount - 2][Y],
784
- x, y);
785
- }
786
- break;
787
-
788
- case QUAD_STRIP:
789
- // 0---2---4
790
- // | | |
791
- // 1---3---5
792
- if ((vertexCount >= 4) && ((vertexCount % 2) == 0)) {
793
- quad(vertices[vertexCount - 4][X],
794
- vertices[vertexCount - 4][Y],
795
- vertices[vertexCount - 2][X],
796
- vertices[vertexCount - 2][Y],
797
- x, y,
798
- vertices[vertexCount - 3][X],
799
- vertices[vertexCount - 3][Y]);
800
- }
801
- break;
799
+ case POINTS:
800
+ point(x, y);
801
+ break;
802
802
 
803
- case POLYGON:
804
- if (gpath == null) {
805
- gpath = new GeneralPath();
806
- gpath.moveTo(x, y);
807
- } else if (breakShape) {
808
- gpath.moveTo(x, y);
809
- breakShape = false;
810
- } else {
811
- gpath.lineTo(x, y);
812
- }
813
- break;
803
+ case LINES:
804
+ if ((vertexCount % 2) == 0) {
805
+ line(vertices[vertexCount-2][X],
806
+ vertices[vertexCount-2][Y], x, y);
807
+ }
808
+ break;
809
+
810
+ case TRIANGLES:
811
+ if ((vertexCount % 3) == 0) {
812
+ triangle(vertices[vertexCount - 3][X],
813
+ vertices[vertexCount - 3][Y],
814
+ vertices[vertexCount - 2][X],
815
+ vertices[vertexCount - 2][Y],
816
+ x, y);
817
+ }
818
+ break;
819
+
820
+ case TRIANGLE_STRIP:
821
+ if (vertexCount >= 3) {
822
+ triangle(vertices[vertexCount - 2][X],
823
+ vertices[vertexCount - 2][Y],
824
+ vertices[vertexCount - 1][X],
825
+ vertices[vertexCount - 1][Y],
826
+ vertices[vertexCount - 3][X],
827
+ vertices[vertexCount - 3][Y]);
828
+ }
829
+ break;
830
+
831
+ case TRIANGLE_FAN:
832
+ if (vertexCount >= 3) {
833
+ // This is an unfortunate implementation because the stroke for an
834
+ // adjacent triangle will be repeated. However, if the stroke is not
835
+ // redrawn, it will replace the adjacent line (when it lines up
836
+ // perfectly) or show a faint line (when off by a small amount).
837
+ // The alternative would be to wait, then draw the shape as a
838
+ // polygon fill, followed by a series of vertices. But that's a
839
+ // poor method when used with PDF, DXF, or other recording objects,
840
+ // since discrete triangles would likely be preferred.
841
+ triangle(vertices[0][X],
842
+ vertices[0][Y],
843
+ vertices[vertexCount - 2][X],
844
+ vertices[vertexCount - 2][Y],
845
+ x, y);
846
+ }
847
+ break;
848
+
849
+ case QUAD:
850
+ case QUADS:
851
+ if ((vertexCount % 4) == 0) {
852
+ quad(vertices[vertexCount - 4][X],
853
+ vertices[vertexCount - 4][Y],
854
+ vertices[vertexCount - 3][X],
855
+ vertices[vertexCount - 3][Y],
856
+ vertices[vertexCount - 2][X],
857
+ vertices[vertexCount - 2][Y],
858
+ x, y);
859
+ }
860
+ break;
861
+
862
+ case QUAD_STRIP:
863
+ // 0---2---4
864
+ // | | |
865
+ // 1---3---5
866
+ if ((vertexCount >= 4) && ((vertexCount % 2) == 0)) {
867
+ quad(vertices[vertexCount - 4][X],
868
+ vertices[vertexCount - 4][Y],
869
+ vertices[vertexCount - 2][X],
870
+ vertices[vertexCount - 2][Y],
871
+ x, y,
872
+ vertices[vertexCount - 3][X],
873
+ vertices[vertexCount - 3][Y]);
874
+ }
875
+ break;
876
+
877
+ case POLYGON:
878
+ if (gpath == null) {
879
+ gpath = new GeneralPath();
880
+ gpath.moveTo(x, y);
881
+ } else if (breakShape) {
882
+ gpath.moveTo(x, y);
883
+ breakShape = false;
884
+ } else {
885
+ gpath.lineTo(x, y);
886
+ }
887
+ break;
814
888
  }
815
889
  }
816
890
 
891
+
817
892
  @Override
818
893
  public void vertex(float x, float y, float z) {
819
894
  showDepthWarningXYZ("vertex");
@@ -824,16 +899,19 @@ public class PGraphicsJava2D extends PGraphics {
824
899
  vertex(v[X], v[Y]);
825
900
  }
826
901
 
902
+
827
903
  @Override
828
904
  public void vertex(float x, float y, float u, float v) {
829
905
  showVariationWarning("vertex(x, y, u, v)");
830
906
  }
831
907
 
908
+
832
909
  @Override
833
910
  public void vertex(float x, float y, float z, float u, float v) {
834
911
  showDepthWarningXYZ("vertex");
835
912
  }
836
913
 
914
+
837
915
  @Override
838
916
  public void beginContour() {
839
917
  if (openContour) {
@@ -853,6 +931,7 @@ public class PGraphicsJava2D extends PGraphics {
853
931
  openContour = true;
854
932
  }
855
933
 
934
+
856
935
  @Override
857
936
  public void endContour() {
858
937
  if (!openContour) {
@@ -861,9 +940,7 @@ public class PGraphicsJava2D extends PGraphics {
861
940
  }
862
941
 
863
942
  // close this contour
864
- if (gpath != null) {
865
- gpath.closePath();
866
- }
943
+ if (gpath != null) gpath.closePath();
867
944
 
868
945
  // switch back to main path
869
946
  GeneralPath contourPath = gpath;
@@ -873,6 +950,7 @@ public class PGraphicsJava2D extends PGraphics {
873
950
  openContour = false;
874
951
  }
875
952
 
953
+
876
954
  @Override
877
955
  public void endShape(int mode) {
878
956
  if (openContour) { // correct automagically, notify user
@@ -894,24 +972,31 @@ public class PGraphicsJava2D extends PGraphics {
894
972
  }
895
973
 
896
974
  //////////////////////////////////////////////////////////////
975
+
897
976
  // CLIPPING
977
+
978
+
898
979
  @Override
899
980
  protected void clipImpl(float x1, float y1, float x2, float y2) {
900
981
  g2.setClip(new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1));
901
982
  }
902
983
 
984
+
903
985
  @Override
904
986
  public void noClip() {
905
987
  g2.setClip(null);
906
988
  }
907
989
 
990
+
991
+
908
992
  //////////////////////////////////////////////////////////////
993
+
909
994
  // BLEND
995
+
910
996
  /**
911
997
  * ( begin auto-generated from blendMode.xml )
912
998
  *
913
- * This is a new reference entry for Processing 2.0.It will be updated
914
- * shortly. ( end auto-generated )
999
+ * This is a new reference entry for Processing 2.0.It will be updated shortly. ( end auto-generated )
915
1000
  *
916
1001
  * @webref Rendering
917
1002
  */
@@ -925,11 +1010,11 @@ public class PGraphicsJava2D extends PGraphics {
925
1010
  }
926
1011
  }
927
1012
 
1013
+
928
1014
  // Blending implementation cribbed from portions of Romain Guy's
929
1015
  // demo and terrific writeup on blending modes in Java 2D.
930
1016
  // http://www.curious-creature.org/2006/09/20/new-blendings-modes-for-java2d/
931
1017
  private static final class BlendingContext implements CompositeContext {
932
-
933
1018
  private final int mode;
934
1019
 
935
1020
  private BlendingContext(int mode) {
@@ -937,15 +1022,14 @@ public class PGraphicsJava2D extends PGraphics {
937
1022
  }
938
1023
 
939
1024
  @Override
940
- public void dispose() {
941
- }
1025
+ public void dispose() { }
942
1026
 
943
1027
  @Override
944
1028
  public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
945
1029
  // not sure if this is really necessary, since we control our buffers
946
- if (src.getSampleModel().getDataType() != DataBuffer.TYPE_INT
947
- || dstIn.getSampleModel().getDataType() != DataBuffer.TYPE_INT
948
- || dstOut.getSampleModel().getDataType() != DataBuffer.TYPE_INT) {
1030
+ if (src.getSampleModel().getDataType() != DataBuffer.TYPE_INT ||
1031
+ dstIn.getSampleModel().getDataType() != DataBuffer.TYPE_INT ||
1032
+ dstOut.getSampleModel().getDataType() != DataBuffer.TYPE_INT) {
949
1033
  throw new IllegalStateException("Source and destination must store pixels as INT.");
950
1034
  }
951
1035
 
@@ -966,47 +1050,64 @@ public class PGraphicsJava2D extends PGraphics {
966
1050
  }
967
1051
  }
968
1052
 
1053
+
1054
+
969
1055
  //////////////////////////////////////////////////////////////
1056
+
970
1057
  // BEZIER VERTICES
1058
+
1059
+
971
1060
  @Override
972
1061
  public void bezierVertex(float x1, float y1,
973
- float x2, float y2,
974
- float x3, float y3) {
1062
+ float x2, float y2,
1063
+ float x3, float y3) {
975
1064
  bezierVertexCheck();
976
1065
  gpath.curveTo(x1, y1, x2, y2, x3, y3);
977
1066
  }
978
1067
 
1068
+
979
1069
  @Override
980
1070
  public void bezierVertex(float x2, float y2, float z2,
981
- float x3, float y3, float z3,
982
- float x4, float y4, float z4) {
1071
+ float x3, float y3, float z3,
1072
+ float x4, float y4, float z4) {
983
1073
  showDepthWarningXYZ("bezierVertex");
984
1074
  }
985
1075
 
1076
+
1077
+
986
1078
  //////////////////////////////////////////////////////////////
1079
+
987
1080
  // QUADRATIC BEZIER VERTICES
1081
+
1082
+
988
1083
  @Override
989
1084
  public void quadraticVertex(float ctrlX, float ctrlY,
990
- float endX, float endY) {
1085
+ float endX, float endY) {
991
1086
  bezierVertexCheck();
992
1087
  Point2D cur = gpath.getCurrentPoint();
993
1088
 
994
1089
  float x1 = (float) cur.getX();
995
1090
  float y1 = (float) cur.getY();
996
1091
 
997
- bezierVertex(x1 + ((ctrlX - x1) * 2 / 3.0f), y1 + ((ctrlY - y1) * 2 / 3.0f),
998
- endX + ((ctrlX - endX) * 2 / 3.0f), endY + ((ctrlY - endY) * 2 / 3.0f),
999
- endX, endY);
1092
+ bezierVertex(x1 + ((ctrlX-x1)*2/3.0f), y1 + ((ctrlY-y1)*2/3.0f),
1093
+ endX + ((ctrlX-endX)*2/3.0f), endY + ((ctrlY-endY)*2/3.0f),
1094
+ endX, endY);
1000
1095
  }
1001
1096
 
1097
+
1002
1098
  @Override
1003
1099
  public void quadraticVertex(float x2, float y2, float z2,
1004
- float x4, float y4, float z4) {
1100
+ float x4, float y4, float z4) {
1005
1101
  showDepthWarningXYZ("quadVertex");
1006
1102
  }
1007
1103
 
1104
+
1105
+
1008
1106
  //////////////////////////////////////////////////////////////
1107
+
1009
1108
  // CURVE VERTICES
1109
+
1110
+
1010
1111
  @Override
1011
1112
  protected void curveVertexCheck() {
1012
1113
  super.curveVertexCheck();
@@ -1019,11 +1120,12 @@ public class PGraphicsJava2D extends PGraphics {
1019
1120
  }
1020
1121
  }
1021
1122
 
1123
+
1022
1124
  @Override
1023
1125
  protected void curveVertexSegment(float x1, float y1,
1024
- float x2, float y2,
1025
- float x3, float y3,
1026
- float x4, float y4) {
1126
+ float x2, float y2,
1127
+ float x3, float y3,
1128
+ float x4, float y4) {
1027
1129
  curveCoordX[0] = x1;
1028
1130
  curveCoordY[0] = y1;
1029
1131
 
@@ -1047,20 +1149,32 @@ public class PGraphicsJava2D extends PGraphics {
1047
1149
  }
1048
1150
 
1049
1151
  gpath.curveTo(curveDrawX[1], curveDrawY[1],
1050
- curveDrawX[2], curveDrawY[2],
1051
- curveDrawX[3], curveDrawY[3]);
1152
+ curveDrawX[2], curveDrawY[2],
1153
+ curveDrawX[3], curveDrawY[3]);
1052
1154
  }
1053
1155
 
1156
+
1054
1157
  @Override
1055
1158
  public void curveVertex(float x, float y, float z) {
1056
1159
  showDepthWarningXYZ("curveVertex");
1057
1160
  }
1058
1161
 
1162
+
1163
+
1059
1164
  //////////////////////////////////////////////////////////////
1165
+
1060
1166
  // RENDERER
1167
+
1168
+
1061
1169
  //public void flush()
1170
+
1171
+
1172
+
1062
1173
  //////////////////////////////////////////////////////////////
1174
+
1063
1175
  // POINT, LINE, TRIANGLE, QUAD
1176
+
1177
+
1064
1178
  @Override
1065
1179
  public void point(float x, float y) {
1066
1180
  if (stroke) {
@@ -1072,15 +1186,17 @@ public class PGraphicsJava2D extends PGraphics {
1072
1186
  }
1073
1187
  }
1074
1188
 
1189
+
1075
1190
  @Override
1076
1191
  public void line(float x1, float y1, float x2, float y2) {
1077
1192
  line.setLine(x1, y1, x2, y2);
1078
1193
  strokeShape(line);
1079
1194
  }
1080
1195
 
1196
+
1081
1197
  @Override
1082
1198
  public void triangle(float x1, float y1, float x2, float y2,
1083
- float x3, float y3) {
1199
+ float x3, float y3) {
1084
1200
  gpath = new GeneralPath();
1085
1201
  gpath.moveTo(x1, y1);
1086
1202
  gpath.lineTo(x2, y2);
@@ -1089,9 +1205,10 @@ public class PGraphicsJava2D extends PGraphics {
1089
1205
  drawShape(gpath);
1090
1206
  }
1091
1207
 
1208
+
1092
1209
  @Override
1093
1210
  public void quad(float x1, float y1, float x2, float y2,
1094
- float x3, float y3, float x4, float y4) {
1211
+ float x3, float y3, float x4, float y4) {
1095
1212
  GeneralPath gp = new GeneralPath();
1096
1213
  gp.moveTo(x1, y1);
1097
1214
  gp.lineTo(x2, y2);
@@ -1101,33 +1218,58 @@ public class PGraphicsJava2D extends PGraphics {
1101
1218
  drawShape(gp);
1102
1219
  }
1103
1220
 
1221
+
1222
+
1104
1223
  //////////////////////////////////////////////////////////////
1224
+
1105
1225
  // RECT
1226
+
1227
+
1106
1228
  //public void rectMode(int mode)
1229
+
1230
+
1107
1231
  //public void rect(float a, float b, float c, float d)
1232
+
1233
+
1108
1234
  @Override
1109
1235
  protected void rectImpl(float x1, float y1, float x2, float y2) {
1110
- rect.setFrame(x1, y1, x2 - x1, y2 - y1);
1236
+ rect.setFrame(x1, y1, x2-x1, y2-y1);
1111
1237
  drawShape(rect);
1112
1238
  }
1113
1239
 
1240
+
1241
+
1114
1242
  //////////////////////////////////////////////////////////////
1243
+
1115
1244
  // ELLIPSE
1245
+
1246
+
1116
1247
  //public void ellipseMode(int mode)
1248
+
1249
+
1117
1250
  //public void ellipse(float a, float b, float c, float d)
1251
+
1252
+
1118
1253
  @Override
1119
1254
  protected void ellipseImpl(float x, float y, float w, float h) {
1120
1255
  ellipse.setFrame(x, y, w, h);
1121
1256
  drawShape(ellipse);
1122
1257
  }
1123
1258
 
1259
+
1260
+
1124
1261
  //////////////////////////////////////////////////////////////
1262
+
1125
1263
  // ARC
1264
+
1265
+
1126
1266
  //public void arc(float a, float b, float c, float d,
1127
1267
  // float start, float stop)
1268
+
1269
+
1128
1270
  @Override
1129
1271
  protected void arcImpl(float x, float y, float w, float h,
1130
- float start, float stop, int mode) {
1272
+ float start, float stop, int mode) {
1131
1273
  // 0 to 90 in java would be 0 to -90 for p5 renderer
1132
1274
  // but that won't work, so -90 to 0?
1133
1275
 
@@ -1180,8 +1322,13 @@ public class PGraphicsJava2D extends PGraphics {
1180
1322
  }
1181
1323
  }
1182
1324
 
1325
+
1326
+
1183
1327
  //////////////////////////////////////////////////////////////
1328
+
1184
1329
  // JAVA2D SHAPE/PATH HANDLING
1330
+
1331
+
1185
1332
  protected void fillShape(Shape s) {
1186
1333
  if (fillGradient) {
1187
1334
  g2.setPaint(fillGradientObject);
@@ -1192,6 +1339,7 @@ public class PGraphicsJava2D extends PGraphics {
1192
1339
  }
1193
1340
  }
1194
1341
 
1342
+
1195
1343
  protected void strokeShape(Shape s) {
1196
1344
  if (strokeGradient) {
1197
1345
  g2.setPaint(strokeGradientObject);
@@ -1202,6 +1350,7 @@ public class PGraphicsJava2D extends PGraphics {
1202
1350
  }
1203
1351
  }
1204
1352
 
1353
+
1205
1354
  protected void drawShape(Shape s) {
1206
1355
  if (fillGradient) {
1207
1356
  g2.setPaint(fillGradientObject);
@@ -1219,66 +1368,115 @@ public class PGraphicsJava2D extends PGraphics {
1219
1368
  }
1220
1369
  }
1221
1370
 
1371
+
1372
+
1222
1373
  //////////////////////////////////////////////////////////////
1374
+
1223
1375
  // BOX
1376
+
1377
+
1224
1378
  //public void box(float size)
1379
+
1380
+
1225
1381
  @Override
1226
1382
  public void box(float w, float h, float d) {
1227
1383
  showMethodWarning("box");
1228
1384
  }
1229
1385
 
1386
+
1387
+
1230
1388
  //////////////////////////////////////////////////////////////
1389
+
1231
1390
  // SPHERE
1391
+
1392
+
1232
1393
  //public void sphereDetail(int res)
1394
+
1395
+
1233
1396
  //public void sphereDetail(int ures, int vres)
1397
+
1398
+
1234
1399
  @Override
1235
1400
  public void sphere(float r) {
1236
1401
  showMethodWarning("sphere");
1237
1402
  }
1238
1403
 
1404
+
1405
+
1239
1406
  //////////////////////////////////////////////////////////////
1407
+
1240
1408
  // BEZIER
1409
+
1410
+
1241
1411
  //public float bezierPoint(float a, float b, float c, float d, float t)
1412
+
1413
+
1242
1414
  //public float bezierTangent(float a, float b, float c, float d, float t)
1415
+
1416
+
1243
1417
  //protected void bezierInitCheck()
1418
+
1419
+
1244
1420
  //protected void bezierInit()
1245
- /**
1246
- * Ignored (not needed) in Java 2D.
1247
- */
1421
+
1422
+
1423
+ /** Ignored (not needed) in Java 2D. */
1248
1424
  @Override
1249
1425
  public void bezierDetail(int detail) {
1250
1426
  }
1251
1427
 
1428
+
1252
1429
  //public void bezier(float x1, float y1,
1253
1430
  // float x2, float y2,
1254
1431
  // float x3, float y3,
1255
1432
  // float x4, float y4)
1433
+
1434
+
1256
1435
  //public void bezier(float x1, float y1, float z1,
1257
1436
  // float x2, float y2, float z2,
1258
1437
  // float x3, float y3, float z3,
1259
1438
  // float x4, float y4, float z4)
1439
+
1440
+
1441
+
1260
1442
  //////////////////////////////////////////////////////////////
1443
+
1261
1444
  // CURVE
1445
+
1446
+
1262
1447
  //public float curvePoint(float a, float b, float c, float d, float t)
1448
+
1449
+
1263
1450
  //public float curveTangent(float a, float b, float c, float d, float t)
1264
- /**
1265
- * Ignored (not needed) in Java 2D.
1266
- */
1451
+
1452
+
1453
+ /** Ignored (not needed) in Java 2D. */
1267
1454
  @Override
1268
1455
  public void curveDetail(int detail) {
1269
1456
  }
1270
1457
 
1271
1458
  //public void curveTightness(float tightness)
1459
+
1460
+
1272
1461
  //protected void curveInitCheck()
1462
+
1463
+
1273
1464
  //protected void curveInit()
1465
+
1466
+
1274
1467
  //public void curve(float x1, float y1,
1275
1468
  // float x2, float y2,
1276
1469
  // float x3, float y3,
1277
1470
  // float x4, float y4)
1471
+
1472
+
1278
1473
  //public void curve(float x1, float y1, float z1,
1279
1474
  // float x2, float y2, float z2,
1280
1475
  // float x3, float y3, float z3,
1281
1476
  // float x4, float y4, float z4)
1477
+
1478
+
1479
+
1282
1480
  // //////////////////////////////////////////////////////////////
1283
1481
  //
1284
1482
  // // SMOOTH
@@ -1342,34 +1540,44 @@ public class PGraphicsJava2D extends PGraphics {
1342
1540
  // g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
1343
1541
  // RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
1344
1542
  // }
1543
+
1544
+
1545
+
1345
1546
  //////////////////////////////////////////////////////////////
1547
+
1346
1548
  // IMAGE
1549
+
1550
+
1347
1551
  //public void imageMode(int mode)
1552
+
1553
+
1348
1554
  //public void image(PImage image, float x, float y)
1555
+
1556
+
1349
1557
  //public void image(PImage image, float x, float y, float c, float d)
1558
+
1559
+
1350
1560
  //public void image(PImage image,
1351
1561
  // float a, float b, float c, float d,
1352
1562
  // int u1, int v1, int u2, int v2)
1563
+
1564
+
1353
1565
  /**
1354
1566
  * Handle renderer-specific image drawing.
1355
- *
1356
- * @param who
1357
1567
  */
1358
1568
  @Override
1359
1569
  protected void imageImpl(PImage who,
1360
- float x1, float y1, float x2, float y2,
1361
- int u1, int v1, int u2, int v2) {
1570
+ float x1, float y1, float x2, float y2,
1571
+ int u1, int v1, int u2, int v2) {
1362
1572
  // Image not ready yet, or an error
1363
- if (who.width <= 0 || who.height <= 0) {
1364
- return;
1365
- }
1573
+ if (who.width <= 0 || who.height <= 0) return;
1366
1574
 
1367
1575
  ImageCache cash = (ImageCache) getCache(who);
1368
1576
 
1369
1577
  // Nuke the cache if the image was resized
1370
1578
  if (cash != null) {
1371
- if (who.pixelWidth != cash.image.getWidth()
1372
- || who.pixelHeight != cash.image.getHeight()) {
1579
+ if (who.pixelWidth != cash.image.getWidth() ||
1580
+ who.pixelHeight != cash.image.getHeight()) {
1373
1581
  cash = null;
1374
1582
  }
1375
1583
  }
@@ -1384,9 +1592,9 @@ public class PGraphicsJava2D extends PGraphics {
1384
1592
 
1385
1593
  // If image previously was tinted, or the color changed
1386
1594
  // or the image was tinted, and tint is now disabled
1387
- if ((tint && !cash.tinted)
1388
- || (tint && (cash.tintedColor != tintColor))
1389
- || (!tint && cash.tinted)) {
1595
+ if ((tint && !cash.tinted) ||
1596
+ (tint && (cash.tintedColor != tintColor)) ||
1597
+ (!tint && cash.tinted)) {
1390
1598
  // For tint change, mark all pixels as needing update.
1391
1599
  who.updatePixels();
1392
1600
  }
@@ -1408,8 +1616,8 @@ public class PGraphicsJava2D extends PGraphics {
1408
1616
  v2 *= who.pixelDensity;
1409
1617
 
1410
1618
  g2.drawImage(((ImageCache) getCache(who)).image,
1411
- (int) x1, (int) y1, (int) x2, (int) y2,
1412
- u1, v1, u2, v2, null);
1619
+ (int) x1, (int) y1, (int) x2, (int) y2,
1620
+ u1, v1, u2, v2, null);
1413
1621
 
1414
1622
  // Every few years I think "nah, Java2D couldn't possibly be that f*king
1415
1623
  // slow, why are we doing this by hand?" then comes the affirmation:
@@ -1434,8 +1642,8 @@ public class PGraphicsJava2D extends PGraphics {
1434
1642
  // }
1435
1643
  }
1436
1644
 
1437
- static class ImageCache {
1438
1645
 
1646
+ static class ImageCache {
1439
1647
  boolean tinted;
1440
1648
  int tintedColor;
1441
1649
  int[] tintedTemp; // one row of tinted pixels
@@ -1450,10 +1658,11 @@ public class PGraphicsJava2D extends PGraphics {
1450
1658
  // //System.out.println("making new buffered image");
1451
1659
  //// image = new BufferedImage(source.width, source.height, type);
1452
1660
  // }
1661
+
1453
1662
  /**
1454
1663
  * Update the pixels of the cache image. Already determined that the tint
1455
- * has changed, or the pixels have changed, so should just go through with
1456
- * the update without further checks.
1664
+ * has changed, or the pixels have changed, so should just go through
1665
+ * with the update without further checks.
1457
1666
  */
1458
1667
  public void update(PImage source, boolean tint, int tintColor) {
1459
1668
  //int bufferType = BufferedImage.TYPE_INT_ARGB;
@@ -1474,7 +1683,7 @@ public class PGraphicsJava2D extends PGraphics {
1474
1683
  // https://github.com/processing/processing/issues/2030
1475
1684
  if (image == null) {
1476
1685
  image = new BufferedImage(source.pixelWidth, source.pixelHeight,
1477
- BufferedImage.TYPE_INT_ARGB);
1686
+ BufferedImage.TYPE_INT_ARGB);
1478
1687
  }
1479
1688
 
1480
1689
  WritableRaster wr = image.getRaster();
@@ -1504,10 +1713,10 @@ public class PGraphicsJava2D extends PGraphics {
1504
1713
  // Prior to 2.1, the alpha channel was commented out here,
1505
1714
  // but can't remember why (just thought unnecessary b/c of RGB?)
1506
1715
  // https://github.com/processing/processing/issues/2030
1507
- tintedTemp[x] = 0xFF000000
1508
- | (((r2 * r1) & 0xff00) << 8)
1509
- | ((g2 * g1) & 0xff00)
1510
- | (((b2 * b1) & 0xff00) >> 8);
1716
+ tintedTemp[x] = 0xFF000000 |
1717
+ (((r2 * r1) & 0xff00) << 8) |
1718
+ ((g2 * g1) & 0xff00) |
1719
+ (((b2 * b1) & 0xff00) >> 8);
1511
1720
  }
1512
1721
  wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp);
1513
1722
  }
@@ -1517,10 +1726,10 @@ public class PGraphicsJava2D extends PGraphics {
1517
1726
  // RescaleOp op = new RescaleOp(scales, offsets, null);
1518
1727
  // op.filter(image, image);
1519
1728
 
1520
- //} else if (bufferType == BufferedImage.TYPE_INT_ARGB) {
1729
+ //} else if (bufferType == BufferedImage.TYPE_INT_ARGB) {
1521
1730
  } else if (targetType == ARGB) {
1522
- if (source.format == RGB
1523
- && (tintColor & 0xffffff) == 0xffffff) {
1731
+ if (source.format == RGB &&
1732
+ (tintColor & 0xffffff) == 0xffffff) {
1524
1733
  int hi = tintColor & 0xff000000;
1525
1734
  int index = 0;
1526
1735
  for (int y = 0; y < source.pixelHeight; y++) {
@@ -1540,12 +1749,11 @@ public class PGraphicsJava2D extends PGraphics {
1540
1749
  int r1 = (argb1 >> 16) & 0xff;
1541
1750
  int g1 = (argb1 >> 8) & 0xff;
1542
1751
  int b1 = (argb1) & 0xff;
1543
- tintedTemp[x] = alpha
1544
- | (((r2 * r1) & 0xff00) << 8)
1545
- | ((g2 * g1) & 0xff00)
1546
- | (((b2 * b1) & 0xff00) >> 8);
1547
- }
1548
- break;
1752
+ tintedTemp[x] = alpha |
1753
+ (((r2 * r1) & 0xff00) << 8) |
1754
+ ((g2 * g1) & 0xff00) |
1755
+ (((b2 * b1) & 0xff00) >> 8);
1756
+ } break;
1549
1757
  case ARGB:
1550
1758
  for (int x = 0; x < source.pixelWidth; x++) {
1551
1759
  int argb1 = source.pixels[index++];
@@ -1553,21 +1761,19 @@ public class PGraphicsJava2D extends PGraphics {
1553
1761
  int r1 = (argb1 >> 16) & 0xff;
1554
1762
  int g1 = (argb1 >> 8) & 0xff;
1555
1763
  int b1 = (argb1) & 0xff;
1556
- tintedTemp[x]
1557
- = (((a2 * a1) & 0xff00) << 16)
1558
- | (((r2 * r1) & 0xff00) << 8)
1559
- | ((g2 * g1) & 0xff00)
1560
- | (((b2 * b1) & 0xff00) >> 8);
1561
- }
1562
- break;
1764
+ tintedTemp[x] =
1765
+ (((a2 * a1) & 0xff00) << 16) |
1766
+ (((r2 * r1) & 0xff00) << 8) |
1767
+ ((g2 * g1) & 0xff00) |
1768
+ (((b2 * b1) & 0xff00) >> 8);
1769
+ } break;
1563
1770
  case ALPHA:
1564
1771
  int lower = tintColor & 0xFFFFFF;
1565
1772
  for (int x = 0; x < source.pixelWidth; x++) {
1566
1773
  int a1 = source.pixels[index++];
1567
- tintedTemp[x]
1568
- = (((a2 * a1) & 0xff00) << 16) | lower;
1569
- }
1570
- break;
1774
+ tintedTemp[x] =
1775
+ (((a2 * a1) & 0xff00) << 16) | lower;
1776
+ } break;
1571
1777
  default:
1572
1778
  break;
1573
1779
  }
@@ -1607,15 +1813,33 @@ public class PGraphicsJava2D extends PGraphics {
1607
1813
  }
1608
1814
  }
1609
1815
 
1816
+
1817
+
1610
1818
  //////////////////////////////////////////////////////////////
1819
+
1611
1820
  // SHAPE
1821
+
1822
+
1612
1823
  //public void shapeMode(int mode)
1824
+
1825
+
1613
1826
  //public void shape(PShape shape)
1827
+
1828
+
1614
1829
  //public void shape(PShape shape, float x, float y)
1830
+
1831
+
1615
1832
  //public void shape(PShape shape, float x, float y, float c, float d)
1833
+
1834
+
1616
1835
  //////////////////////////////////////////////////////////////
1836
+
1617
1837
  // SHAPE I/O
1838
+
1839
+
1618
1840
  //public PShape loadShape(String filename)
1841
+
1842
+
1619
1843
  @Override
1620
1844
  public PShape loadShape(String filename, String options) {
1621
1845
  String extension = PApplet.getExtension(filename);
@@ -1626,10 +1850,19 @@ public class PGraphicsJava2D extends PGraphics {
1626
1850
  return null;
1627
1851
  }
1628
1852
 
1853
+
1854
+
1629
1855
  //////////////////////////////////////////////////////////////
1856
+
1630
1857
  // TEXT ATTRIBTUES
1858
+
1859
+
1631
1860
  //public void textAlign(int align)
1861
+
1862
+
1632
1863
  //public void textAlign(int alignX, int alignY)
1864
+
1865
+
1633
1866
  @Override
1634
1867
  public float textAscent() {
1635
1868
  if (textFont == null) {
@@ -1644,6 +1877,7 @@ public class PGraphicsJava2D extends PGraphics {
1644
1877
  return super.textAscent();
1645
1878
  }
1646
1879
 
1880
+
1647
1881
  @Override
1648
1882
  public float textDescent() {
1649
1883
  if (textFont == null) {
@@ -1657,20 +1891,30 @@ public class PGraphicsJava2D extends PGraphics {
1657
1891
  return super.textDescent();
1658
1892
  }
1659
1893
 
1894
+
1660
1895
  //public void textFont(PFont which)
1896
+
1897
+
1661
1898
  //public void textFont(PFont which, float size)
1899
+
1900
+
1662
1901
  //public void textLeading(float leading)
1902
+
1903
+
1663
1904
  //public void textMode(int mode)
1905
+
1906
+
1664
1907
  @Override
1665
1908
  protected boolean textModeCheck(int mode) {
1666
1909
  return mode == MODEL;
1667
1910
  }
1668
1911
 
1912
+
1669
1913
  /**
1670
1914
  * Same as parent, but override for native version of the font.
1671
- *
1672
- * Called from textFontImpl and textSizeImpl, so the metrics will get recorded
1673
- * properly.
1915
+ *
1916
+ * Called from textFontImpl and textSizeImpl, so the metrics
1917
+ * will get recorded properly.
1674
1918
  */
1675
1919
  @Override
1676
1920
  protected void handleTextSize(float size) {
@@ -1679,11 +1923,11 @@ public class PGraphicsJava2D extends PGraphics {
1679
1923
  // don't derive again if the font size has not changed
1680
1924
  if (font != null) {
1681
1925
  if (font.getSize2D() != size) {
1682
- Map<TextAttribute, Object> map
1683
- = new HashMap<>();
1926
+ Map<TextAttribute, Object> map =
1927
+ new HashMap<>();
1684
1928
  map.put(TextAttribute.SIZE, size);
1685
1929
  map.put(TextAttribute.KERNING,
1686
- TextAttribute.KERNING_ON);
1930
+ TextAttribute.KERNING_ON);
1687
1931
  // map.put(TextAttribute.TRACKING,
1688
1932
  // TextAttribute.TRACKING_TIGHT);
1689
1933
  font = font.deriveFont(map);
@@ -1697,7 +1941,7 @@ public class PGraphicsJava2D extends PGraphics {
1697
1941
  for (TextAttribute ta : attrs.keySet()) {
1698
1942
  System.out.println(ta + " -> " + attrs.get(ta));
1699
1943
  }
1700
- */
1944
+ */
1701
1945
  }
1702
1946
 
1703
1947
  // take care of setting the textSize and textLeading vars
@@ -1706,10 +1950,15 @@ public class PGraphicsJava2D extends PGraphics {
1706
1950
  super.handleTextSize(size);
1707
1951
  }
1708
1952
 
1953
+
1709
1954
  //public float textWidth(char c)
1955
+
1956
+
1710
1957
  //public float textWidth(String str)
1958
+
1959
+
1711
1960
  @Override
1712
- protected float textWidthImpl(char buffer[], int start, int stop) {
1961
+ protected float textWidthImpl(char[] buffer, int start, int stop) {
1713
1962
  if (textFont == null) {
1714
1963
  defaultFontOrDeath("textWidth");
1715
1964
  }
@@ -1742,28 +1991,44 @@ public class PGraphicsJava2D extends PGraphics {
1742
1991
  //// return m2;
1743
1992
  //// return metrics.charsWidth(buffer, start, length);
1744
1993
  // return m2;
1745
- return (float) metrics.getStringBounds(buffer, start, stop, g2).getWidth();
1994
+ return (float)
1995
+ metrics.getStringBounds(buffer, start, stop, g2).getWidth();
1746
1996
  }
1747
1997
  // System.err.println("not native");
1748
1998
  return super.textWidthImpl(buffer, start, stop);
1749
1999
  }
1750
2000
 
2001
+
1751
2002
  // protected void beginTextScreenMode() {
1752
2003
  // loadPixels();
1753
2004
  // }
2005
+
2006
+
1754
2007
  // protected void endTextScreenMode() {
1755
2008
  // updatePixels();
1756
2009
  // }
2010
+
2011
+
1757
2012
  //////////////////////////////////////////////////////////////
2013
+
1758
2014
  // TEXT
2015
+
1759
2016
  // None of the variations of text() are overridden from PGraphics.
2017
+
2018
+
2019
+
1760
2020
  //////////////////////////////////////////////////////////////
2021
+
1761
2022
  // TEXT IMPL
2023
+
2024
+
1762
2025
  //protected void textLineAlignImpl(char buffer[], int start, int stop,
1763
2026
  // float x, float y)
2027
+
2028
+
1764
2029
  @Override
1765
- protected void textLineImpl(char buffer[], int start, int stop,
1766
- float x, float y) {
2030
+ protected void textLineImpl(char[] buffer, int start, int stop,
2031
+ float x, float y) {
1767
2032
  Font font = (Font) textFont.getNative();
1768
2033
  // if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) {
1769
2034
  if (font != null) {
@@ -1781,9 +2046,9 @@ public class PGraphicsJava2D extends PGraphics {
1781
2046
  textFont.smooth ?
1782
2047
  RenderingHints.VALUE_ANTIALIAS_ON :
1783
2048
  RenderingHints.VALUE_ANTIALIAS_OFF);
1784
- */
1785
- Object antialias
1786
- = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
2049
+ */
2050
+ Object antialias =
2051
+ g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
1787
2052
  if (antialias == null) {
1788
2053
  // if smooth() and noSmooth() not called, this will be null (0120)
1789
2054
  antialias = RenderingHints.VALUE_ANTIALIAS_DEFAULT;
@@ -1793,22 +2058,23 @@ public class PGraphicsJava2D extends PGraphics {
1793
2058
  // also changes global setting for antialiasing, but this is because it's
1794
2059
  // not possible to enable/disable them independently in some situations.
1795
2060
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1796
- textFont.isSmooth()
1797
- ? RenderingHints.VALUE_ANTIALIAS_ON
1798
- : RenderingHints.VALUE_ANTIALIAS_OFF);
2061
+ textFont.isSmooth() ?
2062
+ RenderingHints.VALUE_ANTIALIAS_ON :
2063
+ RenderingHints.VALUE_ANTIALIAS_OFF);
1799
2064
 
1800
2065
  g2.setColor(fillColorObject);
1801
2066
 
1802
2067
  int length = stop - start;
1803
2068
  if (length != 0) {
1804
- g2.drawChars(buffer, start, length, (int) (x + 0.5f), (int) (y + 0.5f));
1805
- // better to use round here? also, drawChars now just calls drawString
2069
+ g2.drawChars(buffer, start, length, (int) (x + 0.5f), (int) (y + 0.5f));
2070
+ // better to use round here? also, drawChars now just calls drawString
1806
2071
  // g2.drawString(new String(buffer, start, stop - start), Math.round(x), Math.round(y));
1807
2072
 
1808
- // better to use drawString() with floats? (nope, draws the same)
1809
- //g2.drawString(new String(buffer, start, length), x, y);
1810
- // this didn't seem to help the scaling issue, and creates garbage
1811
- // because of a fairly heavyweight new temporary object
2073
+ // better to use drawString() with floats? (nope, draws the same)
2074
+ //g2.drawString(new String(buffer, start, length), x, y);
2075
+
2076
+ // this didn't seem to help the scaling issue, and creates garbage
2077
+ // because of a fairly heavyweight new temporary object
1812
2078
  // java.awt.font.GlyphVector gv =
1813
2079
  // font.createGlyphVector(g2.getFontRenderContext(), new String(buffer, start, stop - start));
1814
2080
  // g2.drawGlyphVector(gv, x, y);
@@ -1823,6 +2089,7 @@ public class PGraphicsJava2D extends PGraphics {
1823
2089
  }
1824
2090
  }
1825
2091
 
2092
+
1826
2093
  // /**
1827
2094
  // * Convenience method to get a legit FontMetrics object. Where possible,
1828
2095
  // * override this any renderer subclass so that you're not using what's
@@ -1862,121 +2129,161 @@ public class PGraphicsJava2D extends PGraphics {
1862
2129
  return toolkit.getFontMetrics(font);
1863
2130
  //return (g2 != null) ? g2.getFontMetrics(font) : super.getFontMetrics(font);
1864
2131
  }
1865
- */
2132
+ */
2133
+
2134
+
1866
2135
  //////////////////////////////////////////////////////////////
2136
+
1867
2137
  // MATRIX STACK
2138
+
2139
+
1868
2140
  @Override
1869
2141
  public void pushMatrix() {
1870
2142
  if (transformCount == transformStack.length) {
1871
- throw new RuntimeException("pushMatrix() cannot use push more than "
1872
- + transformStack.length + " times");
2143
+ throw new RuntimeException("pushMatrix() cannot use push more than " +
2144
+ transformStack.length + " times");
1873
2145
  }
1874
2146
  transformStack[transformCount] = g2.getTransform();
1875
2147
  transformCount++;
1876
2148
  }
1877
2149
 
2150
+
1878
2151
  @Override
1879
2152
  public void popMatrix() {
1880
2153
  if (transformCount == 0) {
1881
- throw new RuntimeException("missing a pushMatrix() "
1882
- + "to go with that popMatrix()");
2154
+ throw new RuntimeException("missing a pushMatrix() " +
2155
+ "to go with that popMatrix()");
1883
2156
  }
1884
2157
  transformCount--;
1885
2158
  g2.setTransform(transformStack[transformCount]);
1886
2159
  }
1887
2160
 
2161
+
2162
+
1888
2163
  //////////////////////////////////////////////////////////////
2164
+
1889
2165
  // MATRIX TRANSFORMS
2166
+
2167
+
1890
2168
  @Override
1891
2169
  public void translate(float tx, float ty) {
1892
2170
  g2.translate(tx, ty);
1893
2171
  }
1894
2172
 
2173
+
1895
2174
  //public void translate(float tx, float ty, float tz)
2175
+
2176
+
1896
2177
  @Override
1897
2178
  public void rotate(float angle) {
1898
2179
  g2.rotate(angle);
1899
2180
  }
1900
2181
 
2182
+
1901
2183
  @Override
1902
2184
  public void rotateX(float angle) {
1903
2185
  showDepthWarning("rotateX");
1904
2186
  }
1905
2187
 
2188
+
1906
2189
  @Override
1907
2190
  public void rotateY(float angle) {
1908
2191
  showDepthWarning("rotateY");
1909
2192
  }
1910
2193
 
2194
+
1911
2195
  @Override
1912
2196
  public void rotateZ(float angle) {
1913
2197
  showDepthWarning("rotateZ");
1914
2198
  }
1915
2199
 
2200
+
1916
2201
  @Override
1917
2202
  public void rotate(float angle, float vx, float vy, float vz) {
1918
2203
  showVariationWarning("rotate");
1919
2204
  }
1920
2205
 
2206
+
1921
2207
  @Override
1922
2208
  public void scale(float s) {
1923
2209
  g2.scale(s, s);
1924
2210
  }
1925
2211
 
2212
+
1926
2213
  @Override
1927
2214
  public void scale(float sx, float sy) {
1928
2215
  g2.scale(sx, sy);
1929
2216
  }
1930
2217
 
2218
+
1931
2219
  @Override
1932
2220
  public void scale(float sx, float sy, float sz) {
1933
2221
  showDepthWarningXYZ("scale");
1934
2222
  }
1935
2223
 
2224
+
1936
2225
  @Override
1937
2226
  public void shearX(float angle) {
1938
2227
  g2.shear(Math.tan(angle), 0);
1939
2228
  }
1940
2229
 
2230
+
1941
2231
  @Override
1942
2232
  public void shearY(float angle) {
1943
2233
  g2.shear(0, Math.tan(angle));
1944
2234
  }
1945
2235
 
2236
+
2237
+
1946
2238
  //////////////////////////////////////////////////////////////
2239
+
1947
2240
  // MATRIX MORE
2241
+
2242
+
1948
2243
  @Override
1949
2244
  public void resetMatrix() {
1950
2245
  g2.setTransform(new AffineTransform());
1951
2246
  g2.scale(pixelDensity, pixelDensity);
1952
2247
  }
1953
2248
 
2249
+
1954
2250
  //public void applyMatrix(PMatrix2D source)
2251
+
2252
+
1955
2253
  @Override
1956
2254
  public void applyMatrix(float n00, float n01, float n02,
1957
- float n10, float n11, float n12) {
2255
+ float n10, float n11, float n12) {
1958
2256
  //System.out.println("PGraphicsJava2D.applyMatrix()");
1959
2257
  //System.out.println(new AffineTransform(n00, n10, n01, n11, n02, n12));
1960
2258
  g2.transform(new AffineTransform(n00, n10, n01, n11, n02, n12));
1961
2259
  //g2.transform(new AffineTransform(n00, n01, n02, n10, n11, n12));
1962
2260
  }
1963
2261
 
2262
+
1964
2263
  //public void applyMatrix(PMatrix3D source)
2264
+
2265
+
1965
2266
  @Override
1966
2267
  public void applyMatrix(float n00, float n01, float n02, float n03,
1967
- float n10, float n11, float n12, float n13,
1968
- float n20, float n21, float n22, float n23,
1969
- float n30, float n31, float n32, float n33) {
2268
+ float n10, float n11, float n12, float n13,
2269
+ float n20, float n21, float n22, float n23,
2270
+ float n30, float n31, float n32, float n33) {
1970
2271
  showVariationWarning("applyMatrix");
1971
2272
  }
1972
2273
 
2274
+
2275
+
1973
2276
  //////////////////////////////////////////////////////////////
2277
+
1974
2278
  // MATRIX GET/SET
2279
+
2280
+
1975
2281
  @Override
1976
2282
  public PMatrix getMatrix() {
1977
2283
  return getMatrix((PMatrix2D) null);
1978
2284
  }
1979
2285
 
2286
+
1980
2287
  @Override
1981
2288
  public PMatrix2D getMatrix(PMatrix2D target) {
1982
2289
  if (target == null) {
@@ -1984,37 +2291,49 @@ public class PGraphicsJava2D extends PGraphics {
1984
2291
  }
1985
2292
  g2.getTransform().getMatrix(transform);
1986
2293
  target.set((float) transform[0], (float) transform[2], (float) transform[4],
1987
- (float) transform[1], (float) transform[3], (float) transform[5]);
2294
+ (float) transform[1], (float) transform[3], (float) transform[5]);
1988
2295
  return target;
1989
2296
  }
1990
2297
 
2298
+
1991
2299
  @Override
1992
2300
  public PMatrix3D getMatrix(PMatrix3D target) {
1993
2301
  showVariationWarning("getMatrix");
1994
2302
  return target;
1995
2303
  }
1996
2304
 
2305
+
1997
2306
  //public void setMatrix(PMatrix source)
2307
+
2308
+
1998
2309
  @Override
1999
2310
  public void setMatrix(PMatrix2D source) {
2000
2311
  g2.setTransform(new AffineTransform(source.m00, source.m10,
2001
- source.m01, source.m11,
2002
- source.m02, source.m12));
2312
+ source.m01, source.m11,
2313
+ source.m02, source.m12));
2003
2314
  }
2004
2315
 
2316
+
2005
2317
  @Override
2006
2318
  public void setMatrix(PMatrix3D source) {
2007
2319
  showVariationWarning("setMatrix");
2008
2320
  }
2009
2321
 
2322
+
2010
2323
  @Override
2011
2324
  public void printMatrix() {
2012
2325
  getMatrix((PMatrix2D) null).print();
2013
2326
  }
2014
2327
 
2328
+
2329
+
2015
2330
  //////////////////////////////////////////////////////////////
2331
+
2016
2332
  // CAMERA and PROJECTION
2333
+
2017
2334
  // Inherit the plaintive warnings from PGraphics
2335
+
2336
+
2018
2337
  //public void beginCamera()
2019
2338
  //public void endCamera()
2020
2339
  //public void camera()
@@ -2022,6 +2341,7 @@ public class PGraphicsJava2D extends PGraphics {
2022
2341
  // float centerX, float centerY, float centerZ,
2023
2342
  // float upX, float upY, float upZ)
2024
2343
  //public void printCamera()
2344
+
2025
2345
  //public void ortho()
2026
2346
  //public void ortho(float left, float right,
2027
2347
  // float bottom, float top,
@@ -2032,64 +2352,93 @@ public class PGraphicsJava2D extends PGraphics {
2032
2352
  // float bottom, float top,
2033
2353
  // float near, float far)
2034
2354
  //public void printProjection()
2355
+
2356
+
2357
+
2035
2358
  //////////////////////////////////////////////////////////////
2359
+
2036
2360
  // SCREEN and MODEL transforms
2361
+
2362
+
2037
2363
  @Override
2038
2364
  public float screenX(float x, float y) {
2039
2365
  g2.getTransform().getMatrix(transform);
2040
- return (float) transform[0] * x + (float) transform[2] * y + (float) transform[4];
2366
+ return (float)transform[0]*x + (float)transform[2]*y + (float)transform[4];
2041
2367
  }
2042
2368
 
2369
+
2043
2370
  @Override
2044
2371
  public float screenY(float x, float y) {
2045
2372
  g2.getTransform().getMatrix(transform);
2046
- return (float) transform[1] * x + (float) transform[3] * y + (float) transform[5];
2373
+ return (float)transform[1]*x + (float)transform[3]*y + (float)transform[5];
2047
2374
  }
2048
2375
 
2376
+
2049
2377
  @Override
2050
2378
  public float screenX(float x, float y, float z) {
2051
2379
  showDepthWarningXYZ("screenX");
2052
2380
  return 0;
2053
2381
  }
2054
2382
 
2383
+
2055
2384
  @Override
2056
2385
  public float screenY(float x, float y, float z) {
2057
2386
  showDepthWarningXYZ("screenY");
2058
2387
  return 0;
2059
2388
  }
2060
2389
 
2390
+
2061
2391
  @Override
2062
2392
  public float screenZ(float x, float y, float z) {
2063
2393
  showDepthWarningXYZ("screenZ");
2064
2394
  return 0;
2065
2395
  }
2066
2396
 
2397
+
2067
2398
  //public float modelX(float x, float y, float z)
2399
+
2400
+
2068
2401
  //public float modelY(float x, float y, float z)
2402
+
2403
+
2069
2404
  //public float modelZ(float x, float y, float z)
2405
+
2406
+
2407
+
2070
2408
  //////////////////////////////////////////////////////////////
2409
+
2071
2410
  // STYLE
2411
+
2072
2412
  // pushStyle(), popStyle(), style() and getStyle() inherited.
2413
+
2414
+
2415
+
2073
2416
  //////////////////////////////////////////////////////////////
2417
+
2074
2418
  // STROKE CAP/JOIN/WEIGHT
2419
+
2420
+
2075
2421
  @Override
2076
2422
  public void strokeCap(int cap) {
2077
2423
  super.strokeCap(cap);
2078
2424
  strokeImpl();
2079
2425
  }
2080
2426
 
2427
+
2081
2428
  @Override
2082
2429
  public void strokeJoin(int join) {
2083
2430
  super.strokeJoin(join);
2084
2431
  strokeImpl();
2085
2432
  }
2086
2433
 
2434
+
2087
2435
  @Override
2088
2436
  public void strokeWeight(float weight) {
2089
2437
  super.strokeWeight(weight);
2090
2438
  strokeImpl();
2091
2439
  }
2092
2440
 
2441
+
2093
2442
  protected void strokeImpl() {
2094
2443
  int cap = BasicStroke.CAP_BUTT;
2095
2444
  if (strokeCap == ROUND) {
@@ -2109,9 +2458,15 @@ public class PGraphicsJava2D extends PGraphics {
2109
2458
  g2.setStroke(strokeObject);
2110
2459
  }
2111
2460
 
2461
+
2462
+
2112
2463
  //////////////////////////////////////////////////////////////
2464
+
2113
2465
  // STROKE
2466
+
2114
2467
  // noStroke() and stroke() inherited from PGraphics.
2468
+
2469
+
2115
2470
  @Override
2116
2471
  protected void strokeFromCalc() {
2117
2472
  super.strokeFromCalc();
@@ -2119,9 +2474,15 @@ public class PGraphicsJava2D extends PGraphics {
2119
2474
  strokeGradient = false;
2120
2475
  }
2121
2476
 
2477
+
2478
+
2122
2479
  //////////////////////////////////////////////////////////////
2480
+
2123
2481
  // TINT
2482
+
2124
2483
  // noTint() and tint() inherited from PGraphics.
2484
+
2485
+
2125
2486
  @Override
2126
2487
  protected void tintFromCalc() {
2127
2488
  super.tintFromCalc();
@@ -2129,9 +2490,15 @@ public class PGraphicsJava2D extends PGraphics {
2129
2490
  tintColorObject = new Color(tintColor, true);
2130
2491
  }
2131
2492
 
2493
+
2494
+
2132
2495
  //////////////////////////////////////////////////////////////
2496
+
2133
2497
  // FILL
2498
+
2134
2499
  // noFill() and fill() inherited from PGraphics.
2500
+
2501
+
2135
2502
  @Override
2136
2503
  protected void fillFromCalc() {
2137
2504
  super.fillFromCalc();
@@ -2139,8 +2506,13 @@ public class PGraphicsJava2D extends PGraphics {
2139
2506
  fillGradient = false;
2140
2507
  }
2141
2508
 
2509
+
2510
+
2142
2511
  //////////////////////////////////////////////////////////////
2512
+
2143
2513
  // MATERIAL PROPERTIES
2514
+
2515
+
2144
2516
  //public void ambient(int rgb)
2145
2517
  //public void ambient(float gray)
2146
2518
  //public void ambient(float x, float y, float z)
@@ -2154,8 +2526,14 @@ public class PGraphicsJava2D extends PGraphics {
2154
2526
  //public void emissive(float gray)
2155
2527
  //public void emissive(float x, float y, float z )
2156
2528
  //protected void emissiveFromCalc()
2529
+
2530
+
2531
+
2157
2532
  //////////////////////////////////////////////////////////////
2533
+
2158
2534
  // LIGHTS
2535
+
2536
+
2159
2537
  //public void lights()
2160
2538
  //public void noLights()
2161
2539
  //public void ambientLight(float red, float green, float blue)
@@ -2173,8 +2551,14 @@ public class PGraphicsJava2D extends PGraphics {
2173
2551
  //public void lightSpecular(float x, float y, float z)
2174
2552
  //protected void lightPosition(int num, float x, float y, float z)
2175
2553
  //protected void lightDirection(int num, float x, float y, float z)
2554
+
2555
+
2556
+
2176
2557
  //////////////////////////////////////////////////////////////
2558
+
2177
2559
  // BACKGROUND
2560
+
2561
+
2178
2562
  int[] clearPixels;
2179
2563
 
2180
2564
  protected void clearPixels(int color) {
@@ -2202,7 +2586,11 @@ public class PGraphicsJava2D extends PGraphics {
2202
2586
 
2203
2587
  // background() methods inherited from PGraphics, along with the
2204
2588
  // PImage version of backgroundImpl(), since it just calls set().
2589
+
2590
+
2205
2591
  //public void backgroundImpl(PImage image)
2592
+
2593
+
2206
2594
  @Override
2207
2595
  public void backgroundImpl() {
2208
2596
  if (backgroundAlpha) {
@@ -2239,45 +2627,98 @@ public class PGraphicsJava2D extends PGraphics {
2239
2627
  }
2240
2628
  }
2241
2629
 
2630
+
2631
+
2242
2632
  //////////////////////////////////////////////////////////////
2633
+
2243
2634
  // COLOR MODE
2635
+
2244
2636
  // All colorMode() variations are inherited from PGraphics.
2637
+
2638
+
2639
+
2245
2640
  //////////////////////////////////////////////////////////////
2641
+
2246
2642
  // COLOR CALC
2643
+
2247
2644
  // colorCalc() and colorCalcARGB() inherited from PGraphics.
2645
+
2646
+
2647
+
2248
2648
  //////////////////////////////////////////////////////////////
2649
+
2249
2650
  // COLOR DATATYPE STUFFING
2651
+
2250
2652
  // final color() variations inherited.
2653
+
2654
+
2655
+
2251
2656
  //////////////////////////////////////////////////////////////
2657
+
2252
2658
  // COLOR DATATYPE EXTRACTION
2659
+
2253
2660
  // final methods alpha, red, green, blue,
2254
2661
  // hue, saturation, and brightness all inherited.
2662
+
2663
+
2664
+
2255
2665
  //////////////////////////////////////////////////////////////
2666
+
2256
2667
  // COLOR DATATYPE INTERPOLATION
2668
+
2257
2669
  // both lerpColor variants inherited.
2670
+
2671
+
2672
+
2258
2673
  //////////////////////////////////////////////////////////////
2674
+
2259
2675
  // BEGIN/END RAW
2676
+
2677
+
2260
2678
  @Override
2261
2679
  public void beginRaw(PGraphics recorderRaw) {
2262
2680
  showMethodWarning("beginRaw");
2263
2681
  }
2264
2682
 
2683
+
2265
2684
  @Override
2266
2685
  public void endRaw() {
2267
2686
  showMethodWarning("endRaw");
2268
2687
  }
2269
2688
 
2689
+
2690
+
2270
2691
  //////////////////////////////////////////////////////////////
2692
+
2271
2693
  // WARNINGS and EXCEPTIONS
2694
+
2272
2695
  // showWarning and showException inherited.
2696
+
2697
+
2698
+
2273
2699
  //////////////////////////////////////////////////////////////
2700
+
2274
2701
  // RENDERER SUPPORT QUERIES
2702
+
2703
+
2275
2704
  //public boolean displayable() // true
2705
+
2706
+
2276
2707
  //public boolean is2D() // true
2708
+
2709
+
2277
2710
  //public boolean is3D() // false
2711
+
2712
+
2713
+
2278
2714
  //////////////////////////////////////////////////////////////
2715
+
2279
2716
  // PIMAGE METHODS
2717
+
2718
+
2280
2719
  // getImage, setCache, getCache, removeCache, isModified, setModified
2720
+
2721
+
2281
2722
  protected WritableRaster getRaster() {
2282
2723
  WritableRaster raster = null;
2283
2724
  if (primaryGraphics) {
@@ -2308,9 +2749,10 @@ public class PGraphicsJava2D extends PGraphics {
2308
2749
  return raster;
2309
2750
  }
2310
2751
 
2752
+
2311
2753
  @Override
2312
2754
  public void loadPixels() {
2313
- if (pixels == null || (pixels.length != pixelWidth * pixelHeight)) {
2755
+ if (pixels == null || (pixels.length != pixelWidth*pixelHeight)) {
2314
2756
  pixels = new int[pixelWidth * pixelHeight];
2315
2757
  }
2316
2758
 
@@ -2323,11 +2765,12 @@ public class PGraphicsJava2D extends PGraphics {
2323
2765
  pixels[i] = 0xff000000 | pixels[i];
2324
2766
  }
2325
2767
  }
2326
- //((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width);
2768
+ //((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width);
2327
2769
  // WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
2328
2770
  // WritableRaster raster = image.getRaster();
2329
2771
  }
2330
2772
 
2773
+
2331
2774
  // /**
2332
2775
  // * Update the pixels[] buffer to the PGraphics image.
2333
2776
  // * <P>
@@ -2341,11 +2784,15 @@ public class PGraphicsJava2D extends PGraphics {
2341
2784
  //// WritableRaster raster = image.getRaster();
2342
2785
  // updatePixels(0, 0, width, height);
2343
2786
  // }
2787
+
2788
+
2344
2789
  /**
2345
2790
  * Update the pixels[] buffer to the PGraphics image.
2346
2791
  * <P>
2347
- * Unlike in PImage, where updatePixels() only requests that the update
2348
- * happens, in PGraphicsJava2D, this will happen immediately.
2792
+ * Unlike in PImage, where updatePixels() only requests that the
2793
+ * update happens, in PGraphicsJava2D, this will happen immediately.
2794
+ * @param c
2795
+ * @param d
2349
2796
  */
2350
2797
  @Override
2351
2798
  public void updatePixels(int x, int y, int c, int d) {
@@ -2363,6 +2810,7 @@ public class PGraphicsJava2D extends PGraphics {
2363
2810
  modified = true;
2364
2811
  }
2365
2812
 
2813
+
2366
2814
  // @Override
2367
2815
  // protected void updatePixelsImpl(int x, int y, int w, int h) {
2368
2816
  // super.updatePixelsImpl(x, y, w, h);
@@ -2373,15 +2821,20 @@ public class PGraphicsJava2D extends PGraphics {
2373
2821
  // }
2374
2822
  // getRaster().setDataElements(0, 0, width, height, pixels);
2375
2823
  // }
2824
+
2825
+
2826
+
2376
2827
  //////////////////////////////////////////////////////////////
2828
+
2377
2829
  // GET/SET
2378
- static int getset[] = new int[1];
2830
+
2831
+
2832
+ static int[] getset = new int[1];
2833
+
2379
2834
 
2380
2835
  @Override
2381
2836
  public int get(int x, int y) {
2382
- if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
2383
- return 0;
2384
- }
2837
+ if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return 0;
2385
2838
  //return ((BufferedImage) image).getRGB(x, y);
2386
2839
  // WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
2387
2840
  WritableRaster raster = getRaster();
@@ -2393,11 +2846,14 @@ public class PGraphicsJava2D extends PGraphics {
2393
2846
  return getset[0];
2394
2847
  }
2395
2848
 
2849
+
2396
2850
  //public PImage get(int x, int y, int w, int h)
2851
+
2852
+
2397
2853
  @Override
2398
2854
  protected void getImpl(int sourceX, int sourceY,
2399
- int sourceWidth, int sourceHeight,
2400
- PImage target, int targetX, int targetY) {
2855
+ int sourceWidth, int sourceHeight,
2856
+ PImage target, int targetX, int targetY) {
2401
2857
  // last parameter to getRGB() is the scan size of the *target* buffer
2402
2858
  //((BufferedImage) image).getRGB(x, y, w, h, output.pixels, 0, w);
2403
2859
  // WritableRaster raster =
@@ -2418,7 +2874,7 @@ public class PGraphicsJava2D extends PGraphics {
2418
2874
 
2419
2875
  // Copy the temporary output pixels over to the outgoing image
2420
2876
  int sourceOffset = 0;
2421
- int targetOffset = targetY * target.pixelWidth + targetX;
2877
+ int targetOffset = targetY*target.pixelWidth + targetX;
2422
2878
  for (int y = 0; y < sourceHeight; y++) {
2423
2879
  if (raster.getNumBands() == 3) {
2424
2880
  for (int i = 0; i < sourceWidth; i++) {
@@ -2435,11 +2891,10 @@ public class PGraphicsJava2D extends PGraphics {
2435
2891
  }
2436
2892
  }
2437
2893
 
2894
+
2438
2895
  @Override
2439
2896
  public void set(int x, int y, int argb) {
2440
- if ((x < 0) || (y < 0) || (x >= pixelWidth) || (y >= pixelHeight)) {
2441
- return;
2442
- }
2897
+ if ((x < 0) || (y < 0) || (x >= pixelWidth) || (y >= pixelHeight)) return;
2443
2898
  // ((BufferedImage) image).setRGB(x, y, argb);
2444
2899
  getset[0] = argb;
2445
2900
  // WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
@@ -2447,24 +2902,27 @@ public class PGraphicsJava2D extends PGraphics {
2447
2902
  getRaster().setDataElements(x, y, getset);
2448
2903
  }
2449
2904
 
2905
+
2450
2906
  //public void set(int x, int y, PImage img)
2907
+
2908
+
2451
2909
  @Override
2452
2910
  protected void setImpl(PImage sourceImage,
2453
- int sourceX, int sourceY,
2454
- int sourceWidth, int sourceHeight,
2455
- int targetX, int targetY) {
2911
+ int sourceX, int sourceY,
2912
+ int sourceWidth, int sourceHeight,
2913
+ int targetX, int targetY) {
2456
2914
  WritableRaster raster = getRaster();
2457
2915
  // ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
2458
2916
 
2459
- if ((sourceX == 0) && (sourceY == 0)
2460
- && (sourceWidth == sourceImage.pixelWidth)
2461
- && (sourceHeight == sourceImage.pixelHeight)) {
2917
+ if ((sourceX == 0) && (sourceY == 0) &&
2918
+ (sourceWidth == sourceImage.pixelWidth) &&
2919
+ (sourceHeight == sourceImage.pixelHeight)) {
2462
2920
  // System.out.format("%d %d %dx%d %d%n", targetX, targetY,
2463
2921
  // sourceImage.width, sourceImage.height,
2464
2922
  // sourceImage.pixels.length);
2465
2923
  raster.setDataElements(targetX, targetY,
2466
- sourceImage.pixelWidth, sourceImage.pixelHeight,
2467
- sourceImage.pixels);
2924
+ sourceImage.pixelWidth, sourceImage.pixelHeight,
2925
+ sourceImage.pixels);
2468
2926
  } else {
2469
2927
  // TODO optimize, incredibly inefficient to reallocate this much memory
2470
2928
  PImage temp = sourceImage.get(sourceX, sourceY, sourceWidth, sourceHeight);
@@ -2472,10 +2930,16 @@ public class PGraphicsJava2D extends PGraphics {
2472
2930
  }
2473
2931
  }
2474
2932
 
2933
+
2934
+
2475
2935
  //////////////////////////////////////////////////////////////
2936
+
2476
2937
  // MASK
2477
- static final String MASK_WARNING
2478
- = "mask() cannot be used on the main drawing surface";
2938
+
2939
+
2940
+ static final String MASK_WARNING =
2941
+ "mask() cannot be used on the main drawing surface";
2942
+
2479
2943
 
2480
2944
  @Override
2481
2945
  public void mask(int[] alpha) {
@@ -2487,6 +2951,7 @@ public class PGraphicsJava2D extends PGraphics {
2487
2951
  }
2488
2952
  }
2489
2953
 
2954
+
2490
2955
  @Override
2491
2956
  public void mask(PImage alpha) {
2492
2957
  if (primaryGraphics) {
@@ -2497,17 +2962,31 @@ public class PGraphicsJava2D extends PGraphics {
2497
2962
  }
2498
2963
  }
2499
2964
 
2965
+
2966
+
2500
2967
  //////////////////////////////////////////////////////////////
2968
+
2501
2969
  // FILTER
2970
+
2502
2971
  // Because the PImage versions call loadPixels() and
2503
2972
  // updatePixels(), no need to override anything here.
2973
+
2974
+
2504
2975
  //public void filter(int kind)
2976
+
2977
+
2505
2978
  //public void filter(int kind, float param)
2979
+
2980
+
2981
+
2506
2982
  //////////////////////////////////////////////////////////////
2983
+
2507
2984
  // COPY
2985
+
2986
+
2508
2987
  @Override
2509
2988
  public void copy(int sx, int sy, int sw, int sh,
2510
- int dx, int dy, int dw, int dh) {
2989
+ int dx, int dy, int dw, int dh) {
2511
2990
  if ((sw != dw) || (sh != dh)) {
2512
2991
  g2.drawImage(image, dx, dy, dx + dw, dy + dh, sx, sy, sx + sw, sy + sh, null);
2513
2992
 
@@ -2518,27 +2997,44 @@ public class PGraphicsJava2D extends PGraphics {
2518
2997
  }
2519
2998
  }
2520
2999
 
3000
+
2521
3001
  @Override
2522
3002
  public void copy(PImage src,
2523
- int sx, int sy, int sw, int sh,
2524
- int dx, int dy, int dw, int dh) {
3003
+ int sx, int sy, int sw, int sh,
3004
+ int dx, int dy, int dw, int dh) {
2525
3005
  g2.drawImage((Image) src.getNative(),
2526
- dx, dy, dx + dw, dy + dh,
2527
- sx, sy, sx + sw, sy + sh, null);
3006
+ dx, dy, dx + dw, dy + dh,
3007
+ sx, sy, sx + sw, sy + sh, null);
2528
3008
  }
2529
3009
 
3010
+
3011
+
2530
3012
  //////////////////////////////////////////////////////////////
3013
+
2531
3014
  // BLEND
3015
+
3016
+
2532
3017
  // static public int blendColor(int c1, int c2, int mode)
3018
+
3019
+
2533
3020
  // public void blend(int sx, int sy, int sw, int sh,
2534
3021
  // int dx, int dy, int dw, int dh, int mode)
3022
+
3023
+
2535
3024
  // public void blend(PImage src,
2536
3025
  // int sx, int sy, int sw, int sh,
2537
3026
  // int dx, int dy, int dw, int dh, int mode)
3027
+
3028
+
3029
+
2538
3030
  //////////////////////////////////////////////////////////////
3031
+
2539
3032
  // SAVE
2540
- // public void save(String filename) {
2541
- // loadPixels();
2542
- // super.save(filename);
2543
- // }
3033
+
3034
+
3035
+ @Override
3036
+ public boolean save(String filename) {
3037
+ PImageAWT outImage = new PImageAWT(image);
3038
+ return outImage.save(filename);
3039
+ }
2544
3040
  }