A whole lot of widening, refactoring, thinking, rethinking and fiddling around
for what ultimately boils down adding this method to BundledComponentRepository:
@Override // from IMImageProvider
public Mirage getTileImage (String path, Rectangle bounds, Colorization[] zations)
{
// we don't need our images prepared for screen rendering
BufferedImage src = _imgr.getImage(getImageKey(path), zations);
if (bounds != null) {
src = src.getSubimage(bounds.x, bounds.y, bounds.width, bounds.height);
}
return new BufferedMirage(src);
}
So much fun to revisit code I wrote six years ago.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@283 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -31,11 +31,10 @@ import java.io.ObjectInputStream;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
/**
|
||||
* The swiss army tileset supports a diverse variety of tiles in the
|
||||
* tileset image. Each row can contain varying numbers of tiles and each
|
||||
* row can have its own width and height. Tiles can be separated from the
|
||||
* edge of the tileset image by some border offset and can be separated
|
||||
* from one another by a gap distance.
|
||||
* The swiss army tileset supports a diverse variety of tiles in the tileset image. Each row can
|
||||
* contain varying numbers of tiles and each row can have its own width and height. Tiles can be
|
||||
* separated from the edge of the tileset image by some border offset and can be separated from one
|
||||
* another by a gap distance.
|
||||
*/
|
||||
public class SwissArmyTileSet extends TileSet
|
||||
{
|
||||
@@ -45,105 +44,8 @@ public class SwissArmyTileSet extends TileSet
|
||||
return _numTiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile counts which are the number of tiles in each row of
|
||||
* the tileset image. Each row can have an arbitrary number of tiles.
|
||||
*/
|
||||
public void setTileCounts (int[] tileCounts)
|
||||
{
|
||||
_tileCounts = tileCounts;
|
||||
|
||||
// compute our total tile count
|
||||
computeTileCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tile count settings.
|
||||
*/
|
||||
public int[] getTileCounts ()
|
||||
{
|
||||
return _tileCounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes our total tile count from the individual counts for each
|
||||
* row.
|
||||
*/
|
||||
protected void computeTileCount ()
|
||||
{
|
||||
// compute our number of tiles
|
||||
_numTiles = 0;
|
||||
for (int i = 0; i < _tileCounts.length; i++) {
|
||||
_numTiles += _tileCounts[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile widths for each row. Each row can have tiles of a
|
||||
* different width.
|
||||
*/
|
||||
public void setWidths (int[] widths)
|
||||
{
|
||||
_widths = widths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width settings.
|
||||
*/
|
||||
public int[] getWidths ()
|
||||
{
|
||||
return _widths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile heights for each row. Each row can have tiles of a
|
||||
* different height.
|
||||
*/
|
||||
public void setHeights (int[] heights)
|
||||
{
|
||||
_heights = heights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height settings.
|
||||
*/
|
||||
public int[] getHeights ()
|
||||
{
|
||||
return _heights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset in pixels of the upper left corner of the first
|
||||
* tile in the first row. If the tileset image has a border, this can
|
||||
* be set to account for it.
|
||||
*/
|
||||
public void setOffsetPos (Point offsetPos)
|
||||
{
|
||||
_offsetPos = offsetPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the gap between tiles (in pixels). If the tiles
|
||||
* have space between them, this can be set to account for it.
|
||||
*/
|
||||
public void setGapSize (Dimension gapSize)
|
||||
{
|
||||
_gapSize = gapSize;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void toString (StringBuilder buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", widths=").append(StringUtil.toString(_widths));
|
||||
buf.append(", heights=").append(StringUtil.toString(_heights));
|
||||
buf.append(", tileCounts=").append(StringUtil.toString(_tileCounts));
|
||||
buf.append(", offsetPos=").append(StringUtil.toString(_offsetPos));
|
||||
buf.append(", gapSize=").append(StringUtil.toString(_gapSize));
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected Rectangle computeTileBounds (int tileIndex)
|
||||
public Rectangle computeTileBounds (int tileIndex, Rectangle bounds)
|
||||
{
|
||||
// find the row number containing the sought-after tile
|
||||
int ridx, tcount, ty, tx;
|
||||
@@ -165,11 +67,104 @@ public class SwissArmyTileSet extends TileSet
|
||||
tx += (xidx * (_widths[ridx] + _gapSize.width));
|
||||
|
||||
// Log.info("Computed tile bounds [tileIndex=" + tileIndex +
|
||||
// ", ridx=" + ridx + ", xidx=" + xidx +
|
||||
// ", tx=" + tx + ", ty=" + ty + "].");
|
||||
// ", ridx=" + ridx + ", xidx=" + xidx + ", tx=" + tx + ", ty=" + ty + "].");
|
||||
|
||||
// crop the tile-sized image chunk from the full image
|
||||
return new Rectangle(tx, ty, _widths[ridx], _heights[ridx]);
|
||||
bounds.setBounds(tx, ty, _widths[ridx], _heights[ridx]);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile counts which are the number of tiles in each row of the tileset image. Each
|
||||
* row can have an arbitrary number of tiles.
|
||||
*/
|
||||
public void setTileCounts (int[] tileCounts)
|
||||
{
|
||||
_tileCounts = tileCounts;
|
||||
|
||||
// compute our total tile count
|
||||
computeTileCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tile count settings.
|
||||
*/
|
||||
public int[] getTileCounts ()
|
||||
{
|
||||
return _tileCounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes our total tile count from the individual counts for each row.
|
||||
*/
|
||||
protected void computeTileCount ()
|
||||
{
|
||||
// compute our number of tiles
|
||||
_numTiles = 0;
|
||||
for (int i = 0; i < _tileCounts.length; i++) {
|
||||
_numTiles += _tileCounts[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile widths for each row. Each row can have tiles of a different width.
|
||||
*/
|
||||
public void setWidths (int[] widths)
|
||||
{
|
||||
_widths = widths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width settings.
|
||||
*/
|
||||
public int[] getWidths ()
|
||||
{
|
||||
return _widths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile heights for each row. Each row can have tiles of a different height.
|
||||
*/
|
||||
public void setHeights (int[] heights)
|
||||
{
|
||||
_heights = heights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height settings.
|
||||
*/
|
||||
public int[] getHeights ()
|
||||
{
|
||||
return _heights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset in pixels of the upper left corner of the first tile in the first row. If
|
||||
* the tileset image has a border, this can be set to account for it.
|
||||
*/
|
||||
public void setOffsetPos (Point offsetPos)
|
||||
{
|
||||
_offsetPos = offsetPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the gap between tiles (in pixels). If the tiles have space between them,
|
||||
* this can be set to account for it.
|
||||
*/
|
||||
public void setGapSize (Dimension gapSize)
|
||||
{
|
||||
_gapSize = gapSize;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void toString (StringBuilder buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", widths=").append(StringUtil.toString(_widths));
|
||||
buf.append(", heights=").append(StringUtil.toString(_heights));
|
||||
buf.append(", tileCounts=").append(StringUtil.toString(_tileCounts));
|
||||
buf.append(", offsetPos=").append(StringUtil.toString(_offsetPos));
|
||||
buf.append(", gapSize=").append(StringUtil.toString(_gapSize));
|
||||
}
|
||||
|
||||
private void readObject (ObjectInputStream in)
|
||||
@@ -193,15 +188,15 @@ public class SwissArmyTileSet extends TileSet
|
||||
/** The height of the tiles in each row in pixels. */
|
||||
protected int[] _heights;
|
||||
|
||||
/** The offset distance (x, y) in pixels from the top-left of the
|
||||
* image to the start of the first tile image. */
|
||||
/** The offset distance (x, y) in pixels from the top-left of the image to the start of the
|
||||
* first tile image. */
|
||||
protected Point _offsetPos = new Point();
|
||||
|
||||
/** The distance (x, y) in pixels between each tile in each row
|
||||
* horizontally, and between each row of tiles vertically. */
|
||||
/** The distance (x, y) in pixels between each tile in each row horizontally, and between each
|
||||
* row of tiles vertically. */
|
||||
protected Dimension _gapSize = new Dimension();
|
||||
|
||||
/** Increase this value when object's serialized state is impacted by
|
||||
* a class change (modification of fields, inheritance). */
|
||||
/** Increase this value when object's serialized state is impacted by a class change
|
||||
* (modification of fields, inheritance). */
|
||||
private static final long serialVersionUID = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user