Allow padding to be specified for sprite icons.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1678 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-09-13 04:50:31 +00:00
parent 6419d06f3c
commit 05522ebf66
@@ -1,5 +1,5 @@
// //
// $Id: SpriteIcon.java,v 1.2 2002/05/16 03:00:29 mdb Exp $ // $Id: SpriteIcon.java,v 1.3 2002/09/13 04:50:31 mdb Exp $
package com.threerings.media.sprite; package com.threerings.media.sprite;
@@ -24,8 +24,26 @@ public class SpriteIcon implements Icon
* {@link #setOriginOffset}. * {@link #setOriginOffset}.
*/ */
public SpriteIcon (Sprite sprite) public SpriteIcon (Sprite sprite)
{
this(sprite, 0);
}
/**
* Creates a sprite icon that will use the supplied sprite to render
* itself. This sprite should not be used for anything else while
* being used in this icon because it will be "moved" when the icon is
* rendered. The sprite's origin will be set to the bottom center of
* the label. If this is undesirable, the origin can be offset via
* {@link #setOriginOffset}.
*
* @param sprite the sprite to render in this label.
* @param padding the number of pixels of blank space to put on all
* four sides of the sprite.
*/
public SpriteIcon (Sprite sprite, int padding)
{ {
_sprite = sprite; _sprite = sprite;
_padding = padding;
} }
/** /**
@@ -44,26 +62,29 @@ public class SpriteIcon implements Icon
{ {
// move the sprite to a "location" that is in the bottom center of // move the sprite to a "location" that is in the bottom center of
// our bounds (plus whatever offsets we have) // our bounds (plus whatever offsets we have)
_sprite.setLocation(x + _sprite.getWidth()/2 + _offx, _sprite.setLocation(x + _sprite.getWidth()/2 + _offx + _padding,
y + _sprite.getHeight() + _offy); y + _sprite.getHeight() + _offy + _padding);
_sprite.paint((Graphics2D)g); _sprite.paint((Graphics2D)g);
} }
// documentation inherited from interface // documentation inherited from interface
public int getIconWidth () public int getIconWidth ()
{ {
return _sprite.getWidth(); return _sprite.getWidth() + 2*_padding;
} }
// documentation inherited from interface // documentation inherited from interface
public int getIconHeight () public int getIconHeight ()
{ {
return _sprite.getHeight(); return _sprite.getHeight() + 2*_padding;
} }
/** The sprite used to render this icon. */ /** The sprite used to render this icon. */
protected Sprite _sprite; protected Sprite _sprite;
/** Used to put a bit of padding around the sprite image. */
protected int _padding;
/** Origin offsets to use when rendering the icon. */ /** Origin offsets to use when rendering the icon. */
protected int _offx, _offy; protected int _offx, _offy;
} }