Class Texture
java.lang.Object
org.variantsync.diffdetective.show.engine.Texture
- All Implemented Interfaces:
Serializable
This class is used to represent, load and redraw
the Images of the entities and the world.
The upper left corner of the Texture has the coordinates (0/0).
The lower right corner of the Texture has the coordinates (getWidth()/getHeight()).
- Author:
- Paul Maximilian Bittner
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Color
Fieldsprivate Color
private Font
static final int
static final int
private BufferedImage
instance values -
Constructor Summary
ConstructorDescriptionTexture
(int width, int height) Creates a new Texture of the given size in pixels.Texture
(BufferedImage image) Creates a new Texture from a BufferedImage.Creates a new Texture from the given file.Creates a new Texture from the given path.Creates a new Texture, that is only text.Creates a new Texture, that is only text.Creates a copy of the given texture. -
Method Summary
Modifier and TypeMethodDescriptionbluePart()
changeColor
(Color from, Color to) boolean
contains
(int x, int y) contrast
(int blackTop) private BufferedImage
copy
(BufferedImage image) private BufferedImage
static Texture
CreateFromFile
(String path) Creates a new Texture from the given path.cut
(int x, int y, int width, int height) Cuts out the given rectangle, meaning, that this rectangle will be filled transparent.deleteColor
(Color color) void
drawLine
(int x1, int y1, int x2, int y2) Draws a line onto the Texture from P(x1/y1) to Q(x2/y2) with the current drawing color.void
Draws a line onto the Texture from pointA to pointB with the current drawing color.void
drawOval
(int x, int y, int width, int height) Draws an Oval with the current drawing color onto the Texture.void
drawPolygon
(int[] xPoints, int[] yPoints) Draws a closed polygon defined by arrays of x and y coordinates.void
drawPolygon
(Point[] points) Draws a closed polygon defined by the given array of points.void
drawRect
(int x, int y, int width, int height) Draws a rectangle with the current drawing color onto the Texture.void
drawString
(String text, int x, int y) Draws a String onto this image at the location P(x/y) with the given Font and color.void
drawTexture
(Texture texture, int x, int y) Draws the given Texture onto this Texture at the given location.void
fill()
Fills the Texture with the current drawing color.void
fillOval
(int x, int y, int width, int height) Draws an Oval with the current drawing color onto the Texture and fills it.void
fillPolygon
(int[] xPoints, int[] yPoints) Fills a closed polygon defined by arrays of x and y coordinates.void
fillPolygon
(Point[] points) Fills a closed polygon defined by the given array of points.void
fillRect
(int x, int y, int width, int height) Draws a Rectangle onto the Texture and fills it with the current drawing color.getColor()
getColorAt
(int x, int y) getFont()
int
int
getWidth()
boolean
inHeight
(int y) private void
init()
Initializes the values.boolean
inWidth
(int x) static Font
private static BufferedImage
This method loads an image from the given file.static Texture[]
loadSpriteSheet
(String filename, int xOffset, int yOffset) void
The Texture will be mirrored by a horizontal axis, that goes through the center of the Texture.void
The Texture will be mirrored by a vertical axis, that goes through the center of the Texture.negative()
pixelize
(int pixelLength) redPart()
rotate
(double degrees) The size of the returned Texture may be different to the original size, to be able to display the whole rotated image, and not only a part of it.void
The texture will be saved with the given name as a png-file into the screenshots folder.void
scale
(double factor) The Texture will be resized by the given factor, that means, that the width and height of the Texture will be multiplied with factor:void
scale
(int width, int height) The Texture will be resized to the given width and height.void
void
setAwtImage
(BufferedImage image) void
void
setColorAt
(int x, int y, Color color) Paints the pixel at the location p(x/y) with color.void
Sets the current Font for drawing Strings.void
setTransparency
(int value) This method makes images becoming more or less transparent.
-
Field Details
-
clr_TRANSPARENT
Fields -
HD_WIDTH
public static final int HD_WIDTH- See Also:
-
HD_HEIGHT
public static final int HD_HEIGHT- See Also:
-
image
instance values -
drawingColor
-
font
-
-
Constructor Details
-
Texture
public Texture(int width, int height) Creates a new Texture of the given size in pixels. -
Texture
Creates a new Texture from the given path. -
Texture
Creates a new Texture from the given file. -
Texture
Creates a copy of the given texture. -
Texture
Creates a new Texture from a BufferedImage. -
Texture
Creates a new Texture, that is only text.- Parameters:
text
- the String that should be drawn as this Textureheight
- the height of the text in pixelsforeground
- the color of the textbackground
- the color behind the text
-
Texture
Creates a new Texture, that is only text.- Parameters:
text
- the String that should be drawn as this Textureheight
- the height of the text in pixelsforeground
- the color of the textbackground
- the color behind the textfont
- the Font for the text
-
-
Method Details
-
CreateFromFile
Creates a new Texture from the given path. -
init
private void init()Initializes the values. -
copy
-
copy
-
setTransparency
public void setTransparency(int value) This method makes images becoming more or less transparent.- Parameters:
value
- The intensity of transparency. It has to be between 0 and 255 (including both). (It represents the alpha value of a RGB-color.)
-
scale
public void scale(double factor) The Texture will be resized by the given factor, that means, that the width and height of the Texture will be multiplied with factor:- Parameters:
factor
- The factor the width and the height of the texture will be multiplied with. If factor is smaller than 1 the Texture will be shrinked. If factor is larger than 1 the Texture will grow. If factor is 1 it won't change.
-
scale
public void scale(int width, int height) The Texture will be resized to the given width and height.- Parameters:
width
- the new width of the textureheight
- the new height of the texture
-
mirrorHorizontally
public void mirrorHorizontally()The Texture will be mirrored by a horizontal axis, that goes through the center of the Texture. -
mirrorVertically
public void mirrorVertically()The Texture will be mirrored by a vertical axis, that goes through the center of the Texture. -
rotate
The size of the returned Texture may be different to the original size, to be able to display the whole rotated image, and not only a part of it.- Parameters:
degrees
- The amount of degrees, the Texture should be rotated to the right.- Returns:
- A Texture, that is this texture, rotated by the given degrees.
-
cut
Cuts out the given rectangle, meaning, that this rectangle will be filled transparent. NOT IMPLEMENTED -
drawLine
public void drawLine(int x1, int y1, int x2, int y2) Draws a line onto the Texture from P(x1/y1) to Q(x2/y2) with the current drawing color.- Parameters:
x1
- the x coordinate of the first pointy1
- the y coordinate of the first pointx2
- the x coordinate of the second pointy2
- the y coordinate of the second point
-
drawLine
Draws a line onto the Texture from pointA to pointB with the current drawing color.- Parameters:
pointA
- The start point of the line.pointB
- The end point of the line.
-
drawRect
public void drawRect(int x, int y, int width, int height) Draws a rectangle with the current drawing color onto the Texture.- Parameters:
x
- the x coordinate of the upper left corner of the rectangley
- the y coordinate of the upper left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangle
-
drawOval
public void drawOval(int x, int y, int width, int height) Draws an Oval with the current drawing color onto the Texture.- Parameters:
x
- the x coordinate of the upper left corner of the ovaly
- the y coordinate of the upper left corner of the ovalwidth
- the width of the ovalheight
- the height of the oval
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints) Draws a closed polygon defined by arrays of x and y coordinates. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.- Parameters:
xPoints
- the x coordinates of the corner pointsyPoints
- the y coordinates of the corner points
-
drawPolygon
Draws a closed polygon defined by the given array of points. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.- Parameters:
points
- The points of the polygon in the correct order.
-
drawTexture
Draws the given Texture onto this Texture at the given location. The coordinate describes the upper left corner of texture.- Parameters:
texture
- the Texture, that should be painted onto this onex
- the x coordinate of the upper left corner of texture in this Texturey
- the y coordinate of the upper left corner of texture in this Texture
-
drawString
Draws a String onto this image at the location P(x/y) with the given Font and color.- Parameters:
text
- the String, that should be written onto this texturex
- the x coordinate of the lower left corner of texty
- the y coordinate of the lower left corner of text
-
fill
public void fill()Fills the Texture with the current drawing color. -
fillRect
public void fillRect(int x, int y, int width, int height) Draws a Rectangle onto the Texture and fills it with the current drawing color.- Parameters:
x
- the x coordinate of the upper left corner of the rectangley
- the y coordinate of the upper left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangle
-
fillOval
public void fillOval(int x, int y, int width, int height) Draws an Oval with the current drawing color onto the Texture and fills it.- Parameters:
x
- the x coordinate of the upper left corner of the ovaly
- the y coordinate of the upper left corner of the ovalwidth
- the width of the ovalheight
- the height of the oval
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints) Fills a closed polygon defined by arrays of x and y coordinates. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.- Parameters:
xPoints
- the x coordinates of the corner pointsyPoints
- the y coordinates of the corner points
-
fillPolygon
Fills a closed polygon defined by the given array of points. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.- Parameters:
points
- The points of the polygon in the correct order.
-
setColor
- Parameters:
color
- the color used to draw
-
setColorAt
Paints the pixel at the location p(x/y) with color.- Parameters:
x
- the x coordinate of the pixely
- the y coordinate of the pixelcolor
- the color for the pixel
-
setFont
Sets the current Font for drawing Strings.- Parameters:
font
- the font for drawing strings
-
setAwtImage
-
set
-
getColorAt
- Returns:
- the color of the pixel at p(x/y)
-
getWidth
public int getWidth()- Returns:
- the width of the Texture in pixels
-
getHeight
public int getHeight()- Returns:
- the height of the Texture in pixels
-
getAwtImage
- Returns:
- the BufferedImage, that represents this Texture
-
getFont
- Returns:
- the current Font for drawing Strings
-
getColor
- Returns:
- the color used to draw
-
contains
public boolean contains(int x, int y) -
redPart
- Returns:
- a Texture, that represents the red part of this Texture of the RGB spectrum
-
greenPart
- Returns:
- a Texture, that represents the green part of this Texture of the RGB spectrum
-
bluePart
- Returns:
- a Texture, that represents the blue part of this Texture of the RGB spectrum
-
contrast
- Parameters:
blackTop
- It's used to distinguish between black and white. It has to be between 0 and 255 (including both). As higher blackTop is as darker the Texture gets.- Returns:
- a Texture, that is the contrast of this Texture
-
blackAndWhite
- Returns:
- a new Texture, that is this Texture filtered to black and white
-
negative
- Returns:
- a new Texture, that is the negative of this Texture
-
pixelize
- Parameters:
pixelLength
- the length of a pixel in the finished image in pixels- Returns:
- a new Texture, that is this Texture pixeled by the given parameter.
-
deleteColor
- Returns:
- A Texture, which colors equal to the parameter are changed to transparent.
-
changeColor
- Returns:
- A Texture, which colors equal to the parameter are changed to the other one.
-
loadImage
This method loads an image from the given file.- Returns:
- a java.awt.image.BufferdImage representing the image in file.
-
loadFont
- Parameters:
filename
- The directory of the font. It should be placed in "Resources/Fonts/". Otherwise it can't be found.- Returns:
- the font from the file, null if it couldn't be found or loaded
-
loadSpriteSheet
- Parameters:
filename
- The directory of the font. It should be placed in "Resources/Fonts/". Otherwise it can't be found.xOffset
- The width of one image on the sprite sheet.yOffset
- The height of one image on the sprite sheet.- Returns:
- All Texture in the sprite sheet in a Texture array.
-
saveAsPng
The texture will be saved with the given name as a png-file into the screenshots folder.- Parameters:
file
- the file, in which the texture is saved- Throws:
IOException
-
inHeight
public boolean inHeight(int y) -
inWidth
public boolean inWidth(int x)
-