Skip to content

Commit

Permalink
Fix #488.
Browse files Browse the repository at this point in the history
Clean up the footer writer section of the preprocessor for easier reading but also fix adding and looking for --full-screen which appears to have been left off at some point.
  • Loading branch information
sampottinger committed Jun 21, 2022
1 parent fa8eef0 commit ece11f9
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
5 changes: 5 additions & 0 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10277,6 +10277,7 @@ static public void runSketch(final String[] args,

int displayNum = -1; // use default
boolean present = false;
boolean fullScreen = false;
float uiScale = 0;

String param, value;
Expand Down Expand Up @@ -10343,6 +10344,9 @@ static public void runSketch(final String[] args,
} else if (args[argIndex].equals(ARGS_EXTERNAL)) {
external = true;

} else if (args[argIndex].equals(ARGS_FULL_SCREEN)) {
fullScreen = true;

} else {
name = args[argIndex];
break; // because of break, argIndex won't increment again
Expand Down Expand Up @@ -10418,6 +10422,7 @@ static public void runSketch(final String[] args,
sketch.display = displayNum;

sketch.present = present;
sketch.fullScreen = fullScreen;

// For 3.0.1, moved this above handleSettings() so that loadImage() can be
// used inside settings(). Sets a terrible precedent, but the alternative
Expand Down
20 changes: 14 additions & 6 deletions java/src/processing/mode/java/preproc/PdeParseTreeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -1227,21 +1227,29 @@ protected void writeMain(PrintWriterWithEditGen footerWriter,
footerWriter.addCodeLine(indent1 + "static public void main(String[] passedArgs) {");
footerWriter.addCode(indent2 + "String[] appletArgs = new String[] { ");



{ // assemble line with applet args
if (Preferences.getBoolean("export.application.fullscreen")) {
footerWriter.addCode("\"" + PApplet.ARGS_FULL_SCREEN + "\", ");
StringJoiner argsJoiner = new StringJoiner(", ");

boolean shouldFullScreen = Preferences.getBoolean("export.application.present");
shouldFullScreen = shouldFullScreen || Preferences.getBoolean("export.application.fullscreen");
if (shouldFullScreen) {
argsJoiner.add("\"" + PApplet.ARGS_FULL_SCREEN + "\"");

String bgColor = Preferences.get("run.present.bgcolor");
footerWriter.addCode("\"" + PApplet.ARGS_BGCOLOR + "=" + bgColor + "\", ");
argsJoiner.add("\"" + PApplet.ARGS_BGCOLOR + "=" + bgColor + "\"");

if (Preferences.getBoolean("export.application.stop")) {
String stopColor = Preferences.get("run.present.stop.color");
footerWriter.addCode("\"" + PApplet.ARGS_STOP_COLOR + "=" + stopColor + "\", ");
argsJoiner.add("\"" + PApplet.ARGS_STOP_COLOR + "=" + stopColor + "\"");
} else {
footerWriter.addCode("\"" + PApplet.ARGS_HIDE_STOP + "\", ");
argsJoiner.add("\"" + PApplet.ARGS_HIDE_STOP + "\"");
}
}
footerWriter.addCode("\"" + sketchName + "\"");

argsJoiner.add("\"" + sketchName + "\"");
footerWriter.addCode(argsJoiner.toString());
}

footerWriter.addCodeLine(" };");
Expand Down
10 changes: 9 additions & 1 deletion java/test/processing/mode/java/ParserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import java.util.Optional;

import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;

import processing.app.Preferences;
import processing.app.SketchException;
import processing.mode.java.preproc.PreprocessorResult;
import processing.mode.java.preproc.PdePreprocessIssueException;
Expand All @@ -25,6 +27,11 @@ public static void init() {
ProcessingTestUtil.init();
}

@Before
public void before() {
Preferences.setBoolean("export.application.fullscreen", false);
}

static void expectRecognitionException(final String id,
final int expectedLine) {

Expand Down Expand Up @@ -432,7 +439,8 @@ public void testMultilineStringClass() {

@Test
public void testMultiMultilineString() {
expectGood("multimultilinestr");
Preferences.setBoolean("export.application.fullscreen", true);
expectGood("fullscreen_export");
}

}
39 changes: 39 additions & 0 deletions java/test/resources/fullscreen_export.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;

import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class fullscreen_export extends PApplet {

int x = 0;

public void setup() {
background(0);
noStroke();
fill(102);
}

public void draw() {
rect(x, height*0.2f, 1, height*0.6f);
x = x + 2;
}


static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "--full-screen", "--bgcolor=null", "--hide-stop", "fullscreen_export" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
12 changes: 12 additions & 0 deletions java/test/resources/fullscreen_export.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
int x = 0;

void setup() {
background(0);
noStroke();
fill(102);
}

void draw() {
rect(x, height*0.2, 1, height*0.6);
x = x + 2;
}

0 comments on commit ece11f9

Please sign in to comment.