Altered animation manager to separate construction from the start of

actual animation so that animating components can call
AnimationManager.start() when they know they're fully laid out and
ready to be regularly re-painted.  Return desired dimensions based on
requested scene bounds in SceneViewPanel.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@186 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-06 18:57:39 +00:00
parent 17135945d1
commit c09986bab0
5 changed files with 53 additions and 12 deletions
@@ -1,5 +1,5 @@
//
// $Id: AnimationManager.java,v 1.6 2001/08/04 01:41:02 shaper Exp $
// $Id: AnimationManager.java,v 1.7 2001/08/06 18:57:39 shaper Exp $
package com.threerings.miso.sprite;
@@ -40,7 +40,18 @@ public class AnimationManager implements Interval, PerformanceObserver
tick();
}
};
}
/**
* This method should be called by the component the animation
* manager is animating after it's been fully laid out within its
* container(s); typically, after <code>Component.doLayout()</code>
* has been called. The animation manager will then register
* itself with the <code>IntervalManager</code> to effect its
* periodic repainting of the target component.
*/
public void start ()
{
// register to monitor the refresh action
PerformanceMonitor.register(this, "refresh", 1000);
@@ -48,12 +59,21 @@ public class AnimationManager implements Interval, PerformanceObserver
IntervalManager.register(this, REFRESH_INTERVAL, null, true);
}
/**
* Called by our interval when we'd like to begin a tick. Returns
* whether we're already ticking, and notes that we've requested
* another tick.
*/
protected synchronized boolean requestTick ()
{
if (_ticking++ > 0) return false;
return true;
}
/**
* Called by the tick task when it's finished with a tick.
* Returns whether a new tick task should be created immediately.
*/
protected synchronized boolean finishedTick ()
{
if (--_ticking > 0) {
@@ -82,7 +102,7 @@ public class AnimationManager implements Interval, PerformanceObserver
_view.invalidateRects(rects);
// update frame-rate information
//PerformanceMonitor.tick(AnimationManager.this, "refresh");
PerformanceMonitor.tick(AnimationManager.this, "refresh");
// refresh the display
_target.paintImmediately(_target.getBounds());
@@ -1,5 +1,5 @@
//
// $Id: IsoSceneView.java,v 1.25 2001/08/04 00:22:19 shaper Exp $
// $Id: IsoSceneView.java,v 1.26 2001/08/06 18:57:39 shaper Exp $
package com.threerings.miso.scene;
@@ -51,6 +51,8 @@ public class IsoSceneView implements EditableSceneView
*/
public void paint (Graphics g)
{
if (_scene == null) return;
Graphics2D gfx = (Graphics2D)g;
// clip the drawing region to our desired bounds since we
@@ -1,5 +1,5 @@
//
// $Id: SceneViewPanel.java,v 1.1 2001/08/04 01:41:02 shaper Exp $
// $Id: SceneViewPanel.java,v 1.2 2001/08/06 18:57:39 shaper Exp $
package com.threerings.miso.scene;
@@ -52,6 +52,15 @@ public class SceneViewPanel extends JPanel
_view.paint(g);
}
/**
* Return the desired size for the panel based on the requested
* and calculated bounds of the scene view.
*/
public Dimension getPreferredSize ()
{
return (_smodel == null) ? super.getPreferredSize() : _smodel.bounds;
}
/** Tile width in pixels. */
protected static final int TWIDTH = 64;
@@ -1,5 +1,5 @@
//
// $Id: ViewerFrame.java,v 1.7 2001/08/04 01:41:02 shaper Exp $
// $Id: ViewerFrame.java,v 1.8 2001/08/06 18:57:39 shaper Exp $
package com.threerings.miso.viewer;
@@ -50,13 +50,15 @@ class ViewerFrame extends JFrame implements WindowListener
gl.setOffAxisPolicy(GroupLayout.STRETCH);
top.setLayout(gl);
top.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// set up the scene view panel with a default scene
ViewerSceneViewPanel svpanel =
new ViewerSceneViewPanel(_ctx, spritemgr, sprite);
top.add(svpanel, GroupLayout.FIXED);
top.add(svpanel);
// add the scene view panel
getContentPane().add(svpanel, BorderLayout.CENTER);
getContentPane().add(top, BorderLayout.CENTER);
}
/** WindowListener interface methods */
@@ -1,5 +1,5 @@
//
// $Id: ViewerSceneViewPanel.java,v 1.1 2001/08/04 01:41:02 shaper Exp $
// $Id: ViewerSceneViewPanel.java,v 1.2 2001/08/06 18:57:39 shaper Exp $
package com.threerings.miso.viewer;
@@ -31,8 +31,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
_sprite = sprite;
// create an animation manager for this panel
AnimationManager animmgr =
new AnimationManager(spritemgr, this, _view);
_animmgr = new AnimationManager(spritemgr, this, _view);
// listen to the desired events
addMouseListener(this);
@@ -40,8 +39,6 @@ public class ViewerSceneViewPanel extends SceneViewPanel
// load up the initial scene
prepareStartingScene();
PerformanceMonitor.register(this, "paint", 1000);
}
/**
@@ -71,6 +68,14 @@ public class ViewerSceneViewPanel extends SceneViewPanel
Log.info(name + " [ticks=" + ticks + "].");
}
public void doLayout ()
{
super.doLayout();
// now that we've been fully laid out, start animating
_animmgr.start();
}
/** MouseListener interface methods */
public void mousePressed (MouseEvent e)
@@ -104,6 +109,9 @@ public class ViewerSceneViewPanel extends SceneViewPanel
/** The default scene to load and display. */
protected static final String DEF_SCENE = "rsrc/scenes/default.xml";
/** The animation manager. */
AnimationManager _animmgr;
/** The sprite we're manipulating within the view. */
protected Sprite _sprite;