From 6f101a4b5f3b1913c82fa6d5c5d894ba7fb71225 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Wed, 18 Mar 2009 21:34:11 +0000 Subject: [PATCH] Useful for cases where you have a tileset but only want some of the tiles in your multi frame image. This means that multiple different MultiFrameImages can be created using different, possibly overlapping subsets of the same shared tileset. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@782 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../media/tile/TileSubsetMultiFrameImage.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/java/com/threerings/media/tile/TileSubsetMultiFrameImage.java diff --git a/src/java/com/threerings/media/tile/TileSubsetMultiFrameImage.java b/src/java/com/threerings/media/tile/TileSubsetMultiFrameImage.java new file mode 100644 index 00000000..bb6644a9 --- /dev/null +++ b/src/java/com/threerings/media/tile/TileSubsetMultiFrameImage.java @@ -0,0 +1,63 @@ +package com.threerings.media.tile; + +import java.awt.Graphics2D; + +import com.threerings.media.image.Colorization; + +/** + * A {@link MultiFrameImage} implementation that obtains its image frames + * from a tileset but that only uses a subset of the tiles available. + */ +public class TileSubsetMultiFrameImage extends TileMultiFrameImage +{ + /** + * Creates a tile MFI which will obtain its image frames from the + * specified source tileset. + */ + public TileSubsetMultiFrameImage (TileSet source, int startIdx, int numTiles) + { + super(source); + if (startIdx + numTiles > source.getTileCount()) { + throw new IllegalArgumentException("Invalid tile range specified."); + } + _tileCount = numTiles; + _startIdx = startIdx; + } + + /** + * Creates a recoolored tile MFI which will obtain its image frames + * from the specified source tileset. + */ + public TileSubsetMultiFrameImage (TileSet source, Colorization[] zations, + int startIdx, int numTiles) + { + this(source.clone(zations), startIdx, numTiles); + } + + @Override + public int getWidth (int index) + { + return super.getWidth(index + _startIdx); + } + + @Override + public int getHeight (int index) + { + return super.getHeight(index + _startIdx); + } + + @Override + public void paintFrame (Graphics2D g, int index, int x, int y) + { + super.paintFrame(g, index + _startIdx, x, y); + } + + @Override + public boolean hitTest (int index, int x, int y) + { + return super.hitTest(index + _startIdx, x, y); + } + + /** Index of the tile with which we begin this subset. */ + protected int _startIdx; +}