Death, taxes and refactoring: seriously revamped the low-level media code

to handle scrolling in a much cleaner and happier way. There's now a
VirtualMediaPanel which operates in virtual coordinates and can be made to
"view" any location in those virtual coordinates. By changing the view,
the view can be scrolled and the view can be made to center on a pathable
(generally a sprite) which will cause it to scroll around as the pathable
moves around in the virtual coordinate space.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1475 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-06-18 22:25:33 +00:00
parent 4b29f806df
commit 7253a68c7c
10 changed files with 387 additions and 615 deletions
@@ -1,5 +1,5 @@
//
// $Id: Sprite.java,v 1.46 2002/06/11 05:56:44 mdb Exp $
// $Id: Sprite.java,v 1.47 2002/06/18 22:25:33 mdb Exp $
package com.threerings.media.sprite;
@@ -44,25 +44,6 @@ public abstract class Sprite
_y = y;
}
/**
* Returns true if this sprite should scroll along with the view or
* false if it should remain fixed relative to the view when it
* scrolls.
*/
public boolean scrollsWithView ()
{
return _scrollsWithView;
}
/**
* Specifies whether this sprite scrolls when the view scrolls or
* remains fixed relative to the view.
*/
public void setScrollsWithView (boolean scrollsWithView)
{
_scrollsWithView = scrollsWithView;
}
/**
* Called by the sprite manager to initialize the sprite when a sprite
* is added to said manager for management.
@@ -182,8 +163,8 @@ public abstract class Sprite
*/
public void setLocation (int x, int y)
{
// dirty our current bounds
invalidate();
// start with our current bounds
Rectangle dirty = new Rectangle(_bounds);
// move ourselves
_x = x;
@@ -193,8 +174,19 @@ public abstract class Sprite
// size of our current bounds
updateRenderOrigin();
// dirty our new bounds
invalidate();
// grow the dirty rectangle to incorporate our new bounds and pass
// the dirty region to our region manager
if (_spritemgr != null) {
// if our new bounds intersect our old bounds, grow a single
// dirty rectangle to incorporate them both
if (_bounds.intersects(dirty)) {
dirty.add(_bounds);
} else {
// otherwise invalidate our new bounds separately
_spritemgr.getRegionManager().invalidateRegion(_bounds);
}
_spritemgr.getRegionManager().addDirtyRegion(dirty);
}
}
/**
@@ -405,47 +397,6 @@ public abstract class Sprite
_observers.add(obs);
}
/**
* Called by the sprite manager to let us know that the view we occupy
* is scrolling by the specified amount. A sprite anchored to the view
* will simply update its coordinates; a fixed sprite will remain in
* the same position but invalidate its bounds and its scrolled
* bounds.
*/
protected void viewWillScroll (int dx, int dy)
{
if (_scrollsWithView) {
// update our coordinates
_x -= dx;
_y -= dy;
_bounds.x -= dx;
_bounds.y -= dy;
// and let any path that we're following know what's up
if (_path != null) {
_path.viewWillScroll(dx, dy);
}
} else {
// if we're not scrolling, we need to dirty our bounds and the
// part that was just scrolled out from under us
Rectangle dirty = new Rectangle(_bounds);
// expand the rectangle to contain the scrolled regions
int ex = dirty.x - dx, ey = dirty.y - dy;
if (dx < 0) {
ex += dirty.width;
}
if (dy < 0) {
ey += dirty.height;
}
dirty.add(ex, ey);
// give the dirty rectangle to the region manager
_spritemgr.getRegionManager().addDirtyRegion(dirty);
}
}
/**
* Inform all sprite observers of a sprite event.
*
@@ -497,11 +448,6 @@ public abstract class Sprite
/** The orientation of this sprite. */
protected int _orient = NONE;
/** True if we should move along with the view when it scrolls, false
* if we should remain fixed relative to the viewport. We are fixed by
* default. */
protected boolean _scrollsWithView = false;
/** When moving, the path the sprite is traversing. */
protected Path _path;
@@ -1,5 +1,5 @@
//
// $Id: SpriteManager.java,v 1.30 2002/04/25 16:23:31 mdb Exp $
// $Id: SpriteManager.java,v 1.31 2002/06/18 22:25:33 mdb Exp $
package com.threerings.media.sprite;
@@ -38,23 +38,6 @@ public class SpriteManager
_remgr = remgr;
}
/**
* Lets the sprite manager know that the view is about to scroll by
* the specified offsets. It can update the positions of its sprites
* if they are tracking the scrolled view, or generate dirty regions
* for the sprites that remain in place (meaning they move relative to
* the scrolling view).
*/
public void viewWillScroll (int dx, int dy)
{
// let the sprites know that the view is scrolling
int size = _sprites.size();
for (int i = 0; i < size; i++) {
Sprite sprite = (Sprite)_sprites.get(i);
sprite.viewWillScroll(dx, dy);
}
}
/**
* When an animated view processes its dirty rectangles, it may
* require an expansion of the dirty region which may in turn