Fixed up the goddamned repaint fuckola. Fucking pain in the ass, all this

Swing, AWT and frame manager interaction.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2325 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-03-25 23:05:58 +00:00
parent b281725f29
commit 0b0757b98c
3 changed files with 59 additions and 16 deletions
@@ -1,5 +1,5 @@
//
// $Id: FrameManager.java,v 1.33 2003/03/25 19:06:54 mdb Exp $
// $Id: FrameManager.java,v 1.34 2003/03/25 23:05:58 mdb Exp $
package com.threerings.media;
@@ -141,7 +141,9 @@ public class FrameManager
public FrameManager (JFrame frame, MediaTimer timer)
{
_frame = frame;
_frame.setIgnoreRepaint(true);
if (frame instanceof ManagedJFrame) {
((ManagedJFrame)_frame).init(this);
}
_timer = timer;
// set up our custom repaint manager
@@ -457,6 +459,21 @@ public class FrameManager
} while (_backimg.contentsLost());
}
/**
* Called by the {@link ManagedJFrame} when our window was hidden and
* reexposed.
*/
protected void restoreFromBack (Rectangle dirty)
{
if (_fgfx == null) {
_fgfx = _frame.getGraphics();
}
Log.info("Restoring from back buffer " + StringUtil.toString(dirty) + ".");
_fgfx.setClip(dirty);
_fgfx.drawImage(_backimg, 0, 0, null);
_fgfx.setClip(null);
}
/**
* If frame rate display is enabled, builds beginning of performance
* status display.
@@ -594,7 +611,7 @@ public class FrameManager
_fgfx = null;
}
// Log.info("Created back buffer.");
// Log.info("Created back buffer [" + width + "x" + height + "].");
}
/**
@@ -1,15 +1,16 @@
//
// $Id: ManagedJFrame.java,v 1.3 2002/06/11 00:52:37 mdb Exp $
// $Id: ManagedJFrame.java,v 1.4 2003/03/25 23:05:58 mdb Exp $
package com.threerings.media;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Shape;
import javax.swing.JFrame;
import javax.swing.RepaintManager;
import com.samskivert.util.StringUtil;
import com.threerings.media.Log;
/**
@@ -23,6 +24,7 @@ public class ManagedJFrame extends JFrame
*/
public ManagedJFrame ()
{
this("");
}
/**
@@ -33,21 +35,48 @@ public class ManagedJFrame extends JFrame
super(title);
}
/**
* Called by our frame manager when it's ready to go.
*/
public void init (FrameManager fmgr)
{
_fmgr = fmgr;
}
/**
* We catch paint requests and forward them on to the repaint
* infrastructure.
*/
public void paint (Graphics g)
{
update(g);
}
/**
* We catch update requests and forward them on to the repaint
* infrastructure.
*/
public void update (Graphics g)
{
Shape clip = clip = g.getClip();
Shape clip = g.getClip();
Rectangle dirty;
if (clip != null) {
Rectangle cb = clip.getBounds();
RepaintManager.currentManager(this).addDirtyRegion(
getRootPane(), cb.x, cb.y, cb.width, cb.height);
dirty = clip.getBounds();
} else {
RepaintManager.currentManager(this).addDirtyRegion(
getRootPane(), 0, 0, getWidth(), getHeight());
dirty = getRootPane().getBounds();
// account for our frame insets
Insets insets = getInsets();
dirty.x += insets.left;
dirty.y += insets.top;
}
if (_fmgr != null) {
_fmgr.restoreFromBack(dirty);
} else {
Log.info("Dropping AWT dirty rect " + StringUtil.toString(dirty) +
" [clip=" + StringUtil.toString(clip) + "].");
}
}
protected FrameManager _fmgr;
}
@@ -1,5 +1,5 @@
//
// $Id: MediaPanel.java,v 1.29 2003/03/25 19:06:54 mdb Exp $
// $Id: MediaPanel.java,v 1.30 2003/03/25 23:05:58 mdb Exp $
package com.threerings.media;
@@ -67,9 +67,6 @@ public class MediaPanel extends JComponent
_animmgr = new AnimationManager(_remgr);
_spritemgr = new SpriteManager(_remgr);
// we don't want to hear about repaints
setIgnoreRepaint(true);
// participate in the frame when we're visible
addAncestorListener(new AncestorAdapter() {
public void ancestorAdded (AncestorEvent event) {