public class

CoordinateSystem

extends Object
java.lang.Object
   ↳ sofia.graphics.CoordinateSystem

Class Overview

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.

Summary

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

Protected Constructors

protected CoordinateSystem (ShapeView owner)

Creates a new CoordinateSystem for the specified ShapeView.

Parameters
owner the ShapeView that owns this coordinate system

Public Methods

public PointF deviceToLocal (PointF pt)

Transforms a point from device coordinates (pixels on the view/screen) to local coordinates.

Parameters
pt the device coordinates to transform
Returns
  • the local coordinates in this coordinate system corresponding to the specified device coordinates

public PointF deviceToLocal (float x, float y)

Transforms a point from device coordinates (pixels on the view/screen) to local coordinates.

Parameters
x the x-coordinate
y the y-coordinate
Returns
  • the local coordinates in this coordinate system corresponding to the specified device coordinates

public 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.

Returns
  • this coordinate system, for chaining method calls

public CoordinateSystem flipY ()

Flips the y-axis of the coordinate system so that it higher values on the y-axis are above lower values.

Returns
  • this coordinate system, for chaining method calls

public CoordinateSystem height (float units)

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.

Parameters
units the number of vertical units that the view should occupy
Returns
  • this coordinate system, for chaining method calls

public 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).

Returns
  • true if the coordinate system's x-axis is flipped, otherwise false

public 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).

Returns
  • true if the coordinate system's y-axis is flipped, otherwise false

public CoordinateSystem origin (Anchor anchor)

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.

Parameters
anchor the Anchor representing the origin of the coordinate system with respect to the view
Returns
  • this coordinate system, for chaining method calls

public 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.

public CoordinateSystem width (float units)

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.

Parameters
units the number of horizontal units that the view should occupy
Returns
  • this coordinate system, for chaining method calls

Protected Methods

protected void applyTransform (Canvas canvas)

Applies the transformation represented by this coordinate system to the specified Graphics2D object.

protected void updateTransform ()

Called internally to update the AffineTransform that will be used to transform this view.