Sofia API Reference

  • Package Index
  • Class Index
  • Packages
  • sofia.app
  • sofia.content
  • sofia.data
  • sofia.graphics
    • Interfaces
    • Joint
    • PropertyTransformer
    • Classes
    • AbstractJoint
    • Anchor
    • Color
    • CoordinateSystem
    • DirectionalPad
    • DistanceJoint
    • ElasticInInterpolator
    • ElasticInOutInterpolator
    • ElasticOutInterpolator
    • FillableShape
    • FillableShape.Animator
    • Geometry
    • Image
    • LineShape
    • MotionStep
    • OvalShape
    • PointAndAnchor
    • Polygon
    • PolygonShape
    • Predicate
    • RectangleShape
    • RevoluteJoint
    • Shape
    • Shape.Animator
    • Shape.Filter
    • ShapeField
    • ShapeFilter
    • ShapeSet
    • ShapeView
    • SizeF
    • StrokedShape
    • StrokedShape.Animator
    • TextShape
    • TextShape.Animator
    • Timings
    • ViewEdges
    • ZIndexComparator
    • Enums
    • RepeatMode
    • ShapeMotion
  • sofia.util
  • sofia.view
  • sofia.widget

public abstract class
FillableShape

extends StrokedShape

Inheritance

  • java.lang.Object
    • sofia.graphics.Shape
      • sofia.graphics.StrokedShape
        • sofia.graphics.FillableShape
Known Direct Subclasses
OvalShape, PolygonShape, RectangleShape
OvalShape A shape that is drawn as an oval. 
PolygonShape

A shape that is drawn using an arbitrary polygon. 

RectangleShape A shape that is drawn as a rectangle. 
Known Indirect Subclasses
DirectionalPad
DirectionalPad An on-screen directional pad (d-pad) suitable for games, based on the cross-shaped d-pad used on classic console game systems. 

Class Overview

An abstract class that represents shapes that can be filled when they are drawn, and for which the fill color can be set independently of the shape's other color (for the stroke).


Summary

Nested Classes
class FillableShape.Animator<AnimatorType extends Animator<AnimatorType>> Provides animation support for shapes. 
Public Constructors
FillableShape()
Creates a new FillableShape.
Public Methods
Animator<?> animate(long duration)

Gets an animator object that lets the user animate properties of the receiving shape.

int getAlpha()

A convenience method that gets the alpha (opacity) component of the shape's color.

Color getFillColor()
Gets the color used to fill the shape.
Image getImage()
Gets the image used to fill this shape.
boolean isFilled()
Gets a value indicating whether the shape will be filled when it is drawn.
void removeImage()
Removes the image used to fill this shape.
void setAlpha(int newAlpha)
A convenience method that sets the alpha (opacity) component of the shape's color and fill color without changing the other color components.
void setFillColor(Color newFillColor)
Sets the color used to fill the shape.
void setFilled(boolean newFilled)
Sets a value indicating whether the shape will be filled when it is drawn.
void setImage(Image newImage)
Sets the image used to fill this shape.
void setImage(String imageName)
Sets the image used to fill this shape.
Protected Methods
void drawBitmap(Canvas canvas)
Draws the image for this shape.
Paint getFillPaint()
Gets a Paint used to fill the shape.
Paint getImagePaint()
Gets a Paint object suitable for drawing the image for this shape.
Methods inherited from class sofia.graphics.StrokedShape
Animator<?> animate(long duration)

Gets an animator object that lets the user animate properties of the receiving shape.

Paint getPaint()
Gets the Paint object that describes how this shape should be drawn.
Paint.Cap getStrokeCap()
Gets the stroke's cap, which determines how to treat the beginning and end of the stroke.
Paint.Join getStrokeJoin()
Gets the stroke's join type.
double getStrokeMiter()
Gets the stroke's miter value, which is used to control the behavior of miter joins when the join angle is sharp.
double getStrokeWidth()
Gets the width of the stroke.
void setStrokeCap(Paint.Cap newStrokeCap)
Sets the stroke's cap, which determines how to treat the beginning and end of the stroke.
void setStrokeJoin(Paint.Join newStrokeJoin)
Sets the stroke's join type.
void setStrokeMiter(double newStrokeMiter)
Sets the stroke's miter value, which is used to control the behavior of miter joins when the join angle is sharp.
void setStrokeWidth(double newStrokeWidth)
Sets the width of the stroke.
Methods inherited from class sofia.graphics.Shape
void addFixtureForShape(org.jbox2d.collision.shapes.Shape b2Shape)
This method should only be called internally from within #createFixtures(Body) in order to create fixtures for the shape and add them to the shape's internal list of fixtures.
void addOther(Shape newShape)
Add another shape to the same view (or composite shape) containing this shape.
Animator<?> animate(long duration)

Gets an animator object that lets the user animate properties of the receiving shape.

void applyLinearImpulse(float x, float y)
TODO document
void conditionallyRepaint()
Called to indicate that the shape needs to be repainted on the screen.
boolean contains(PointF point)
Gets a value indicating whether the specified pixel location is contained in the receiver.
boolean contains(float x, float y)

Gets a value indicating whether the specified pixel location is contained in the receiver.

abstract void createFixtures()
This method is intended for internal use only, or by advanced users subclassing one of the abstract shape types.
void destroyFixtures()
Destroys the fixtures associated with this shape.
abstract void draw(Canvas canvas)
Subclasses must implement this method to define how the shape is to be drawn on the canvas.
ViewEdges extendsOutside(RectF bounds)
Determine whether any part of this shape extends outside the given rectangle.
int getAlpha()
A convenience method that gets the alpha (opacity) component of the shape's color.
float getAngularDamping()
Gets the angular damping of the shape, which is used to reduce the angular velocity of the shape.
float getAngularVelocity()
Gets the angular velocity of the shape, in degrees per second.
Body getB2Body()
For advanced usage only.
BodyDef getB2BodyDef()

For advanced usage only.

abstract RectF getBounds()
Gets the bounding rectangle of the shape.
Color getColor()
Gets the color of the receiver.
float getDensity()
Gets the density of the shape.
float getFriction()
Gets the coefficient of friction for the shape.
float getGravityScale()
Gets the gravity scaling factory for this shape.
float getHeight()
Gets the height of the shape, in pixels.
float getLeft()
Gets the x-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default).
float getLinearDamping()
Gets the linear damping of the shape, which is used to reduce the linear velocity of the shape.
PointF getLinearVelocity()
Gets the linear velocity of the center of mass of the shape, in units per second.
float getMass()

Gets the mass of this shape (which is the density of the shape multiplied by its surface area).

Paint getPaint()
Gets the Paint object that describes how this shape should be drawn.
final ShapeView getParentView()
Gets the parent of the receiver.
PointF getPosition()
Gets the location of the centroid of the shape.
PointF getPositionAnchor()
Get the current position anchor, which is an offset relative to the upper left corner of the shape that is used as the shape's "origin" for the purposes of getting/setting x-y positions.
float getRestitution()
Gets the coefficient of restitution, which controls the "bounciness" of the shape (or in more precise terms, the relationship between the velocity of the shape before and after a collision).
float getRotation()
Gets the current angle of rotation of the shape, in degrees clockwise.
final ShapeField getShapeField()
Gets the ShapeField that contains this shape.
ShapeMotion getShapeMotion()
Gets a value indicating how this shape acts with regard to motion in the physical world.
float getTop()
Gets the y-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default).
Matrix getTransform()
Gets the current linear transformation that will be applied to the shape when it is drawn.
float getWidth()
Gets the width of the shape, in pixels.
float getX()
Gets the x-coordinate of the centroid of the shape.
float getY()
Gets the y-coordinate of the centroid of the shape.
int getZIndex()
Gets the z-index of the receiver.
boolean intersects(Shape otherShape)
Determine whether this shape intersects another, based on their bounding boxes.
float[] inverseTransformPoint(float x, float y)
Transforms a point on the screen into the original bounds of a shape, pre-rotation.
boolean isActive()
Gets a value indicating whether or not the shape is active.
boolean isAwake()
Gets a value indicating whether or not the shape is awake.
boolean isBullet()
Gets a value indicating whether this shape is a "bullet." Bullets are very fast moving objects that require more precise contact/collision handling than ordinary objects, and they require more processing power as a result.
boolean isFixedRotation()
Gets a value indicating whether this shape's rotation is fixed -- that is, even under a physical load, the shape will never rotate.
boolean isInFrontOf(Shape other)
Returns true if this shape is drawn in front of (later than) the other shape.
boolean isSensor()
Gets a value indicating whether or not the shape is a sensor.
boolean isVisible()
Gets a value indicating whether the receiver is visible (drawn on the screen).
void moveBy(float dx, float dy)
Moves the receiver by the specified horizontal and vertical distance.
void recreateFixtures()
Destroys and recreates the shape's fixtures.
void remove()
Remove this shape from its view (or parent).
void rotateBy(float angleDelta)
Increments the shape's rotation by the specified number of degrees, around the same pivot point that was used previously (or the center of the shape if no other pivot has been previously used).
void setActive(boolean isActive)
Sets a value indicating whether or not the shape is active.
void setAlpha(int newAlpha)
A convenience method that sets the alpha (opacity) component of the shape's color without changing the other color components.
void setAngularDamping(float newDamping)
Sets the angular damping of the shape, which is used to reduce the angular velocity of the shape.
void setAngularVelocity(float newVelocity)
Sets the angular velocity of the shape, in degrees per second.
abstract void setBounds(RectF newBounds)
Sets the bounding rectangle of the shape.
void setBullet(boolean bullet)
Sets a value indicating whether this shape is a "bullet." Bullets are very fast moving objects that require more precise contact/collision handling than ordinary objects, and they require more processing power as a result.
void setColor(Color newColor)
Sets the color of the receiver.
void setDensity(float newDensity)
Sets the density of the shape.
void setFixedRotation(boolean fixedRotation)
Sets a value indicating whether this shape's rotation is fixed -- that is, even under a physical load, the shape will never rotate.
void setFriction(float newFriction)
Set the coefficient of friction for the shape.
void setGravityScale(float gravityScale)
Sets the gravity scaling factor for the shape.
void setLeft(float x)
Sets the x-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default).
void setLinearDamping(float newDamping)
Sets the linear damping of the shape, which is used to reduce the linear velocity of the shape.
void setLinearVelocity(PointF newVelocity)
Sets the linear velocity of the center of mass of the shape, in units per second.
void setLinearVelocity(float xVelocity, float yVelocity)
Sets the linear velocity of the center of mass of the shape, in units per second.
void setPosition(float x, float y)
Sets the location of the centroid of the shape.
void setPosition(PointF position)
Sets the location of the centroid of the shape.
void setPositionAnchor(PointF anchor)
Set the position anchor, which is an offset relative to the upper left corner of the shape that is used as the shape's "origin" for the purposes of getting/setting x-y positions.
void setRestitution(float newRestitution)

Sets the coefficient of restitution, which controls the "bounciness" of the shape (or in more precise terms, the relationship between the velocity of the shape before and after a collision).

void setRotation(float newRotation)
Sets the angle of rotation of the shape in degrees clockwise, using the center of the shape's bounding box as the pivot point.
void setSensor(boolean isSensor)
Gets a value indicating whether or not the shape is a sensor.
void setShapeMotion(ShapeMotion motion)
Sets a value indicating how this shape acts with regard to motion in the physical world.
void setTop(float y)
Sets the y-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default).
void setVisible(boolean newVisible)
Sets a value indicating whether the receiver is visible (drawn on the screen).
void setZIndex(int newZIndex)
Sets the z-index of the receiver.
void stopAnimation()
Stops the current animation for this shape, if there is one.
String toString()
Returns a human-readable string representation of the shape.
void updateTransform(float x, float y, float angle)
TODO document
void updateTransform(float x, float y)
TODO document
void updateTransform(float angle)
TODO document
Methods inherited from class java.lang.Object
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait()
final void wait(long arg0, int arg1)
final void wait(long arg0)

Public Constructors

public FillableShape ()

Creates a new FillableShape.


Public Methods

public Animator<?> animate (long duration)

Gets an animator object that lets the user animate properties of the receiving shape.

For ease of use, the description of the animation desired can be chained directly to the result of this method. For example, the following code fragment would create an animation that runs for 2 seconds, gradually changing the shape's color to red, its position to the top-right corner of the view, and then starts the animation after a delay of 1 second after the method is called:

     shape.animate(2000)
          .delay(1000)
          .color(Color.red)
          .position(Anchor.TOP_RIGHT.ofView())
          .play();

Parameters
duration
The length of the animation in milliseconds.
Returns

A ShapeAnimator that lets the user animate properties of the receiving shape.

public int getAlpha ()

A convenience method that gets the alpha (opacity) component of the shape's color.

Note that calling the setAlpha(int) method will update the alpha components of both the color and the fill color of the shape, so this method would return the single alpha value in that case. In the event that the shape's color and fill color have been set explicitly to have different alpha components, this method returns the alpha component of the color returned by getColor().

Returns

The alpha component of the shape's color, where 0 means that the color is fully transparent and 255 means that it is fully opaque.

public Color getFillColor ()

Gets the color used to fill the shape. This color can be set explicitly by calling setFillColor(Color); if it has not been set, then the shape's color as defined by getColor() will be used to fill the shape.

Returns

the Color used to fill the shape

public Image getImage ()

Gets the image used to fill this shape.

Returns

the image used to fill this shape

public boolean isFilled ()

Gets a value indicating whether the shape will be filled when it is drawn.

Returns

true if the shape will be filled when it is drawn, or false if it will be drawn as an outline

public void removeImage ()

Removes the image used to fill this shape. This method exists for ease of use because trying to call setImage(null) would be ambiguous without an explicit cast.

public void setAlpha (int newAlpha)

A convenience method that sets the alpha (opacity) component of the shape's color and fill color without changing the other color components.

Parameters
newAlpha
The new alpha component of the shape's color, where 0 means that the color is fully transparent and 255 means that it is fully opaque.
public void setFillColor (Color newFillColor)

Sets the color used to fill the shape. If it has not been set, then the shape's color as defined by getColor() will be used to fill the shape.

Parameters
newFillColor
the Color to use to fill the shape
public void setFilled (boolean newFilled)

Sets a value indicating whether the shape will be filled when it is drawn.

Parameters
newFilled
true if the shape will be filled when it is drawn, or false to draw it as an outline
public void setImage (Image newImage)

Sets the image used to fill this shape.

Parameters
newImage
the image used to fill this shape, or null to remove the image
public void setImage (String imageName)

Sets the image used to fill this shape.


Protected Methods

protected void drawBitmap (Canvas canvas)

Draws the image for this shape. Called by subclasses inside their draw(Canvas) methods.

Parameters
canvas
the Canvas to draw on
protected Paint getFillPaint ()

Gets a Paint used to fill the shape. Android's drawing primitives in the Canvas class do not support having separate stroke and fill colors in a single drawing operation, so subclasses of FillableShapes typically draw themselves twice -- once for the fill, using the Paint returned by this method, and then again for the outline, using the Paint returned by getPaint().

Returns

the Paint used to fill the shape when it is drawn

protected Paint getImagePaint ()

Gets a Paint object suitable for drawing the image for this shape.

Returns

a Paint object