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 its 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 |
getBottomEdge()
Returns the y-coordinate in pixels of this Viewport's rendering region's
actual bottom edge on the screen.
|
SpaceObject |
getCamera()
Returns this Viewport's camera, or null if it has none.
|
long |
getHeight()
Returns this Viewport's height in pixels on the screen.
|
HUD<T> |
getHUD()
Returns the HUD that is assigned to this Viewport, or null if there is
none.
|
int |
getLeftEdge()
Returns the x-coordinate in pixels of this Viewport's rendering region's
actual left edge on the screen.
|
int |
getRightEdge()
Returns the x-coordinate in pixels of this Viewport's rendering region's
actual right edge on the screen.
|
int |
getTopEdge()
Returns the y-coordinate in pixels of this Viewport's rendering region's
actual top edge on the screen.
|
long |
getWidth()
Returns this Viewport's width in pixels on the screen.
|
long |
getX1()
Returns the x-coordinate in pixels of this Viewport's left edge on the
screen.
|
long |
getX2()
Returns the x-coordinate in pixels of this Viewport's right edge on the
screen.
|
long |
getY1()
Returns the y-coordinate in pixels of this Viewport's top edge on the
screen.
|
long |
getY2()
Returns the y-coordinate in pixels 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 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.
|
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 pixels 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 pixels 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 pixels 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 pixels 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 getCamera()
public final void setCamera(SpaceObject 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 pixels of this Viewport's left edgepublic final long getY1()
public final boolean setY1(long y1)
y1
- The new y-coordinate in pixels of this Viewport's top edgepublic final long getX2()
public final boolean setX2(long x2)
x2
- The new x-coordinate in pixels of this Viewport's right edgepublic final long getY2()
public final boolean setY2(long y2)
y2
- The new y-coordinate in pixels of this Viewport's bottom edgepublic final long getWidth()
public final long getHeight()
public final int getLeftEdge()
public final int getRightEdge()
public final int getTopEdge()
public final int getBottomEdge()
public 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