|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgreenfoot.sofiainternal.Actor
sofia.graphics.Shape
public abstract class Shape
Write a one-sentence summary of your class here. Follow it with additional details about its purpose, what abstraction it represents, and how to use it.
Constructor Summary | |
---|---|
Shape()
Creates a new shape with default bounds (located at the center of the screen and 100 pixels wide by 100 pixels tall). |
|
Shape(android.graphics.RectF bounds)
Creates a new shape with the specified bounds. |
Method Summary | |
---|---|
void |
addOther(Shape newShape)
Add another shape to the same view (or parent) containing this shape. |
protected void |
conditionallyRelayout()
Called to recalculate the layout of the shape on the screen. |
protected void |
conditionallyRepaint()
Called to indicate that the shape needs to be repainted on the screen. |
boolean |
contains(float x,
float y)
Gets a value indicating whether the specified pixel location is contained in the receiver. |
boolean |
contains(android.graphics.PointF point)
Gets a value indicating whether the specified pixel location is contained in the receiver. |
sofia.graphics.ViewEdges |
extendsOutside(android.graphics.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. |
android.graphics.RectF |
getBounds()
Gets the bounding rectangle of the shape. |
sofia.graphics.Color |
getColor()
Gets the color of the receiver. |
float |
getHeight()
Gets the height of the shape, in pixels. |
android.graphics.PointF |
getPosition()
Gets the origin (top-left corner) of the receiver. |
android.graphics.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 |
getRotation()
Gets the current angle of rotation of the shape, in degrees clockwise. |
android.graphics.PointF |
getRotationPivot()
Gets the point around which the shape's rotation will pivot. |
sofia.graphics.ShapeParent |
getShapeParent()
Gets the parent of the receiver. |
float |
getWidth()
Gets the width of the shape, in pixels. |
float |
getX()
Gets the x-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default). |
float |
getY()
Gets the y-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default). |
int |
getZIndex()
Gets the z-index of the receiver. |
boolean |
intersects(Shape otherShape)
Determine whether this shape intersects another, based on their bounding boxes. |
boolean |
isInFrontOf(Shape other)
Returns true if this shape is drawn in front of (later than) the other shape. |
boolean |
isVisible()
Gets a value indicating whether the receiver is visible (drawn on the screen). |
void |
move(float dx,
float dy)
Moves the receiver by the specified horizontal and vertical distance. |
protected void |
notifyParentOfPositionChange()
Called to recalculate the layout of the shape on the screen. |
void |
onBoundsResolved()
Called when the bounds of the shape have been resolved. |
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 |
setAlpha(int newAlpha)
A convenience method that sets the alpha (opacity) component of the shape's color without changing the other color components. |
void |
setBounds(android.graphics.RectF newBounds)
Sets the bounding rectangle of the shape. |
void |
setColor(sofia.graphics.Color newColor)
Sets the color of the receiver. |
void |
setPosition(sofia.graphics.PointAndAnchor pointAndAnchor)
Sets the position of the receiver based on the specified point and anchor, leaving its size unchanged. |
void |
setPosition(android.graphics.PointF position)
Sets the origin (top-left corner) of the receiver. |
void |
setPositionAnchor(sofia.graphics.Anchor 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 |
setPositionAnchor(android.graphics.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 |
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 |
setRotation(float newRotation,
android.graphics.PointF newPivot)
Sets the angle of rotation of the shape in degrees clockwise, using the specified point as the pivot point. |
void |
setVisible(boolean newVisible)
Sets a value indicating whether the receiver is visible (drawn on the screen). |
void |
setX(float x)
Sets the x-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default). |
void |
setY(float y)
Sets the y-coordinate of the anchor point of the shape's bounding box (the top-left corner, by default). |
void |
setZIndex(int newZIndex)
Sets the z-index of the receiver. |
java.lang.String |
toString()
Returns a human-readable string representation of the shape. |
Methods inherited from class greenfoot.sofiainternal.Actor |
---|
_gf_addToWorld, _gf_getBoundingXs, _gf_getBoundingYs, _gf_getDelegate, _gf_getImage, _gf_getIntersectingObjects, _gf_getNeighbours, _gf_getObjectsAtOffset, _gf_getObjectsInRange, _gf_getOneIntersectingObject, _gf_getOneObjectAtOffset, _gf_getRotation, _gf_getX, _gf_getY, _gf_setImage, _gf_setImage, _gf_setLocation, _gf_setRotation, _gf_turn, act, addedToWorld, containsPoint, getWorld, intersects, move, turnTowards |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Shape()
public Shape(android.graphics.RectF bounds)
bounds
- The bounds of the shape.Method Detail |
---|
public void addOther(Shape newShape)
newShape
- The other shape to add.public void remove()
public android.graphics.RectF getBounds()
public void setBounds(android.graphics.RectF newBounds)
newBounds
- The new bounding rectangle of the shape.public android.graphics.PointF getPositionAnchor()
public void setPositionAnchor(android.graphics.PointF anchor)
anchor
- The new position anchor.public void setPositionAnchor(sofia.graphics.Anchor anchor)
anchor
- The new position anchor.public float getRotation()
public android.graphics.PointF getRotationPivot()
public void setRotation(float newRotation)
newRotation
- The new angle of rotation of the shape.public void setRotation(float newRotation, android.graphics.PointF newPivot)
newRotation
- The new angle of rotation of the shape.newPivot
- The point around which the rotation will pivot.public void rotateBy(float angleDelta)
angleDelta
- The number of degrees to add to the shape's rotation.public float getX()
setPositionAnchor(Anchor)
public void setX(float x)
x
- The x-coordinate of the anchor point of the shape's
bounding box.setPositionAnchor(Anchor)
public float getY()
setPositionAnchor(Anchor)
public void setY(float y)
y
- The y-coordinate of the anchor point of the shape's
bounding box.setPositionAnchor(Anchor)
public float getWidth()
public float getHeight()
public android.graphics.PointF getPosition()
PointF.x
and PointF.y
fields of the returned point may
not be valid if layout of the shapes has not yet occurred.
PointF
object describing the origin of the shape.public void setPosition(android.graphics.PointF position)
position
- A PointF
object describing the origin of the
shape.public void setPosition(sofia.graphics.PointAndAnchor pointAndAnchor)
pointAndAnchor
- A PointAndAnchor
object describing the
position of the shape.public void move(float dx, float dy)
dx
- The number of pixels to move the shape horizontally.dy
- The number of pixels to move the shape vertically.public boolean contains(float x, float y)
Gets a value indicating whether the specified pixel location is contained in the receiver.
By default, this method checks to see whether the point is located within the bounding rectangle of the shape. Shapes where this would produce incorrect results, such as ovals or lines, override this method accordingly.
This method does take the shape's rotation into
account. This means that if you subclass Shape
and need to
provide logic that is different from the default bounding box behavior,
then you may need to undo the rotation of the incoming point before
testing it against your shape's bounds.
x
- The x-coordinate.y
- The y-coordinate.
public boolean contains(android.graphics.PointF point)
point
- The point.
public void onBoundsResolved()
public int getZIndex()
public void setZIndex(int newZIndex)
newZIndex
- The new z-index of the shape.public boolean isInFrontOf(Shape other)
other
- The shape to check against.
public final sofia.graphics.ShapeParent getShapeParent()
public sofia.graphics.Color getColor()
public void setColor(sofia.graphics.Color newColor)
newColor
- The new color of the receiver.public int getAlpha()
public void setAlpha(int newAlpha)
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 boolean isVisible()
public void setVisible(boolean newVisible)
newVisible
- True if the shape should be visible, otherwise false.protected void conditionallyRepaint()
protected void conditionallyRelayout()
protected void notifyParentOfPositionChange()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean intersects(Shape otherShape)
otherShape
- The other shape to check against.
public sofia.graphics.ViewEdges extendsOutside(android.graphics.RectF bounds)
bounds
- The rectangle to check against.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |