Skip to content

Commit 42a6bbf

Browse files
committed
fix a bug in the caching mechanism and add PGraphics javadoc
1 parent 34de036 commit 42a6bbf

4 files changed

Lines changed: 72 additions & 6 deletions

File tree

core/api.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
public void setParent(PApplet parent)
23
public void setPrimary(boolean primary)
34
public void setPath(String path)
@@ -361,6 +362,8 @@
361362

362363
//
363364

365+
These are the methods found in PImage, which are inherited by PGraphics.
366+
364367
public PImage(Image)
365368
public Image getImage()
366369

core/src/processing/core/PGraphics.java

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
/**
3232
* Main graphics and rendering context, as well as the base API implementation.
33-
* <p>
33+
*
34+
* <h2>Subclassing and initializing PGraphics objects</h2>
3435
* Starting in release 0149, subclasses of PGraphics are handled differently.
3536
* The constructor for subclasses takes no parameters, instead a series of
3637
* functions are called by the hosting PApplet to specify its attributes.
37-
*
3838
* <ul>
3939
* <li>setParent(PApplet) - is called to specify the parent PApplet.
4040
* <li>setPrimary(boolean) - called with true if this PGraphics will be the
@@ -44,13 +44,65 @@
4444
* <li>setSize(int, int) - this is called last, at which point it's safe for
4545
* the renderer to complete its initialization routine.
4646
* </ul>
47-
*
4847
* The functions were broken out because of the growing number of parameters
4948
* such as these that might be used by a renderer, yet with the exception of
5049
* setSize(), it's not clear which will be necessary. So while the size could
5150
* be passed in to the constructor instead of a setSize() function, a function
5251
* would still be needed that would notify the renderer that it was time to
5352
* finish its initialization. Thus, setSize() simply does both.
53+
*
54+
* <h2>Know your rights: public vs. private methods</h2>
55+
* Methods that are protected are often subclassed by other renderers, however
56+
* they are not set 'public' because they shouldn't be part of the user-facing
57+
* public API accessible from PApplet. That is, we don't want sketches calling
58+
* textModeCheck() or vertexTexture() directly.
59+
*
60+
* <h2>Handling warnings and exceptions</h2>
61+
* Methods that are unavailable generally show a warning, unless their lack of
62+
* availability will soon cause another exception. For instance, if a method
63+
* like getMatrix() returns null because it is unavailable, an exception will
64+
* be thrown stating that the method is unavailable, rather than waiting for
65+
* the NullPointerException that will occur when the sketch tries to use that
66+
* method. As of release 0149, warnings will only be shown once, and exceptions
67+
* have been changed to warnings where possible.
68+
*
69+
* <h2>Using xxxxImpl() for subclassing smoothness</h2>
70+
* The xxxImpl() methods are generally renderer-specific handling for some
71+
* subset if tasks for a particular function (vague enough for you?) For
72+
* instance, imageImpl() handles drawing an image whose x/y/w/h and u/v coords
73+
* have been specified, and screen placement (independent of imageMode) has
74+
* been determined. There's no point in all renderers implementing the
75+
* <tt>if (imageMode == BLAH)</tt> placement/sizing logic, so that's handled
76+
* by PGraphics, which then calls imageImpl() once all that is figured out.
77+
*
78+
* <h2>His brother PImage</h2>
79+
* PGraphics subclasses PImage so that it can be drawn and manipulated in a
80+
* similar fashion. As such, many methods are inherited from PGraphics,
81+
* though many are unavailable: for instance, resize() is not likely to be
82+
* implemented; the same goes for mask(), depending on the situation.
83+
*
84+
* <h2>What's in PGraphics, what ain't</h2>
85+
* For the benefit of subclasses, as much as possible has been placed inside
86+
* PGraphics. For instance, bezier interpolation code and implementations of
87+
* the strokeCap() method (that simply sets the strokeCap variable) are
88+
* handled here. Features that will vary widely between renderers are located
89+
* inside the subclasses themselves. For instance, all matrix handling code
90+
* is per-renderer: Java 2D uses its own AffineTransform, P2D uses a PMatrix2D,
91+
* and PGraphics3D needs to keep continually update forward and reverse
92+
* transformations. A proper (future) OpenGL implementation will have all its
93+
* matrix madness handled by the card. Lighting also falls under this
94+
* category, however the base material property settings (emissive, specular,
95+
* et al.) are handled in PGraphics because they use the standard colorMode()
96+
* logic. Subclasses should override methods like emissiveFromCalc(), which
97+
* is a point where a valid color has been defined internally, and can be
98+
* applied in some manner based on the calcXxxx values.
99+
*
100+
* <h2>What's in the PGraphics documentation, what ain't</h2>
101+
* Some things are noted here, some things are not. For public API, always
102+
* refer to the <a href="http://processing.org/reference">reference</A>
103+
* on Processing.org for proper explanations. <b>No attempt has been made to
104+
* keep the javadoc up to date or complete.</b> It's an enormous task for
105+
* which we simply do not have the time.
54106
*/
55107
public class PGraphics extends PImage implements PConstants {
56108

core/src/processing/core/PImage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public java.awt.Image getImage() {
220220
* PGraphicsOpenGL.
221221
*/
222222
public void setCache(Object parent, Object storage) {
223+
if (cacheMap == null) cacheMap = new HashMap<Object, Object>();
223224
cacheMap.put(parent, storage);
224225
}
225226

@@ -233,6 +234,7 @@ public void setCache(Object parent, Object storage) {
233234
* @return data stored for the specified parent
234235
*/
235236
public Object getCache(Object parent) {
237+
if (cacheMap == null) return null;
236238
return cacheMap.get(parent);
237239
}
238240

@@ -242,7 +244,9 @@ public Object getCache(Object parent) {
242244
* @param parent The PGraphics object whose cache data should be removed
243245
*/
244246
public void removeCache(Object parent) {
245-
cacheMap.remove(parent);
247+
if (cacheMap != null) {
248+
cacheMap.remove(parent);
249+
}
246250
}
247251

248252

todo.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ X fix other instances of match() using the wrong array indices
4444
X add additional newline hack so that autoformat complains less
4545
X video capture problems with opengl (on mac os x)
4646
X http://dev.processing.org/bugs/show_bug.cgi?id=882
47+
X sketch export results in 100x100 default size, regardless of size() setting
48+
X http://dev.processing.org/bugs/show_bug.cgi?id=945
4749

4850
reference
4951
X do some edits on the "getting started" text
@@ -91,13 +93,18 @@ X update match(), write new reference for matchAll()
9193
this release: start specifically supporting libraries in the sketchbook folder via a 'libraries' subfolder
9294
next release: osx inside .app, sketchbook/libraries and sketchbook/tools folders, improved native support for libraries with better export.txt
9395

94-
96+
_ third tab throws NullPointerException
97+
_ http://dev.processing.org/bugs/show_bug.cgi?id=940
9598
_ sketch must be saved to use a constructor
9699
_ http://dev.processing.org/bugs/show_bug.cgi?id=929
97-
98100
_ get new version of examples and reference
99101

100102

103+
. . . .
104+
105+
106+
after 0149
107+
101108
major windows launcher problem
102109
_ windows jdk sometimes not getting picked up, even if it's there
103110
_ notes somewhere about choosing the right jvm...

0 commit comments

Comments
 (0)