Modified the animation interface not to take a target component and an

animated view, but to combine those so that the animated view provides the
necessary means by which to invalidate and paint. Now the SceneViewPanel
rather than the SceneView is what the animation manager talks to. It then
passes the necessary information on to the SceneView.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@297 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-21 20:02:39 +00:00
parent 30a6e3f3a2
commit eb13ed5cc1
5 changed files with 64 additions and 41 deletions
@@ -1,8 +1,9 @@
//
// $Id: AnimatedView.java,v 1.1 2001/08/14 23:35:22 mdb Exp $
// $Id: AnimatedView.java,v 1.2 2001/08/21 20:02:39 mdb Exp $
package com.threerings.media.sprite;
import java.awt.Graphics;
import java.util.List;
/**
@@ -20,4 +21,12 @@ public interface AnimatedView
* @param rects the list of {@link java.awt.Rectangle} objects.
*/
public void invalidateRects (List rects);
/**
* Requests that the animated view paint itself immediately (that it
* complete the painting process before returning from this function).
* This will only be called on the AWT thread and when it is safe to
* paint.
*/
public void paintImmediately ();
}
@@ -1,5 +1,5 @@
//
// $Id: AnimationManager.java,v 1.12 2001/08/14 23:35:22 mdb Exp $
// $Id: AnimationManager.java,v 1.13 2001/08/21 20:02:39 mdb Exp $
package com.threerings.media.sprite;
@@ -24,14 +24,12 @@ public class AnimationManager implements Interval, PerformanceObserver
{
/**
* Construct and initialize the animation manager with a sprite
* manager and the panel that animations will take place within.
* manager and the view in which the animations will take place.
*/
public AnimationManager (SpriteManager spritemgr, JComponent target,
AnimatedView view)
public AnimationManager (SpriteManager spritemgr, AnimatedView view)
{
// save off references to the objects we care about
_spritemgr = spritemgr;
_target = target;
_view = view;
// create a ticker for queueing up tick requests on the AWT thread
@@ -111,33 +109,12 @@ public class AnimationManager implements Interval, PerformanceObserver
// invalidate screen-rects dirtied by sprites
ArrayList rects = _spritemgr.getDirtyRects();
if (rects.size() > 0) {
// pass the dirty-rects on to the scene view
_view.invalidateRects(rects);
// refresh the display.
// since we know the target panel is always opaque and not
// dependent on swing's double-buffering, we bypass the
// antics that <code>paintImmediately()</code> performs in
// the interest of better performance and grab the
// target's graphics object straightaway.
Graphics g = null;
try {
Graphics pcg = _target.getGraphics();
g = pcg.create();
pcg.dispose();
} catch(NullPointerException e) {
g = null;
e.printStackTrace();
}
if (g != null) {
_target.paint(g);
}
// refresh the display
_view.paintImmediately();
}
// update refresh-rate information
@@ -172,9 +149,6 @@ public class AnimationManager implements Interval, PerformanceObserver
/** The sprite manager. */
protected SpriteManager _spritemgr;
/** The component to refresh. */
protected JComponent _target;
/** The view on which we are animating. */
protected AnimatedView _view;
}
@@ -1,21 +1,29 @@
//
// $Id: SceneView.java,v 1.13 2001/08/16 23:14:21 mdb Exp $
// $Id: SceneView.java,v 1.14 2001/08/21 20:02:39 mdb Exp $
package com.threerings.miso.scene;
import java.awt.Component;
import java.awt.Graphics;
import java.util.List;
import com.threerings.media.sprite.*;
import com.threerings.media.sprite.Path;
import com.threerings.media.tile.Tile;
/**
* The SceneView interface provides an interface to be implemented by
* The scene view interface provides an interface to be implemented by
* classes that provide a view of a given scene by drawing the scene
* contents onto a particular GUI component.
*/
public interface SceneView extends AnimatedView
public interface SceneView
{
/**
* Invalidate a list of rectangles in screen pixel coordinates in the
* scene view for later repainting.
*
* @param rects the list of {@link java.awt.Rectangle} objects.
*/
public void invalidateRects (List rects);
/**
* Render the scene to the given graphics context.
*
@@ -1,11 +1,13 @@
//
// $Id: SceneViewPanel.java,v 1.8 2001/08/16 23:14:21 mdb Exp $
// $Id: SceneViewPanel.java,v 1.9 2001/08/21 20:02:39 mdb Exp $
package com.threerings.miso.scene;
import java.awt.*;
import java.util.List;
import javax.swing.JPanel;
import com.threerings.media.sprite.AnimatedView;
import com.threerings.media.sprite.SpriteManager;
import com.threerings.media.tile.TileManager;
@@ -14,7 +16,8 @@ import com.threerings.media.tile.TileManager;
* <code>SceneView</code>, rendering it to the screen, and handling
* view-related UI events.
*/
public class SceneViewPanel extends JPanel
public class SceneViewPanel
extends JPanel implements AnimatedView
{
/**
* Construct the panel and initialize it with a context.
@@ -64,6 +67,35 @@ public class SceneViewPanel extends JPanel
g.drawImage(_offimg, 0, 0, null);
}
// documentation inherited
public void invalidateRects (List rects)
{
// pass the invalid rects on to our scene view
_view.invalidateRects(rects);
}
/**
* Paints this panel immediately. Since we know that we are always
* opaque and not dependent on Swing's double-buffering, we bypass the
* antics that <code>JComponent.paintImmediately()</code> performs in
* the interest of better performance.
*/
public void paintImmediately ()
{
Graphics g = null;
try {
Graphics pcg = getGraphics();
g = pcg.create();
pcg.dispose();
paint(g);
} catch (NullPointerException e) {
g = null;
e.printStackTrace();
}
}
public void paintComponent (Graphics g)
{
render(g);
@@ -1,5 +1,5 @@
//
// $Id: ViewerSceneViewPanel.java,v 1.11 2001/08/15 22:06:21 shaper Exp $
// $Id: ViewerSceneViewPanel.java,v 1.12 2001/08/21 20:02:39 mdb Exp $
package com.threerings.miso.viewer;
@@ -32,7 +32,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
_sprite = sprite;
// create an animation manager for this panel
_animmgr = new AnimationManager(spritemgr, this, _view);
_animmgr = new AnimationManager(spritemgr, this);
// listen to the desired events
addMouseListener(this);