Skip to content

Draw2DElement ​

com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement

Since1.8.4

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 nest
  • x: the x position
  • y: the y position
  • width: the width supplier
  • height: the height supplier
  • zIndex: the ordering value on the parent overlay
  • scale: the scale to apply
  • rotation: the rotation in degrees

Fields ​

draw2D ​

draw2D: Draw2Dread-only#
The overlay rendered by this element.

height ​

height: IntSupplier#
Supplies the element's height; its default and replacement behavior matches width.

parent ​

parent: IDraw2D<?>#
The parent overlay used for parent-size queries, or null to use the window's GUI-scaled dimensions. Builders set this when creating the element.

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 ​

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 ​

getDraw2D(): Draw2DSince1.8.4#
Returns the overlay nested by this element.
Returns: the nested overlay

getHeight ​

getHeight(): intSince1.8.4#
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 ​

getRotation(): floatSince1.8.4#
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 ​

getScale(): floatSince1.8.4#
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 ​

getWidth(): intSince1.8.4#
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 ​

getX(): intSince1.8.4#
Returns the element's x position, which scaling does not change.
Returns: the x position

getY ​

getY(): intSince1.8.4#
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 ​

isRotatingCenter(): booleanSince1.8.4#
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 position
  • y: the new y position
Returns: self for chaining.

render ​

render(GuiGraphicsExtractor 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 into
  • mouseX: the mouse x, not used by this element
  • mouseY: the mouse y, not used by this element
  • delta: the frame delta, not used by this element

setHeight ​

setHeight(int height): Draw2DElementSince1.8.4#
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, or null for the window
Returns: self for chaining.

setPos ​

setPos(int x, int y): Draw2DElementSince1.8.4#
Sets the element's position without changing its dimensions.

Parameters:

  • x: the x position
  • y: the y position
Returns: self for chaining.

setRotateCenter ​

setRotateCenter(boolean rotateCenter): Draw2DElementSince1.8.4#
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 ​

setRotation(double rotation): Draw2DElementSince1.8.4#
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 ​

setScale(double scale): Draw2DElementSince1.8.4#
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 ​

setSize(int width, int height): Draw2DElementSince1.8.4#
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 width
  • height: the height
Returns: self for chaining.

setWidth ​

setWidth(int width): Draw2DElementSince1.8.4#
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 ​

setX(int x): Draw2DElementSince1.8.4#
Sets the x position without changing the y position or dimensions.

Parameters:

  • x: the x position
Returns: self for chaining.

setY ​

setY(int y): Draw2DElementSince1.8.4#
Sets the y position without changing the x position or dimensions.

Parameters:

  • y: the y position
Returns: self for chaining.

setZIndex ​

setZIndex(int zIndex): Draw2DElementSince1.8.4#
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.