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:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: GeomUtil.java,v 1.7 2004/02/25 14:42:30 mdb Exp $
|
// $Id: GeomUtil.java,v 1.8 2004/08/17 00:48:40 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.geom;
|
package com.threerings.geom;
|
||||||
|
|
||||||
@@ -207,4 +207,27 @@ public class GeomUtil
|
|||||||
}
|
}
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the rectangle containing the specified tile in the supplied
|
||||||
|
* larger rectangle. Tiles go from left to right, top to bottom.
|
||||||
|
*/
|
||||||
|
public static Rectangle getTile (
|
||||||
|
int width, int height, int tileWidth, int tileHeight, int tileIndex)
|
||||||
|
{
|
||||||
|
// figure out from whence to crop the tile
|
||||||
|
int tilesPerRow = width / tileWidth;
|
||||||
|
|
||||||
|
// if we got a bogus region, return bogus tile bounds
|
||||||
|
if (tilesPerRow == 0) {
|
||||||
|
return new Rectangle(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
int row = tileIndex / tilesPerRow;
|
||||||
|
int col = tileIndex % tilesPerRow;
|
||||||
|
|
||||||
|
// crop the tile-sized image chunk from the full image
|
||||||
|
return new Rectangle(
|
||||||
|
tileWidth*col, tileHeight*row, tileWidth, tileHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
import com.threerings.geom.GeomUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A uniform tileset is one that is composed of tiles that are all the
|
* 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
|
* 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)
|
protected Rectangle computeTileBounds (int tileIndex)
|
||||||
{
|
{
|
||||||
BufferedImage tsimg = getRawTileSetImage();
|
BufferedImage tsimg = getRawTileSetImage();
|
||||||
|
return GeomUtil.getTile(tsimg.getWidth(), tsimg.getHeight(),
|
||||||
// figure out from whence to crop the tile
|
_width, _height, tileIndex);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
|
|||||||
Reference in New Issue
Block a user