PulpCore

pulpcore.sprite
Class StretchableSprite

java.lang.Object
  extended by pulpcore.sprite.Sprite
      extended by pulpcore.sprite.ImageSprite
          extended by pulpcore.sprite.StretchableSprite
All Implemented Interfaces:
PropertyListener

public class StretchableSprite
extends ImageSprite

Stretchable sprites are sprites that, when scaled, draw the "static" sections normally and scale the "stretchable" sections. Typically, corners are drawn normally while the inside is scaled. The format used is identical to Android's nine-patch format.

Example:

    import pulpcore.image.Colors;
    import pulpcore.scene.Scene2D;
    import pulpcore.sprite.FilledSprite;
    import pulpcore.sprite.StretchableSprite;

    public class StretchableSpriteTest extends Scene2D {
        public void load() {
            add(new FilledSprite(Colors.BLUE));
            add(new StretchableSprite("button.9.png", 5, 5, 200, 200));
        }
    }
    


Field Summary
 
Fields inherited from class pulpcore.sprite.ImageSprite
antiAlias
 
Fields inherited from class pulpcore.sprite.Sprite
alpha, anchorX, anchorY, angle, CENTER, DEFAULT, EAST, enabled, height, NORTH, NORTH_EAST, NORTH_WEST, pixelSnapping, SOUTH, SOUTH_EAST, SOUTH_WEST, visible, WEST, width, x, y
 
Constructor Summary
StretchableSprite(CoreImage image, double x, double y)
          Creates a StretchableSprite from an image with defined stretchable sections.
StretchableSprite(CoreImage image, double x, double y, double w, double h)
          Creates a StretchableSprite from an image with defined stretchable sections.
StretchableSprite(CoreImage image, int capWidth, int capHeight, double x, double y, double w, double h)
          Creates a StretchableSprite with the specified cap size.
StretchableSprite(String imageName, double x, double y)
          Creates a StretchableSprite from an image with defined stretchable sections.
StretchableSprite(String imageName, double x, double y, double w, double h)
          Creates a StretchableSprite from an image with defined stretchable sections.
StretchableSprite(String imageName, int capWidth, int capHeight, double x, double y, double w, double h)
          Creates a StretchableSprite with the specified cap size.
 
Method Summary
protected  void drawSprite(CoreGraphics g)
          Draws the sprite.
protected  int getNaturalHeight()
          Gets the fixed-point value of the Sprite's natural height.
protected  int getNaturalWidth()
          Gets the fixed-point value of the Sprite's natural width.
 int getPaddingBottom()
           
 int getPaddingLeft()
           
 int getPaddingRight()
           
 int getPaddingTop()
           
protected  boolean isTransparent(int localX, int localY)
          Checks if the pixel at the specified integer location is transparent.
 CoreImage render()
          Creates a rendered version of this StretchableSprite at the current dimensions.
 CoreImage render(int width, int height)
          Creates a rendered version of this StretchableSprite with the specified dimensions.
 void setAnchorToHotSpot()
          Sets the anchor to the underlying image's hotspot.
 void setImage(CoreImage image)
          Sets this ImageSprite's internal image.
 
Methods inherited from class pulpcore.sprite.ImageSprite
getImage, getPixelLevelChecks, isOpaque, propertyChange, setAnchor, setImage, setPixelLevelChecks, update
 
Methods inherited from class pulpcore.sprite.Sprite
bindLocationTo, bindSizeTo, clearCursor, clearDirtyRect, contains, draw, getBlendMode, getCursor, getDirtyRect, getFilter, getLocalX, getLocalY, getParent, getRoot, getScene2D, getTag, getViewX, getViewX, getViewY, getViewY, intersects, isDirty, isEnabled, isEnabledAndVisible, isMouseDoubleClicked, isMouseDown, isMouseHover, isMouseOver, isMousePressed, isMouseReleased, isMouseTripleClicked, isMouseWheelRotated, isPick, isPickEnabledAndVisible, move, move, move, move, move, move, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, removeFromParent, scale, scale, scale, scale, scale, scale, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, setAnchor, setBlendMode, setCursor, setDirty, setFilter, setLocation, setLocation, setSize, setSize, setTag, translate, translate, updateDirtyRect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StretchableSprite

public StretchableSprite(String imageName,
                         double x,
                         double y)
Creates a StretchableSprite from an image with defined stretchable sections. The format used is identical to Android's nine-patch format


StretchableSprite

public StretchableSprite(String imageName,
                         double x,
                         double y,
                         double w,
                         double h)
Creates a StretchableSprite from an image with defined stretchable sections. The format used is identical to Android's nine-patch format


StretchableSprite

public StretchableSprite(CoreImage image,
                         double x,
                         double y)
Creates a StretchableSprite from an image with defined stretchable sections. The format used is identical to Android's nine-patch format


StretchableSprite

public StretchableSprite(CoreImage image,
                         double x,
                         double y,
                         double w,
                         double h)
Creates a StretchableSprite from an image with defined stretchable sections. The format used is identical to Android's nine-patch format


StretchableSprite

public StretchableSprite(String imageName,
                         int capWidth,
                         int capHeight,
                         double x,
                         double y,
                         double w,
                         double h)
Creates a StretchableSprite with the specified cap size. The caps (in the four corners) are not stretched.


StretchableSprite

public StretchableSprite(CoreImage image,
                         int capWidth,
                         int capHeight,
                         double x,
                         double y,
                         double w,
                         double h)
Creates a StretchableSprite with the specified cap size. The caps (in the four corners) are not stretched.

Method Detail

setImage

public void setImage(CoreImage image)
Description copied from class: ImageSprite
Sets this ImageSprite's internal image. The width, height, and anchor of this ImageSprite are not changed.

Overrides:
setImage in class ImageSprite

render

public CoreImage render()
Creates a rendered version of this StretchableSprite at the current dimensions. The angle is ignored.


render

public CoreImage render(int width,
                        int height)
Creates a rendered version of this StretchableSprite with the specified dimensions. The angle is ignored.


getPaddingTop

public int getPaddingTop()

getPaddingRight

public int getPaddingRight()

getPaddingBottom

public int getPaddingBottom()

getPaddingLeft

public int getPaddingLeft()

setAnchorToHotSpot

public void setAnchorToHotSpot()
Description copied from class: ImageSprite
Sets the anchor to the underlying image's hotspot. An image's hotspot is defined at build time with a property file.

Overrides:
setAnchorToHotSpot in class ImageSprite

isTransparent

protected boolean isTransparent(int localX,
                                int localY)
Description copied from class: Sprite
Checks if the pixel at the specified integer location is transparent. This method does not check if this sprite is enabled or visible, nor does it check its alpha value.

The default implementation always returns false. Subclasses of this class may need to override this method to return accurate results.

This method is called from Sprite.contains(int,int).

Overrides:
isTransparent in class ImageSprite
Parameters:
localX - integer x-coordinate in local space
localY - integer y-coordinate in local space

getNaturalWidth

protected int getNaturalWidth()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural width. Subclasses will override this method to specify the natural width. The natural width is the width of the Sprite if no scaling is applied - for an ImageSprite, the natural width is the width of the image.

Overrides:
getNaturalWidth in class ImageSprite

getNaturalHeight

protected int getNaturalHeight()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural height. Subclasses will override this method to specify the natural height. The natural height is the height of the Sprite if no scaling is applied - for an ImageSprite, the natural height is the height of the image.

Overrides:
getNaturalHeight in class ImageSprite

drawSprite

protected void drawSprite(CoreGraphics g)
Description copied from class: Sprite
Draws the sprite. The graphic context's alpha is set to this sprite's alpha, and it's translation is offset by this sprite's location. This method is not called if the sprite is not visible or it's alpha is less than or equal to zero.

This method may be called multiple times for each dirty rectangle. The clip of the graphics context will be set to the current dirty rectangle.

When the contents of this sprite change (in another words, the graphic output of this method will be different from the last time it is called), subclasses should call setDirty(true).

Implementors should not save a reference to the graphics context as it can change between calls to this method.

Overrides:
drawSprite in class ImageSprite

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.