take care of bug #209 and bug #243

This commit is contained in:
benfry
2005-12-14 07:10:53 +00:00
parent 9a7c2d5e93
commit c3b6299a40
3 changed files with 66 additions and 29 deletions
+3 -1
View File
@@ -302,7 +302,9 @@ public class Runner implements MessageConsumer {
applet.setBounds((windowW - applet.width)/2,
insets.top + (usableH - applet.height) / 2,
applet.width, applet.height);
//windowW, windowH);
// handle frame resizing events
applet.setupFrameResizeListener();
applet.setVisible(true); // no effect
if (windowLocation != null) {
+44 -13
View File
@@ -551,6 +551,10 @@ public class PApplet extends Applet
}
/**
* This returns the last width and height specified by the user
* via the size() command.
*/
public Dimension getPreferredSize() {
return new Dimension(width, height);
}
@@ -830,9 +834,6 @@ public class PApplet extends Applet
this.height = iheight;
defaultSize = false;
println("size()");
println(" iwidth, iheight = " + iwidth + ", " + iheight);
println(" setting size to " + width + ", " + height);
// make the applet itself larger.. it's a subclass of Component,
// so this is important for when it's embedded inside another app.
setSize(width, height);
@@ -1327,11 +1328,11 @@ public class PApplet extends Applet
public void componentResized(ComponentEvent e) {
Component c = e.getComponent();
Rectangle bounds = c.getBounds();
System.out.println("componentResized()");
//System.out.println("componentResized()");
//System.out.println(" " + c.getClass().getName());
println(" visible " + isVisible());
System.out.println(" " + e);
System.out.println(" bounds: " + bounds);
//println(" visible " + isVisible());
//System.out.println(" " + e);
//System.out.println(" bounds: " + bounds);
//int newWidth = bounds.width - bounds.x * 2;
//int newHeight = bounds.height - (bounds.y + bounds.x);
//System.out.println(" new: " + newWidth + " " + newHeight);
@@ -5382,10 +5383,11 @@ public class PApplet extends Applet
* (so that it will be saved by the PDE for the next run) and
* notify on quit. See more notes in the Worker class.
*/
public void setupExternalMessages(Frame parentFrame) {
public void setupExternalMessages() { //Frame parentFrame) {
final Worker worker = new Worker();
parentFrame.addComponentListener(new ComponentAdapter() {
//parentFrame.addComponentListener(new ComponentAdapter() {
frame.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
Point where = ((Frame) e.getSource()).getLocation();
System.err.println(PApplet.EXTERNAL_MOVE + " " +
@@ -5394,7 +5396,8 @@ public class PApplet extends Applet
}
});
parentFrame.addWindowListener(new WindowAdapter() {
//parentFrame.addWindowListener(new WindowAdapter() {
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.err.println(PApplet.EXTERNAL_QUIT);
System.err.flush(); // important
@@ -5404,6 +5407,32 @@ public class PApplet extends Applet
}
/**
* Set up a listener that will fire proper component resize events
* in cases where frame.setResizable(true) is called.
*/
public void setupFrameResizeListener() {
frame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
// might be multiple resize calls before visible (i.e. first
// when pack() is called, then when it's resized for use).
// ignore them because it's not the user resizing things.
Frame farm = (Frame) e.getComponent();
if (farm.isVisible()) {
Insets insets = farm.getInsets();
Dimension windowSize = farm.getSize();
int usableW = windowSize.width - insets.left - insets.right;
int usableH = windowSize.height - insets.top - insets.bottom;
// the ComponentListener in PApplet will handle calling size()
setBounds(insets.left, insets.top, usableW, usableH);
}
}
});
}
/**
* main() method for running this class from the command line.
* <P>
@@ -5600,7 +5629,7 @@ public class PApplet extends Applet
// not always running externally when in present mode
if (external) {
applet.setupExternalMessages(frame);
applet.setupExternalMessages();
}
} else { // if not presenting
@@ -5662,10 +5691,9 @@ public class PApplet extends Applet
applet.setBounds((windowW - applet.width)/2,
insets.top + (usableWindowH - applet.height)/2,
applet.width, applet.height);
//windowW, windowH);
if (external) {
applet.setupExternalMessages(frame);
applet.setupExternalMessages();
} else { // !external
frame.addWindowListener(new WindowAdapter() {
@@ -5675,6 +5703,9 @@ public class PApplet extends Applet
});
}
// handle frame resizing events
applet.setupFrameResizeListener();
// all set for rockin
frame.show();
}
+19 -15
View File
@@ -2,16 +2,26 @@
X PSound.play() won't play the sound a 2nd time (reopened)
_ http://dev.processing.org/bugs/show_bug.cgi?id=208
X removed playing() method
X ComponentListener is probably what's needed for resize()
X make sure that components can be resized properly via size()
X http://dev.processing.org/bugs/show_bug.cgi?id=209
X or that it properly responds to a setBounds() call
X calling size() elsewhere in the app doesn't quite work
X A second call to size almost works.
X The buffer apparently gets allocated and saveFrame saves the
X new size but drawing appears to be disabled.
X http://dev.processing.org/bugs/show_bug.cgi?id=243
_ ComponentListener is probably what's needed for resize()
_ make sure that components can be resized properly via size()
_ http://dev.processing.org/bugs/show_bug.cgi?id=209
_ or that it properly responds to a setBounds() call
_ calling size() elsewhere in the app doesn't quite work
_ A second call to size almost works.
_ The buffer apparently gets allocated and saveFrame saves the
_ new size but drawing appears to be disabled.
_ http://dev.processing.org/bugs/show_bug.cgi?id=243
_ fix the flicker in java2d mode
_ http://dev.processing.org/bugs/show_bug.cgi?id=122
_ framerate(30) is still flickery and jumpy..
_ not clear what's happening here
_ appears to be much worse (unfinished drawing) on macosx
_ try turning off hw accel on the mac to see if that's the problem
_ framerate that's reported is out of joint with actual
_ seems to be aliasing effect of low resolution on millis()
_ so rates coming out double or half of their actual
_ probably need to integrate over a rolling array of 10 frames or so
_ don't block on loadImage()
_ use a MediaTracker that's shared, so that while an image is still
@@ -460,12 +470,6 @@ _ set(x, y, image)
_ x, y not setting with processing
_ don't let users on < 1.3 load JAVA2D
_ set upper bound on framerate so as not to completely hose things?
_ fix the flicker in java2d mode
_ http://dev.processing.org/bugs/show_bug.cgi?id=122
_ framerate(30) is still flickery and jumpy..
_ not clear what's happening here
_ appears to be much worse (unfinished drawing) on macosx
_ try turning off hw accel on the mac to see if that's the problem
_ textSpace(SCREEN_SPACE) needs to be faster
_ need flat image implementation that takes no transforms
_ along with 90, 180 and 270 versions of it as well