propane 3.4.2-java → 3.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +9 -1
  7. data/Gemfile +2 -0
  8. data/README.md +7 -10
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +4 -2
  12. data/lib/propane/app.rb +5 -1
  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 +22 -23
  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 +20 -14
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +2 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +2 -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 +2 -0
  33. data/library/slider/slider.rb +23 -22
  34. data/library/vector_utils/vector_utils.rb +4 -0
  35. data/library/video_event/video_event.rb +2 -0
  36. data/pom.rb +37 -36
  37. data/pom.xml +7 -7
  38. data/propane.gemspec +13 -9
  39. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  40. data/src/main/java/monkstone/ColorUtil.java +1 -3
  41. data/src/main/java/monkstone/MathToolModule.java +1 -1
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  44. data/src/main/java/monkstone/fastmath/Deglut.java +6 -56
  45. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  46. data/src/main/java/monkstone/noise/Noise.java +116 -0
  47. data/src/main/java/monkstone/noise/NoiseGenerator.java +63 -0
  48. data/src/main/java/monkstone/noise/NoiseMode.java +15 -0
  49. data/src/main/java/monkstone/noise/SimplexNoise.java +137 -103
  50. data/src/main/java/monkstone/noise/ValueNoise.java +170 -0
  51. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  53. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  54. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  55. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  56. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  57. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  58. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  59. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  60. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  61. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  62. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  63. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  64. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  65. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  66. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  67. data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
  68. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  69. data/src/main/java/processing/core/PApplet.java +13142 -13883
  70. data/src/main/java/processing/core/PConstants.java +477 -447
  71. data/src/main/java/processing/core/PFont.java +914 -880
  72. data/src/main/java/processing/core/PGraphics.java +152 -136
  73. data/src/main/java/processing/core/PImage.java +275 -372
  74. data/src/main/java/processing/core/PMatrix.java +172 -159
  75. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  76. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  77. data/src/main/java/processing/core/PShape.java +2887 -2651
  78. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  79. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  80. data/src/main/java/processing/core/PStyle.java +40 -37
  81. data/src/main/java/processing/core/PSurface.java +139 -97
  82. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  83. data/src/main/java/processing/core/PVector.java +995 -963
  84. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  85. data/src/main/java/processing/data/DoubleDict.java +756 -710
  86. data/src/main/java/processing/data/DoubleList.java +749 -696
  87. data/src/main/java/processing/data/FloatDict.java +748 -702
  88. data/src/main/java/processing/data/FloatList.java +751 -697
  89. data/src/main/java/processing/data/IntDict.java +720 -673
  90. data/src/main/java/processing/data/IntList.java +699 -633
  91. data/src/main/java/processing/data/JSONArray.java +931 -873
  92. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  93. data/src/main/java/processing/data/JSONTokener.java +351 -341
  94. data/src/main/java/processing/data/LongDict.java +710 -663
  95. data/src/main/java/processing/data/LongList.java +701 -635
  96. data/src/main/java/processing/data/Sort.java +37 -41
  97. data/src/main/java/processing/data/StringDict.java +525 -486
  98. data/src/main/java/processing/data/StringList.java +626 -580
  99. data/src/main/java/processing/data/Table.java +3690 -3510
  100. data/src/main/java/processing/data/TableRow.java +182 -183
  101. data/src/main/java/processing/data/XML.java +957 -883
  102. data/src/main/java/processing/event/Event.java +87 -67
  103. data/src/main/java/processing/event/KeyEvent.java +48 -41
  104. data/src/main/java/processing/event/MouseEvent.java +88 -113
  105. data/src/main/java/processing/event/TouchEvent.java +10 -6
  106. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  107. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  108. data/src/main/java/processing/net/Client.java +20 -20
  109. data/src/main/java/processing/net/Server.java +9 -9
  110. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  111. data/src/main/java/processing/opengl/FrameBuffer.java +389 -377
  112. data/src/main/java/processing/opengl/LinePath.java +132 -89
  113. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  114. data/src/main/java/processing/opengl/PGL.java +660 -567
  115. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  116. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  117. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  118. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  119. data/src/main/java/processing/opengl/PShader.java +369 -461
  120. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  121. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  122. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  123. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  124. data/test/create_test.rb +21 -20
  125. data/test/deglut_spec_test.rb +4 -2
  126. data/test/helper_methods_test.rb +49 -20
  127. data/test/math_tool_test.rb +39 -32
  128. data/test/native_folder.rb +47 -0
  129. data/test/respond_to_test.rb +3 -2
  130. data/test/sketches/key_event.rb +2 -2
  131. data/test/sketches/library/my_library/my_library.rb +3 -0
  132. data/test/test_helper.rb +2 -0
  133. data/test/vecmath_spec_test.rb +35 -22
  134. data/vendors/Rakefile +35 -40
  135. metadata +47 -23
  136. data/library/simplex_noise/simplex_noise.rb +0 -3
  137. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  138. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  139. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  140. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -0,0 +1,170 @@
1
+ package monkstone.noise;
2
+ import java.util.Random;
3
+ import monkstone.fastmath.DegLutTables;
4
+ import processing.core.PConstants;
5
+
6
+ public class ValueNoise implements Noise {
7
+
8
+ //////////////////////////////////////////////////////////////
9
+ // PROCESSING NOISE, rewritten by cfloutier to change the way cosinus is computed
10
+ // [toxi 040903]
11
+ // octaves and amplitude amount per octave are now user controlled
12
+ // via the noiseDetail() function.
13
+ // [toxi 030902]
14
+ // cleaned up code and now using bagel's cosine table to speed up
15
+ // [toxi 030901]
16
+ // implementation by the german demo group farbrausch
17
+ // as used in their demo "art": http://www.farb-rausch.de/fr010src.zip
18
+ static final int PERLIN_YWRAPB = 4;
19
+ static final int PERLIN_YWRAP = 1 << PERLIN_YWRAPB;
20
+ static final int PERLIN_ZWRAPB = 8;
21
+ static final int PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB;
22
+ static final int PERLIN_SIZE = 4095;
23
+
24
+ int perlin_octaves = 4; // default to medium smooth
25
+ float perlin_amp_falloff = 0.5f; // 50% reduction/octave
26
+ int perlin_PI;
27
+ static final int PERLIN_TWOPI = 65536;
28
+
29
+ //float[] perlin_cosTable;
30
+ float[] perlin;
31
+
32
+ Random perlinRandom;
33
+
34
+ @Override
35
+ public float noise(float x) {
36
+ return noise(x, 0f, 0f);
37
+ }
38
+
39
+ @Override
40
+ public float noise(float x, float y) {
41
+ return noise(x, y, 0f);
42
+ }
43
+
44
+ private float noise_fsc(float i) {
45
+ float cosvalue = DegLutTables.cos(i * PConstants.PI);
46
+ return 0.5f * (1.0f - cosvalue);
47
+ }
48
+
49
+ /**
50
+ *
51
+ * @param x
52
+ * @param y
53
+ * @param z
54
+ * @return
55
+ */
56
+ @Override
57
+ public float noise(float x, float y, float z) {
58
+ if (perlin == null) {
59
+ if (perlinRandom == null) {
60
+ perlinRandom = new Random();
61
+ }
62
+ perlin = new float[PERLIN_SIZE + 1];
63
+ for (int i = 0; i < PERLIN_SIZE + 1; i++) {
64
+ perlin[i] = perlinRandom.nextFloat();
65
+ }
66
+ }
67
+
68
+ if (x < 0) {
69
+ x = -x;
70
+ }
71
+ if (y < 0) {
72
+ y = -y;
73
+ }
74
+ if (z < 0) {
75
+ z = -z;
76
+ }
77
+
78
+ int xi = (int) x, yi = (int) y, zi = (int) z;
79
+ float xf = x - xi;
80
+ float yf = y - yi;
81
+ float zf = z - zi;
82
+ float rxf, ryf;
83
+
84
+ float r = 0;
85
+ float ampl = 0.5f;
86
+
87
+ float n1, n2, n3;
88
+
89
+ for (int i = 0; i < perlin_octaves; i++) {
90
+ int of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB);
91
+
92
+ rxf = noise_fsc(xf);
93
+ ryf = noise_fsc(yf);
94
+
95
+ n1 = perlin[of & PERLIN_SIZE];
96
+ n1 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n1);
97
+ n2 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
98
+ n2 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n2);
99
+ n1 += ryf * (n2 - n1);
100
+
101
+ of += PERLIN_ZWRAP;
102
+ n2 = perlin[of & PERLIN_SIZE];
103
+ n2 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n2);
104
+ n3 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
105
+ n3 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n3);
106
+ n2 += ryf * (n3 - n2);
107
+
108
+ n1 += noise_fsc(zf) * (n2 - n1);
109
+
110
+ r += n1 * ampl;
111
+ ampl *= perlin_amp_falloff;
112
+ xi <<= 1;
113
+ xf *= 2;
114
+ yi <<= 1;
115
+ yf *= 2;
116
+ zi <<= 1;
117
+ zf *= 2;
118
+
119
+ if (xf >= 1.0f) {
120
+ xi++;
121
+ xf--;
122
+ }
123
+ if (yf >= 1.0f) {
124
+ yi++;
125
+ yf--;
126
+ }
127
+ if (zf >= 1.0f) {
128
+ zi++;
129
+ zf--;
130
+ }
131
+ }
132
+ return r;
133
+ }
134
+
135
+ @Override
136
+ public void noiseMode(NoiseMode mode) {
137
+
138
+ }
139
+
140
+ @Override
141
+ public void noiseDetail(int lod) {
142
+ if (lod > 0) {
143
+ perlin_octaves = lod;
144
+ }
145
+ }
146
+
147
+ @Override
148
+ public void noiseDetail(int lod, float falloff) {
149
+ if (lod > 0) {
150
+ perlin_octaves = lod;
151
+ }
152
+ if (falloff > 0) {
153
+ perlin_amp_falloff = falloff;
154
+ }
155
+ }
156
+
157
+ @Override
158
+ public void noiseSeed(long seed) {
159
+ if (perlinRandom == null) {
160
+ perlinRandom = new Random();
161
+ }
162
+ perlinRandom.setSeed(seed);
163
+ perlin = null;
164
+ }
165
+
166
+ @Override
167
+ public float noise(float x, float y, float z, float w) {
168
+ throw new UnsupportedOperationException("Not supported yet.");
169
+ }
170
+ }
@@ -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,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) 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
@@ -33,7 +33,6 @@ import org.jruby.runtime.ThreadContext;
33
33
  import org.jruby.runtime.builtin.IRubyObject;
34
34
  import monkstone.vecmath.JRender;
35
35
  import monkstone.vecmath.vec2.Vec2;
36
- import org.jruby.RubyNumeric;
37
36
 
38
37
  /**
39
38
  *
@@ -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) 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) 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
  }