Package buildengine.engine.graphics
Class Draw
java.lang.Object
buildengine.engine.graphics.Draw
Utility class for java graphics drawing.
This class has the unit
object, used to translate and scale the Draws.
The screen therefore consists of units. The amount of units depends on the aspect
ratio, and the standard unit product. Every time you use methods from this class
it expects unit coordinates, with the exception of the convert()
methods,
witch are used to convert units to pixels on the screen, and vise versa.
The class also contains a Transform, to apply to the drawing. Use the methods
Draw.translate(), Draw.scale() and Draw.rotate()
before drawing to apply transformations.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
applyTransform
(Transform transform) Transform the Draw.static Vector2i
convertPositionToPixel
(Vector2f vector2F) Converts unit coordinates to screen pixel coordinates and applies the draw transform.static Vector2i
convertSizeToPixel
(float width, float height) Converts unit sizes to screen pixel coordinates and applies the draw transform.static Vector2f
convertToUnit
(Vector2i vector2i) Converts pixel coordinates to draw unit coordinates and takes the draw transform into account.static void
drawCenteredString
(String string, Vector2f position) Draws a centered string to the screen.static void
drawCenteredString
(String string, Vector2f position, Color color) Draws a centered string to the screen.static void
drawCenteredString
(String string, Vector2f position, Color color, Font font) Draws a centered string to the screen.static void
drawImage
(BufferedImage image, Vector2f position, float width, float height) DrawImage method.static void
drawImage
(BufferedImage image, Vector2f position, float width, float height, double theta, Vector2f center) DrawImage method.static void
Draws a line to the screen, between two specified points.static void
Draws a line to the screen, between two specified points.static void
Draws a line to the screen, between two specified points.static void
Draws a point to the screen, on a specified point.static void
Draws a point to the screen, on a specified point.static void
Draws a rectangular shape to the screen.static void
Draws a rectangular shape to the screen.static void
Draws a rectangular shape to the screen.static void
Draws a rectangular shape to the screen.static void
Draws a rectangular shape to the screen.static void
Draws a rectangular shape to the screen.static void
drawRect
(Vector2f position, float width, float height, Color color, boolean fill, double theta, Vector2f center) Draws a rectangular shape to the screen.static void
drawString
(String string, Vector2f position) Draws a specified string to a specified position on the screen using the specified color, using the default font.static void
drawString
(String string, Vector2f position, Color color) Draws a specified string to a specified position on the screen using the specified color, using the default font.static void
drawString
(String string, Vector2f position, Color color, Font font) Draws a string to the screen, with specified position, color and font.static Vector2f
static float
static Transform
Gets the current transformation of the Drawstatic Vector2f
getUnit()
static float
getWidth()
static boolean
Check if horizontal stretching is active.static void
prepare
(Graphics2D graphics2D) Sets a newGraphics2D
object for the Draw to use.static void
Resets the transform of draw.static void
Recalculates the unit relative to the#size
and theaspectRatio
.static void
rotate
(float theta) Rotate the transform of Draw.static void
Scale the transform of Draw.static void
setStretch
(boolean stretch) Allows you to enable horizontal stretching.static void
Changes the unitstatic void
Translate the transform of Draw.
-
Field Details
-
UNIT
public static final float UNIT- See Also:
-
ASPECT_RATIO
-
DRAW_POINT_SIZE_MUL
public static final float DRAW_POINT_SIZE_MUL- See Also:
-
DEFAULT_COLOR
-
-
Method Details
-
prepare
Sets a newGraphics2D
object for the Draw to use. Always call this first in the render method of the Draw.- Parameters:
graphics2D
- up-to-dateGraphics2D
object.- See Also:
-
g
-
applyTransform
Transform the Draw. After altering applies to all Draw calls.- Parameters:
transform
- the transform to apply
-
translate
Translate the transform of Draw. After altering applies to all Draw calls.- Parameters:
vector2f
- translation position in units
-
scale
Scale the transform of Draw. After altering applies to all Draw calls.- Parameters:
size
- translation scale in units
-
rotate
public static void rotate(float theta) Rotate the transform of Draw. After altering applies to all Draw calls.- Parameters:
theta
- the rotation in radians
-
resetTransform
public static void resetTransform()Resets the transform of draw. After calling applies to all Draw calls. -
drawImage
DrawImage method. This is the main method for rendering graphics/images to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
image
- image to draw.position
- the position to draw in units.width
- the width stretch in units.height
- the height stretch in units.
-
drawImage
public static void drawImage(BufferedImage image, Vector2f position, float width, float height, double theta, Vector2f center) DrawImage method. This is the main method for rendering graphics/images to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
image
- image to draw.position
- the position to draw in units.width
- the width stretch in units.height
- the height stretch in units.theta
- the rotationcenter
- center, around witch the image should be rotated.
-
drawString
Draws a specified string to a specified position on the screen using the specified color, using the default font. This method usesjava.awt.Graphics2D
.- Parameters:
string
- the string to draw.position
- position of the string in units.
-
drawString
Draws a specified string to a specified position on the screen using the specified color, using the default font. This method usesjava.awt.Graphics2D
.- Parameters:
string
- the string to draw.position
- position of the string in units.color
- color to draw in.
-
drawString
Draws a string to the screen, with specified position, color and font. This method usesjava.awt.Graphics2D
.- Parameters:
string
- the string to draw.position
- position of the string in units.color
- color to draw in.font
- font to use.
-
drawCenteredString
Draws a centered string to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
string
- the string to draw.position
- position of the string in units(CENTERED).- See Also:
-
drawCenteredString
Draws a centered string to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
string
- the string to draw.position
- position of the string in units(CENTERED).color
- color to draw in.- See Also:
-
drawCenteredString
Draws a centered string to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
string
- the string to draw.position
- position of the string in units(CENTERED).color
- color to draw in.font
- font to use.- See Also:
-
drawRect
Draws a rectangular shape to the screen. This method usesbuildengine.math.shape.Rectangle
.- Parameters:
rectangle
- The rectangle object to draw.fill
- Whether the rectangle should be filled or not.
-
drawRect
Draws a rectangular shape to the screen. This method usesbuildengine.math.shape.Rectangle
.- Parameters:
rectangle
- The rectangle object to draw.color
- The color of the rectangle.fill
- Whether the rectangle should be filled or not.
-
drawRect
Draws a rectangular shape to the screen. This method usesbuildengine.math.shape.Rectangle
.- Parameters:
rectangle
- The rectangle object to draw.position
- Position to draw the rectangle.color
- The color of the rectangle.fill
- Whether the rectangle should be filled or not.
-
drawRect
Draws a rectangular shape to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
position
- Position in units.width
- Width in units.height
- Height in units.fill
- Whether the rectangle should be filled or not.
-
drawRect
public static void drawRect(Vector2f position, float width, float height, Color color, boolean fill) Draws a rectangular shape to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
position
- Position in units.width
- Width in units.height
- Height in units.color
- Color of the rectangle.fill
- Whether the rectangle should be filled or not.
-
drawRect
public static void drawRect(Vector2f position, float width, float height, boolean fill, double theta, Vector2f center) Draws a rectangular shape to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
position
- the position to draw in units.width
- the width stretch in units.height
- the height stretch in units.fill
- whether the rectangle should be filled or not.theta
- the rotationcenter
- if you're working with rotations, different center point
-
drawRect
public static void drawRect(Vector2f position, float width, float height, Color color, boolean fill, double theta, Vector2f center) Draws a rectangular shape to the screen. This method usesjava.awt.Graphics2D
.- Parameters:
position
- the position to draw in units.width
- the width stretch in units.height
- the height stretch in units.color
- the color of the rectangle.fill
- whether the rectangle should be filled or not.theta
- the rotationcenter
- if you're working with rotations, different center point
-
drawLine
Draws a line to the screen, between two specified points. This method usesjava.awt.Graphics2D
.- Parameters:
a
- starting point of the line.b
- end point of the line.
-
drawLine
Draws a line to the screen, between two specified points. This method usesjava.awt.Graphics2D
.- Parameters:
a
- starting point of the line.b
- end point of the line.color
- color of the line
-
drawLine
Draws a line to the screen, between two specified points. This method usesjava.awt.Graphics2D
.- Parameters:
line
- Line to draw.color
- color of the line
-
drawPoint
Draws a point to the screen, on a specified point.- Parameters:
point
- The point to draw
-
drawPoint
Draws a point to the screen, on a specified point.- Parameters:
point
- The point to drawcolor
- The color to draw it in.
-
resize
Recalculates the unit relative to the#size
and theaspectRatio
. -
convertPositionToPixel
Converts unit coordinates to screen pixel coordinates and applies the draw transform.- Parameters:
vector2F
- unit coordinate- Returns:
- pixel coordinate
-
convertSizeToPixel
Converts unit sizes to screen pixel coordinates and applies the draw transform.- Parameters:
width
- Width in unitsheight
- Height in units- Returns:
- Pixel coordinate
-
convertToUnit
Converts pixel coordinates to draw unit coordinates and takes the draw transform into account.- Parameters:
vector2i
- pixel coordinate- Returns:
- unit coordinate
-
isStretch
public static boolean isStretch()Check if horizontal stretching is active. The screen will resize horizontally too with this enabled.- Returns:
- true if vStretch is enabled
-
setStretch
public static void setStretch(boolean stretch) Allows you to enable horizontal stretching. The screen will resize horizontal too with this enabled.- Parameters:
stretch
- true - enables vStretch false(default) - disables vStretch; only resizes vertically
-
setUnit
Changes the unit- Parameters:
newUnit
- new unit- See Also:
-
unit
-
getUnit
- Returns:
- the unit object.
- See Also:
-
unit
-
getTransform
Gets the current transformation of the Draw- Returns:
- a copy of the current Transform object
-
getWidth
public static float getWidth()- Returns:
- the screen width in units
-
getHeight
public static float getHeight()- Returns:
- the screen height in units
-
getCenter
- Returns:
- the screen center in units
-