major updates to full screen handling, remove FSEM, add native OS X menubar hiding

This commit is contained in:
benfry
2012-03-25 12:52:46 +00:00
parent 38fe999d73
commit 51eee1ad6b
8 changed files with 271 additions and 101 deletions
+36 -13
View File
@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-10 Ben Fry and Casey Reas
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
@@ -222,16 +222,17 @@ public class Compiler {
if (m != null) {
// System.out.println("'" + m[1] + "'");
if (m[1].equals("processing.xml")) {
exception.setMessage("processing.xml no longer exists, this code needs to be updated for 2.0.");
System.err.println("The processing.xml library has been replaced " +
"with a new 'XML' class that's built-in.");
handleCrustyCode(exception);
handleCrustyCode();
} else {
exception.setMessage("The package " +
"\u201C" + m[1] + "\u201D" +
" does not exist. " +
"You might be missing a library.");
System.err.println("As of release 1.0, libraries must be " +
System.err.println("Libraries must be " +
"installed in a folder named 'libraries' " +
"inside the 'sketchbook' folder.");
}
@@ -254,7 +255,8 @@ public class Compiler {
if (what.equals("BFont") ||
what.equals("BGraphics") ||
what.equals("BImage")) {
handleCrustyCode(exception);
exception.setMessage(what + " has been replaced with P" + what.substring(1));
handleCrustyCode();
} else {
exception.setMessage("Cannot find a class or type " +
@@ -268,9 +270,20 @@ public class Compiler {
String what = errorMessage.substring(0, errorMessage.indexOf(' '));
if (what.equals("LINE_LOOP") ||
what.equals("LINE_STRIP") ||
what.equals("framerate")) {
handleCrustyCode(exception);
what.equals("LINE_STRIP")) {
exception.setMessage("LINE_LOOP and LINE_STRIP are not available, " +
"please update your code.");
handleCrustyCode();
} else if (what.equals("framerate")) {
exception.setMessage("framerate should be changed to frameRate");
handleCrustyCode();
} else if (what.equals("screen")) {
// handleCrustyCode(exception, what);
exception.setMessage("Change screen.width and screen.height to " +
"screenWidth and screenHeight for 2.0.");
handleCrustyCode();
} else {
exception.setMessage("Cannot find anything " +
@@ -294,9 +307,18 @@ public class Compiler {
"The method (\\S+\\(.*\\)) is undefined for the type (.*)";
parts = PApplet.match(errorMessage, undefined);
if (parts != null) {
if (parts[1].equals("framerate(int)") ||
parts[1].equals("push()")) {
handleCrustyCode(exception);
if (parts[1].equals("framerate(int)")) {
exception.setMessage("framerate() no longer exists, use frameRate() instead.");
handleCrustyCode();
} else if (parts[1].equals("push()")) {
exception.setMessage("push() no longer exists, use pushMatrix() instead.");
handleCrustyCode();
} else if (parts[1].equals("pop()")) {
exception.setMessage("pop() no longer exists, use popMatrix() instead.");
handleCrustyCode();
} else {
String mess = "The function " + parts[1] + " does not exist.";
exception.setMessage(mess);
@@ -667,9 +689,10 @@ public class Compiler {
// }
static protected void handleCrustyCode(SketchException rex) {
rex.setMessage("This code needs to be updated, " +
"please read the Changes page on the Wiki.");
static protected void handleCrustyCode() {
System.err.println("This code needs to be updated " +
"for this version of Processing, " +
"please read the Changes page on the Wiki.");
JavaEditor.showChanges();
}
@@ -668,7 +668,7 @@ public class PdePreprocessor {
out.print(indent + indent + "PApplet.main(new String[] { ");
if (Preferences.getBoolean("export.application.fullscreen")) {
out.print("\"" + PApplet.ARGS_PRESENT + "\", ");
out.print("\"" + PApplet.ARGS_FULL_SCREEN + "\", ");
String farbe = Preferences.get("run.present.bgcolor");
out.print("\"" + PApplet.ARGS_BGCOLOR + "=" + farbe + "\", ");
@@ -243,10 +243,10 @@ public class Runner implements MessageConsumer {
build.getSketchPath());
if (presenting) {
params.add(PApplet.ARGS_PRESENT);
if (Preferences.getBoolean("run.present.exclusive")) {
params.add(PApplet.ARGS_EXCLUSIVE);
}
params.add(PApplet.ARGS_FULL_SCREEN);
// if (Preferences.getBoolean("run.present.exclusive")) {
// params.add(PApplet.ARGS_EXCLUSIVE);
// }
params.add(PApplet.ARGS_STOP_COLOR + "=" +
Preferences.get("run.present.stop.color"));
params.add(PApplet.ARGS_BGCOLOR + "=" +
+3 -2
View File
@@ -254,7 +254,8 @@ preproc.imports.list = java.applet.*,java.awt.Dimension,java.awt.Frame,java.awt.
# FULL SCREEN (PRESENT MODE)
run.present.bgcolor = #666666
run.present.stop.color = #cccccc
# Starting in 2.0a6, don't use FSEM at all, embed native lib to hide menubar
# starting in release 0159, don't use full screen exclusive anymore
run.present.exclusive = false
#run.present.exclusive = false
# use this by default to hide the menu bar and dock on osx
run.present.exclusive.macosx = true
#run.present.exclusive.macosx = true
+80
View File
@@ -0,0 +1,80 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 hansi raber, released under LGPL under agreement
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
package japplemenubar;
import java.io.*;
import processing.core.PApplet;
/**
* Starting point for the application. General initialization should be done
* inside the ApplicationController's init() method. If certain kinds of
* non-Swing initialization takes too long, it should happen in a new Thread
* and off the Swing event dispatch thread (EDT).
*
* @author hansi
*/
public class JAppleMenuBar {
static JAppleMenuBar instance;
static final String FILENAME = "libjAppleMenuBar.jnilib";
static {
try {
File temp = File.createTempFile("processing", "menubar");
temp.delete(); // remove the file itself
temp.mkdirs(); // create a directory out of it
temp.deleteOnExit();
File jnilibFile = new File(temp, FILENAME);
InputStream input = JAppleMenuBar.class.getResourceAsStream(FILENAME);
PApplet.saveStream(jnilibFile, input);
// String libraryPath = System.getProperty("java.library.path");
// libraryPath += File.pathSeparator + temp.getAbsolutePath();
// System.setProperty("java.library.path", libraryPath);
// System.out.println("java library path should be: " + libraryPath);
// System.out.println(" get returns: " + System.getProperty("java.library.path"));
// System.out.println("LD library path is: " + System.getenv("LD_LIBRARY_PATH"));
// System.loadLibrary("jAppleMenuBar");
System.load(jnilibFile.getAbsolutePath());
instance = new JAppleMenuBar();
} catch (IOException e) {
e.printStackTrace();
}
}
// static public void show() {
// instance.setVisible(true);
// }
static public void hide() {
instance.setVisible(false);
}
public native void setVisible(boolean visibility, boolean kioskMode);
public void setVisible(boolean visibility) {
// Keep original API in-tact. Default kiosk-mode to off.
setVisible(visibility, false);
}
}
+72 -25
View File
@@ -321,6 +321,12 @@ public class PApplet extends Applet
static public final int MIN_WINDOW_WIDTH = 128;
static public final int MIN_WINDOW_HEIGHT = 128;
/**
* Gets set by main() if --present (old) or --full-screen (newer) are used,
* and is returned by sketchFullscreen() when initializing in main().
*/
// protected boolean fullScreen = false;
/**
* Exception thrown when size() is called the first time.
* <p>
@@ -755,9 +761,12 @@ public class PApplet extends Applet
static public final String ARGS_BGCOLOR = "--bgcolor";
/** @deprecated use --full-screen instead. */
static public final String ARGS_PRESENT = "--present";
static public final String ARGS_FULL_SCREEN = "--full-screen";
static public final String ARGS_EXCLUSIVE = "--exclusive";
// static public final String ARGS_EXCLUSIVE = "--exclusive";
static public final String ARGS_STOP_COLOR = "--stop-color";
@@ -873,7 +882,7 @@ public class PApplet extends Applet
}
public int sketchAntiAlias() {
public int sketchSmooth() {
return 2;
}
@@ -891,6 +900,12 @@ public class PApplet extends Applet
public String sketchRenderer() {
return JAVA2D;
}
public boolean sketchFullScreen() {
// return fullScreen;
return false;
}
public void orientation(int which) {
@@ -1569,7 +1584,7 @@ public class PApplet extends Applet
pg.setParent(this);
pg.setPrimary(iprimary);
if (ipath != null) pg.setPath(ipath);
pg.setAntiAlias(sketchAntiAlias());
pg.setAntiAlias(sketchSmooth());
pg.setSize(iwidth, iheight);
// everything worked, return it
@@ -9017,6 +9032,20 @@ public class PApplet extends Applet
};
// Not gonna do this dynamically, only on startup. Too much headache.
// public void fullscreen() {
// if (frame != null) {
// if (PApplet.platform == MACOSX) {
// japplemenubar.JAppleMenuBar.hide();
// }
// GraphicsConfiguration gc = frame.getGraphicsConfiguration();
// Rectangle rect = gc.getBounds();
//// GraphicsDevice device = gc.getDevice();
// frame.setBounds(rect.x, rect.y, rect.width, rect.height);
// }
// }
/**
* main() method for running this class from the command line.
* <p>
@@ -9037,12 +9066,7 @@ public class PApplet extends Applet
* should appear on screen. if not used,
* the default is to center on the main screen.
*
* --present put the applet into full screen presentation
* mode. requires java 1.4 or later.
*
* --exclusive use full screen exclusive mode when presenting.
* disables new windows or interaction with other
* monitors, this is like a "game" mode.
* --full-screen put the applet into full screen "present" mode.
*
* --hide-stop use to hide the stop button in situations where
* you don't want to allow users to exit. also
@@ -9102,7 +9126,7 @@ public class PApplet extends Applet
String name = null;
boolean present = false;
boolean exclusive = false;
// boolean exclusive = false;
Color backgroundColor = Color.BLACK;
Color stopColor = Color.GRAY;
GraphicsDevice displayDevice = null;
@@ -9161,11 +9185,14 @@ public class PApplet extends Applet
}
} else {
if (args[argIndex].equals(ARGS_PRESENT)) {
if (args[argIndex].equals(ARGS_PRESENT)) { // keep for compatability
present = true;
} else if (args[argIndex].equals(ARGS_EXCLUSIVE)) {
exclusive = true;
} else if (args[argIndex].equals(ARGS_FULL_SCREEN)) {
present = true;
// } else if (args[argIndex].equals(ARGS_EXCLUSIVE)) {
// exclusive = true;
} else if (args[argIndex].equals(ARGS_HIDE_STOP)) {
hideStop = true;
@@ -9225,9 +9252,14 @@ public class PApplet extends Applet
}
}
// these are needed before init/start
// A handful of things that need to be set before init/start.
applet.frame = frame;
applet.sketchPath = folder;
// If the applet doesn't call for full screen, but the command line does,
// enable it. Conversely, if the command line does not, don't disable it.
// applet.fullScreen |= present;
// Query the applet to see if it wants to be full screen all the time.
present |= applet.sketchFullScreen();
// pass everything after the class name in as args to the sketch itself
// (fixed for 2.0a5, this was just subsetting by 1, which didn't skip opts)
applet.args = PApplet.subset(args, argIndex + 1);
@@ -9237,6 +9269,14 @@ public class PApplet extends Applet
// because pack() will cause the bounds to go to zero.
// http://dev.processing.org/bugs/show_bug.cgi?id=923
Rectangle fullScreenRect = null;
DisplayMode mode = displayDevice.getDisplayMode();
fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
// Sketch has already requested to be the same as the screen's
// width and height, so let's roll with full screen mode.
if (mode.getWidth() == applet.sketchWidth() &&
mode.getHeight() == applet.sketchHeight()) {
present = true;
}
// For 0149, moving this code (up to the pack() method) before init().
// For OpenGL (and perhaps other renderers in the future), a peer is
@@ -9246,19 +9286,23 @@ public class PApplet extends Applet
// http://dev.processing.org/bugs/show_bug.cgi?id=891
// http://dev.processing.org/bugs/show_bug.cgi?id=908
if (present) {
if (platform == MACOSX) {
// Call some native code to remove the menu bar on OS X. Not necessary
// on Linux and Windows, who are happy to make full screen windows.
japplemenubar.JAppleMenuBar.hide();
}
frame.setUndecorated(true);
frame.setBackground(backgroundColor);
if (exclusive) {
displayDevice.setFullScreenWindow(frame);
// this trashes the location of the window on os x
//frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
fullScreenRect = frame.getBounds();
} else {
DisplayMode mode = displayDevice.getDisplayMode();
fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
frame.setBounds(fullScreenRect);
frame.setVisible(true);
}
// if (exclusive) {
// displayDevice.setFullScreenWindow(frame);
// // this trashes the location of the window on os x
// //frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
// fullScreenRect = frame.getBounds();
// } else {
frame.setBounds(fullScreenRect);
frame.setVisible(true);
// }
}
frame.setLayout(null);
frame.add(applet);
@@ -9415,6 +9459,7 @@ public class PApplet extends Applet
runSketch(args, null);
}
/**
* These methods provide a means for running an already-constructed
* sketch. In particular, it makes it easy to launch a sketch in
@@ -9435,9 +9480,11 @@ public class PApplet extends Applet
runSketch(argsWithSketchName, this);
}
protected void runSketch() {
runSketch(new String[0]);
}
//////////////////////////////////////////////////////////////
+72 -56
View File
@@ -1,6 +1,57 @@
0205 core
sort out full screen issues
X boolean sketchFullscreen() ?
X for more options, just integrate the fs library?
_ let hansi know when it's integrated so he can update his library
X casey: I think we only want to most basic functionality,
X to go full screen across monitors.
X http://www.superduper.org/processing/fullscreen_api/
X https://github.com/kritzikratzi/jAppleMenuBar/blob/master/src/native/jAppleMenuBar.m
X detect when using full screen
X and if so, remove decoration and don't bother with bg present frame
o this will help for exported applets that don't need 'present'
X only doing this via sketchXxxx() methods, but should work well
o add option to use full screen exclusive mode on present inside pde?
o override default setting of macosx (yes) and linux/win (no)
o http://dev.processing.org/bugs/show_bug.cgi?id=1043
o linux present mode isn't working properly
X removing FSEM, too buggy and problematic
_ --display not working on osx
_ http://code.google.com/p/processing/issues/detail?id=71
X implement full screen mode.. this takes over the screen as best it can
X size(screen.width, screen.height, OPENGL);
X if size is screen.width and screen.height, does its best
X needs to get the size of the main screen
o this probably works but just needs to be tested
_ 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
o exceptions in full screen mode will quit the app completely
o can't keep window open because things are hosed
X nah, this is fine--not ideal but fine
_ doc: if you want to use multiple monitors
_ set full screen to true (for one screen)
_ have sketchWidth() and sketchHeight() return the size of both monitors
_ provide example for doing this with multiple displays?
_ there are just too many possibilities for monitor arrangement
_ and display depth changes that there's no way for us to do it correctly
_ frame.setSize() works, but we aren't going to add the title bar back
_ just too problematic and buggy to get this to work perfectly
_ 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
_ static mode sketches seem to break ESC... noLoop() problem?
_ PUtil -> move match(), lots of other non-gui functions into own class
_ and merge it in statically via the methods code
_ make sure rendering is happening on the EDT
_ (hopefully fixes flicker issues)
_ look into using BufferStrategy again to improve performance
_ there are more improvements to be made ala issue #729
@@ -51,24 +102,6 @@ _ change how beginRecord() works.. passing around PApplet vs PGraphics is gross
_ have to pass PApplet just to make the rendering work to both renderers
_ should instead be a renderer that splits things out
sort out full screen issues
_ boolean sketchFullscreen() ?
_ for more options, just integrate the fs library?
_ let hansi know when it's integrated so he can update his library
_ casey: I think we only want to most basic functionality, to go full screen across monitors.
_ http://www.superduper.org/processing/fullscreen_api/
_ https://github.com/kritzikratzi/jAppleMenuBar/blob/master/src/native/jAppleMenuBar.m
_ detect when using full screen
_ and if so, remove decoration and don't bother with bg present frame
_ frame.setUndecorated(true);
_ frame.setLocation(0,0);
_ size(screen.width,screen,height);
_ this will help for exported applets that don't need 'present'
_ add option to use full screen exclusive mode on present inside pde?
_ override default setting of macosx (yes) and linux/win (no)
_ http://dev.processing.org/bugs/show_bug.cgi?id=1043
_ linux present mode isn't working properly
_ if save() returns boolean, does saveFrame()?
_ also need to copy this over to android
@@ -76,9 +109,6 @@ _ disable smoothing on noSmooth(), use hint to do 2x vs 4x smoothing
_ document how things are sometimes null in XML
_ test xml examples to see if they break
_ add resize().. make it call setSize().
_ also needs to do a redraw if noLoop() has been called
_ trimming text on URLs?
_ http://code.google.com/p/processing/issues/detail?id=715
@@ -162,6 +192,27 @@ _ json issues
_ http://www.xml.com/lpt/a/1658
_ http://www.json.org/java/
2.0 / methods
_ decision on registered methods
_ remove registerPre() et al
_ add register("pause", ...)
_ add PEvent
_ size() and resize() and whatever?
_ should be setSize(), but that's odd for image files
_ -> resize() is fine with PImage and PGraphics...
_ we may be inheriting the resize() from Java -> make it final?
_ add resize().. make it call setSize().
_ also needs to do a redraw if noLoop() has been called
_ the registered method for size() also needs to be called
_ need to wrap mouse/key events for p5
_ need a version that works with both android and desktop
_ also need to interleave events properly (as per report)
_ touch events.. can't do MouseEvent et al with Android
_ http://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html
_ http://www.html5rocks.com/en/mobile/touch.html
_ decision: go with what looks like javascript/ios
_ touchEvent(), gestureEvent()?
2.0
_ PNode.getChildren() shouldn't make a new array.. toArray() can do that
_ thread() causes weird flickering
@@ -171,18 +222,6 @@ _ toColorArray(), toColorArray(float[])...
_ remove blend(), add blendMode()
_ fix blue-channel bias on blend() so that blendMode() will work in 2.0
_ http://code.google.com/p/processing/issues/detail?id=475
_ decision on registered methods
_ remove registerPre() et al
_ add register("pause", ...)
_ add PEvent
_ need to wrap mouse/key events for p5
_ need a version that works with both android and desktop
_ also need to interleave events properly (as per report)
_ touch events.. can't do MouseEvent et al with Android
_ http://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html
_ http://www.html5rocks.com/en/mobile/touch.html
_ decision: go with what looks like javascript/ios
_ touchEvent(), gestureEvent()?
_ load/save methods.. is it save("blah.svg") or saveSVG("blah.svg")
_ also works that way with tables
_ decision: useExtension() or something like that
@@ -200,15 +239,9 @@ _ PShape API to handle internal vertex stuff
_ add deconstruct() method for paths
_ toArray() and toVector()
_ setVertex(0, x, y), setVertex(0, x, y, z)
_ PUtil -> move match(), lots of other non-gui functions into own class
_ and merge it in statically via the methods code
_ how much of com.benfry.* should go in?
_ Table? StringIntPairs? JSON? MD5? Integrator? ColorIntegrator?
_ decision: depends on if we can think of a good name
_ size() and resize() and whatever?
_ should be setSize(), but that's odd for image files
_ -> resize() is fine with PImage and PGraphics...
_ we may be inheriting the resize() from Java -> make it final?
_ if PShape3D, then is it PShape2D? or do you handle both the same?
_ svg fonts
_ would be nifty if we could convert on the fly to ttf for speed...
@@ -345,29 +378,12 @@ _ don't bother using a buffering stream, just handle internally. gah!
CORE / PApplet - main()
_ implement full screen mode.. this takes over the screen as best it can
_ size(screen.width, screen.height, OPENGL);
_ if size is screen.width and screen.height, does its best
_ needs to get the size of the main screen
_ this probably works but just needs to be tested
_ exceptions in full screen mode will quit the app completely
_ can't keep window open because things are hosed
_ 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
_ 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
_ hitting cmd-q when an applet is running quits p5 (on macosx)
_ but cmd-q when running externally is ok because it just quits
_ is there a way to catch cmd-q when running a sketch?
_ so that it could avoid quitting if the sketch hasn't been stopped
_ or if the sketch window is foremost
_ maybe a hack where a new menubar is added?
_ --display not working on osx
_ http://code.google.com/p/processing/issues/detail?id=71
CORE / PFont and text()
+3
View File
@@ -1,4 +1,7 @@
0205 pde
X fix up some of the error messages inside Compiler
X add EditorState class, device-aware placement