T
- The type of CellGame that uses the SpaceStates that this Viewport
can be assigned topublic class Viewport<T extends CellGame> extends SpaceThinker<T>
A Viewport is a SpaceThinker that 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 marked by a SpaceObject called the Viewport's camera. To render any visuals, including its HUD if it has one, a Viewport must be assigned to a SpaceState through its setViewport() method. 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 region of the Graphics context to which it is rendering that is outside its rendering region cannot be drawn to. 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. To render visuals, an HUD must be assigned to a Viewport through its setHUD() method. Only one HUD may be assigned to a given Viewport in this way 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)
Creates a new Viewport that occupies the specified region of the screen.
|
Modifier and Type | Method and Description |
---|---|
int |
getBottom()
Returns the difference of the y-coordinates in pixels of this Viewport's
bottom edge and the position of its camera on the screen.
|
long |
getBottomEdge()
Returns the y-coordinate of the bottom edge of this Viewport's field of
view in a SpaceState.
|
SpaceObject<T> |
getCamera()
Returns this Viewport's camera, or null if it has none.
|
long |
getHeight()
Returns this Viewport's height in fracunits on the screen.
|
HUD<T> |
getHUD()
Returns the HUD that is assigned to this Viewport, or null if there is
none.
|
int |
getLeft()
Returns the difference of the x-coordinates in pixels of this Viewport's
left edge and the position of its camera on the screen.
|
long |
getLeftEdge()
Returns the x-coordinate of the left edge of this Viewport's field of
view in a SpaceState.
|
int |
getRight()
Returns the difference of the x-coordinates in pixels of this Viewport's
right edge and the position of its camera on the screen.
|
long |
getRightEdge()
Returns the x-coordinate 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 on-screen
rendering region.
|
int |
getTop()
Returns the difference of the y-coordinates in pixels of this Viewport's
top edge and the position of its camera on the screen.
|
long |
getTopEdge()
Returns the y-coordinate 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 x-coordinate in fracunits of this Viewport's left edge on the
screen.
|
long |
getX2()
Returns the x-coordinate in fracunits of this Viewport's right edge on
the screen.
|
long |
getY1()
Returns the y-coordinate in fracunits of this Viewport's top edge on the
screen.
|
long |
getY2()
Returns the y-coordinate 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<T> camera)
Sets this Viewport's camera to the specified SpaceObject, or to none if
the specified SpaceObject is null.
|
boolean |
setHUD(HUD<T> hud)
Sets the HUD that is assigned to this Viewport to the specified HUD, if
it is not already assigned to a ThinkerGroup.
|
boolean |
setX1(long x1)
Sets the x-coordinate 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 x-coordinate 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 y-coordinate 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 y-coordinate 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.
|
beforeMovementActions, getThis
addedActions, addThinkerActions, addThinkerActions, frameActions, getActionPriority, getEffectiveTimeFactor, getGame, getGameState, getNewActionPriority, getNewThinkerGroup, getThinkerGroup, getTimeFactor, getTimerValue, removedActions, removeThinkerActions, removeThinkerActions, setActionPriority, setThinkerGroup, setTimeFactor, setTimerValue, timeUnitActions
addThinker, getNumThinkers, iteratingThroughThinkers, removeAllSubThinkers, removeAllThinkers, removeLineage, removeThinker, thinkerIterator, updateThinkerListActions
public Viewport(long x1, long y1, long x2, long y2)
x1
- The x-coordinate in pixels of this Viewport's left edge on the
screeny1
- The y-coordinate in pixels of this Viewport's top edge on the
screenx2
- The x-coordinate in pixels of this Viewport's right edge on the
screeny2
- The y-coordinate in pixels of this Viewport's bottom edge on
the screenpublic final SpaceObject<T> getCamera()
public final void setCamera(SpaceObject<T> camera)
camera
- The new camerapublic final HUD<T> getHUD()
public final boolean setHUD(HUD<T> hud)
hud
- The HUD to addpublic final long getX1()
public final boolean setX1(long x1)
x1
- The new x-coordinate in fracunits of this Viewport's left edgepublic final long getY1()
public final boolean setY1(long y1)
y1
- The new y-coordinate in fracunits of this Viewport's top edgepublic final long getX2()
public final boolean setX2(long x2)
x2
- The new x-coordinate in fracunits of this Viewport's right edgepublic final long getY2()
public final boolean setY2(long y2)
y2
- The new y-coordinate 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 x-coordinate of the screen pointy
- The y-coordinate 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 x-coordinate of the SpaceState pointy
- The y-coordinate of the SpaceState pointpublic final boolean rectangleIsVisible(long x1, long y1, long x2, long y2)
x1
- The x-coordinate of the region's left edgey1
- The y-coordinate of the region's top edgex2
- The x-coordinate of the region's right edgey2
- The y-coordinate of the region's bottom edge