From ddb3c92fa1467932cc6b1849dcfac327aa58cede Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Wed, 26 Sep 2007 22:18:27 +0000 Subject: [PATCH] Let's not make things that actually compose stuff hop about the screen by using their VolatileMirage offset in the place of their origin offset. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@296 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../cast/CompositedMaskedImage.java | 24 +++++++++++---- .../com/threerings/cast/CompositedMirage.java | 6 ++-- .../cast/CompositedMultiFrameImage.java | 18 ++++------- .../cast/CompositedShadowImage.java | 30 +++++++++++++++---- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/java/com/threerings/cast/CompositedMaskedImage.java b/src/java/com/threerings/cast/CompositedMaskedImage.java index b2851fa6..3df352c4 100644 --- a/src/java/com/threerings/cast/CompositedMaskedImage.java +++ b/src/java/com/threerings/cast/CompositedMaskedImage.java @@ -66,20 +66,18 @@ public class CompositedMaskedImage extends CompositedMultiFrameImage // documentation inherited from interface public void paintFrame (Graphics2D g, int index, int x, int y) { - _images[index].paint(g, x + _images[index].getX(), - y + _images[index].getY()); + _images[index].paint(g, x + getX(index), y + getY(index)); } // documentation inherited from interface public boolean hitTest (int index, int x, int y) { - return _images[index].hitTest(x + _images[index].getX(), - y + _images[index].getY()); + return _images[index].hitTest(x + getX(index), y + getY(index)); } // documentation inherited from interface TrimmedMultiFrameImage public void getTrimmedBounds (int index, Rectangle bounds) { - bounds.setBounds(_images[index].getX(), _images[index].getY(), - _images[index].getWidth(), _images[index].getHeight()); + bounds.setBounds(getX(index), getY(index), _images[index].getWidth(), + _images[index].getHeight()); } // documentation inherited @@ -129,4 +127,18 @@ public class CompositedMaskedImage extends CompositedMultiFrameImage } } } + + /** + * @return the x offset into the source image for the image at index + */ + protected int getX (int index) { + return ((VolatileMirage)_images[index]).getX(); + } + + /** + * @return the y offset into the source image for the image at index + */ + protected int getY (int index) { + return ((VolatileMirage)_images[index]).getY(); + } }; diff --git a/src/java/com/threerings/cast/CompositedMirage.java b/src/java/com/threerings/cast/CompositedMirage.java index c2e75f6d..100fd50e 100644 --- a/src/java/com/threerings/cast/CompositedMirage.java +++ b/src/java/com/threerings/cast/CompositedMirage.java @@ -6,16 +6,16 @@ import com.threerings.cast.CompositedActionFrames.ComponentFrames; import com.threerings.media.image.Mirage; public interface CompositedMirage - extends Mirage, Comparator + extends Mirage { /** * Returns the x offset into our image. */ - public int getX (); + public int getXOrigin (); /** * Returns the y offset into our image. */ - public int getY (); + public int getYOrigin (); } diff --git a/src/java/com/threerings/cast/CompositedMultiFrameImage.java b/src/java/com/threerings/cast/CompositedMultiFrameImage.java index 84008aed..c080f38e 100644 --- a/src/java/com/threerings/cast/CompositedMultiFrameImage.java +++ b/src/java/com/threerings/cast/CompositedMultiFrameImage.java @@ -27,6 +27,7 @@ import java.awt.Rectangle; import java.awt.Transparency; import java.awt.image.BufferedImage; import java.util.Arrays; +import java.util.Comparator; import com.threerings.cast.CompositedActionFrames.ComponentFrames; import com.threerings.cast.bundle.BundledComponentRepository.TileSetFrameImage; @@ -75,12 +76,12 @@ public class CompositedMultiFrameImage public int getXOrigin (int index) { - return _images[index].getX(); + return _images[index].getXOrigin(); } public int getYOrigin (int index) { - return _images[index].getY(); + return _images[index].getYOrigin(); } // documentation inherited from interface @@ -137,22 +138,15 @@ public class CompositedMultiFrameImage this.y = y; } - public int getX () + public int getXOrigin () { return x; } - public int getY () + public int getYOrigin () { return y; } - - // documentation inherited from interface - public int compare (ComponentFrames cf1, ComponentFrames cf2) - { - return (cf1.ccomp.componentClass.getRenderPriority(_action, _orient) - - cf2.ccomp.componentClass.getRenderPriority(_action, _orient)); - } public long getEstimatedMemoryUsage () { @@ -214,7 +208,7 @@ public class CompositedMultiFrameImage * Used to create our mirage using the source action frame images. */ protected class CompositedVolatileMirage extends VolatileMirage - implements CompositedMirage + implements CompositedMirage, Comparator { public CompositedVolatileMirage (int index) { diff --git a/src/java/com/threerings/cast/CompositedShadowImage.java b/src/java/com/threerings/cast/CompositedShadowImage.java index ea85e8fc..f7d34942 100644 --- a/src/java/com/threerings/cast/CompositedShadowImage.java +++ b/src/java/com/threerings/cast/CompositedShadowImage.java @@ -65,26 +65,44 @@ public class CompositedShadowImage extends CompositedMultiFrameImage public int getYOrigin (int index) { return _sources[0].frames.getYOrigin(_orient, index); } + + @Override // documentation inherited + protected CompositedMirage createCompositedMirage (int index) { + // Always use a CompositedVolatileMirage for ShadowImage since we need to draw into it. + return new CompositedVolatileMirage(index); + } // documentation inherited from interface public void paintFrame (Graphics2D g, int index, int x, int y) { Composite ocomp = g.getComposite(); g.setComposite(_shadowAlpha); - _images[index].paint(g, x + _images[index].getX(), - y + _images[index].getY()); + _images[index].paint(g, x + getX(index), y + getY(index)); g.setComposite(ocomp); } // documentation inherited from interface public boolean hitTest (int index, int x, int y) { - return _images[index].hitTest(x + _images[index].getX(), - y + _images[index].getY()); + return _images[index].hitTest(x + getX(index), y + getY(index)); } // documentation inherited from interface TrimmedMultiFrameImage public void getTrimmedBounds (int index, Rectangle bounds) { - bounds.setBounds(_images[index].getX(), _images[index].getY(), - _images[index].getWidth(), _images[index].getHeight()); + bounds.setBounds(getX(index), getY(index), _images[index].getWidth(), + _images[index].getHeight()); + } + + /** + * @return the x offset into the source image for the image at index + */ + protected int getX (int index) { + return ((VolatileMirage)_images[index]).getX(); + } + + /** + * @return the y offset into the source image for the image at index + */ + protected int getY (int index) { + return ((VolatileMirage)_images[index]).getY(); } /** The alpha value at which we render our shadow. */