Pulled tile calculations out into a handy utility method.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3082 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2004-08-17 00:48:40 +00:00
parent cb5c7c5d22
commit b7d43b786f
2 changed files with 29 additions and 16 deletions
@@ -1,11 +1,13 @@
//
// $Id: UniformTileSet.java,v 1.14 2003/05/13 21:33:58 ray Exp $
// $Id: UniformTileSet.java,v 1.15 2004/08/17 00:48:40 mdb Exp $
package com.threerings.media.tile;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import com.threerings.geom.GeomUtil;
/**
* A uniform tileset is one that is composed of tiles that are all the
* same width and height and are arranged into rows, with each row having
@@ -60,20 +62,8 @@ public class UniformTileSet extends TileSet
protected Rectangle computeTileBounds (int tileIndex)
{
BufferedImage tsimg = getRawTileSetImage();
// figure out from whence to crop the tile
int tilesPerRow = tsimg.getWidth() / _width;
// if we got a bogus image, return bogus tile bounds
if (tilesPerRow == 0) {
return new Rectangle(0, 0, tsimg.getWidth(), tsimg.getHeight());
}
int row = tileIndex / tilesPerRow;
int col = tileIndex % tilesPerRow;
// crop the tile-sized image chunk from the full image
return new Rectangle(_width*col, _height*row, _width, _height);
return GeomUtil.getTile(tsimg.getWidth(), tsimg.getHeight(),
_width, _height, tileIndex);
}
// documentation inherited