From a5bba441bedcbab61bc936b94623b013006c0a2c Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 17 Sep 2002 20:39:03 +0000 Subject: [PATCH] An MFI implementation that obtains its source frames from a tileset. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1699 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../media/tile/TileMultiFrameImage.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/java/com/threerings/media/tile/TileMultiFrameImage.java diff --git a/src/java/com/threerings/media/tile/TileMultiFrameImage.java b/src/java/com/threerings/media/tile/TileMultiFrameImage.java new file mode 100644 index 000000000..5c59e3ebb --- /dev/null +++ b/src/java/com/threerings/media/tile/TileMultiFrameImage.java @@ -0,0 +1,84 @@ +// +// $Id: TileMultiFrameImage.java,v 1.1 2002/09/17 20:39:03 mdb Exp $ + +package com.threerings.media.tile; + +import java.awt.Graphics; + +import com.threerings.media.Log; +import com.threerings.media.util.MultiFrameImage; + +/** + * A {@link MultiFrameImage} implementation that obtains its image frames + * from a tileset. + */ +public class TileMultiFrameImage implements MultiFrameImage +{ + /** + * Creates a tile MFI which will obtain its image frames from the + * specified source tileset. + */ + public TileMultiFrameImage (TileSet source) + { + _source = source; + } + + // documentation inherited from interface + public int getFrameCount () + { + return _source.getTileCount(); + } + + // documentation inherited from interface + public int getWidth (int index) + { + try { + return _source.getTile(index).getWidth(); + } catch (NoSuchTileException nste) { + Log.warning("Eh? Tile set reported 'no such tile' " + + "[tcount=" + _source.getTileCount() + + ", tindex=" + index + "]."); + return -1; + } + } + + // documentation inherited from interface + public int getHeight (int index) + { + try { + return _source.getTile(index).getHeight(); + } catch (NoSuchTileException nste) { + Log.warning("Eh? Tile set reported 'no such tile' " + + "[tcount=" + _source.getTileCount() + + ", tindex=" + index + "]."); + return -1; + } + } + + // documentation inherited from interface + public void paintFrame (Graphics g, int index, int x, int y) + { + try { + _source.getTile(index).paint(g, x, y); + } catch (NoSuchTileException nste) { + Log.warning("Eh? Tile set reported 'no such tile' " + + "[tcount=" + _source.getTileCount() + + ", tindex=" + index + "]."); + } + } + + // documentation inherited from interface + public boolean hitTest (int index, int x, int y) + { + try { + return _source.getTile(index).hitTest(x, y); + } catch (NoSuchTileException nste) { + Log.warning("Eh? Tile set reported 'no such tile' " + + "[tcount=" + _source.getTileCount() + + ", tindex=" + index + "]."); + return false; + } + } + + protected TileSet _source; +}