Class MapGraphics<C,P>
- Type Parameters:
C
- The render target (e.g. ClientsideMap)P
- The render params
- Direct Known Subclasses:
ClientsideMapGraphics
,FastMapScreenGraphics
,MapScreenGraphics
,StandaloneMapGraphics
This class is huge and should maybe be split into multiple classes, but I haven't found an elegant solution yet.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyFilterToArea(Filter filter, int x, int y, int width, int height)
Apply a filter to a rectangular areavoid
boxBlur(int x, int y, int width, int height)
Perform box blur on a rectangular areavoid
boxBlur(int passes, int x, int y, int width, int height)
Perform box blur on a rectangular areavoid
boxBlur(int passes, BoxBlurFilter.TransparencyHandling transparencyHandling, int x, int y, int width, int height)
Perform box blur on a rectangular areavoid
boxBlur(BoxBlurFilter.TransparencyHandling transparencyHandling, int x, int y, int width, int height)
Perform box blur on a rectangular areaprotected byte
calculateComposite(byte source, byte dest, float alpha)
Composite two colors togetherprotected int
composite(int comp1, int comp2, float a)
Calculate the new component value for two color components with a specific alpha value.void
compositeAtop(MapGraphics<?,?> graphics, int atX, int atY)
Perform an 'atop' alpha composition.void
compositeIn(MapGraphics<?,?> graphics, int atX, int atY)
Perform an 'in' alpha composition.void
compositeOut(MapGraphics<?,?> graphics, int atX, int atY)
Perform an 'out' alpha composition.void
compositeOver(MapGraphics<?,?> graphics, int atX, int atY)
Perform an 'over' alpha composition.void
compositeXor(MapGraphics<?,?> graphics, int atX, int atY)
Perform an 'xor' alpha composition.abstract MapGraphics<C,P>
copy()
Make a copy of this buffervoid
drawEllipse(int atX, int atY, int widthRad, int heightRad, byte color)
void
drawEllipse(int atX, int atY, int widthRad, int heightRad, byte color, float alpha)
Outlines an ellipse using the midpoint ellipse algorithmvoid
drawImage(BufferedImage img, int x, int y)
Draws an image onto the graphics buffervoid
drawLine(int x1, int y1, int x2, int y2, byte color, float alpha)
Draws a linevoid
Draws a lineprotected void
drawLineX(int x1, int x2, int y, byte color, float alpha)
protected void
drawLineY(int y1, int y2, int x, byte color, float alpha)
void
drawRect(int x, int y, int w, int h, byte color, float alpha)
Outlines a rectanglevoid
Draws textvoid
Draws textvoid
fill(int x, int y, byte color, float alpha)
Perform a flood fill operation at a specific coordinatevoid
fillComplete(byte color)
Fills the whole buffer with a specific colorvoid
fillRect(int x, int y, int w, int h, byte color, float alpha)
Draws and fills a rectanglevoid
fillWithBuffer(MapGraphics<?,?> graphics, float alpha, boolean ignoreTransparent)
byte[]
abstract int
Get the height in pixels of this bufferabstract byte
getPixel(int x, int y)
Get a pixelabstract int
getWidth()
Get the width in pixels of this buffervoid
grayscale(int x, int y, int width, int height)
Grayscale a rectangular areaboolean
int
index(int x, int y)
int
index(int x, int y, int w, int h)
boolean
isTransparent(byte color)
Returns true when the specified color is transparent.static MapGraphics<MapGraphics<?,?>,?>
newGraphicsObject(int width, int height)
Creates a new standalone graphics instanceprotected float
normalizeAlpha(float a)
void
place(MapGraphics<?,?> graphics, int x, int y)
Copy the contents of the specified graphics instance onto the buffer of this graphics instance at the specified positionvoid
place(MapGraphics<?,?> graphics, int x, int y, float alpha)
Copy the contents of the specified graphics instance onto the buffer of this graphics instance at the specified positionvoid
place(MapGraphics<?,?> graphics, int x, int y, float alpha, boolean ignoreTransparent)
Copy the contents of the specified graphics instance onto the buffer of this graphics instance at the specified positionvoid
renderOnto(C renderTarget)
Basically copies this buffer onto the buffer of the specified render targetabstract void
renderOnto(C renderTarget, P params)
Basically copies this buffer onto the buffer of the specified render targetvoid
replace(byte colorToReplace, byte color)
Replace a color with another color across the whole bufferbyte
setPixel(int x, int y, byte color)
Set a pixelabstract byte
setPixel(int x, int y, float alpha, byte color)
Set a pixelstatic MapGraphics<MapGraphics<?,?>,?>
standalone(int width, int height)
Creates a new standalone graphics instance
-
Constructor Details
-
MapGraphics
public MapGraphics()
-
-
Method Details
-
standalone
Creates a new standalone graphics instance- Parameters:
width
- Width of the graphicsheight
- Height of the graphics- Returns:
- New standalone graphics
-
newGraphicsObject
Creates a new standalone graphics instance- Parameters:
width
- Width of the graphicsheight
- Height of the graphics- Returns:
- New standalone graphics
-
compositeOver
Perform an 'over' alpha composition. See https://cerus.dev/img/maps_alpha_composition.png# = Non transparent pixel with color from this instance % = Non transparent pixel with color from the other instance * * * %%%%%%%% * * %% OTHER %%% * * %%%%%%%%%%%% * +----------+ %%%% * | # THIS # | * | ######## | +----------+
- Parameters:
graphics
- The graphics instance to compositeatX
- The x coordinate where the composition should startatY
- The y coordinate where the composition should start
-
compositeIn
Perform an 'in' alpha composition. See https://cerus.dev/img/maps_alpha_composition.png# = Non transparent pixel with color from this instance % = Non transparent pixel with color from the other instance * * * * * OTHER * * * +-------#### * | THIS ## * | | +----------+
- Parameters:
graphics
- The graphics instance to compositeatX
- The x coordinate where the composition should startatY
- The y coordinate where the composition should start
-
compositeOut
Perform an 'out' alpha composition. See https://cerus.dev/img/maps_alpha_composition.png# = Non transparent pixel with color from this instance % = Non transparent pixel with color from the other instance * * * * * OTHER * * * +------* * | # THIS # * * | ######## | +----------+
- Parameters:
graphics
- The graphics instance to compositeatX
- The x coordinate where the composition should startatY
- The y coordinate where the composition should start
-
compositeAtop
Perform an 'atop' alpha composition. See https://cerus.dev/img/maps_alpha_composition.png# = Non transparent pixel with color from this instance % = Non transparent pixel with color from the other instance * * * %%%%%%%% * * %% OTHER %%% * * %%%%%%%%%%%% * +-------####%%%%% * | THIS ##% * | | +----------+
- Parameters:
graphics
- The graphics instance to compositeatX
- The x coordinate where the composition should startatY
- The y coordinate where the composition should start
-
compositeXor
Perform an 'xor' alpha composition. See https://cerus.dev/img/maps_alpha_composition.png# = Non transparent pixel with color from this instance % = Non transparent pixel with color from the other instance * * * %%%%%%%% * * %% OTHER %%% * * %%%%%%%%%%%% * +----------+ %%%% * | # THIS | * | ######## | +----------+
- Parameters:
graphics
- The graphics instance to compositeatX
- The x coordinate where the composition should startatY
- The y coordinate where the composition should start
-
fillWithBuffer
-
place
Copy the contents of the specified graphics instance onto the buffer of this graphics instance at the specified position- Parameters:
graphics
- The graphics instance to copy fromx
- X coordinatey
- Y coordinate
-
place
Copy the contents of the specified graphics instance onto the buffer of this graphics instance at the specified position- Parameters:
graphics
- The graphics instance to copy fromx
- X coordinatey
- Y coordinatealpha
- The alpha value of the contents
-
place
public void place(MapGraphics<?,?> graphics, int x, int y, float alpha, boolean ignoreTransparent)Copy the contents of the specified graphics instance onto the buffer of this graphics instance at the specified position- Parameters:
graphics
- The graphics instance to copy fromx
- X coordinatey
- Y coordinatealpha
- The alpha value of the contentsignoreTransparent
- Should transparent pixels not be copied?
-
grayscale
public void grayscale(int x, int y, int width, int height)Grayscale a rectangular area- Parameters:
x
- X coordinatey
- Y coordinatewidth
- Area widthheight
- Area height
-
boxBlur
public void boxBlur(int x, int y, int width, int height)Perform box blur on a rectangular area- Parameters:
x
- X coordinatey
- Y coordinatewidth
- Area widthheight
- Area height
-
boxBlur
public void boxBlur(BoxBlurFilter.TransparencyHandling transparencyHandling, int x, int y, int width, int height)Perform box blur on a rectangular area- Parameters:
transparencyHandling
- How transparent pixels should be handledx
- X coordinatey
- Y coordinatewidth
- Area widthheight
- Area height
-
boxBlur
public void boxBlur(int passes, int x, int y, int width, int height)Perform box blur on a rectangular area- Parameters:
passes
- The intensity of the blur (2-5 for best effect)x
- X coordinatey
- Y coordinatewidth
- Area widthheight
- Area height
-
boxBlur
public void boxBlur(int passes, BoxBlurFilter.TransparencyHandling transparencyHandling, int x, int y, int width, int height)Perform box blur on a rectangular area- Parameters:
passes
- The intensity of the blur (2-5 for best effect)transparencyHandling
- How transparent pixels should be handledx
- X coordinatey
- Y coordinatewidth
- Area widthheight
- Area height
-
applyFilterToArea
Apply a filter to a rectangular area- Parameters:
filter
- The filter to applyx
- X coordinatey
- Y coordinatewidth
- Area widthheight
- Area height
-
fill
public void fill(int x, int y, byte color, float alpha)Perform a flood fill operation at a specific coordinateWill do nothing if the color at the starting coordinate is the same as the fill color.
- Parameters:
x
- The starting x coordinatey
- The starting y coordinatecolor
- The color to fill withalpha
- The alpha of the filling color
-
fillComplete
public void fillComplete(byte color)Fills the whole buffer with a specific color- Parameters:
color
- The color to fill the buffer with
-
fillRect
public void fillRect(int x, int y, int w, int h, byte color, float alpha)Draws and fills a rectangle- Parameters:
x
- The x coordinatey
- The y coordinatew
- The widthh
- The heightcolor
- The fill coloralpha
- The alpha of the rectangle
-
drawRect
public void drawRect(int x, int y, int w, int h, byte color, float alpha)Outlines a rectangle- Parameters:
x
- The x coordinatey
- The y coordinatew
- The widthh
- The heightcolor
- The outline coloralpha
- The alpha of the rectangle
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2, byte color, float alpha)Draws a line- Parameters:
x1
- The starting x coordinatey1
- The starting y coordinatex2
- The finishing x coordinatey2
- The finishing y coordinatecolor
- The outline coloralpha
- The alpha of the rectangle
-
drawLineX
protected void drawLineX(int x1, int x2, int y, byte color, float alpha) -
drawLineY
protected void drawLineY(int y1, int y2, int x, byte color, float alpha) -
drawLine
Draws a line- Parameters:
v1
- The starting coordinatev2
- The finishing coordinatecolor
- The outline coloralpha
- The alpha of the rectangle
-
drawImage
Draws an image onto the graphics buffer- Parameters:
img
- The image to drawx
- The x coordinate where the image should be drawny
- The y coordinate where the image should be drawn
-
drawText
Draws text- Parameters:
x
- X coordinatey
- Y coordinatetext
- The textcolor
- The colorsize
- The size multiplier (1 = normal)
-
drawText
Draws textThis method was originally copied from Bukkit. It has been heavily modified since then to fit our needs.
- Parameters:
x
- X coordinatey
- Y coordinatetext
- The textfont
- The fontcolor
- The colorsize
- The size multiplier (1 = normal)
-
drawEllipse
public void drawEllipse(int atX, int atY, int widthRad, int heightRad, byte color) -
drawEllipse
public void drawEllipse(int atX, int atY, int widthRad, int heightRad, byte color, float alpha)Outlines an ellipse using the midpoint ellipse algorithmhttps://www.geeksforgeeks.org/midpoint-ellipse-drawing-algorithm/
- Parameters:
atX
- Center x of the ellipseatY
- Center y of the ellipsewidthRad
- Horizontal radiusheightRad
- Vertical radiuscolor
- Color of the ellipsealpha
- Alpha of the ellipse
-
replace
public void replace(byte colorToReplace, byte color)Replace a color with another color across the whole buffer- Parameters:
colorToReplace
- The color to replacecolor
- The color to replace the other color with
-
setPixel
public byte setPixel(int x, int y, byte color)Set a pixel- Parameters:
x
- The x coordinatey
- The y coordinatecolor
- The pixel color- Returns:
- The old pixel color. Might return the specified color if the method does not end up setting the pixel.
-
setPixel
public abstract byte setPixel(int x, int y, float alpha, byte color)Set a pixel- Parameters:
x
- The x coordinatey
- The y coordinatealpha
- The pixel alphacolor
- The pixel color- Returns:
- The old pixel color. Might return the specified color if the method does not end up setting the pixel.
-
getPixel
public abstract byte getPixel(int x, int y)Get a pixel- Parameters:
x
- The x coordinatey
- The y coordinate- Returns:
- The pixels color
-
calculateComposite
protected byte calculateComposite(byte source, byte dest, float alpha)Composite two colors together- Parameters:
source
- The new colordest
- The old color (e.g. background)alpha
- The alpha- Returns:
- The composited color
-
composite
protected int composite(int comp1, int comp2, float a)Calculate the new component value for two color components with a specific alpha value. A color component is either red, green or blue.Example:
Color someColor = new Color(0, 0, 0); Color background = new Color(255, 255, 255); float alpha = 0.5f; Color newColor = new Color( composite(someColor.getRed(), background.getRed(), alpha), composite(someColor.getGreen(), background.getGreen(), alpha), composite(someColor.getBlue(), background.getBlue(), alpha) ); // newColor ==> java.awt.Color[r=127,g=127,b=127]
- Parameters:
comp1
- First componentcomp2
- Second componenta
- Alpha- Returns:
- New component
-
isTransparent
public boolean isTransparent(byte color)Returns true when the specified color is transparent.Technically there are 4 transparent colors (0 - 3), but we only return true on 0. This is because we use 0 to mark the absence of a color. This allows us to use 1 - 3 as transparent colors in other processing methods (blending for example).
Implementations of this class are allowed to modify this to suit their needs, but that could affect the functionality of other default features.
- Parameters:
color
- The color to check- Returns:
- True if transparent
-
normalizeAlpha
protected float normalizeAlpha(float a) -
renderOnto
Basically copies this buffer onto the buffer of the specified render target- Parameters:
renderTarget
- The render target
-
renderOnto
Basically copies this buffer onto the buffer of the specified render target- Parameters:
renderTarget
- The render targetparams
- The render parameters
-
copy
Make a copy of this buffer- Returns:
- A copy of this buffer
-
getWidth
public abstract int getWidth()Get the width in pixels of this buffer- Returns:
- The width
-
getHeight
public abstract int getHeight()Get the height in pixels of this buffer- Returns:
- The height
-
hasDirectAccessCapabilities
public boolean hasDirectAccessCapabilities() -
getDirectAccessData
public byte[] getDirectAccessData() -
index
public int index(int x, int y) -
index
public int index(int x, int y, int w, int h)
-