java.lang.Object | |
↳ | sofia.graphics.CoordinateSystem |
Allows the user to modify the coordinate system of a ShapeView (or a ShapeScreen).
You cannot create instances of this class. Instead, you should call ShapeScreen#getCoordinateSystem() or ShapeView#getCoordinateSystem() to retrieve the current coordinate system and then chain method calls to it to apply modifications to the system. For example,
getCoordinateSystem().origin(Anchor.BOTTOM_LEFT).flipY().width(400);
will set the origin (0, 0) at the bottom-left corner of the view, flip the y-axis so that it grows upward in the positive direction, and fixes the width of the view to be 400 units, scaling it to fit the actual pixel size of the view.
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CoordinateSystem(ShapeView owner)
Creates a new
CoordinateSystem for the specified
ShapeView . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
PointF |
deviceToLocal(PointF pt)
Transforms a point from device coordinates (pixels on the view/screen)
to local coordinates.
| ||||||||||
PointF |
deviceToLocal(float x, float y)
Transforms a point from device coordinates (pixels on the view/screen)
to local coordinates.
| ||||||||||
CoordinateSystem |
flipX()
Flips the x-axis of the coordinate system so that it higher values on
the x-axis are to the left of lower values.
| ||||||||||
CoordinateSystem |
flipY()
Flips the y-axis of the coordinate system so that it higher values on
the y-axis are above lower values.
| ||||||||||
CoordinateSystem |
height(float units)
Sets the number of vertical units that the view should occupy.
| ||||||||||
boolean |
isFlippedX()
Gets a value indicating whether the x-axis of this coordinate system is
flipped (that is, higher values of x are to the left lower values).
| ||||||||||
boolean |
isFlippedY()
Gets a value indicating whether the y-axis of this coordinate system is
flipped (that is, higher values of y are above lower values).
| ||||||||||
CoordinateSystem |
origin(Anchor anchor)
Sets the location on the view where the origin (0, 0) is located.
| ||||||||||
void |
reset()
Resets the coordinate system so that the origin is in the top-left
corner of the view, the x-axis goes right in the positive direction,
the y-axis goes down in the positive direction, and one unit is equal
to one pixel.
| ||||||||||
CoordinateSystem |
width(float units)
Sets the number of horizontal units that the view should occupy.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
applyTransform(Canvas canvas)
Applies the transformation represented by this coordinate system to the
specified
Graphics2D object. | ||||||||||
void |
updateTransform()
Called internally to update the
AffineTransform that will be
used to transform this view. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a new CoordinateSystem
for the specified
ShapeView
.
owner | the ShapeView that owns this coordinate system
|
---|
Transforms a point from device coordinates (pixels on the view/screen) to local coordinates.
pt | the device coordinates to transform |
---|
Transforms a point from device coordinates (pixels on the view/screen) to local coordinates.
x | the x-coordinate |
---|---|
y | the y-coordinate |
Flips the x-axis of the coordinate system so that it higher values on the x-axis are to the left of lower values.
Flips the y-axis of the coordinate system so that it higher values on the y-axis are above lower values.
Sets the number of vertical units that the view should occupy. The view will be scaled so that it always occupies this many units; that is, if the height of the coordinate system is 400 units and the view is 800 pixels tall, each unit will be 2 pixels tall. Likewise, if the view is 200 pixels tall, each unit will be 0.5 pixels tall.
units | the number of vertical units that the view should occupy |
---|
Gets a value indicating whether the x-axis of this coordinate system is flipped (that is, higher values of x are to the left lower values).
Gets a value indicating whether the y-axis of this coordinate system is flipped (that is, higher values of y are above lower values).
Sets the location on the view where the origin (0, 0) is located. Note
that if you set the origin to be the right and/or bottom edges of the
view, you should make sure to call flipX()
and/or
flipY()
to ensure that the coordinate system has the correct
orientation.
anchor | the Anchor representing the origin of the coordinate system with respect to the view |
---|
Resets the coordinate system so that the origin is in the top-left corner of the view, the x-axis goes right in the positive direction, the y-axis goes down in the positive direction, and one unit is equal to one pixel.
Sets the number of horizontal units that the view should occupy. The view will be scaled so that it always occupies this many units; that is, if the width of the coordinate system is 400 units and the view is 800 pixels wide, each unit will be 2 pixels wide. Likewise, if the view is 200 pixels wide, each unit will be 0.5 pixels wide.
units | the number of horizontal units that the view should occupy |
---|
Applies the transformation represented by this coordinate system to the
specified Graphics2D
object.
Called internally to update the AffineTransform
that will be
used to transform this view.