|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.aplu.jgamegrid.GGBackground
public class GGBackground
Class for drawing into the GameGrid background using Java Graphics2D methods.
The size of the drawing area is determined by the number and size of the cells
when constructing the GameGrid: In pixel units, e.g. distance between adjacent pixel,
the width of the background is nbHorzCells * cellSize horizontally and
the height is nbVertCells * cellSize vertically. Thus the background contains
width + 1 pixels horizontally and height + 1 pixels vertically,
and the pixel coordinates are 0 <= i <= width (inclusive), 0 <= k <= height
(inclusive) respectively.
Example: Constructing new GameGrid(600, 400, 1) will give a background with 601x401
pixels. x-pixel coordinates are in the range 0 <= x <= 600, y-pixel coordinates
in the range 0 <=y <= 400. The center is exactly at coordinate (300, 200).
Defaults:
- paint color: white
- line width: 1 pixel
- background color: black
- font: SansSerif, Font.PLAIN, 24 pixel
GGBackground uses an won offscreen buffer that may contain a background image,
the grid lines and any background graphics. The current content of the buffer
may be saved and restored in an extra buffer using save() and restore().
All drawing methods draw into the buffer that is automatically rendered
to the screen in every simulation cycle when the actor's act() methods are called.
If act() is not active, an explicit call to GameGrid.refresh() may be necessary to
render the buffer. Because actor sprite images are drawn in the foreground,
use text as sprite image to display it in the foreground.
Method Summary | |
---|---|
void |
clear()
Clears the background buffer by painting it with the current background color. |
void |
clear(java.awt.Color color)
Clears the background buffer by painting it with the given background color. |
void |
drawArc(java.awt.Point pt,
int radius,
double startAngle,
double extentAngle)
Draws an arc with given center, radius, start angle and angle extent. |
void |
drawCircle(java.awt.Point center,
int radius)
Draws a circle with given center and given radius. |
void |
drawGeneralPath(java.awt.geom.GeneralPath gp)
Draws a figure defined by the given GeneralPath. |
void |
drawGridLines(java.awt.Color color)
Draws the grid lines using the given color. |
void |
drawImage(java.awt.image.BufferedImage bi)
Draws the given image at position (0, 0) into the background buffer. |
void |
drawImage(java.awt.image.BufferedImage bi,
int x,
int y)
Draws the given image into the background buffer. |
void |
drawImage(java.lang.String imagePath,
int x,
int y)
Retrieves the image either from the jar resource, from local drive or from a internet server and draws it into the background buffer. |
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line from one coordinate pair to another coordinate pair. |
void |
drawLine(java.awt.Point pt1,
java.awt.Point pt2)
Draws a line from one coordinate pair to another coordinate pair. |
void |
drawPoint(java.awt.Point pt)
Draws a single point. |
void |
drawPolygon(java.awt.Point[] vertexes)
Draws a polygon with given vertexes. |
void |
drawRectangle(java.awt.Point pt1,
java.awt.Point pt2)
Draws a rectangle with given opposite corners. |
void |
drawText(java.lang.String text,
java.awt.Point pt)
Displays the given text at the given position using the current font. |
void |
fillArc(java.awt.Point pt,
int radius,
double startAngle,
double extentAngle)
Fills an arc with given center, radius, start angle and angle extent. |
void |
fillCell(Location location,
java.awt.Color fillColor)
Fills a cell with given color. |
void |
fillCell(Location location,
java.awt.Color fillColor,
boolean boundary)
Fills a cell with given color. |
void |
fillCircle(java.awt.Point center,
int radius)
Draws a filled circle with given center and given radius. |
void |
fillGeneralPath(java.awt.geom.GeneralPath gp)
Fills a figure defined by the given GeneralPath. |
void |
fillPolygon(java.awt.Point[] vertexes)
Draws a filled polygon with given vertexes. |
void |
fillRectangle(java.awt.Point pt1,
java.awt.Point pt2)
Draws a filled rectangle with given opposite corners. |
static java.lang.String[] |
getAvailableFontFamilies()
Returns the available font families for the current platform. |
java.awt.image.BufferedImage |
getBackgroundImage()
Returns the BufferedImage of the current background. |
java.awt.Color |
getBgColor()
Returns the current background color. |
java.awt.Color |
getColor(Location location)
Returns the color of the pixel of the background at given cell's center. |
java.awt.Color |
getColor(java.awt.Point pt)
Returns the color of the pixel of the background at given point. |
java.awt.Graphics2D |
getContext()
Returns the graphics device context of the background. |
int |
getLineWidth()
Returns the current line width in pixels. |
java.awt.Color |
getPaintColor()
Returns the current paint color. |
void |
restore()
Restores a previously saved background. |
void |
save()
Saves the current background to an extra buffer. |
void |
setBgColor(java.awt.Color color)
Sets the given new background color. |
void |
setFont(java.awt.Font font)
Sets the current font for displaying text with drawText() |
void |
setLineWidth(int width)
Sets the current line width in pixels. |
void |
setPaintColor(java.awt.Color color)
Sets the given new paint color (for drawing and filling). |
void |
setPaintMode()
Sets the paint mode of the graphics context to overwrite with current color. |
void |
setXORMode(java.awt.Color c)
Sets the paint mode to alternate between the current color and the given color. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public java.awt.image.BufferedImage getBackgroundImage()
public void save()
public void restore()
public void drawImage(java.lang.String imagePath, int x, int y)
imagePath
- the file name or urlx
- x-coordinate of upper left cornery
- y-coordinate of upper left cornerpublic void drawImage(java.awt.image.BufferedImage bi, int x, int y)
x
- x-coordinate of upper left cornery
- y-coordinate of upper left cornerpublic void drawImage(java.awt.image.BufferedImage bi)
public void clear(java.awt.Color color)
color
- the color of the background, alpha channel ignoredpublic void clear()
public void drawGridLines(java.awt.Color color)
color
- the color of the grid linespublic int getLineWidth()
public void setLineWidth(int width)
width
- the new line widthpublic java.awt.Color getPaintColor()
public void setPaintColor(java.awt.Color color)
color
- the new line colorpublic java.awt.Color getBgColor()
public void setBgColor(java.awt.Color color)
color
- the new background colorpublic void drawLine(int x1, int y1, int x2, int y2)
x1
- the x-coordinate of the start pointy1
- the y-coordinate of the start pointx2
- the x-coordinate of the endpointy2
- the y-coordinate of the endpointpublic void drawLine(java.awt.Point pt1, java.awt.Point pt2)
pt1
- the start pointpt2
- the endpointpublic void drawCircle(java.awt.Point center, int radius)
radius
- the radius of the circlepublic void fillCircle(java.awt.Point center, int radius)
center
- the center of the circleradius
- the radius of the circlepublic void drawRectangle(java.awt.Point pt1, java.awt.Point pt2)
pt1
- upper left vertex of the rectanglept2
- lower right vertex of the rectanglepublic void fillRectangle(java.awt.Point pt1, java.awt.Point pt2)
pt1
- upper left vertex of the rectanglept2
- lower right vertex of the rectanglepublic void drawArc(java.awt.Point pt, int radius, double startAngle, double extentAngle)
pt
- the center of the arcradius
- the radius of the arcstartAngle
- the start angle in degrees (zero to east, positive counterclockwise)extentAngle
- the angle extent of the arc in degreespublic void fillArc(java.awt.Point pt, int radius, double startAngle, double extentAngle)
pt
- the center of the arcradius
- the radius of the arcstartAngle
- the start angle in degrees (zero to east, positive counterclockwise)extentAngle
- the angle extent of the arc in degreespublic void drawPolygon(java.awt.Point[] vertexes)
vertexes
- the vertexes of the polygonpublic void fillPolygon(java.awt.Point[] vertexes)
vertexes
- the vertexes of the polygonpublic void drawGeneralPath(java.awt.geom.GeneralPath gp)
gp
- the GeneralPath that defines the shapepublic void fillGeneralPath(java.awt.geom.GeneralPath gp)
gp
- the GeneralPath that defines the shapepublic void drawPoint(java.awt.Point pt)
pt
- the point to drawpublic void fillCell(Location location, java.awt.Color fillColor)
location
- the cell's location (cell indices).fillColor
- the filling color of the cellpublic void fillCell(Location location, java.awt.Color fillColor, boolean boundary)
location
- the cell's location (cell indices).fillColor
- the filling color of the cellboundary
- if true the boundary lines are considered to be part of the cell;
otherwise the boundary lines are left intactpublic java.awt.Color getColor(java.awt.Point pt)
pt
- point, where to pick the color; if pt is outside
the grid, returns Color.black.
public java.awt.Color getColor(Location location)
location
- cell's location where to pick the color; if location is outside
the grid, returns Color.black.
public void setFont(java.awt.Font font)
font
- the font to be usedpublic void drawText(java.lang.String text, java.awt.Point pt)
text
- the text to displaypt
- the start point of the text baselinepublic static java.lang.String[] getAvailableFontFamilies()
public java.awt.Graphics2D getContext()
public void setPaintMode()
public void setXORMode(java.awt.Color c)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |