Skip to content
Browse files

Expose PConstants on Processing prototype, don't keep mirror of PCons…

…tants in rewrite-pconstants.js
  • Loading branch information...
1 parent d60640d commit f1890393cf03991a688ca8f88a46b467629d872c David Humphrey committed Aug 15, 2011
Showing with 25 additions and 310 deletions.
  1. +4 −1 Makefile
  2. +3 −2 processing.js
  3. +18 −307 tools/rewrite-pconstants.js
View
5 Makefile
@@ -118,7 +118,10 @@ extensions: release-dir
$(PJS_RELEASE_SRC): $(PJS_SRC) release-dir
@@echo "Creating $(PJS_RELEASE_SRC)..."
@@$(call compile,$(PJS_SRC),$(RELEASE_DIR)/closurecompile.out,--compilation_level WHITESPACE_ONLY)
- @@$$JSSHELL $(TOOLS_DIR)/rewrite-pconstants.js < $(RELEASE_DIR)/closurecompile.out > $(RELEASE_DIR)/processing.js-no-pconstants
+ @@$$JSSHELL -f $(TOOLS_DIR)/fake-dom.js \
+ -f $(PJS_SRC) \
+ $(TOOLS_DIR)/rewrite-pconstants.js < $(RELEASE_DIR)/closurecompile.out > \
+ $(RELEASE_DIR)/processing.js-no-pconstants
@@$(TOOLS_DIR)/jsbeautify.py $(JSSHELL) $(RELEASE_DIR)/processing.js-no-pconstants > $(PJS_RELEASE_SRC)
@@rm -f $(RELEASE_DIR)/closurecompile.out
@@rm -f $(RELEASE_DIR)/processing.js-no-pconstants
View
5 processing.js
@@ -59,8 +59,8 @@
/* Browsers fixes end */
/**
- * NOTE: keep this in sync with tools/rewrite-pconstants.js. Also, use full
- * symbolic names (PConstants.X vs. 0) in code below, since we rewrite on release.
+ * NOTE: in releases we replace symbolic PConstants.* names with their values.
+ * Using PConstants.* in code below is fine. See tools/rewrite-pconstants.js.
*/
var PConstants = {
X: 0,
@@ -1231,6 +1231,7 @@
defaultScope.HashMap = HashMap;
defaultScope.PVector = PVector;
defaultScope.ObjectIterator = ObjectIterator;
+ defaultScope.PConstants = PConstants;
//defaultScope.PImage = PImage; // TODO
//defaultScope.PShape = PShape; // TODO
//defaultScope.PShapeSVG = PShapeSVG; // TODO
View
325 tools/rewrite-pconstants.js
@@ -1,320 +1,31 @@
/**
* Rewrites PConstants from symbolic names to values for space/size.
*
- * Usage: $JSSHELL rewrite-pconstants.js < processing.js
- *
- * PConstants lifted from procesing.js. Changes there should get mirrored
- * here. The following changes have been made:
- *
- * - quotes are doubled ( "'..'"), so strings like 'foo' are returned vs. foo
- * - keys with values longer than the symbolic name are commented out.
+ * Usage: $JSSHELL -f fake-dom.js -f ../processing.js rewrite-pconstants.js < processing.js
*/
-var PConstants = {
- X: 0,
- Y: 1,
- Z: 2,
-
- R: 3,
- G: 4,
- B: 5,
- A: 6,
-
- U: 7,
- V: 8,
-
- NX: 9,
- NY: 10,
- NZ: 11,
-
- EDGE: 12,
-
- // Stroke
- SR: 13,
- SG: 14,
- SB: 15,
- SA: 16,
-
- SW: 17,
-
- // Transformations (2D and 3D)
- TX: 18,
- TY: 19,
- TZ: 20,
-
- VX: 21,
- VY: 22,
- VZ: 23,
- VW: 24,
-
- // Material properties
- AR: 25,
- AG: 26,
- AB: 27,
-
- DR: 3,
- DG: 4,
- DB: 5,
- DA: 6,
-
- SPR: 28,
- SPG: 29,
- SPB: 30,
-
- SHINE: 31,
-
- ER: 32,
- EG: 33,
- EB: 34,
-
- BEEN_LIT: 35,
-
- VERTEX_FIELD_COUNT: 36,
-
- // Renderers
- P2D: 1,
- JAVA2D: 1,
- WEBGL: 2,
- P3D: 2,
- OPENGL: 2,
- PDF: 0,
- DXF: 0,
-
- // Platform IDs
- OTHER: 0,
- WINDOWS: 1,
- MAXOSX: 2,
- LINUX: 3,
-
- EPSILON: 0.0001,
-
- MAX_FLOAT: 3.4028235e+38,
- MIN_FLOAT: -3.4028235e+38,
- MAX_INT: 2147483647,
- MIN_INT: -2147483648,
-
-// Shorter to leave these as symbols
-// PI: Math.PI,
-// TWO_PI: 2 * Math.PI,
-// HALF_PI: Math.PI / 2,
-// THIRD_PI: Math.PI / 3,
- QUARTER_PI: Math.PI / 4,
-
- DEG_TO_RAD: Math.PI / 180,
- RAD_TO_DEG: 180 / Math.PI,
-
-// This one expands in a buggy way...
-// WHITESPACE: "' \t\n\r\f\u00A0'",
- // Color modes
- RGB: 1,
- ARGB: 2,
- HSB: 3,
- ALPHA: 4,
- CMYK: 5,
+var regexPConstants = /(PConstants)\s*\.([a-zA-Z0-9_]+)/g,
+ PConstants = Processing.prototype.PConstants,
+ line,
+ undefined;
- // Image file types
- TIFF: 0,
- TARGA: 1,
- JPEG: 2,
- GIF: 3,
-
- // Filter/convert types
- BLUR: 11,
- GRAY: 12,
- INVERT: 13,
- OPAQUE: 14,
- POSTERIZE: 15,
- THRESHOLD: 16,
- ERODE: 17,
- DILATE: 18,
-
- // Blend modes
- REPLACE: 0,
- BLEND: 1 << 0,
- ADD: 1 << 1,
- SUBTRACT: 1 << 2,
- LIGHTEST: 1 << 3,
- DARKEST: 1 << 4,
- DIFFERENCE: 1 << 5,
- EXCLUSION: 1 << 6,
- MULTIPLY: 1 << 7,
- SCREEN: 1 << 8,
- OVERLAY: 1 << 9,
- HARD_LIGHT: 1 << 10,
- SOFT_LIGHT: 1 << 11,
- DODGE: 1 << 12,
- BURN: 1 << 13,
-
- // Color component bit masks
- ALPHA_MASK: 0xff000000,
- RED_MASK: 0x00ff0000,
- GREEN_MASK: 0x0000ff00,
- BLUE_MASK: 0x000000ff,
-
- // Projection matrices
- CUSTOM: 0,
- ORTHOGRAPHIC: 2,
- PERSPECTIVE: 3,
-
- // Shapes
- POINT: 2,
- POINTS: 2,
- LINE: 4,
- LINES: 4,
- TRIANGLE: 8,
- TRIANGLES: 9,
- TRIANGLE_STRIP: 10,
- TRIANGLE_FAN: 11,
- QUAD: 16,
- QUADS: 16,
- QUAD_STRIP: 17,
- POLYGON: 20,
- PATH: 21,
- RECT: 30,
- ELLIPSE: 31,
- ARC: 32,
- SPHERE: 40,
- BOX: 41,
-
- GROUP: 0,
- PRIMITIVE: 1,
- //PATH: 21, // shared with Shape PATH
- GEOMETRY: 3,
-
- // Shape Vertex
- VERTEX: 0,
- BEZIER_VERTEX: 1,
- CURVE_VERTEX: 2,
- BREAK: 3,
- CLOSESHAPE: 4,
-
- // Shape closing modes
- OPEN: 1,
- CLOSE: 2,
-
- // Shape drawing modes
- CORNER: 0, // Draw mode convention to use (x, y) to (width, height)
- CORNERS: 1, // Draw mode convention to use (x1, y1) to (x2, y2) coordinates
- RADIUS: 2, // Draw mode from the center, and using the radius
- CENTER_RADIUS: 2, // Deprecated! Use RADIUS instead
- CENTER: 3, // Draw from the center, using second pair of values as the diameter
- DIAMETER: 3, // Synonym for the CENTER constant. Draw from the center
- CENTER_DIAMETER: 3, // Deprecated! Use DIAMETER instead
-
- // Text vertical alignment modes
- BASELINE: 0, // Default vertical alignment for text placement
- TOP: 101, // Align text to the top
- BOTTOM: 102, // Align text from the bottom, using the baseline
-
- // UV Texture coordinate modes
- NORMAL: 1,
- NORMALIZED: 1,
- IMAGE: 2,
-
- // Text placement modes
- MODEL: 4,
- SHAPE: 5,
-
- // Stroke modes
- SQUARE: "'butt'",
- ROUND: "'round'",
- PROJECT: "'square'",
- MITER: "'miter'",
- BEVEL: "'bevel'",
-
- // Lighting modes
- AMBIENT: 0,
- DIRECTIONAL: 1,
- //POINT: 2, Shared with Shape constant
- SPOT: 3,
-
- // Key constants
-
- // Both key and keyCode will be equal to these values
- BACKSPACE: 8,
- TAB: 9,
- ENTER: 10,
- RETURN: 13,
- ESC: 27,
- DELETE: 127,
- CODED: 0xffff,
-
- // p.key will be CODED and p.keyCode will be this value
- SHIFT: 16,
- CONTROL: 17,
- ALT: 18,
- CAPSLK: 20,
- PGUP: 33,
- PGDN: 34,
- END: 35,
- HOME: 36,
- LEFT: 37,
- UP: 38,
- RIGHT: 39,
- DOWN: 40,
- F1: 112,
- F2: 113,
- F3: 114,
- F4: 115,
- F5: 116,
- F6: 117,
- F7: 118,
- F8: 119,
- F9: 120,
- F10: 121,
- F11: 122,
- F12: 123,
- NUMLK: 144,
- META: 157,
- INSERT: 155,
-
- // Cursor types
- ARROW: "'default'",
- CROSS: "'crosshair'",
- HAND: "'pointer'",
- MOVE: "'move'",
- TEXT: "'text'",
- WAIT: "'wait'",
-// too long
-// NOCURSOR: "url('data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), auto",
-
- // Hints
- DISABLE_OPENGL_2X_SMOOTH: 1,
- ENABLE_OPENGL_2X_SMOOTH: -1,
- ENABLE_OPENGL_4X_SMOOTH: 2,
- ENABLE_NATIVE_FONTS: 3,
- DISABLE_DEPTH_TEST: 4,
- ENABLE_DEPTH_TEST: -4,
- ENABLE_DEPTH_SORT: 5,
- DISABLE_DEPTH_SORT: -5,
- DISABLE_OPENGL_ERROR_REPORT: 6,
- ENABLE_OPENGL_ERROR_REPORT: -6,
- ENABLE_ACCURATE_TEXTURES: 7,
- DISABLE_ACCURATE_TEXTURES: -7,
- HINT_COUNT: 10,
+while((line = readline()) !== null) {
+ line = line.replace(regexPConstants, function(str, g1, g2) {
+ // Skip native methods on the prototype
+ var val = PConstants.hasOwnProperty(g2) ? PConstants[g2] : undefined;
- // PJS defined constants
- SINCOS_LENGTH: 720, // every half degree
- PRECISIONB: 15, // fixed point precision is limited to 15 bits!!
- PRECISIONF: 1 << 15,
- PREC_MAXVAL: (1 << 15) - 1,
- PREC_ALPHA_SHIFT: 24 - 15,
- PREC_RED_SHIFT: 16 - 15,
- NORMAL_MODE_AUTO: 0,
- NORMAL_MODE_SHAPE: 1,
- NORMAL_MODE_VERTEX: 2,
- MAX_LIGHTS: 8
-};
+ // Wrap strings in quotes
+ if (typeof val === 'string') {
+ val = "'" + val + "'";
+ }
-regexPConstants = /(PConstants)\s*\.([a-zA-Z0-9_]+)/g
+ // Don't shorten if it makes it longer
+ if ( ('' + val).length > ('PConstants.' + g2).length ) {
+ val = str;
+ }
-// Read js file
-var line, undefined;
-while((line = readline()) !== null) {
- line = line.replace(regexPConstants, function(str, p1, p2, offset, s) {
- // Skip native methods on the prototype
- var val = PConstants.hasOwnProperty(p2) ? PConstants[p2] : undefined;
return val === undefined ? str : val;
});
+
print(line);
}

0 comments on commit f189039

Please sign in to comment.
Something went wrong with that request. Please try again.