Draw2DElement
com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement
Draws a Draw2D as a positioned, scaled, and rotated element of another overlay.
Its nested overlay is transformed as one element; content outside its width or height is not clipped. Dimensions default to suppliers that follow the builder's parent.
js
const outer = Hud.createDraw2D();
const panel = Hud.createDraw2D();
panel.addText("inside the panel", 5, 5, Color.rgb(0xFF, 0xFF, 0xFF), true);
// lands at 25, 25 on the outer overlay, and is not clipped to 100 by 50
outer.draw2DBuilder(panel).pos(20, 20).size(100, 50).buildAndAdd();
outer.register();Available in scripts as RenderElements.Draw2D.
Nested types
Constructors
new Draw2DElement
new Draw2DElement(Draw2D draw2D, int x, int y, IntSupplier width, IntSupplier height, int zIndex, float scale, float rotation)#Creates an element nesting the specified overlay. Rotation is about the positioned corner by default; use setRotateCenter(boolean) to rotate about its center.
Parameters:
draw2D: the overlay to nestx: the x positiony: the y positionwidth: the width supplierheight: the height supplierzIndex: the ordering value on the parent overlayscale: the scale to applyrotation: the rotation in degrees
Fields
draw2D
height
height: IntSupplier#Supplies the element's height; its default and replacement behavior matches width.
parent
rotateCenter
rotateCenter: boolean#Whether rotation is about the element's center rather than its positioned corner. Direct construction defaults to
false; builders default to true.rotation
rotation: float#The rotation in degrees. Constructors and setRotation(double) normalize angles to
[-180, 180). Assigning directly to this field bypasses normalization.scale
scale: float#The scale applied to the element and nested content. Builders default it to
1.width
width: IntSupplier#Supplies the element's width. The builder's default supplier follows its parent; setWidth(int) replaces the supplier with a fixed value.
x
x: int#The element's x position; scaling is applied after translation.
y
y: int#The element's y position; scaling is applied after translation.
zIndex
zIndex: int#This element's ordering value on its overlay; lower values are drawn first.
Methods
getDraw2D
getHeight
Returns the current height from this element's height supplier.
Returns: the height of this draw2D.
getParentHeight
getParentHeight(): int#Returns the parent overlay's height, or the window's GUI-scaled height when no parent is set.
Returns: the height of the parent
getParentWidth
getParentWidth(): int#Returns the parent overlay's width, or the window's GUI-scaled width when no parent is set.
Returns: the width of the parent
getRotation
Returns the rotation in degrees. Constructors and setters normalize the value; direct writes to the public field do not.
Returns: the rotation of this draw2D.
getScale
Returns the scale used to calculate the element's scaled dimensions.
Returns: the scale of this draw2D.
getScaledHeight
getScaledHeight(): int#Returns the element height multiplied by its scale and cast to an integer (truncated toward zero).
Returns: the scaled height of this element
getScaledLeft
getScaledLeft(): int#Returns this element's x position; scaling does not change the left edge.
Returns: the position of the scaled element's left side
getScaledTop
getScaledTop(): int#Returns this element's y position; scaling does not change the top edge.
Returns: the position of the scaled element's top side
getScaledWidth
getScaledWidth(): int#Returns the element width multiplied by its scale and cast to an integer (truncated toward zero). Alignment calculations use this scaled width.
Returns: the scaled width of this element
getWidth
Returns the current width from its supplier, before scaling. A supplier tied to another overlay reflects that overlay's current width.
Returns: the current width
getX
Returns the element's x position, which scaling does not change.
Returns: the x position
getY
Returns the element's y position, which scaling does not change.
Returns: the y position
getZIndex
getZIndex(): int#Returns this element's ordering value on its overlay. Lower values draw first; newly constructed elements default to zero.
Returns: the z-index of this element
isRotatingCenter
Returns whether rotation is about the element's center. Builders enable this by default; directly constructed elements do not.
Returns:
true if this draw2D should be rotated around its center, false otherwise.moveTo
moveTo(int x, int y): Draw2DElement#Sets this element's position without changing its size.
Parameters:
x: the new x positiony: the new y position
Returns: self for chaining.
render
render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#Renders the nested overlay under this element's position, scale, and rotation transform. Rotation is about the element's center when
rotateCenter is enabled, and otherwise about its positioned corner. Mouse coordinates and frame delta are unused.Parameters:
drawContext: the graphics context to draw intomouseX: the mouse x, not used by this elementmouseY: the mouse y, not used by this elementdelta: the frame delta, not used by this element
setHeight
Sets a fixed height, replacing any supplier that tracks another overlay. Zero is allowed; negative values throw IllegalArgumentException.
Parameters:
height: the height
Returns: self for chaining.
setParent
setParent(IDraw2D<?> parent): Draw2DElement#Sets the overlay used as this element's parent for parent-size queries. Builders set it when constructing the element; passing
null makes those queries use the window's GUI-scaled dimensions.Parameters:
parent: the overlay this element is on, ornullfor the window
Returns: self for chaining.
setPos
Sets the element's position without changing its dimensions.
Parameters:
x: the x positiony: the y position
Returns: self for chaining.
setRotateCenter
Sets whether rotation is about the element's center rather than its positioned corner. Builders enable this by default; directly constructed elements do not.
Parameters:
rotateCenter: whether this draw2D should be rotated around its center
Returns: self for chaining.
setRotation
Sets the rotation in degrees; the value is narrowed to
float and normalized to [-180, 180).Parameters:
rotation: the rotation
Returns: self for chaining.
setScale
Sets the scale applied to this element and its nested overlay. The value is narrowed to
float; zero and negative values throw IllegalArgumentException.Parameters:
scale: the scale
Returns: self for chaining.
setSize
Sets fixed width and height. Zero is allowed; negative dimensions throw IllegalArgumentException. Width is set before height, so a negative height leaves the width changed.
Parameters:
width: the widthheight: the height
Returns: self for chaining.
setWidth
Sets a fixed width, replacing any supplier that tracks another overlay. Zero is allowed; negative values throw IllegalArgumentException.
Parameters:
width: the width
Returns: self for chaining.
setX
Sets the x position without changing the y position or dimensions.
Parameters:
x: the x position
Returns: self for chaining.
setY
Sets the y position without changing the x position or dimensions.
Parameters:
y: the y position
Returns: self for chaining.
setZIndex
Sets this element's ordering value relative to other elements on its overlay; lower values are drawn first. A nested overlay is ordered as a single element.
Parameters:
zIndex: the z-index of this draw2D
Returns: self for chaining.