Interface MapCanvas
public interface MapCanvas
A 128×128 grid of map pixels, see
MapPalette.
Column 0 is on the left, row 0 at the top, as the map is seen in hand or in an
item frame. Drawing outside the grid is silently clipped, so shapes and text can overflow the
edges. Canvases are safe to draw on from any thread; group related changes in a
batch(Consumer) so viewers never see half of them.
- Since:
- 0.1.0
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidRuns several changes at once: other threads, and viewers, see either none or all of them.voidCopies every pixel of another canvas, transparent ones included.voidDraws an image.voidfill(byte pixel) Fills the whole canvas.voidfill(int x, int y, int width, int height, byte pixel) Fills a rectangle.voidline(int x1, int y1, int x2, int y2, byte pixel) Draws a straight line, both ends included.bytepixel(int x, int y) Returns a pixel.voidpixel(int x, int y, byte pixel) Sets a pixel.byte[]pixels()Returns a copy of every pixel, row by row.voidpixels(byte[] pixels) Replaces every pixel.voidrectangle(int x, int y, int width, int height, byte pixel) Draws the outline of a rectangle, one pixel thick.intWrites text in one color, with the standard font.inttext(int x, int y, ComponentLike text, MapFont font, byte pixel, boolean shadow) Writes text.
-
Field Details
-
SIZE
static final int SIZEThe width and height of a canvas.- See Also:
-
-
Method Details
-
pixel
byte pixel(int x, int y) Returns a pixel.- Parameters:
x- the columny- the row- Returns:
- the pixel,
MapPalette.TRANSPARENToutside the canvas - Since:
- 0.1.0
-
pixel
void pixel(int x, int y, byte pixel) Sets a pixel. Does nothing outside the canvas.- Parameters:
x- the columny- the rowpixel- the pixel- Since:
- 0.1.0
-
batch
-
pixels
byte[] pixels()Returns a copy of every pixel, row by row.- Returns:
- a copy of every pixel, row by row
- Since:
- 0.1.0
-
pixels
-
fill
void fill(byte pixel) Fills the whole canvas.- Parameters:
pixel- the pixel,MapPalette.TRANSPARENTto clear- Since:
- 0.1.0
-
fill
void fill(int x, int y, int width, int height, byte pixel) Fills a rectangle.- Parameters:
x- the left columny- the top rowwidth- the widthheight- the heightpixel- the pixel- Since:
- 0.1.0
-
rectangle
void rectangle(int x, int y, int width, int height, byte pixel) Draws the outline of a rectangle, one pixel thick.- Parameters:
x- the left columny- the top rowwidth- the widthheight- the heightpixel- the pixel- Since:
- 0.1.0
-
line
void line(int x1, int y1, int x2, int y2, byte pixel) Draws a straight line, both ends included.- Parameters:
x1- the column of the starty1- the row of the startx2- the column of the endy2- the row of the endpixel- the pixel- Since:
- 0.1.0
-
draw
Draws an image. Transparent pixels of the image leave the canvas unchanged.- Parameters:
image- the imagex- the column of the left edge of the imagey- the row of its top edge- Since:
- 0.1.0
-
copy
Copies every pixel of another canvas, transparent ones included.- Parameters:
source- the canvas to copy- Since:
- 0.1.0
-
text
Writes text in one color, with the standard font.- Parameters:
x- the column where lines starty- the row of the top of the first linetext- the text;\nstarts a new linepixel- the color of the text- Returns:
- the width of the widest line, in pixels
- Since:
- 0.1.0
-
text
Writes text.Each part of the text takes the map color closest to its color; parts without a color take
pixel. Bold parts are drawn one pixel wider. Other decorations are ignored. Translatable parts show their fallback, or their key.- Parameters:
x- the column where lines starty- the row of the top of the first linetext- the text;\nstarts a new linefont- the fontpixel- the color of uncolored partsshadow- whether to draw a darker copy one pixel down and right first, like chat does- Returns:
- the width of the widest line, in pixels
- Since:
- 0.1.0
-