Skip to content

Commit 82b3b3d

Browse files
committed
put renderer list with the renderers
1 parent 594f58e commit 82b3b3d

2 files changed

Lines changed: 35 additions & 15 deletions

File tree

core/src/processing/core/PConstants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.awt.Cursor;
2828
import java.awt.event.KeyEvent;
2929

30+
import processing.data.StringList;
31+
3032

3133
/**
3234
* Numbers shared throughout processing.core.
@@ -46,6 +48,15 @@ public interface PConstants {
4648

4749
// renderers known to processing.core
4850

51+
// List of renderers used inside PdePreprocessor
52+
static final StringList rendererList = new StringList(new String[] {
53+
"JAVA2D", "JAVA2D_2X",
54+
"P2D", "P2D_2X", "P3D", "P3D_2X", "OPENGL",
55+
"E2D", "FX2D", "FX2D_2X", // experimental
56+
"LWJGL.P2D", "LWJGL.P3D", // hmm
57+
"PDF" // no DXF because that's only for beginRaw()
58+
});
59+
4960
static final String JAVA2D = "processing.core.PGraphicsJava2D";
5061
static final String JAVA2D_2X = "processing.core.PGraphicsJava2D2X";
5162

java/src/processing/mode/java/preproc/PdePreprocessor.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import processing.app.Preferences;
3737
import processing.app.SketchException;
3838
import processing.core.PApplet;
39+
import processing.core.PConstants;
3940
import processing.mode.java.preproc.PdeLexer;
4041
import processing.mode.java.preproc.PdeRecognizer;
4142
import processing.mode.java.preproc.PdeTokenTypes;
@@ -170,14 +171,14 @@ public static enum Mode {
170171
"(?:^|\\s|;)size\\s*\\(\\s*([^\\s,]+)\\s*,\\s*([^\\s,\\)]+)\\s*,?\\s*([^\\)]*)\\s*\\)\\s*\\;";
171172
//"(?:^|\\s|;)size\\s*\\(\\s*(\\S+)\\s*,\\s*([^\\s,\\)]+),?\\s*([^\\)]*)\\s*\\)\\s*\\;";
172173

173-
174+
174175
private static final Pattern PUBLIC_CLASS =
175176
Pattern.compile("(^|;)\\s*public\\s+class\\s+\\S+\\s+extends\\s+PApplet", Pattern.MULTILINE);
176177
// Can't only match any 'public class', needs to be a PApplet
177178
// http://code.google.com/p/processing/issues/detail?id=551
178179
//Pattern.compile("(^|;)\\s*public\\s+class", Pattern.MULTILINE);
179180

180-
181+
181182
private static final Pattern FUNCTION_DECL =
182183
Pattern.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*" +
183184
"(void|int|float|double|String|char|byte)" +
@@ -290,7 +291,7 @@ static public String scrubComments(String what) {
290291
int index = 0;
291292
while (index < p.length) {
292293
// for any double slash comments, ignore until the end of the line
293-
if (!insideQuote &&
294+
if (!insideQuote &&
294295
(p[index] == '/') &&
295296
(index < p.length - 1) &&
296297
(p[index+1] == '/')) {
@@ -329,7 +330,7 @@ static public String scrubComments(String what) {
329330
} else if (p[index] == '"' && index > 0 && p[index-1] != '\\') {
330331
insideQuote = !insideQuote;
331332
index++;
332-
333+
333334
} else { // any old character, move along
334335
index++;
335336
}
@@ -518,10 +519,10 @@ public PreprocessorResult write(Writer out, String program,
518519
program = substituteUnicode(program);
519520
}
520521

521-
// For 0215, adding } as a legitimate prefix to the import (along with
522+
// For 0215, adding } as a legitimate prefix to the import (along with
522523
// newline and semicolon) for cases where a tab ends with } and an import
523524
// statement starts the next tab.
524-
final String importRegexp =
525+
final String importRegexp =
525526
"((?:^|;|\\})\\s*)(import\\s+)((?:static\\s+)?\\S+)(\\s*;)";
526527
final Pattern importPattern = Pattern.compile(importRegexp);
527528
String scrubbed = scrubComments(program);
@@ -551,9 +552,9 @@ public PreprocessorResult write(Writer out, String program,
551552
// Remove the import from the main program
552553
program = program.substring(0, start) + program.substring(stop);
553554
scrubbed = scrubbed.substring(0, start) + scrubbed.substring(stop);
554-
// Set the offset to start, because everything between
555+
// Set the offset to start, because everything between
555556
// start and stop has been deleted.
556-
offset = m.start();
557+
offset = m.start();
557558
}
558559
} while (found);
559560
// System.out.println("program now:");
@@ -566,13 +567,13 @@ public PreprocessorResult write(Writer out, String program,
566567
}
567568

568569
final PrintWriter stream = new PrintWriter(out);
569-
final int headerOffset =
570+
final int headerOffset =
570571
writeImports(stream, programImports, codeFolderImports);
571-
return new PreprocessorResult(mode, headerOffset + 2,
572+
return new PreprocessorResult(mode, headerOffset + 2,
572573
write(program, stream), programImports);
573574
}
574575

575-
576+
576577
static String substituteUnicode(String program) {
577578
// check for non-ascii chars (these will be/must be in unicode format)
578579
char p[] = program.toCharArray();
@@ -698,7 +699,7 @@ private String write(final String program, final PrintWriter stream)
698699

699700
return className;
700701
}
701-
702+
702703

703704
private PdeRecognizer createParser(final String program) {
704705
// create a lexer with the stream reader, and tell it to handle
@@ -885,17 +886,25 @@ protected void writeFooter(PrintWriter out, String className) {
885886
out.println(indent + "public int sketchHeight() { return " + sketchHeight + "; }");
886887
}
887888
}
888-
if (sketchRenderer != null && !hasMethod("sketchRenderer")) {
889+
if (sketchRenderer != null && !hasMethod("sketchRenderer")) {
889890
// Only include if it's a known renderer (otherwise it might be a variable)
891+
if (PConstants.rendererList.hasValue(sketchRenderer)) {
892+
/*
893+
}
890894
if (sketchRenderer.equals("P2D") ||
891895
sketchRenderer.equals("P2D_2X") ||
892896
sketchRenderer.equals("P3D") ||
893897
sketchRenderer.equals("P3D_3X") ||
894898
sketchRenderer.equals("OPENGL") ||
895899
sketchRenderer.equals("JAVA2D") ||
896-
sketchRenderer.equals("JAVA2D_2X") ||
900+
sketchRenderer.equals("JAVA2D_2X") ||
901+
sketchRenderer.equals("E2D") ||
902+
sketchRenderer.equals("FX2D") ||
903+
sketchRenderer.equals("FX2D_2X") ||
904+
sketchRenderer.equals("PDF") ||
897905
sketchRenderer.equals("LWJGL.P2D") ||
898906
sketchRenderer.equals("LWJGL.P3D")) {
907+
*/
899908
out.println(indent + "public String sketchRenderer() { return " + sketchRenderer + "; }");
900909
}
901910
}
@@ -952,7 +961,7 @@ public String[] getDefaultImports() {
952961
// These may change in-between (if the prefs panel adds this option)
953962
//String prefsLine = Preferences.get("preproc.imports");
954963
//return PApplet.splitTokens(prefsLine, ", ");
955-
return new String[] {
964+
return new String[] {
956965
"java.util.HashMap",
957966
"java.util.ArrayList",
958967
"java.io.File",

0 commit comments

Comments
 (0)