Draw2D
com.jsmacrosce.jsmacros.client.api.classes.render.Draw2D
A 2D overlay that stores and draws screen elements.
Element coordinates use GUI-scaled pixels from the window's top-left corner.
The overlay renders only while registered with register(); call unregister() to stop it.
Registering also runs initialization. When an init function is installed, the overlay is emptied before that function rebuilds it; without one, hand-built elements are preserved.
Coordinates are absolute. getZIndex() orders whole overlays (lower first),
while each element's z-index orders elements within its overlay.
Elements are stored in insertion order in a set; adding an equal element does not create a duplicate.
Overlays can be nested with addDraw2D(Draw2D, int, int, int, int); cyclic nesting is rejected. A Surface displays overlays in the world.
// an overlay that builds itself, registered so it renders
const draw = Hud.createDraw2D();
draw.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addRect(10, 10, 110, 60, Color.argb(0x80, 0, 0, 0));
self.addText("a panel", 16, 20, Color.rgb(0xFF, 0xFF, 0xFF), true);
}));
draw.register();
// taken off again, which keeps the elements for next time
draw.unregister();Constructors
new Draw2D
new Draw2D()#Fields
heightSupplier
visible
true.widthSupplier
zIndex
0; use setZIndex(int) to set it.Methods
addDraw2D
null if nesting would create a cycle, including nesting this overlay inside itself.Parameters:
draw2D: the overlay to draw inside this onex: the x position of the nested overlay within this oney: the y position of the nested overlay within this onewidth: how wide the nested overlay thinks it isheight: how tall the nested overlay thinks it is
null if the nesting would make a cyclenull if nesting would create a cycle.Parameters:
draw2D: the overlay to draw inside this onex: the x position of the nested overlay within this oney: the y position of the nested overlay within this onewidth: how wide the nested overlay thinks it isheight: how tall the nested overlay thinks it iszIndex: the z-index of the nested overlay against this one's other elements
null if the nesting would make a cycleaddImage
addImage(int x, int y, int width, int height, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight): ImageSince1.2.3#width and height are the on-screen dimensions.Parameters:
x: screen x, top left cornery: screen y, top left cornerwidth: width on screenheight: height on screenid: image id, in the formminecraft:texturespath'd as found in texture packs, ieassets/minecraft/textures/gui/recipe_book.pngbecomesminecraft:textures/gui/recipe_book.pngimageX: the left-most coordinate of the texture regionimageY: the top-most coordinate of the texture regionregionWidth: the width the texture regionregionHeight: the height the texture regiontextureWidth: the width of the entire texturetextureHeight: the height of the entire texture
See:
addImage(int x, int y, int width, int height, int zIndex, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight): ImageSince1.2.3#zIndex against other overlay elements.Parameters:
x: screen x, top left cornery: screen y, top left cornerwidth: width on screenheight: height on screenzIndex: z-indexid: image id, in the formminecraft:texturespath'd as found in texture packs, ieassets/minecraft/textures/gui/recipe_book.pngbecomesminecraft:textures/gui/recipe_book.pngimageX: the left-most coordinate of the texture regionimageY: the top-most coordinate of the texture regionregionWidth: the width the texture regionregionHeight: the height the texture regiontextureWidth: the width of the entire texturetextureHeight: the height of the entire texture
See:
addImage(int x, int y, int width, int height, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight, double rotation): ImageSince1.2.6#rotation degrees. The position remains the unrotated image's top-left corner.Parameters:
x: screen x, top left cornery: screen y, top left cornerwidth: width on screenheight: height on screenid: image id, in the formminecraft:texturespath'd as found in texture packs, ieassets/minecraft/textures/gui/recipe_book.pngbecomesminecraft:textures/gui/recipe_book.pngimageX: the left-most coordinate of the texture regionimageY: the top-most coordinate of the texture regionregionWidth: the width the texture regionregionHeight: the height the texture regiontextureWidth: the width of the entire texturetextureHeight: the height of the entire texturerotation: the rotation (clockwise) of the texture (as degrees)
See:
addImage(int x, int y, int width, int height, int zIndex, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight, double rotation): ImageSince1.2.6#Parameters:
x: screen x, top left cornery: screen y, top left cornerwidth: width on screenheight: height on screenzIndex: z-indexid: image id, in the formminecraft:texturespath'd as found in texture packs, ieassets/minecraft/textures/gui/recipe_book.pngbecomesminecraft:textures/gui/recipe_book.pngimageX: the left-most coordinate of the texture regionimageY: the top-most coordinate of the texture regionregionWidth: the width the texture regionregionHeight: the height the texture regiontextureWidth: the width of the entire texturetextureHeight: the height of the entire texturerotation: the rotation (clockwise) of the texture (as degrees)
addImage(int x, int y, int width, int height, int zIndex, int color, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight, double rotation): ImageSince1.6.5#Parameters:
x: screen x, top left cornery: screen y, top left cornerwidth: width on screenheight: height on screenzIndex: z-indexcolor: the tint laid over the imageid: image id, in the formminecraft:texturespath'd as found in texture packs, ieassets/minecraft/textures/gui/recipe_book.pngbecomesminecraft:textures/gui/recipe_book.pngimageX: the left-most coordinate of the texture regionimageY: the top-most coordinate of the texture regionregionWidth: the width the texture regionregionHeight: the height the texture regiontextureWidth: the width of the entire texturetextureHeight: the height of the entire texturerotation: the rotation (clockwise) of the texture (as degrees)
See:
addImage(int x, int y, int width, int height, int zIndex, int alpha, int color, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight, double rotation): ImageSince1.6.5#Parameters:
x: screen x, top left cornery: screen y, top left cornerwidth: width on screenheight: height on screenzIndex: z-indexalpha: the transparency of the image, from 0 to 255color: the tint laid over the imageid: image id, in the formminecraft:texturespath'd as found in texture packs, ieassets/minecraft/textures/gui/recipe_book.pngbecomesminecraft:textures/gui/recipe_book.pngimageX: the left-most coordinate of the texture regionimageY: the top-most coordinate of the texture regionregionWidth: the width the texture regionregionHeight: the height the texture regiontextureWidth: the width of the entire texturetextureHeight: the height of the entire texturerotation: the rotation (clockwise) of the texture (as degrees)
See:
addItem
minecraft: namespace.Parameters:
x: left most cornery: top most cornerid: item id
See:
Parameters:
x: left most cornery: top most cornerzIndex: z-indexid: item id
Parameters:
x: left most cornery: top most cornerid: item idoverlay: whether to draw the game's item decorations, including durability and count
See:
Parameters:
x: left most cornery: top most cornerzIndex: z-indexid: item idoverlay: whether to draw the game's item decorations, including durability and count
Parameters:
x: left most cornery: top most cornerid: item idoverlay: whether to draw the game's item decorationsscale: size multiplierrotation: rotation in degrees
See:
addItem(int x, int y, int zIndex, String id, boolean overlay, double scale, double rotation): ItemSince1.2.0#Parameters:
x: left most cornery: top most cornerzIndex: z-indexid: item idoverlay: whether to draw the game's item decorationsscale: size multiplierrotation: rotation in degrees
Parameters:
x: screen-pixel x-coordinate of the icon's top-left cornery: screen-pixel y-coordinate of the icon's top-left cornerItem: item stack to draw, such as one from an inventory
See:
Parameters:
x: left most cornery: top most cornerzIndex: z-indexitem: from inventory as helper
Parameters:
x: left most cornery: top most cornerItem: item stack to draw, such as one from an inventoryoverlay: whether to draw the game's item decorations, including durability and count
See:
Parameters:
x: left most cornery: top most cornerzIndex: z-indexitem: from inventory as helperoverlay: whether to draw the game's item decorations, including durability and count
addItem(int x, int y, ItemStackHelper item, boolean overlay, double scale, double rotation): ItemSince1.2.6#Parameters:
x: left most cornery: top most corneritem: from inventory as helperoverlay: whether to draw the game's item decorationsscale: size multiplierrotation: rotation in degrees
See:
addItem(int x, int y, int zIndex, ItemStackHelper item, boolean overlay, double scale, double rotation): ItemSince1.2.6#Parameters:
x: left coordinatey: top coordinatezIndex: element draw order; lower values draw firstitem: item stack to drawoverlay: whether to draw the item overlayscale: icon scalerotation: rotation in degrees
addLine
Parameters:
x1: the x position of the starty1: the y position of the startx2: the x position of the endy2: the y position of the endcolor: the line color, including any alpha value
See:
Parameters:
x1: the x position of the starty1: the y position of the startx2: the x position of the endy2: the y position of the endcolor: the line color, including any alpha valuezIndex: draw order relative to other overlay elements
See:
Parameters:
x1: the x position of the starty1: the y position of the startx2: the x position of the endy2: the y position of the endcolor: the line color, including any alpha valuewidth: the line width in screen pixels
See:
Parameters:
x1: the x position of the starty1: the y position of the startx2: the x position of the endy2: the y position of the endcolor: the line color, including any alpha valuezIndex: draw order relative to other overlay elementswidth: the line width in screen pixels
See:
Parameters:
x1: the x position of the starty1: the y position of the startx2: the x position of the endy2: the y position of the endcolor: the line color, including any alpha valuewidth: the line width in screen pixelsrotation: rotation in degrees
See:
addLine(int x1, int y1, int x2, int y2, int color, int zIndex, double width, double rotation): LineSince1.8.4#Parameters:
x1: the x position of the starty1: the y position of the startx2: the x position of the endy2: the y position of the endcolor: the line color, including any alpha valuezIndex: draw order relative to other overlay elementswidth: the line width in screen pixelsrotation: rotation in degrees
See:
addRect
Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornercolor: as hex, with alpha channel
See:
Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornercolor: as hexalpha: alpha channel 0-255
See:
rotation and uses rotation and z-index zero; use the full overload to set both.Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornercolor: as hexalpha: alpha channel 0-255rotation: ignored; this overload always uses zero rotation
See:
addRect(int x1, int y1, int x2, int y2, int color, int alpha, double rotation, int zIndex): RectSince1.2.6#Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornercolor: rectangle coloralpha: transparency from 0 (transparent) to 255 (opaque)rotation: rotation in degreeszIndex: draw order relative to other overlay elements
See:
addText
0, scale 1, and no rotation.Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorshadow: include shadow layer
See:
zIndex, this overload currently uses z-index 0. Use the full overload to specify the element z-index.Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorzIndex: currently ignored; the added text uses z-index0shadow: include shadow layer
addText(String text, int x, int y, int color, boolean shadow, double scale, double rotation): TextSince1.2.6#0.Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorshadow: include shadow layerscale: text scale (as double)rotation: text rotation (as degrees)
See:
addText(String text, int x, int y, int color, int zIndex, boolean shadow, double scale, double rotation): TextSince1.2.6#Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorzIndex: z-indexshadow: include shadow layerscale: text scale (as double)rotation: text rotation (as degrees)
See:
color tints its existing styling. This overload uses z-index 0, scale 1, and no rotation.Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorshadow: include shadow layer
See:
color tints its existing styling. This overload uses scale 1 and no rotation.Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorzIndex: z-indexshadow: include shadow layer
See:
addText(TextHelper text, int x, int y, int color, boolean shadow, double scale, double rotation): TextSince1.0.5#Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorshadow: include shadow layerscale: text scale (as double)rotation: text rotation (as degrees)
See:
addText(TextHelper text, int x, int y, int color, int zIndex, boolean shadow, double scale, double rotation): TextSince1.0.5#Parameters:
text: the text to displayx: screen xy: screen ycolor: text colorzIndex: z-indexshadow: include shadow layerscale: text scale (as double)rotation: text rotation (as degrees)
See:
clear
getDraw2Ds
getElements
getElementsByZIndex
getHeight
getLines
getWidth
getZIndex
init
isVisible
true if this draw2d is visible, false otherwise.reAddElement
null if they have no underlying overlay, refer to this overlay, or would create a cycle. When this overlay is a Surface, adding a nested overlay initializes it immediately.Parameters:
e: the element to put back
Type Parameters:
T: the type of element to add
null if it is a nested overlay that was refusedregister
removeDraw2D
Parameters:
draw2D: the wrapper to take off
removeElement
Parameters:
e: the element to take off
removeLine
Parameters:
l: the line to remove
See:
setOnFailInit
setOnInit
setVisible
setZIndex
Parameters:
zIndex: this overlay's order relative to other overlays