Package com.dkt.graphics.extras
Class GPixMap
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.extras.GPixMap
- All Implemented Interfaces:
 Cloneable
- Author:
 - Federico Vera <[email protected]>
 
- 
Field Summary
 - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionclone()colorAt(int i, int j) Retrieves theColoron a given position of theGPixMap
Note: The value ofjis affected by the direction of theY axisbooleancontains(int x, int y) Tells if a given set of coordinates is contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anythingbooleanTells if aGLineis contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anythingbooleanTells if aGPointis contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anythingbooleanTells if aGRectangleis contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anythingvoiddraw(Graphics2D g) Draws the component on the given graphicsbooleanTells if theGPixMapwill draw the inner lines or notbooleanstatic voidSaves a text representation of thisGPixMapto a fileRetrieves the bounds of thisGPixMapat this particular moment, if you plan on using this to check for collisions, it's better to use thecontains(...)methods of this classColor[][]Retrieves a copy of the color data expressed as aColormatrixint[][]getData()Retrieves a copy of the color data expressed as anintmatrixThis will retrieve the position of the lower left corner of theGPixMap.
Note: if the canvas is inverting theY axisthen it will represent the upper left cornerintgetXSize()Retrieves the number of horizontal pixels in thisGPixMapintgetYSize()Retrieves the number of vertical pixels in thisGPixMapinthashCode()static GPixMapImports aGPixMapfrom a filestatic GPixMapimportMap(InputStream is) Imports aGPixMapfrom a givenInputStreambooleanTells thisGPixMapintersects with a givenGRectangle
Note: invisibleGPixMaps don't intersect with anythingbooleanintersects(GPixMap map) Tells twoGPixMaps intersect
Note: invisibleGPixMaps don't intersect with anythingbooleanisSquare()Tells if theGPixMaphas the same number of rows and columnsbooleanTells if theGPixMapwill be drawn
Note: invisibleGPixMaps don't intersect with anythingRetrieves a newGPixMapwhich is the horizontally mirrored version of this one.Retrieves a newGPixMapwhich is the vertically mirrored version of this one.intRetrieves the pixel sizeRetrieves a newGPixMapwhich is the result of rotating this one counterclockwise 90°.rotateCW()Retrieves a newGPixMapwhich is the result of rotating this one clockwise 90°.voidsetColorAt(int i, int j, Color col) Set's theColorat the specified coordinates
Note: The value ofjis affected by the direction of theY axisvoidsetDrawLines(boolean draw) Tells theGPixMapto draw the inner/outer linesvoidsetPixelSize(int size) Set's the pixel size of theGPixMapvoidsetValueAt(int i, int j, int argb, boolean hasAlpha) Set's theColorat the specified coordinates which will be created asnew Color(argb, hasAlpha)
Note: The value ofjis affected by the direction of theY axisvoidsetVisible(boolean v) Tells theGPixMapto draw itself in the canvas Note: invisibleGPixMaps don't intersect with anythingCreates aStringrepresentation of theGPixMap, which consists of space separated values representing the hex representation of the colors of each pixel.booleanTells if twoGPixMaps touch each other, this differs from theintersects(GPixMap)because this checks if the images are actually touching each other ignoring the transparent pixels.
This method will only work onGPixMaps that have the same pixel size.
Note: This method will most likely fail miserably when combined withGTransforms.
Note 2: There are some issues when the traslation step is different from the pixel size, but that should be a non issue, since it's a "very rare" scenario, and that's why we have atraslateUnits(int, int)method.voidtraslate(int x, int y) Traslates this element on X and YvoidtraslateUnits(int h, int v) As opposed toGraphicE.traslate(int, int)this method will traslate the PixMap a certain amount ofpixels(consideringpixelthe size of each square drawn in the screen)intvalueAt(int i, int j) Retrieves theColoron a given position of theGPixMap
Note: The value ofjis affected by the direction of theY axis 
- 
Constructor Details
- 
GPixMap
Copy constructor- Parameters:
 e-GPixMapto copy- Throws:
 IllegalArgumentException- ifeisnull
 - 
GPixMap
Creates a newGPixMapof a given size- Parameters:
 x- horizontal size in pixelsy- vertical size in pixels- Throws:
 InvalidArgumentException- if eitherxoryare smaller or equal to zero
 - 
GPixMap
Constructs a newGPixMapfrom a givenColormatrix- Parameters:
 data- The data that will form theGPixMap- Throws:
 IllegalArgumentException- ifdataisnullor if any of the rows arenullInvalidArgumentException- if the matrix isn't rectangular (given that matrix implementations in Java are based on Iliffe vectors, it's possible for the rows to have different sizes
 - 
GPixMap
public GPixMap(int[][] data, boolean hasAlpha) throws IllegalArgumentException, InvalidArgumentException Constructs a newGPixMapfrom a givenintmatrix- Parameters:
 data- The data that will form theGPixMapall this data will be converted toColorobjects, so they should have the formARGBhasAlpha- Tells if the ints represent a color with alpha- Throws:
 IllegalArgumentException- ifdataisnullor if any of the rows arenullInvalidArgumentException- if the matrix isn't rectangular (given that matrix implementations in Java are based on Iliffe vectors, it's possible for the rows to have different sizes
 
 - 
 - 
Method Details
- 
setPixelSize
Set's the pixel size of theGPixMap- Parameters:
 size- new pixel size- Throws:
 InvalidArgumentException- if thesize <= 0
 - 
getXSize
public int getXSize()Retrieves the number of horizontal pixels in thisGPixMap- Returns:
 - horizontal pixels
 
 - 
getYSize
public int getYSize()Retrieves the number of vertical pixels in thisGPixMap- Returns:
 - vertical pixels
 
 - 
colorAt
Retrieves theColoron a given position of theGPixMap
Note: The value ofjis affected by the direction of theY axis- Parameters:
 i- vertical coordinatej- horizontal coordinate- Returns:
 - Color
 - Throws:
 IntervalException- if eitheriorjare out of range
 - 
setColorAt
Set's theColorat the specified coordinates
Note: The value ofjis affected by the direction of theY axis- Parameters:
 i- vertical coordinatej- horizontal coordinatecol- the color to set- Throws:
 IntervalException- if eitheriorjare out of rangeIllegalArgumentException- ifcolisnull
 - 
valueAt
Retrieves theColoron a given position of theGPixMap
Note: The value ofjis affected by the direction of theY axis- Parameters:
 i- vertical coordinatej- horizontal coordinate- Returns:
 - numerical value of the color
 - Throws:
 IntervalException- if eitheriorjare out of range
 - 
setValueAt
Set's theColorat the specified coordinates which will be created asnew Color(argb, hasAlpha)
Note: The value ofjis affected by the direction of theY axis- Parameters:
 i- vertical coordinatej- horizontal coordinateargb- color datahasAlpha-trueif the color has alpha andfalseotherwise- Throws:
 IntervalException- if eitheriorjare out of range
 - 
getPosition
This will retrieve the position of the lower left corner of theGPixMap.
Note: if the canvas is inverting theY axisthen it will represent the upper left corner- Returns:
 GPointrepresenting the lower left corner
 - 
setDrawLines
public void setDrawLines(boolean draw) Tells theGPixMapto draw the inner/outer lines- Parameters:
 draw-trueto draw the lines andfalseotherwise
 - 
drawLines
public boolean drawLines()Tells if theGPixMapwill draw the inner lines or not- Returns:
 trueif theGPixMapis drawing the inner lines andfalseotherwise
 - 
pixelSize
public int pixelSize()Retrieves the pixel size- Returns:
 - pixel size
 
 - 
getBounds
Retrieves the bounds of thisGPixMapat this particular moment, if you plan on using this to check for collisions, it's better to use thecontains(...)methods of this class- Returns:
 GRectangleobject representing the bounds of thisGPixMap- See Also:
 
 - 
contains
public boolean contains(int x, int y) Tells if a given set of coordinates is contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anything- Parameters:
 x-xcoordinate of the pointy-ycoordinate of the point- Returns:
 trueif the point is contained andfalseotherwise- See Also:
 
 - 
contains
Tells if aGPointis contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anything- Parameters:
 p-GPoint- Returns:
 trueif the point is contained andfalseotherwise- See Also:
 
 - 
contains
Tells if aGLineis contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anything- Parameters:
 l-GLine- Returns:
 trueif the point is contained andfalseotherwise- See Also:
 
 - 
intersects
Tells thisGPixMapintersects with a givenGRectangle
Note: invisibleGPixMaps don't intersect with anything- Parameters:
 r-GRectangle- Returns:
 trueif the maps intersect andfalseotherwise- See Also:
 
 - 
intersects
Tells twoGPixMaps intersect
Note: invisibleGPixMaps don't intersect with anything- Parameters:
 map- otherGPixMap- Returns:
 trueif the maps intersect andfalseotherwise- See Also:
 
 - 
contains
Tells if aGRectangleis contained in the bounds of thisGPixMap
Note: invisibleGPixMaps don't intersect with anything- Parameters:
 r- rectangle- Returns:
 trueif the point is contained andfalseotherwise- See Also:
 
 - 
traslateUnits
public void traslateUnits(int h, int v) As opposed toGraphicE.traslate(int, int)this method will traslate the PixMap a certain amount ofpixels(consideringpixelthe size of each square drawn in the screen)- Parameters:
 h- number of horizontal pixelsv- number of vertical pixels- See Also:
 
 - 
isVisible
public boolean isVisible()Tells if theGPixMapwill be drawn
Note: invisibleGPixMaps don't intersect with anything- Returns:
 trueif it's visible andfalseotherwise- See Also:
 
 - 
setVisible
public void setVisible(boolean v) Tells theGPixMapto draw itself in the canvas Note: invisibleGPixMaps don't intersect with anything- Parameters:
 v-trueif theGPixMapwill be drawn andfalseotherwise- See Also:
 
 - 
isSquare
public boolean isSquare()Tells if theGPixMaphas the same number of rows and columns- Returns:
 trueif theGPixMapis square andfalseotherwise
 - 
rotateCW
Retrieves a newGPixMapwhich is the result of rotating this one clockwise 90°.+-----+ +-------+ | *** | | ***** | | * | | * | -> | * | | * | | * | +-------+ | * | +-----+- Returns:
 - Clockwise turn of this 
GPixMap 
 - 
rotateCCW
Retrieves a newGPixMapwhich is the result of rotating this one counterclockwise 90°.+-----+ +-------+ | * | | ***** | | * | | * | -> | * | | * | | * | +-------+ | *** | +-----+- Returns:
 - Counterclockwise turn of this 
GPixMap 
 - 
mirrorHorizontal
Retrieves a newGPixMapwhich is the horizontally mirrored version of this one.+------+ +------+ | **** | | **** | | * | -> | * | | **** | | **** | +------+ +------+- Returns:
 - Horizontal mirror of this 
GPixMap 
 - 
mirrorVertical
Retrieves a newGPixMapwhich is the vertically mirrored version of this one.+------+ +------+ | * * | | **** | | * * | -> | * * | | **** | | * * | +------+ +------+- Returns:
 - Vertical mirror of this 
GPixMap 
 - 
touches
Tells if twoGPixMaps touch each other, this differs from theintersects(GPixMap)because this checks if the images are actually touching each other ignoring the transparent pixels.
This method will only work onGPixMaps that have the same pixel size.
Note: This method will most likely fail miserably when combined withGTransforms.
Note 2: There are some issues when the traslation step is different from the pixel size, but that should be a non issue, since it's a "very rare" scenario, and that's why we have atraslateUnits(int, int)method. Oops... it appears to be a more common scenario than predicted... my bad. If someone actually wants to take care of this, that would be great.- Parameters:
 map- theGPixMapto check against- Returns:
 trueif the twoGPixMaps touch andfalseotherwise- Throws:
 IllegalArgumentException- ifmapisnullInvalidArgumentException- if the pixel sizes don't match- See Also:
 
 - 
traslate
public void traslate(int x, int y) Description copied from class:GraphicETraslates this element on X and Y - 
draw
Description copied from class:GraphicEDraws the component on the given graphics - 
getColorData
Retrieves a copy of the color data expressed as aColormatrix- Returns:
 - color data
 
 - 
getData
public int[][] getData()Retrieves a copy of the color data expressed as anintmatrix- Returns:
 - color data
 
 - 
toDataString
Creates aStringrepresentation of theGPixMap, which consists of space separated values representing the hex representation of the colors of each pixel. This method does not include either pixel size nor visibility of the grid.- Returns:
 Stringrepresenting the data of theGPixMap
 - 
exportMap
Saves a text representation of thisGPixMapto a file- Parameters:
 map-GPixMapto exportfile- file in which to export- Throws:
 IOException- if something goes wrong when writing the fileIllegalArgumentException- iffileormaparenull- See Also:
 
 - 
importMap
Imports aGPixMapfrom a givenInputStream- Parameters:
 is-InputStreamof the file- Returns:
 - a new 
GPixMapdecoded from theInputStream - Throws:
 IOException- if something goes wrong when reading the fileIllegalArgumentException- ifisisnull- See Also:
 
 - 
importMap
public static GPixMap importMap(File file) throws FileNotFoundException, IOException, IllegalArgumentException Imports aGPixMapfrom a file- Parameters:
 file- file from which to read theGPixMap- Returns:
 - a new 
GPixMapdecoded from theFile - Throws:
 FileNotFoundException- if the file doesn't existIOException- if something goes wrong when reading the fileIllegalArgumentException- ifisisnull- See Also:
 
 - 
clone
 - 
hashCode
public int hashCode() - 
equals
 
 -