mirror of
https://github.com/processing/processing4.git
synced 2026-01-28 02:41:08 +01:00
Finish fix of preproc handeling of smooth.
Fixes #149 as reported by @benfry.
This commit is contained in:
@@ -75,6 +75,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
private String sketchWidth;
|
||||
private String sketchHeight;
|
||||
private String pixelDensity;
|
||||
private String smoothParam;
|
||||
private String sketchRenderer = null;
|
||||
private String sketchOutputFilename = null;
|
||||
|
||||
@@ -82,6 +83,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
private boolean pixelDensityRequiresRewrite = false;
|
||||
private boolean sizeIsFullscreen = false;
|
||||
private boolean noSmoothRequiresRewrite = false;
|
||||
private boolean smoothRequiresRewrite = false;
|
||||
private RewriteResult headerResult;
|
||||
private RewriteResult footerResult;
|
||||
|
||||
@@ -317,6 +319,8 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
handlePixelDensityCall(ctx);
|
||||
} else if (NO_SMOOTH_METHOD_NAME.equals(methodName)) {
|
||||
handleNoSmoothCall(ctx);
|
||||
} else if (SMOOTH_METHOD_NAME.equals(methodName)) {
|
||||
handleSmoothCall(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,6 +628,20 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
if (argsContext.getChildCount() > 5) {
|
||||
sketchOutputFilename = argsContext.getChild(6).getText();
|
||||
}
|
||||
|
||||
if (argsContext.getChildCount() > 7) {
|
||||
pdeParseTreeErrorListenerMaybe.ifPresent((listener) -> {
|
||||
Token token = ctx.getStart();
|
||||
int line = token.getLine();
|
||||
int charOffset = token.getCharPositionInLine();
|
||||
|
||||
listener.onError(new PdePreprocessIssue(
|
||||
line,
|
||||
charOffset,
|
||||
PreprocessIssueMessageSimplifier.getLocalStr("editor.status.bad.size")
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (isFullscreen) {
|
||||
@@ -669,6 +687,38 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
noSmoothRequiresRewrite = true;
|
||||
}
|
||||
|
||||
protected void handleSmoothCall(ParserRuleContext ctx) {
|
||||
// Check that this is a call for processing and not a user defined size method.
|
||||
if (!calledFromGlobalOrSetup(ctx)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ParseTree argsContext = ctx.getChild(2);
|
||||
if (argsContext.getChildCount() > 0) {
|
||||
smoothParam = argsContext.getChild(0).getText();
|
||||
} else {
|
||||
smoothParam = "";
|
||||
}
|
||||
|
||||
if (argsContext.getChildCount() > 2) {
|
||||
pdeParseTreeErrorListenerMaybe.ifPresent((listener) -> {
|
||||
Token token = ctx.getStart();
|
||||
int line = token.getLine();
|
||||
int charOffset = token.getCharPositionInLine();
|
||||
|
||||
listener.onError(new PdePreprocessIssue(
|
||||
line,
|
||||
charOffset,
|
||||
PreprocessIssueMessageSimplifier.getLocalStr("editor.status.bad.smooth")
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
delete(ctx.start, ctx.stop);
|
||||
insertAfter(ctx.stop, "/* smooth commented out by preprocessor */");
|
||||
smoothRequiresRewrite = true;
|
||||
}
|
||||
|
||||
protected boolean calledFromGlobalOrSetup(ParserRuleContext callContext) {
|
||||
ParserRuleContext outerContext = callContext.getParent()
|
||||
.getParent()
|
||||
@@ -1017,6 +1067,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
boolean noRewriteRequired = !sizeRequiresRewrite;
|
||||
noRewriteRequired = noRewriteRequired && !pixelDensityRequiresRewrite;
|
||||
noRewriteRequired = noRewriteRequired && !noSmoothRequiresRewrite;
|
||||
noRewriteRequired = noRewriteRequired && !smoothRequiresRewrite;
|
||||
if (noRewriteRequired) {
|
||||
return;
|
||||
}
|
||||
@@ -1060,6 +1111,10 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
settingsInner.add("noSmooth();");
|
||||
}
|
||||
|
||||
if (smoothRequiresRewrite) {
|
||||
settingsInner.add(String.format("smooth(%s);", smoothParam));
|
||||
}
|
||||
|
||||
String newCode = String.format(settingsOuterTemplate, settingsInner.toString());
|
||||
|
||||
classBodyWriter.addEmptyLine();
|
||||
|
||||
@@ -370,7 +370,7 @@ public class ParserTests {
|
||||
expectGood("nosmooth");
|
||||
}
|
||||
|
||||
/*@Test
|
||||
@Test
|
||||
public void testSmooth() {
|
||||
expectGood("smoothnoparam");
|
||||
}
|
||||
@@ -378,6 +378,6 @@ public class ParserTests {
|
||||
@Test
|
||||
public void testSmoothWithParam() {
|
||||
expectGood("smoothparam");
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class bug315g extends PApplet {
|
||||
|
||||
public void setup() {
|
||||
/* size commented out by preprocessor */;
|
||||
smooth();
|
||||
/* smooth commented out by preprocessor */;
|
||||
int y;
|
||||
y = 60;
|
||||
int d;
|
||||
@@ -25,7 +25,8 @@ ellipse(75, y, d, d);
|
||||
noLoop();
|
||||
}
|
||||
|
||||
public void settings() { size(480,120); }
|
||||
public void settings() { size(480,120);
|
||||
smooth();}
|
||||
|
||||
static public void main(String[] passedArgs) {
|
||||
String[] appletArgs = new String[] { "bug315g" };
|
||||
|
||||
@@ -14,28 +14,22 @@ import java.io.IOException;
|
||||
|
||||
public class smoothnoparam extends PApplet {
|
||||
|
||||
public void setup() {
|
||||
/* size commented out by preprocessor */;
|
||||
/* smooth commented out by preprocessor */;
|
||||
public void setup(){
|
||||
/* size commented out by preprocessor */;
|
||||
/* smooth commented out by preprocessor */;
|
||||
}
|
||||
|
||||
@Override public void draw() {
|
||||
background(0);
|
||||
fill(255,0,0);
|
||||
ellipse(100,100,100,100);
|
||||
fill(0,255,0);
|
||||
ellipse(150,150,100,100);
|
||||
}
|
||||
|
||||
class Test {
|
||||
private void draw() {}
|
||||
public void draw(){
|
||||
background(0);
|
||||
fill(255,0,0);
|
||||
ellipse(100,100,100,100);
|
||||
fill(0,255,0);
|
||||
ellipse(150,150,100,100);
|
||||
}
|
||||
|
||||
|
||||
public void settings() {
|
||||
size(300,300, P2D);
|
||||
smooth();
|
||||
}
|
||||
public void settings() { size(300, 300, P2D);
|
||||
smooth(); }
|
||||
|
||||
static public void main(String[] passedArgs) {
|
||||
String[] appletArgs = new String[] { "smoothnoparam" };
|
||||
|
||||
@@ -14,28 +14,22 @@ import java.io.IOException;
|
||||
|
||||
public class smoothparam extends PApplet {
|
||||
|
||||
public void setup() {
|
||||
/* size commented out by preprocessor */;
|
||||
/* smooth commented out by preprocessor */;
|
||||
public void setup(){
|
||||
/* size commented out by preprocessor */;
|
||||
/* smooth commented out by preprocessor */;
|
||||
}
|
||||
|
||||
@Override public void draw() {
|
||||
background(0);
|
||||
fill(255,0,0);
|
||||
ellipse(100,100,100,100);
|
||||
fill(0,255,0);
|
||||
ellipse(150,150,100,100);
|
||||
}
|
||||
|
||||
class Test {
|
||||
private void draw() {}
|
||||
public void draw(){
|
||||
background(0);
|
||||
fill(255,0,0);
|
||||
ellipse(100,100,100,100);
|
||||
fill(0,255,0);
|
||||
ellipse(150,150,100,100);
|
||||
}
|
||||
|
||||
|
||||
public void settings() {
|
||||
size(300,300, P2D);
|
||||
smooth(4);
|
||||
}
|
||||
public void settings() { size(300, 300, P2D);
|
||||
smooth(4); }
|
||||
|
||||
static public void main(String[] passedArgs) {
|
||||
String[] appletArgs = new String[] { "smoothparam" };
|
||||
|
||||
Reference in New Issue
Block a user