public class

LineShape

extends StrokedShape
java.lang.Object
   ↳ sofia.graphics.Shape
     ↳ sofia.graphics.StrokedShape
       ↳ sofia.graphics.LineShape

Class Overview

A shape that is drawn as a line between two points.

Physics

Lines have no volume, and therefore cannot collide with each other. However, lines can still be involved in collisions with other shapes that do have volume, such as RectangleShape, OvalShape, and ImageShape to name a few.

Summary

Public Constructors
LineShape()
Creates a new LineShape with default position and size.
LineShape(PointF point1, PointF point2)
Creates a new LineShape between two points.
LineShape(float x1, float y1, float x2, float y2)
Creates a new LineShape between two points.
LineShape(RectF bounds)
Creates a new LineShape that starts at the top-left corner of the specified rectangle and ends at the bottom-right corner.
Public Methods
boolean contains(float x, float y)

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

void draw(Canvas canvas)
Subclasses must implement this method to define how the shape is to be drawn on the canvas.
RectF getBounds()
Gets the bounding rectangle of the shape.
void setBounds(RectF newBounds)
Sets the bounding rectangle of the shape.
Protected Methods
void createFixtures()
This method is intended for internal use only, or by advanced users subclassing one of the abstract shape types.
[Expand]
Inherited Methods
From class sofia.graphics.StrokedShape
From class sofia.graphics.Shape
From class java.lang.Object

Public Constructors

public LineShape ()

Creates a new LineShape with default position and size.

public LineShape (PointF point1, PointF point2)

Creates a new LineShape between two points.

public LineShape (float x1, float y1, float x2, float y2)

Creates a new LineShape between two points.

Parameters
x1 the x-coordinate of the first endpoint
y1 the y-coordinate of the first endpoint
x2 the x-coordinate of the second endpoint
y2 the y-coordinate of the second endpoint

public LineShape (RectF bounds)

Creates a new LineShape that starts at the top-left corner of the specified rectangle and ends at the bottom-right corner.

Parameters
bounds the bounding rectangle of the line

Public Methods

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. The inverseTransformPoint(float, float) method has been provided to simplify this.

Parameters
x The x-coordinate.
y The y-coordinate.
Returns
  • True if the shape contains the point, otherwise false.

public void draw (Canvas canvas)

Subclasses must implement this method to define how the shape is to be drawn on the canvas. Users should never call this method directly; it is called as part of the repaint cycle by the ShapeView that contains the shape.

Parameters
canvas The Canvas on which to draw the shape.

public RectF getBounds ()

Gets the bounding rectangle of the shape. The top-left corner of the bounding rectangle is the shape's origin, and the bottom-right corner is the shape's extent.

Returns
  • The bounding rectangle of the shape.

public void setBounds (RectF newBounds)

Sets the bounding rectangle of the shape. The bounding rectangle passed to this method is copied, so changes to it after this method is called will not be reflected by the shape.

Parameters
newBounds The new bounding rectangle of the shape.

Protected Methods

protected void createFixtures ()

This method is intended for internal use only, or by advanced users subclassing one of the abstract shape types. Subclasses must override this method to create the necessary fixtures for the body that this shape represents. Use the getB2Body() method to access the body when creating fixtures.