clearing brush, back on the EDT, fix focus issues #3380 #3389

This commit is contained in:
Ben Fry
2015-06-18 15:29:32 -04:00
parent 70b1809684
commit 5f5a0ed55f
4 changed files with 75 additions and 60 deletions
+14 -14
View File
@@ -9870,20 +9870,20 @@ public class PApplet implements PConstants {
// also suspecting that these "not showing up" bugs might be EDT issues.
static public void runSketch(final String[] args,
final PApplet constructedSketch) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// runSketchEDT(args, constructedSketch);
// }
// });
// }
//
//
// /**
// * Moving this to the EDT for 3.0a6 because that's the proper thing to do
// * when messing with AWT/Swing components. And boy, do we mess with 'em.
// */
// static protected void runSketchEDT(final String[] args,
// final PApplet constructedSketch) {
EventQueue.invokeLater(new Runnable() {
public void run() {
runSketchEDT(args, constructedSketch);
}
});
}
/**
* Moving this to the EDT for 3.0a6 because that's the proper thing to do
* when messing with AWT/Swing components. And boy, do we mess with 'em.
*/
static protected void runSketchEDT(final String[] args,
final PApplet constructedSketch) {
// Supposed to help with flicker, but no effect on OS X.
// TODO IIRC this helped on Windows, but need to double check.
System.setProperty("sun.awt.noerasebackground", "true");
+46 -31
View File
@@ -26,7 +26,6 @@ import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.ArrayList;
@@ -64,6 +63,7 @@ public class PSurfaceAWT extends PSurfaceNone {
//this.graphics = graphics;
super(graphics);
/*
if (checkRetina()) {
// System.out.println("retina in use");
@@ -84,6 +84,7 @@ public class PSurfaceAWT extends PSurfaceNone {
// flicker--pushing pixels out before the screen has finished rendering.
// useStrategy = false;
}
*/
canvas = new SmoothCanvas();
// if (useStrategy) {
canvas.setIgnoreRepaint(true);
@@ -104,36 +105,40 @@ public class PSurfaceAWT extends PSurfaceNone {
}
/**
* Handle grabbing the focus on startup. Other renderers can override this
* if handling needs to be different. For the AWT, the request is invoked
* later on the EDT. Other implementations may not require that, so the
* invokeLater() happens in here rather than requiring the caller to wrap it.
*/
@Override
void requestFocus() {
// for 2.0a6, moving this request to the EDT
EventQueue.invokeLater(new Runnable() {
public void run() {
// Call the request focus event once the image is sure to be on
// screen and the component is valid. The OpenGL renderer will
// request focus for its canvas inside beginDraw().
// http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/FocusSpec.html
// Disabling for 0185, because it causes an assertion failure on OS X
// http://code.google.com/p/processing/issues/detail?id=258
// requestFocus();
// Changing to this version for 0187
// http://code.google.com/p/processing/issues/detail?id=279
//requestFocusInWindow();
// For 3.0, just call this directly on the Canvas object
if (canvas != null) {
canvas.requestFocusInWindow();
}
}
});
}
// /**
// * Handle grabbing the focus on startup. Other renderers can override this
// * if handling needs to be different. For the AWT, the request is invoked
// * later on the EDT. Other implementations may not require that, so the
// * invokeLater() happens in here rather than requiring the caller to wrap it.
// */
// @Override
// void requestFocus() {
//// System.out.println("requesFocus() outer " + EventQueue.isDispatchThread());
// // for 2.0a6, moving this request to the EDT
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// // Call the request focus event once the image is sure to be on
// // screen and the component is valid. The OpenGL renderer will
// // request focus for its canvas inside beginDraw().
// // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/FocusSpec.html
// // Disabling for 0185, because it causes an assertion failure on OS X
// // http://code.google.com/p/processing/issues/detail?id=258
// // requestFocus();
//
// // Changing to this version for 0187
// // http://code.google.com/p/processing/issues/detail?id=279
// //requestFocusInWindow();
//
// // For 3.0, just call this directly on the Canvas object
// if (canvas != null) {
// //System.out.println("requesting focus " + EventQueue.isDispatchThread());
// //System.out.println("requesting focus " + frame.isVisible());
// //canvas.requestFocusInWindow();
// canvas.requestFocus();
// }
// }
// });
// }
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@@ -749,6 +754,12 @@ public class PSurfaceAWT extends PSurfaceNone {
// If displayable() is false, then PSurfaceNone should be used, but...
if (sketch.getGraphics().displayable()) {
frame.setVisible(true);
System.out.println("setting visible on EDT? " + EventQueue.isDispatchThread());
//requestFocus();
if (canvas != null) {
//canvas.requestFocusInWindow();
canvas.requestFocus();
}
}
}
@@ -827,6 +838,7 @@ public class PSurfaceAWT extends PSurfaceNone {
}
/*
private boolean checkRetina() {
if (PApplet.platform == PConstants.MACOSX) {
// This should probably be reset each time there's a display change.
@@ -852,6 +864,7 @@ public class PSurfaceAWT extends PSurfaceNone {
}
return false;
}
*/
/** Get the bounds rectangle for all displays. */
@@ -1262,11 +1275,13 @@ public class PSurfaceAWT extends PSurfaceNone {
canvas.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
System.out.println(e);
sketch.focused = true;
sketch.focusGained();
}
public void focusLost(FocusEvent e) {
System.out.println(e);
sketch.focused = false;
sketch.focusLost();
}
+5 -7
View File
@@ -141,10 +141,8 @@ public class PSurfaceNone implements PSurface {
}
void requestFocus() {
// TODO Auto-generated method stub
}
// void requestFocus() {
// }
// public void blit() {
// // TODO Auto-generated method stub
@@ -298,9 +296,9 @@ public class PSurfaceNone implements PSurface {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
if (sketch.frameCount == 1) {
requestFocus();
}
// if (sketch.frameCount == 1) {
// requestFocus();
// }
// }
// });
+10 -8
View File
@@ -23,6 +23,10 @@ X HashMap sucks b/c we'd have to cast everything
X doesn't help to have intParam() etc, too many types (5ish? OutputStream)
X just stick with the current setup
X remove launch(String) since it was calling itself, and anachronistic
X sketches with new fullScreen() method should grab focus by default
X https://github.com/processing/processing/issues/3380
X sketches not getting focus with Java2D
X https://github.com/processing/processing/issues/3389
cleaning
o possible addition for 'implementation' variable
@@ -51,6 +55,8 @@ X ortho function is broken
X https://github.com/processing/processing/issues/1278
X errors with loading SVGs in P3D/P2D
X https://github.com/processing/processing/issues/3379
X sketch window briefly appears on top left corner when using OpenGL
X https://github.com/processing/processing/issues/3308
fixed earlier
X sketch window is not placed at correct location when running a second time
@@ -61,6 +67,8 @@ X save() and saveFrame() with 2X renderers fails
X https://github.com/processing/processing/issues/3255
X NPE when using image() created with createGraphics(PGraphicsRetina2D)
X https://github.com/processing/processing/issues/2510
X Closing OpenGL sketch from the PDE doesn't stop java.exe process
X https://github.com/processing/processing/issues/2335
docs
@@ -79,10 +87,6 @@ _ removeNotify(), addNotify(), setUndecorated(boolean)
_ setting menubar will be surface-specific
_ setLocation(int, int) and setSize(int, int)
_ add the "don't use this" warning to the JFrame in PSurfaceAWT
_ sketches with new fullScreen() method should grab focus by default
_ https://github.com/processing/processing/issues/3380
_ sketches not getting focus with Java2D
_ https://github.com/processing/processing/issues/3389
_ draw() executes twice when noLoop() called in setup()
_ https://github.com/processing/processing/issues/3310
_ broken since 3.0a7, but not in 3.0a5
@@ -92,8 +96,6 @@ _ sketch sometimes doesn't show with noLoop() on Linux
_ https://github.com/processing/processing/issues/3316
_ sketch not always showing with empty draw()
_ https://github.com/processing/processing/issues/3363
_ sketch window briefly appears on top left corner when using OpenGL
_ https://github.com/processing/processing/issues/3308
_ Window never shows with exported application on 64-bit Linux
_ https://github.com/processing/processing/issues/3303
@@ -128,8 +130,6 @@ _ implement external messages (moving the window)
opengl
_ hard crash at 1920x1080, mirrored, Casey's GT 650M 1GB
_ Closing OpenGL sketch from the PDE doesn't stop java.exe process
_ https://github.com/processing/processing/issues/2335
_ add attrib() method
_ https://github.com/processing/processing/issues/2963
_ andres needs input on how the api works
@@ -139,6 +139,8 @@ _ https://github.com/processing/processing/issues/3339
opengl questions
_ issues with how JOGL handles window layout/sizing
_ https://github.com/processing/processing/issues/3401
_ exitCalled() and exitActual made public by Andres, breaks Python
_ also not API we want to expose, so sort this out
_ or maybe we're fine b/c now FX2D needs it as well