From 4bfd64c54c732938914ac115b561664266a7cfa2 Mon Sep 17 00:00:00 2001 From: benfry Date: Fri, 13 May 2005 07:06:18 +0000 Subject: [PATCH] fixes to PApplet.main() so that applets run as applications --- app/Runner.java | 2 +- core/PApplet.java | 142 ++++++++++++++++++++++++---------------------- core/todo.txt | 16 ++++-- todo.txt | 2 +- 4 files changed, 86 insertions(+), 76 deletions(-) diff --git a/app/Runner.java b/app/Runner.java index 134b78671..620700062 100644 --- a/app/Runner.java +++ b/app/Runner.java @@ -122,7 +122,7 @@ public class Runner implements MessageConsumer { params.add(PApplet.ARGS_EXTERNAL); params.add(PApplet.ARGS_PRESENT); - params.add(PApplet.ARGS_PRESENT_BGCOLOR + "=" + + params.add(PApplet.ARGS_BGCOLOR + "=" + Preferences.get("run.present.bgcolor")); params.add(PApplet.ARGS_DISPLAY + "=" + Preferences.get("run.display")); diff --git a/core/PApplet.java b/core/PApplet.java index 646b1abf1..2f340ce26 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -350,7 +350,7 @@ public class PApplet extends Applet static public final String ARGS_PRESENT = "--present"; - static public final String ARGS_PRESENT_BGCOLOR = "--present-color"; + static public final String ARGS_BGCOLOR = "--bgcolor"; static public final String ARGS_PRESENT_STOP_COLOR = "--present-stop-color"; @@ -5224,7 +5224,7 @@ v PApplet.this.stop(); * --present put the applet into full screen presentation * mode. requires java 1.4. * - * --present-color background color of the presentation window + * --bgcolor=#xxxxxx background color of the window * * --sketch-folder location of where to save files from functions * like saveStrings() or saveFrame(). defaults to @@ -5263,7 +5263,7 @@ v PApplet.this.stop(); String folder = System.getProperty("user.dir"); String name = null; boolean present = false; - Color presentColor = Color.BLACK; + Color backgroundColor = Color.BLACK; Color stopColor = Color.GRAY; GraphicsDevice displayDevice = null; @@ -5296,9 +5296,9 @@ v PApplet.this.stop(); "using the default display instead."); } - } else if (param.equals(ARGS_PRESENT_BGCOLOR)) { + } else if (param.equals(ARGS_BGCOLOR)) { if (value.charAt(0) == '#') value = value.substring(1); - presentColor = new Color(Integer.parseInt(value, 16)); + backgroundColor = new Color(Integer.parseInt(value, 16)); } else if (param.equals(ARGS_PRESENT_STOP_COLOR)) { if (value.charAt(0) == '#') value = value.substring(1); @@ -5326,18 +5326,23 @@ v PApplet.this.stop(); argIndex++; } - Frame frame = null; //new Frame(); + if (displayDevice == null) { + GraphicsEnvironment environment = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + displayDevice = environment.getDefaultScreenDevice(); + } + + Frame frame = new Frame(displayDevice.getDefaultConfiguration()); + /* + Frame frame = null; if (displayDevice != null) { - //GraphicsConfiguration gc = displayDevice.getDefaultConfiguration(); - //frame = new Frame(gc); frame = new Frame(displayDevice.getDefaultConfiguration()); - //println(displayDevice.getDefaultConfiguration()); } else { frame = new Frame(); } + */ - Dimension screen = - Toolkit.getDefaultToolkit().getScreenSize(); + Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); frame.setResizable(false); // remove the grow box //frame.pack(); // get insets. get more. @@ -5362,17 +5367,14 @@ v PApplet.this.stop(); if (present) { frame.setUndecorated(true); - frame.setBackground(presentColor); - //println("background color should be " + presentColor); + frame.setBackground(backgroundColor); displayDevice.setFullScreenWindow(frame); frame.add(applet); Dimension fullscreen = frame.getSize(); - //System.out.println("frame size is " + fullscreen); applet.setBounds((fullscreen.width - applet.width) / 2, (fullscreen.height - applet.height) / 2, applet.width, applet.height); - //println("applet bounds now " + applet.getBounds()); if (external) { Label label = new Label("stop"); @@ -5401,65 +5403,68 @@ v PApplet.this.stop(); } } else { // if not presenting - // can't do this earlier cuz present mode don't like it + // can't do pack earlier cuz present mode don't like it frame.pack(); + Insets insets = frame.getInsets(); + + int windowW = + Math.max(applet.width, 120) + insets.left + insets.right; + int windowH = + Math.max(applet.height, 120) + insets.top + insets.bottom; + + frame.setSize(windowW, windowH); + + if (location != null) { + // a specific location was received from PdeRuntime + // (applet has been run more than once, user placed window) + frame.setLocation(location[0], location[1]); + + } else if (external) { + int locationX = editorLocation[0] - 20; + int locationY = editorLocation[1]; + + if (locationX - windowW > 10) { + // if it fits to the left of the window + frame.setLocation(locationX - windowW, locationY); + + } else { // doesn't fit + // if it fits inside the editor window, + // offset slightly from upper lefthand corner + // so that it's plunked inside the text area + locationX = editorLocation[0] + 66; + locationY = editorLocation[1] + 66; + + if ((locationX + windowW > screen.width - 33) || + (locationY + windowH > screen.height - 33)) { + // otherwise center on screen + locationX = (screen.width - windowW) / 2; + locationY = (screen.height - windowH) / 2; + } + frame.setLocation(locationX, locationY); + } + } else { // just center on screen + frame.setLocation((screen.width - applet.width) / 2, + (screen.height - applet.height) / 2); + } + + frame.setLayout(null); + frame.add(applet); + + if (backgroundColor == Color.BLACK) { + // this means no bg color unless specified + backgroundColor = SystemColor.control; + } + frame.setBackground(backgroundColor); + + int usableWindowH = windowH - insets.top - insets.bottom; + applet.setBounds((windowW - applet.width)/2, + insets.top + (usableWindowH - applet.height)/2, + windowW, windowH); if (external) { - Insets insets = frame.getInsets(); // does pack() first above - - int windowW = - Math.max(applet.width, 120) + insets.left + insets.right; - int windowH = - Math.max(applet.height, 120) + insets.top + insets.bottom; - frame.setSize(windowW, windowH); - - if (location != null) { - // a specific location was received from PdeRuntime - // (applet has been run more than once, user placed window) - frame.setLocation(location[0], location[1]); - - } else { - int locationX = editorLocation[0] - 20; - int locationY = editorLocation[1]; - - if (locationX - windowW > 10) { - // if it fits to the left of the window - frame.setLocation(locationX - windowW, locationY); - - } else { - // if it fits inside the editor window, - // offset slightly from upper lefthand corner - // so that it's plunked inside the text area - locationX = editorLocation[0] + 66; - locationY = editorLocation[1] + 66; - - if ((locationX + windowW > screen.width - 33) || - (locationY + windowH > screen.height - 33)) { - // otherwise center on screen - locationX = (screen.width - windowW) / 2; - locationY = (screen.height - windowH) / 2; - } - frame.setLocation(locationX, locationY); - } - } - - frame.setLayout(null); - frame.add(applet); - frame.setBackground(SystemColor.control); - int usableWindowH = windowH - insets.top - insets.bottom; - applet.setBounds((windowW - applet.width)/2, - insets.top + (usableWindowH - applet.height)/2, - windowW, windowH); applet.setupExternal(frame); } else { // !external - frame.setLayout(new BorderLayout()); - frame.add(applet, BorderLayout.CENTER); - //frame.pack(); // is this necessary? - - frame.setLocation((screen.width - applet.width) / 2, - (screen.height - applet.height) / 2); - frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); @@ -5467,6 +5472,7 @@ v PApplet.this.stop(); }); } + // all set for rockin frame.show(); } diff --git a/core/todo.txt b/core/todo.txt index 5f325a623..b026af9ca 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -2,6 +2,12 @@ X change to synchronization to hopefully fix some update issues X curveVertex() problem in P2D when > 128 points fixed _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1115856359;start=0 +X for present mode, need to set a default display +X currently crashes if only --present is specified w/o --display +o make the 1.4 code in PApplet load via reflection +X doesn't appear necessary with 1.3 applets +o or is some of the stuff usable in 1.3 but not all? +o ie. the device config classes exist but not the set full screen method _ currently some bugs in the main() because it's not sizing applets _ if running in present mode it works ok @@ -104,12 +110,6 @@ _ files not in the data folder (works in env, not in sketch) CORE / PApplet - main() -_ make the 1.4 code in PApplet load via reflection -_ doesn't appear necessary with 1.3 applets -_ or is some of the stuff usable in 1.3 but not all? -_ ie. the device config classes exist but not the set full screen method -_ for present mode, need to set a default display -_ currently crashes if only --present is specified w/o --display _ present mode is flakey.. applet doesn't always come up _ seems like hitting stop helps shut it down? _ is full screen window not being taken down properly? @@ -124,6 +124,7 @@ _ needs to get the size of the main screen _ ability to select monitor via preferences panel _ this applies to any applet that's run externally currently (verify) _ make it also work with anything that's run inside of p5 itself +_ this means changing the frame creation code inside Runner _ check current present code with multiple monitors _ first pass on full screen _ exceptions in full screen mode will quit the app completely @@ -132,6 +133,9 @@ _ default is that full screen app doesn't cover multiple displays _ this is fine since opengl can't usually go across both _ but include an example for how to use full in gl _ (use toolkit.getscreensize) +_ cmd-q when running externally causes trouble because it quits +_ but when running internally it quits p5 +_ how to shut off the cmd-q when running externally on osx? CORE / PFont and text() diff --git a/todo.txt b/todo.txt index d3ce70019..2abe9bf74 100644 --- a/todo.txt +++ b/todo.txt @@ -3,7 +3,7 @@ X error messages from external not coming through very well X especially on macosx.. is it writing to stdout.txt tho? X figure out why it's killing things early? the process maybe? X gl exceptions really not coming through -_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1114520230;start=5 +X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1114520230;start=5 X command keys don't work w/ shift X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1114661169;start=0 X printing 32k chars to console w/o a line break will cause massive error