diff --git a/core/src/main/java/com/threerings/jiggl/tween/Tween.java b/core/src/main/java/com/threerings/jiggl/tween/Tween.java index 7c3f095..8254db2 100644 --- a/core/src/main/java/com/threerings/jiggl/tween/Tween.java +++ b/core/src/main/java/com/threerings/jiggl/tween/Tween.java @@ -5,6 +5,7 @@ package com.threerings.jiggl.tween; import com.threerings.jiggl.util.Scalar; +import com.threerings.jiggl.view.Viz; /** * Manages the animation of a particular property of a visible. @@ -146,9 +147,8 @@ protected boolean apply (float time) { /** A tween that repeats its underlying tween over and over again (until removed). */ public static class Repeat extends Tween { - /** Cancels this repeating tween. */ - public void cancel () { - _cancelled = true; + public Repeat (Viz viz) { + _viz = viz; } @Override @@ -167,12 +167,12 @@ protected boolean apply (float time) { @Override protected boolean apply (Tweener tweener, float time) { - // if we're canceled, stop now - if (_cancelled) return true; - // if our current chain of tweens is still running, keep going if (!super.apply(tweener, time)) return false; + // if our target viz is no longer active, we're done + if (!_viz.isAdded()) return true; + // otherwise, reset to the head of the chain and keep going float overrun = _current.getOverrun(time); _current = _next; @@ -180,7 +180,7 @@ protected boolean apply (Tweener tweener, float time) return false; } - protected boolean _cancelled = false; + protected Viz _viz; } /** diff --git a/core/src/main/java/com/threerings/jiggl/tween/Tweener.java b/core/src/main/java/com/threerings/jiggl/tween/Tweener.java index 56636e7..15ba3f0 100644 --- a/core/src/main/java/com/threerings/jiggl/tween/Tweener.java +++ b/core/src/main/java/com/threerings/jiggl/tween/Tweener.java @@ -9,6 +9,7 @@ import com.threerings.jiggl.util.Driver; import com.threerings.jiggl.util.Scalar; +import com.threerings.jiggl.view.Viz; /** * Handles the animation of viz properties (position, rotation, etc.). @@ -104,12 +105,13 @@ public Tween.Delay delay (float seconds) } /** - * Returns a tweener which can be used to construct a tween that will be repeated until - * canceled. + * Returns a tweener which can be used to construct a tween that will be repeated until the + * supplied viz has been removed from its view. The viz must be added to the view in question + * before the next frame tick, or the cancellation will trigger immediately. */ - public Tweener repeat () + public Tweener repeat (Viz viz) { - return register(new Tween.Repeat()).then(); + return register(new Tween.Repeat(viz)).then(); } /** diff --git a/core/src/main/java/com/threerings/jiggl/view/View.java b/core/src/main/java/com/threerings/jiggl/view/View.java index f0d40f2..1f1ee2c 100644 --- a/core/src/main/java/com/threerings/jiggl/view/View.java +++ b/core/src/main/java/com/threerings/jiggl/view/View.java @@ -8,6 +8,7 @@ import java.util.List; import com.threerings.jiggl.rsrc.Tile; +import com.threerings.jiggl.util.Color; /** * Coordinates the display and animation of a collection of {@link Viz} instances. @@ -30,7 +31,7 @@ public T add (T viz) public void remove (Viz viz) { _vizs.remove(viz); - viz.onRemove(this); + viz.onRemove(); } /** @@ -39,7 +40,7 @@ public void remove (Viz viz) public void clear () { for (Viz v : _vizs) { - v.onRemove(this); + v.onRemove(); } _vizs.clear(); } @@ -50,9 +51,9 @@ public void clear () public abstract void render (); /** - * Creates a visible that renders the supplied geometry. + * Creates a visible that renders the supplied geometry using the supplied color. */ - public abstract Viz newGeomViz (Geometry geom); + public abstract Viz newGeomViz (Geometry geom, Color color); /** * Creates a visible to render the supplied tile. @@ -65,7 +66,7 @@ public void clear () protected void renderVisibles () { for (int ii = 0, ll = _vizs.size(); ii < ll; ii++) { - _vizs.get(ii).render(this); + _vizs.get(ii).render(); } } diff --git a/core/src/main/java/com/threerings/jiggl/view/Viz.java b/core/src/main/java/com/threerings/jiggl/view/Viz.java index 4de4001..146f783 100644 --- a/core/src/main/java/com/threerings/jiggl/view/Viz.java +++ b/core/src/main/java/com/threerings/jiggl/view/Viz.java @@ -4,7 +4,6 @@ package com.threerings.jiggl.view; -import com.threerings.jiggl.util.Color; import com.threerings.jiggl.util.Scalar; /** @@ -30,9 +29,6 @@ public abstract class Viz /** The rotation of this visible, in radians. */ public final Scalar rotation = new Scalar(0); - /** The color of this visible, or null. */ - public Color color; - /** * Returns the width of this visible, including local scaling transformations (but not * rotation). Transformations applied by a parent of this visible are also not included. @@ -45,6 +41,11 @@ public abstract class Viz */ public abstract float getHeight (); + /** + * Returns true if this viz is added to a view, false otherwise. + */ + public abstract boolean isAdded (); + /** * Called when this viz is added to a view. The viz should prepare any buffers or shader * programs it will need to render itself. Any exception thrown by this method will result in @@ -57,10 +58,10 @@ public abstract class Viz * Called when this viz is removed from a view. The viz should destroy any buffers or shader * programs it created in {@link #onAdd}. */ - protected abstract void onRemove (View view); + protected abstract void onRemove (); /** * Instructs this viz to issue the rendering calls needed to visualize itself. */ - protected abstract void render (View view); + protected abstract void render (); }