wrap up fullscreen issues (issue #71), better screenWidth and screenHeight setup

This commit is contained in:
benfry
2012-03-25 14:18:59 +00:00
parent d012e2cc9a
commit 23b887907f
3 changed files with 97 additions and 69 deletions
+54 -57
View File
@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-11 Ben Fry and Casey Reas
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This library is free software; you can redistribute it and/or
@@ -37,6 +37,7 @@ import java.util.zip.*;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
//import javax.swing.JFrame;
import javax.swing.SwingUtilities;
@@ -48,6 +49,10 @@ import javax.swing.SwingUtilities;
* problems with redraw of components drawn above it. If you'd like to
* integrate other Java components, see below.
* <p/>
* The <A HREF="http://wiki.processing.org/w/Window_Size_and_Full_Screen">
* Window Size and Full Screen</A> page on the Wiki has useful information
* about sizing, multiple displays, full screen, etc.
* <p/>
* As of release 0145, Processing uses active mode rendering in all cases.
* All animation tasks happen on the "Processing Animation Thread". The
* setup() and draw() methods are handled by that thread, and events (like
@@ -59,11 +64,10 @@ import javax.swing.SwingUtilities;
* animation thread. Use of a callback function or the registerXxx() methods
* in PApplet can help ensure that your code doesn't do something naughty.
* <p/>
* As of release 0136 of Processing, we have discontinued support for versions
* of Java prior to 1.5. We don't have enough people to support it, and for a
* project of our size, we should be focusing on the future, rather than
* working around legacy Java code. In addition, Java 1.5 gives us access to
* better timing facilities which will improve the steadiness of animation.
* As of Processing 2.0, we have discontinued support for versions of Java
* prior to 1.6. We don't have enough people to support it, and for a
* project of our (tiny) size, we should be focusing on the future, rather
* than working around legacy Java code.
* <p/>
* This class extends Applet instead of JApplet because 1) historically,
* we supported Java 1.1, which does not include Swing (without an
@@ -74,28 +78,22 @@ import javax.swing.SwingUtilities;
* Similarly, Processing runs in a Frame and not a JFrame. However, there's
* nothing to prevent you from embedding a PApplet into a JFrame, it's just
* that the base version uses a regular AWT frame because there's simply
* no need for swing in that context. If people want to use Swing, they can
* no need for Swing in that context. If people want to use Swing, they can
* embed themselves as they wish.
* <p/>
* It is possible to use PApplet, along with core.jar in other projects.
* In addition to enabling you to use Java 1.5+ features with your sketch,
* this also allows you to embed a Processing drawing area into another Java
* This also allows you to embed a Processing drawing area into another Java
* application. This means you can use standard GUI controls with a Processing
* sketch. Because AWT and Swing GUI components cannot be used on top of a
* PApplet, you can instead embed the PApplet inside another GUI the way you
* would any other Component.
* <p/>
* It is also possible to resize the Processing window by including
* <tt>frame.setResizable(true)</tt> inside your <tt>setup()</tt> method.
* Note that the Java method <tt>frame.setSize()</tt> will not work unless
* you first set the frame to be resizable.
* <p/>
* Because the default animation thread will run at 60 frames per second,
* an embedded PApplet can make the parent sluggish. You can use frameRate()
* to make it update less often, or you can use noLoop() and loop() to disable
* and then re-enable looping. If you want to only update the sketch
* intermittently, use noLoop() inside setup(), and redraw() whenever
* the screen needs to be updated once (or loop() to re-enable the animation
* an embedded PApplet can make the parent application sluggish. You can use
* frameRate() to make it update less often, or you can use noLoop() and loop()
* to disable and then re-enable looping. If you want to only update the sketch
* intermittently, use noLoop() inside setup(), and redraw() whenever the
* screen needs to be updated once (or loop() to re-enable the animation
* thread). The following example embeds a sketch and also uses the noLoop()
* and redraw() methods. You need not use noLoop() and redraw() when embedding
* if you want your application to animate continuously.
@@ -138,25 +136,6 @@ import javax.swing.SwingUtilities;
* }
* }
* </PRE>
*
* <H2>Processing on multiple displays</H2>
* <p>I was asked about Processing with multiple displays, and for lack of a
* better place to document it, things will go here.</P>
* <p>You can address both screens by making a window the width of both,
* and the height of the maximum of both screens. In this case, do not use
* present mode, because that's exclusive to one screen. Basically it'll
* give you a PApplet that spans both screens. If using one half to control
* and the other half for graphics, you'd just have to put the 'live' stuff
* on one half of the canvas, the control stuff on the other. This works
* better in windows because on the mac we can't get rid of the menu bar
* unless it's running in present mode.</P>
* <p>For more control, you need to write straight java code that uses p5.
* You can create two windows, that are shown on two separate screens,
* that have their own PApplet. this is just one of the tradeoffs of one of
* the things that we don't support in p5 from within the environment
* itself (we must draw the line somewhere), because of how messy it would
* get to start talking about multiple screens. It's also not that tough to
* do by hand w/ some Java code.</P>
* @usage Web &amp; Application
*/
public class PApplet extends Applet
@@ -252,7 +231,16 @@ public class PApplet extends Applet
/** The frame containing this applet (if any) */
public Frame frame;
// public JFrame frame;
/**
* Usually just 0, but with multiple displays, the X and Y coordinates of
* the screen will depend on the current screen's position relative to
* the other displays.
*/
public int screenX;
public int screenY;
/**
* ( begin auto-generated from screenWidth.xml )
*
@@ -813,9 +801,9 @@ public class PApplet extends Applet
public void init() {
// println("init() called " + Integer.toHexString(hashCode()));
// using a local version here since the class variable is deprecated
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
screenWidth = screen.width;
screenHeight = screen.height;
// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
// screenWidth = screen.width;
// screenHeight = screen.height;
// send tab keys through to the PApplet
setFocusTraversalKeysEnabled(false);
@@ -1902,6 +1890,13 @@ public class PApplet extends Applet
long now = System.nanoTime();
if (frameCount == 0) {
GraphicsDevice displayDevice =
getGraphicsConfiguration().getDevice();
Rectangle screenRect =
displayDevice.getDefaultConfiguration().getBounds();
screenWidth = screenRect.width;
screenHeight = screenRect.height;
try {
//println("Calling setup()");
setup();
@@ -9156,9 +9151,6 @@ public class PApplet extends Applet
} else if (param.equals(ARGS_DISPLAY)) {
int deviceIndex = Integer.parseInt(value) - 1;
//DisplayMode dm = device.getDisplayMode();
//if ((dm.getWidth() == 1024) && (dm.getHeight() == 768)) {
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice devices[] = environment.getScreenDevices();
@@ -9220,6 +9212,7 @@ public class PApplet extends Applet
}
Frame frame = new Frame(displayDevice.getDefaultConfiguration());
// JFrame frame = new JFrame(displayDevice.getDefaultConfiguration());
/*
Frame frame = null;
if (displayDevice != null) {
@@ -9268,13 +9261,15 @@ public class PApplet extends Applet
// Need to save the window bounds at full screen,
// 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());
Rectangle screenRect =
displayDevice.getDefaultConfiguration().getBounds();
// DisplayMode doesn't work here, because we can't get the upper-left
// corner of the display, which is important for multi-display setups.
// 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()) {
if (screenRect.width == applet.sketchWidth() &&
screenRect.height == applet.sketchHeight()) {
present = true;
}
@@ -9300,7 +9295,7 @@ public class PApplet extends Applet
// //frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
// fullScreenRect = frame.getBounds();
// } else {
frame.setBounds(fullScreenRect);
frame.setBounds(screenRect);
frame.setVisible(true);
// }
}
@@ -9338,9 +9333,9 @@ public class PApplet extends Applet
if (present) {
// After the pack(), the screen bounds are gonna be 0s
frame.setBounds(fullScreenRect);
applet.setBounds((fullScreenRect.width - applet.width) / 2,
(fullScreenRect.height - applet.height) / 2,
frame.setBounds(screenRect);
applet.setBounds((screenRect.width - applet.width) / 2,
(screenRect.height - applet.height) / 2,
applet.width, applet.height);
if (!hideStop) {
@@ -9358,7 +9353,7 @@ public class PApplet extends Applet
//System.out.println("label width is " + labelSize.width);
labelSize = new Dimension(100, labelSize.height);
label.setSize(labelSize);
label.setLocation(20, fullScreenRect.height - labelSize.height - 20);
label.setLocation(20, screenRect.height - labelSize.height - 20);
}
// not always running externally when in present mode
@@ -9380,7 +9375,7 @@ public class PApplet extends Applet
frame.setSize(windowW, windowH);
if (location != null) {
// a specific location was received from PdeRuntime
// a specific location was received from the Runner
// (applet has been run more than once, user placed window)
frame.setLocation(location[0], location[1]);
@@ -9408,8 +9403,10 @@ public class PApplet extends Applet
frame.setLocation(locationX, locationY);
}
} else { // just center on screen
frame.setLocation((applet.screenWidth - applet.width) / 2,
(applet.screenHeight - applet.height) / 2);
// Can't use frame.setLocationRelativeTo(null) because it sends the
// frame to the main display, which undermines the --display setting.
frame.setLocation(screenRect.x + (screenRect.width - applet.width) / 2,
screenRect.y + (screenRect.height - applet.height) / 2);
}
Point frameLoc = frame.getLocation();
if (frameLoc.y < 0) {
+33 -2
View File
@@ -2,6 +2,8 @@
sort out full screen issues
X make screenWidth and screenHeight work properly with multiple screens
X also set screenX and screenY
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
@@ -44,6 +46,36 @@ _ 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
http://wiki.processing.org/index.php?title=Window_Size_and_Full_Screen&action=edit&redlink=1
_ look into using BufferStrategy again to improve performance
_ there are more improvements to be made ala issue #729
* It is also possible to resize the Processing window by including
* <tt>frame.setResizable(true)</tt> inside your <tt>setup()</tt> method.
* Note that the Java method <tt>frame.setSize()</tt> will not work unless
* you first set the frame to be resizable.
* <p/>
* <H2>Processing on multiple displays</H2>
* <p>I was asked about Processing with multiple displays, and for lack of a
* better place to document it, things will go here.</P>
* <p>You can address both screens by making a window the width of both,
* and the height of the maximum of both screens. In this case, do not use
* present mode, because that's exclusive to one screen. Basically it'll
* give you a PApplet that spans both screens. If using one half to control
* and the other half for graphics, you'd just have to put the 'live' stuff
* on one half of the canvas, the control stuff on the other. This works
* better in windows because on the mac we can't get rid of the menu bar
* unless it's running in present mode.</P>
* <p>For more control, you need to write straight java code that uses p5.
* You can create two windows, that are shown on two separate screens,
* that have their own PApplet. this is just one of the tradeoffs of one of
* the things that we don't support in p5 from within the environment
* itself (we must draw the line somewhere), because of how messy it would
* get to start talking about multiple screens. It's also not that tough to
* do by hand w/ some Java code.</P>
_ static mode sketches seem to break ESC... noLoop() problem?
@@ -52,8 +84,7 @@ _ 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
_ change PApplet.java javadoc to reflect the change
_ memory leak when many createGraphics(..., JAVA2D) calls are used
_ http://code.google.com/p/processing/issues/detail?id=507
+10 -10
View File
@@ -8,6 +8,16 @@ X add EditorState class, device-aware placement
X get rid of restore sketch feature
_ remove pref for restoring sketches
_ implement recent sketches menu
_ casey: recent sketches is a yes, window menu could go either way
window menu:
http://code.google.com/p/processing/issues/detail?id=545
recent sketches:
http://code.google.com/p/processing/issues/detail?id=188
_ multiple sketch windows.. having a windows menu?
_ examples button on toolbar? open / recent / sketchbook?
_ add "recent files" list to open menu?
o http://dev.processing.org/bugs/show_bug.cgi?id=1335
_ find in reference for copy() (on image) tries to open PVector.copy()
_ might need disambiguation pages?
@@ -23,12 +33,6 @@ _ http://code.google.com/p/processing/issues/detail?id=776
_ undo seems to not be going to the right location (now with example)
_ http://code.google.com/p/processing/issues/detail?id=668
_ casey: recent sketches is a yes, window menu could go either way
window menu:
http://code.google.com/p/processing/issues/detail?id=545
recent sketches:
http://code.google.com/p/processing/issues/detail?id=188
_ move Movie Maker out to its own separate tool package (with separate build)
_ http://code.google.com/p/processing/issues/detail?id=837
@@ -220,8 +224,6 @@ _ blockCaret always false.. remove it?
_ EditorToolbar, two TODO items for open menu handling
blob of mess
_ multiple sketch windows.. having a windows menu?
_ examples button on toolbar? open / recent / sketchbook?
_ modes have their own methods for digging through sketch & libraries folders
_ therefore it need only check the sketch.txt file to see if it's ok
_ (between android and java)
@@ -1067,8 +1069,6 @@ _ dragging title bar while sketch running causes strange selection behavior
_ http://dev.processing.org/bugs/show_bug.cgi?id=504
_ convert tabs to spaces when pasting text
_ http://dev.processing.org/bugs/show_bug.cgi?id=506
_ add "recent files" list to open menu?
_ http://dev.processing.org/bugs/show_bug.cgi?id=1335
_ unchecking 'use external editor' sketch should not set modified
_ dangerous if a version that hasn't been re-loaded has possibility
_ to overwrite. i.e. make a change and save in external editor,