Let our sprite manager know when we scroll; modified the rendering such

that scrolled views are copied to the display in their entirety instead of
just updating the dirtied regions (because we can't scroll the visible
screen buffer and then paint on top of it because the user will see things
in an intermediate stage).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1046 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-02-19 19:56:49 +00:00
parent ee3532f6f1
commit d869e1168e
@@ -1,5 +1,5 @@
// //
// $Id: AnimatedPanel.java,v 1.14 2002/02/19 07:19:04 mdb Exp $ // $Id: AnimatedPanel.java,v 1.15 2002/02/19 19:56:49 mdb Exp $
package com.threerings.media.animation; package com.threerings.media.animation;
@@ -47,15 +47,13 @@ public class AnimatedPanel extends Canvas implements AnimatedView
*/ */
public AnimatedPanel () public AnimatedPanel ()
{ {
// set our attributes for optimal display performance
// setIgnoreRepaint(true);
// create our animation manager // create our animation manager
_animmgr = new AnimationManager(this); _animmgr = new AnimationManager(this);
// create a sprite manager if we haven't been requested not to // create a sprite manager if we haven't been requested not to
if (needsSpriteManager()) { if (needsSpriteManager()) {
_animmgr.setSpriteManager(new SpriteManager()); _spritemgr = new SpriteManager();
_animmgr.setSpriteManager(_spritemgr);
} }
} }
@@ -203,9 +201,20 @@ public class AnimatedPanel extends Canvas implements AnimatedView
invalidRects.add(new Rectangle(0, 0, width, -dy)); invalidRects.add(new Rectangle(0, 0, width, -dy));
} }
// let our derived classes do whatever they need to do to // make sure we're actually scrolling before telling people
// prepare to be scrolled // about it
viewWillScroll(dx, dy); if (dx != 0 || dy != 0) {
// if we are working with a sprite manager, let it know
// that we're about to scroll out from under its sprites
// and allow it to provide us with more dirty rects
if (_spritemgr != null) {
_spritemgr.viewWillScroll(dx, dy, invalidRects);
}
// let our derived classes do whatever they need to do to
// prepare to be scrolled
viewWillScroll(dx, dy);
}
} }
// if we didn't scroll and have no invalid rects, there's no need // if we didn't scroll and have no invalid rects, there's no need
@@ -241,6 +250,10 @@ public class AnimatedPanel extends Canvas implements AnimatedView
invalidRects.clear(); invalidRects.clear();
invalidRects.add(new Rectangle(0, 0, width, height)); invalidRects.add(new Rectangle(0, 0, width, height));
Log.info("Lost back buffer, redrawing."); Log.info("Lost back buffer, redrawing.");
} else if (dx != 0 || dy != 0) {
// if it was OK, we may need to do some scrolling
g.copyArea(0, 0, width, height, -dx, -dy);
} }
// now do our actual rendering // now do our actual rendering
@@ -254,19 +267,21 @@ public class AnimatedPanel extends Canvas implements AnimatedView
try { try {
g = getGraphics(); g = getGraphics();
// do any scrolling that we need to do // if we're scrolling, we've got to copy the whole image
if (_stime != 0) { // to the screen, otherwise we can just copy the dirty
// if it was OK, we may need to do some scrolling // regions
g.copyArea(0, 0, width, height, -dx, -dy); if (dx != 0 || dy != 0) {
}
// iterate through the invalid rectangles, copying those
// areas from the back buffer to the display
int isize = invalidRects.size();
for (int i = 0; i < isize; i++) {
Rectangle rect = (Rectangle)invalidRects.get(i);
g.setClip(rect);
g.drawImage(_backimg, 0, 0, null); g.drawImage(_backimg, 0, 0, null);
} else {
// iterate through the invalid rectangles, copying
// those areas from the back buffer to the display
int isize = invalidRects.size();
for (int i = 0; i < isize; i++) {
Rectangle rect = (Rectangle)invalidRects.get(i);
g.setClip(rect);
g.drawImage(_backimg, 0, 0, null);
}
} }
} finally { } finally {
@@ -312,6 +327,9 @@ public class AnimatedPanel extends Canvas implements AnimatedView
/** The animation manager we use in this panel. */ /** The animation manager we use in this panel. */
protected AnimationManager _animmgr; protected AnimationManager _animmgr;
/** The sprite manager in use by this panel. */
protected SpriteManager _spritemgr;
/** The image used to render off-screen. */ /** The image used to render off-screen. */
protected VolatileImage _backimg; protected VolatileImage _backimg;