Skip to content

Commit ddd7f2c

Browse files
committed
sorting out multi-display, fullScreen(), param passing with surface...
1 parent 824e8f2 commit ddd7f2c

File tree

16 files changed

+212
-148
lines changed

16 files changed

+212
-148
lines changed

build/shared/lib/defaults.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ run.options.bits.macosx = 32
185185
# Index of the display to use for running sketches (starts at 1).
186186
# Kept this 1-indexed because older vesions of Processing were setting
187187
# the preference even before it was being used.
188-
run.display = 0
188+
# -1 means the default display, 0 means all displays
189+
run.display = -1
189190

190191
# set internally
191192
#run.window.bgcolor=

core/src/processing/core/PApplet.java

Lines changed: 125 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public class PApplet implements PConstants {
105105
//{
106106
/**
107107
* Full name of the Java version (i.e. 1.5.0_11).
108-
* Prior to 0125, this was only the first three digits.
109108
*/
110109
public static final String javaVersionName =
111110
System.getProperty("java.version");
@@ -690,11 +689,11 @@ public class PApplet implements PConstants {
690689

691690
static public final String ARGS_DISPLAY = "--display";
692691

693-
static public final String ARGS_BGCOLOR = "--bgcolor";
692+
static public final String ARGS_SPAN_DISPLAYS = "--span";
694693

695-
static public final String ARGS_FULL_SCREEN = "--full-screen";
694+
static public final String ARGS_WINDOW_COLOR = "--window-color";
696695

697-
static public final String ARGS_SPAN_SCREENS = "--span";
696+
static public final String ARGS_PRESENT = "--present";
698697

699698
static public final String ARGS_STOP_COLOR = "--stop-color";
700699

@@ -810,13 +809,20 @@ public void init() {
810809
boolean insideSettings;
811810

812811
String renderer = JAVA2D;
813-
int quality = 2;
812+
// int quality = 2;
813+
int smooth = 1;
814814
boolean fullScreen;
815-
boolean spanDisplays;
816-
int displayIndex;
815+
// boolean spanDisplays;
816+
int display; // set to SPAN when using all displays
817+
817818
String outputPath;
818819
OutputStream outputStream;
819820

821+
// Background default needs to be different from the default value in
822+
// PGraphics.backgroundColor, otherwise size(100, 100) bg spills over.
823+
// https://github.com/processing/processing/issues/2297
824+
int windowColor = 0xffDDDDDD;
825+
820826

821827
boolean insideSettings(Object... args) {
822828
if (insideSettings) {
@@ -839,42 +845,48 @@ void handleSettings() {
839845
insideSettings = true;
840846

841847
// Workaround for https://github.com/processing/processing/issues/3295
842-
// until we resolved https://github.com/processing/processing/issues/3296
848+
// until we resolve https://github.com/processing/processing/issues/3296
843849
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
844850
GraphicsDevice device = ge.getDefaultScreenDevice();
845851
GraphicsDevice[] devices = ge.getScreenDevices();
846-
// default or unparsed will be -1
847-
if (displayIndex >= 0 && displayIndex < devices.length) {
848-
device = devices[displayIndex];
852+
853+
// Default or unparsed will be -1, spanning will be 0, actual displays will
854+
// be numbered from 1 because it's too weird to say "display 0" in prefs.
855+
if (display > 0 && display <= devices.length) {
856+
device = devices[display-1];
849857
}
850858
DisplayMode displayMode = device.getDisplayMode();
851859
displayWidth = displayMode.getWidth();
852860
displayHeight = displayMode.getHeight();
853861

862+
// Here's where size(), fullScreen(), smooth(N) and noSmooth() might
863+
// be called, conjuring up the demons of various rendering configurations.
854864
settings();
865+
855866
insideSettings = false;
856867
}
857868

858869

859870
/** Override this method to call size() when not using the PDE. */
860871
public void settings() {
861-
size(DEFAULT_WIDTH, DEFAULT_HEIGHT, JAVA2D);
872+
// is this necessary? (doesn't appear to be, so removing)
873+
//size(DEFAULT_WIDTH, DEFAULT_HEIGHT, JAVA2D);
862874
}
863875

864876

865-
public int sketchWidth() {
877+
final public int sketchWidth() {
866878
//return DEFAULT_WIDTH;
867879
return width;
868880
}
869881

870882

871-
public int sketchHeight() {
883+
final public int sketchHeight() {
872884
//return DEFAULT_HEIGHT;
873885
return height;
874886
}
875887

876888

877-
public String sketchRenderer() {
889+
final public String sketchRenderer() {
878890
//return JAVA2D;
879891
return renderer;
880892
}
@@ -887,46 +899,55 @@ public String sketchRenderer() {
887899
// smoothing at any given time. It's also a bit like getFill() would return
888900
// true/false for whether fill was enabled, getFillColor() would return the
889901
// color itself. Or at least that's what I can recall at the moment. [fry]
890-
public int sketchQuality() {
891-
//return 2;
892-
return quality;
902+
// public int sketchQuality() {
903+
// //return 2;
904+
// return quality;
905+
// }
906+
// smoothing 1 is default.. 0 is none.. 2,4,8 depend on renderer
907+
final public int sketchSmooth() {
908+
return smooth;
893909
}
894910

895911

896-
public boolean sketchFullScreen() {
912+
final public boolean sketchFullScreen() {
897913
//return false;
898914
return fullScreen;
899915
}
900916

901917

902-
// Could be named 'screen' instead of display since it's the people using
903-
// full screen who will be looking for it. On the other hand, screenX/Y/Z
904-
// makes things confusing, and if 'displayIndex' exists...
905-
public boolean sketchSpanDisplays() {
906-
//return false;
907-
return spanDisplays;
908-
}
918+
// // Could be named 'screen' instead of display since it's the people using
919+
// // full screen who will be looking for it. On the other hand, screenX/Y/Z
920+
// // makes things confusing, and if 'displayIndex' exists...
921+
// public boolean sketchSpanDisplays() {
922+
// //return false;
923+
// return spanDisplays;
924+
// }
909925

910926

911-
// Or should this be sketchDisplayNum instead of sketchDisplayIndex?
912-
// (Index seems weird, but we don't use 'num' anywhere.)
913-
public int sketchDisplayIndex() {
914-
return displayIndex;
927+
// Using num instead of index since the latter usually refers 0-indexed lists
928+
// SPAN is used when using all displays
929+
final public int sketchDisplay() {
930+
return display;
915931
}
916932

917933

918-
public String sketchOutputPath() {
934+
final public String sketchOutputPath() {
919935
//return null;
920936
return outputPath;
921937
}
922938

923939

924-
public OutputStream sketchOutputStream() {
940+
final public OutputStream sketchOutputStream() {
925941
//return null;
926942
return outputStream;
927943
}
928944

929945

946+
final public int sketchWindowColor() {
947+
return windowColor;
948+
}
949+
950+
930951
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
931952

932953

@@ -935,6 +956,7 @@ public PGraphics getGraphics() {
935956
}
936957

937958

959+
// TODO should this join the sketchXxxx() functions specific to settings()?
938960
public void orientation(int which) {
939961
// ignore calls to the orientation command
940962
}
@@ -1485,6 +1507,16 @@ protected void resizeRenderer(int newWidth, int newHeight) {
14851507
*/
14861508

14871509

1510+
public void fullScreen(String renderer) {
1511+
1512+
}
1513+
1514+
1515+
public void fullScreen(String renderer, int display) {
1516+
1517+
}
1518+
1519+
14881520
/**
14891521
* ( begin auto-generated from size.xml )
14901522
*
@@ -9447,38 +9479,46 @@ void frameResized(int w, int h) {
94479479
* <PRE>
94489480
* Parameters useful for launching or also used by the PDE:
94499481
*
9450-
* --location=x,y upper-lefthand corner of where the applet
9451-
* should appear on screen. if not used,
9452-
* the default is to center on the main screen.
9482+
* --location=x,y Upper-lefthand corner of where the applet
9483+
* should appear on screen. If not used,
9484+
* the default is to center on the main screen.
9485+
*
9486+
* --present Presentation mode: blanks the entire screen and
9487+
* shows the sketch by itself. If the sketch is
9488+
* smaller than the screen, the background around it
9489+
* will use the --window-color setting.
94539490
*
9454-
* --full-screen put the applet into full screen "present" mode.
9491+
* --hide-stop Use to hide the stop button in situations where
9492+
* you don't want to allow users to exit. also
9493+
* see the FAQ on information for capturing the ESC
9494+
* key when running in presentation mode.
94559495
*
9456-
* --hide-stop use to hide the stop button in situations where
9457-
* you don't want to allow users to exit. also
9458-
* see the FAQ on information for capturing the ESC
9459-
* key when running in presentation mode.
9496+
* --stop-color=#xxxxxx Color of the 'stop' text used to quit an
9497+
* sketch when it's in present mode.
94609498
*
9461-
* --stop-color=#xxxxxx color of the 'stop' text used to quit an
9462-
* sketch when it's in present mode.
9499+
* --window-color=#xxxxxx Background color of the window. The color used
9500+
* around the sketch when it's smaller than the
9501+
* minimum window size for the OS, and the matte
9502+
* color when using 'present' mode.
94639503
*
9464-
* --bgcolor=#xxxxxx background color of the window.
9504+
* --sketch-path location of where to save files from functions
9505+
* like saveStrings() or saveFrame(). defaults to
9506+
* the folder that the java application was
9507+
* launched from, which means if this isn't set by
9508+
* the pde, everything goes into the same folder
9509+
* as processing.exe.
94659510
*
9466-
* --sketch-path location of where to save files from functions
9467-
* like saveStrings() or saveFrame(). defaults to
9468-
* the folder that the java application was
9469-
* launched from, which means if this isn't set by
9470-
* the pde, everything goes into the same folder
9471-
* as processing.exe.
9511+
* --display=n set what display should be used by this sketch.
9512+
* displays are numbered starting from 1.
94729513
*
9473-
* --display=n set what display should be used by this sketch.
9474-
* displays are numbered starting from 0.
9514+
* --span Makes the sketch full screen across all displays.
94759515
*
94769516
* Parameters used by Processing when running via the PDE
94779517
*
9478-
* --external set when the applet is being used by the PDE
9518+
* --external set when the applet is being used by the PDE
94799519
*
9480-
* --editor-location=x,y position of the upper-lefthand corner of the
9481-
* editor window, for placement of applet window
9520+
* --editor-location=x,y position of the upper-lefthand corner of the
9521+
* editor window, for placement of applet window
94829522
*
94839523
* All parameters *after* the sketch class name are passed to the sketch
94849524
* itself and available from its 'args' array while the sketch is running.
@@ -9555,13 +9595,13 @@ static protected void runSketchEDT(final String[] args,
95559595
int[] editorLocation = null;
95569596

95579597
String name = null;
9558-
int backgroundColor = 0;
9559-
//int stopColor = java.awt.Color.GRAY.getRGB();
9598+
int windowColor = 0;
95609599
int stopColor = 0xff808080;
95619600
boolean hideStop = false;
95629601

9563-
int displayIndex = -1; // -1 means use default, b/c numbered from 0
9564-
boolean fullScreen = false;
9602+
int displayIndex = -1; // use default
9603+
// boolean fullScreen = false;
9604+
boolean present = false;
95659605
boolean spanDisplays = false;
95669606

95679607
String param = null, value = null;
@@ -9584,12 +9624,12 @@ static protected void runSketchEDT(final String[] args,
95849624
System.err.println("Could not parse " + value + " for " + ARGS_DISPLAY);
95859625
}
95869626

9587-
} else if (param.equals(ARGS_BGCOLOR)) {
9627+
} else if (param.equals(ARGS_WINDOW_COLOR)) {
95889628
if (value.charAt(0) == '#' && value.length() == 7) {
95899629
value = value.substring(1);
9590-
backgroundColor = 0xff000000 | Integer.parseInt(value, 16);
9630+
windowColor = 0xff000000 | Integer.parseInt(value, 16);
95919631
} else {
9592-
System.err.println(ARGS_BGCOLOR + " should be a # followed by six digits");
9632+
System.err.println(ARGS_WINDOW_COLOR + " should be a # followed by six digits");
95939633
}
95949634

95959635
} else if (param.equals(ARGS_STOP_COLOR)) {
@@ -9608,10 +9648,10 @@ static protected void runSketchEDT(final String[] args,
96089648
}
96099649

96109650
} else {
9611-
if (args[argIndex].equals(ARGS_FULL_SCREEN)) {
9612-
fullScreen = true;
9651+
if (args[argIndex].equals(ARGS_PRESENT)) {
9652+
present = true;
96139653

9614-
} else if (args[argIndex].equals(ARGS_SPAN_SCREENS)) {
9654+
} else if (args[argIndex].equals(ARGS_SPAN_DISPLAYS)) {
96159655
spanDisplays = true;
96169656

96179657
} else if (args[argIndex].equals(ARGS_HIDE_STOP)) {
@@ -9673,15 +9713,19 @@ static protected void runSketchEDT(final String[] args,
96739713
// A handful of things that need to be set before init/start.
96749714
sketch.sketchPath = folder;
96759715

9676-
sketch.spanDisplays = spanDisplays;
9716+
// sketch.spanDisplays = spanDisplays;
96779717
// If spanning screens, that means we're also full screen.
9678-
fullScreen |= spanDisplays;
9718+
// fullScreen |= spanDisplays;
9719+
if (spanDisplays) {
9720+
displayIndex = SPAN;
9721+
// fullScreen = true;
9722+
}
96799723

9680-
// If the applet doesn't call for full screen, but the command line does,
9681-
// enable it. Conversely, if the command line does not, don't disable it.
9682-
// Query the applet to see if it wants to be full screen all the time.
9683-
//fullScreen |= sketch.sketchFullScreen();
9684-
sketch.fullScreen |= fullScreen;
9724+
// // If the applet doesn't call for full screen, but the command line does,
9725+
// // enable it. Conversely, if the command line does not, don't disable it.
9726+
// // Query the applet to see if it wants to be full screen all the time.
9727+
// //fullScreen |= sketch.sketchFullScreen();
9728+
// sketch.fullScreen |= fullScreen;
96859729

96869730
// Don't set 'args' to a zero-length array if it should be null [3.0a8]
96879731
if (args.length != argIndex + 1) {
@@ -9692,8 +9736,12 @@ static protected void runSketchEDT(final String[] args,
96929736

96939737
sketch.external = external;
96949738

9695-
PSurface surface =
9696-
sketch.initSurface(backgroundColor, displayIndex, fullScreen, spanDisplays);
9739+
if (windowColor != 0) {
9740+
sketch.windowColor = windowColor;
9741+
}
9742+
9743+
PSurface surface = sketch.initSurface();
9744+
// sketch.initSurface(windowColor, displayIndex, fullScreen, spanDisplays);
96979745

96989746
// Wait until the applet has figured out its width. In a static mode app,
96999747
// everything happens inside setup(), so this will be after setup() has
@@ -9708,7 +9756,7 @@ static protected void runSketchEDT(final String[] args,
97089756
}
97099757
}
97109758

9711-
if (fullScreen) {
9759+
if (present) {
97129760
if (hideStop) {
97139761
stopColor = 0; // they'll get the hint
97149762
}
@@ -9723,8 +9771,8 @@ static protected void runSketchEDT(final String[] args,
97239771
}
97249772

97259773

9726-
protected PSurface initSurface(int backgroundColor, int displayIndex,
9727-
boolean fullScreen, boolean spanDisplays) {
9774+
protected PSurface initSurface() {/*int backgroundColor, int displayNum,
9775+
boolean fullScreen, boolean spanDisplays) {*/
97289776
g = createPrimaryGraphics();
97299777
surface = g.createSurface();
97309778

@@ -9755,7 +9803,7 @@ private void deprecationWarning(String method) {
97559803
}
97569804
};
97579805

9758-
surface.initFrame(this, backgroundColor, displayIndex, fullScreen, spanDisplays);
9806+
surface.initFrame(this); //, backgroundColor, displayNum, fullScreen, spanDisplays);
97599807
surface.setTitle(getClass().getName());
97609808

97619809
} else {

0 commit comments

Comments
 (0)