T
 The type of CellGame that uses this Viewport's SpaceStatesU
 The type of SpaceState that uses this Viewportpublic class Viewport<T extends CellGame,U extends SpaceState<T,U,?>>
extends java.lang.Object
A Viewport represents a rectangular region of the screen through which the space of the SpaceState to which it is assigned can be viewed. The center of a Viewport's rectangular field of view in a SpaceState is the center of a SpaceObject called the Viewport's camera. To render the region of its SpaceState in its field of view, a Viewport's camera must be assigned to the same SpaceState as it. One pixel in a Viewport's rendering region on the screen is equal to one fracunit in its SpaceState.
While a Viewport is rendering visuals, the Graphics context to which it is rendering can only be drawn on within the Viewport's rendering region. When drawn to the Graphics context, shapes and Drawables will automatically be clipped so that they do not extend beyond the rendering region.
HUDs may be assigned to Viewports to render visuals in front of the Viewport's own. Only one HUD may be assigned to a given Viewport in this capacity at once. A Viewport's HUD uses the region of the screen that the Viewport occupies as its rendering region.
Constructor and Description 

Viewport(long x1,
long y1,
long x2,
long y2)
Constructs a Viewport that occupies the specified region of the screen.

Modifier and Type  Method and Description 

int 
getBottom()
Returns the difference of the ycoordinates in pixels of this Viewport's
bottom edge and the position of its camera on the screen.

long 
getBottomEdge()
Returns the ycoordinate of the bottom edge of this Viewport's field of
view in a SpaceState.

SpaceObject 
getCamera()
Returns this Viewport's camera, or null if it has none.

T 
getGame()
Returns the CellGame of the SpaceState to which this Viewport is
assigned, or null if it is not assigned to a SpaceState.

U 
getGameState()
Returns the SpaceState to which this Viewport is assigned, or null if it
is not assigned to one.

long 
getHeight()
Returns this Viewport's height in fracunits on the screen.

HUD 
getHUD()
Returns the HUD that is assigned to this Viewport, or null if there is
none.

int 
getLeft()
Returns the difference of the xcoordinates in pixels of this Viewport's
left edge and the position of its camera on the screen.

long 
getLeftEdge()
Returns the xcoordinate of the left edge of this Viewport's field of
view in a SpaceState.

int 
getRight()
Returns the difference of the xcoordinates in pixels of this Viewport's
right edge and the position of its camera on the screen.

long 
getRightEdge()
Returns the xcoordinate of the right edge of this Viewport's field of
view in a SpaceState.

java.awt.Point 
getScreenPoint(CellVector spacePoint)
Returns the point in pixels on the screen that corresponds to the
specified point in a SpaceState as seen through this Viewport.

java.awt.Point 
getScreenPoint(long x,
long y)
Returns the point in pixels on the screen that corresponds to the
specified point in a SpaceState as seen through this Viewport.

CellVector 
getSpacePoint(int x,
int y)
Returns the point in a SpaceState, as seen through this Viewport, that
corresponds to the specified point in pixels in this Viewport's onscreen
rendering region.

int 
getTop()
Returns the difference of the ycoordinates in pixels of this Viewport's
top edge and the position of its camera on the screen.

long 
getTopEdge()
Returns the ycoordinate of the top edge of this Viewport's field of view
in a SpaceState.

long 
getWidth()
Returns this Viewport's width in fracunits on the screen.

long 
getX1()
Returns the xcoordinate in fracunits of this Viewport's left edge on the
screen.

long 
getX2()
Returns the xcoordinate in fracunits of this Viewport's right edge on
the screen.

long 
getY1()
Returns the ycoordinate in fracunits of this Viewport's top edge on the
screen.

long 
getY2()
Returns the ycoordinate in fracunits of this Viewport's bottom edge on
the screen.

boolean 
rectangleIsVisible(long x1,
long y1,
long x2,
long y2)
Returns whether any part of the specified rectangular region of a
SpaceState's space is visible through this Viewport.

void 
setCamera(SpaceObject camera)
Sets this Viewport's camera to the specified SpaceObject, or to none if
the specified SpaceObject is null.

void 
setHUD(HUD hud)
Sets the HUD that is assigned to this Viewport to the specified one.

boolean 
setX1(long x1)
Sets the xcoordinate in fracunits of this Viewport's left edge on the
screen to the specified value, if doing so would not cause this
Viewport's width to be negative.

boolean 
setX2(long x2)
Sets the xcoordinate in fracunits of this Viewport's right edge on the
screen to the specified value, if doing so would not cause this
Viewport's width to be negative.

boolean 
setY1(long y1)
Sets the ycoordinate in fracunits of this Viewport's top edge on the
screen to the specified value, if doing so would not cause this
Viewport's height to be negative.

boolean 
setY2(long y2)
Sets the ycoordinate in fracunits of this Viewport's bottom edge on the
screen to the specified value, if doing so would not cause this
Viewport's height to be negative.

public Viewport(long x1, long y1, long x2, long y2)
x1
 The xcoordinate in pixels of this Viewport's left edge on the
screeny1
 The ycoordinate in pixels of this Viewport's top edge on the
screenx2
 The xcoordinate in pixels of this Viewport's right edge on the
screeny2
 The ycoordinate in pixels of this Viewport's bottom edge on
the screenpublic final T getGame()
public final U getGameState()
public final SpaceObject getCamera()
public final void setCamera(SpaceObject camera)
camera
 The new camerapublic final HUD getHUD()
public final void setHUD(HUD hud)
hud
 The HUD to addpublic final long getX1()
public final boolean setX1(long x1)
x1
 The new xcoordinate in fracunits of this Viewport's left edgepublic final long getY1()
public final boolean setY1(long y1)
y1
 The new ycoordinate in fracunits of this Viewport's top edgepublic final long getX2()
public final boolean setX2(long x2)
x2
 The new xcoordinate in fracunits of this Viewport's right edgepublic final long getY2()
public final boolean setY2(long y2)
y2
 The new ycoordinate in fracunits of this Viewport's bottom
edgepublic final long getWidth()
public final long getHeight()
public final int getLeft()
public final int getRight()
public final int getTop()
public final int getBottom()
public final long getLeftEdge() throws java.lang.NullPointerException
java.lang.NullPointerException
 if this Viewport has no camerapublic final long getRightEdge() throws java.lang.NullPointerException
java.lang.NullPointerException
 if this Viewport has no camerapublic final long getTopEdge() throws java.lang.NullPointerException
java.lang.NullPointerException
 if this Viewport has no camerapublic final long getBottomEdge() throws java.lang.NullPointerException
java.lang.NullPointerException
 if this Viewport has no camerapublic final CellVector getSpacePoint(int x, int y)
x
 The xcoordinate of the screen pointy
 The ycoordinate of the screen pointpublic final java.awt.Point getScreenPoint(CellVector spacePoint)
spacePoint
 The SpaceState pointpublic final java.awt.Point getScreenPoint(long x, long y)
x
 The xcoordinate of the SpaceState pointy
 The ycoordinate of the SpaceState pointpublic final boolean rectangleIsVisible(long x1, long y1, long x2, long y2)
x1
 The xcoordinate of the region's left edgey1
 The ycoordinate of the region's top edgex2
 The xcoordinate of the region's right edgey2
 The ycoordinate of the region's bottom edge