Skip to content

Rect ​

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

Since1.0.5

A filled rectangle defined by two corner positions. Corners may be given in either order; width and height are their absolute coordinate differences. Colors use packed ARGB, and a zero-alpha color with nonzero RGB is treated as opaque.

js
const draw = Hud.createDraw2D();  
// Corners may be specified in either order.  
const rect = draw.addRect(110, 60, 10, 10, Color.argb(0x80, 0, 0, 0));  
draw.register();  
Chat.log(`${rect.getWidth()} by ${rect.getHeight()}, from ${rect.getX1()}, ${rect.getY1()}`);

Available in scripts as RenderElements.Rect.

Nested types ​

Constructors ​

new Rect ​

new Rect(int x1, int y1, int x2, int y2, int color, float rotation, int zIndex)#
Constructs a rectangle from two corners, applying setColor(int)'s alpha fix-up and normalizing the rotation with Mth.wrapDegrees(float).

Parameters:

  • x1: the first x position of this rectangle
  • y1: the first y position of this rectangle
  • x2: the second x position of this rectangle
  • y2: the second y position of this rectangle
  • color: the colour, with the alpha in the top byte
  • rotation: the rotation in degrees
  • zIndex: the z-index against the other elements on the overlay
new Rect(int x1, int y1, int x2, int y2, int color, int alpha, float rotation, int zIndex)#
Constructs a rectangle from two corners, replacing the color's top byte with the separately supplied alpha and normalizing rotation with Mth.wrapDegrees(float).

Parameters:

  • x1: the first x position of this rectangle
  • y1: the first y position of this rectangle
  • x2: the second x position of this rectangle
  • y2: the second y position of this rectangle
  • color: the colour, whose top byte is replaced by the alpha
  • alpha: the value shifted into the top byte
  • rotation: the rotation in degrees
  • zIndex: the z-index against the other elements on the overlay

Fields ​

color ​

color: int#
The packed ARGB color. A zero-alpha value with nonzero RGB is made opaque by the one-argument color setter; pure black remains transparent.

parent ​

parent: IDraw2D<?>#
The overlay this rectangle belongs to, or null to use the window dimensions for parent-relative alignment.

rotateCenter ​

rotateCenter: boolean#
Whether rotation is about the rectangle's center rather than its first corner. Directly constructed rectangles default to false; builders default to true.

rotation ​

rotation: float#
Rotation in degrees, normalized by the constructor and setRotation(double).

x1 ​

x1: int#
The x coordinate of the first corner; it is not necessarily the left edge.

x2 ​

x2: int#
The x coordinate of the second corner.

y1 ​

y1: int#
The y coordinate of the first corner; it is not necessarily the top edge.

y2 ​

y2: int#
The y coordinate of the second corner.

zIndex ​

zIndex: int#
Draw-order value relative to other elements on the overlay; lower values draw first.

Methods ​

getAlpha ​

getAlpha(): intSince1.8.4#
Returns the alpha byte of this rectangle's packed color, from 0 (transparent) to 255 (opaque).
Returns: the alpha value of this rectangle.

getColor ​

getColor(): intSince1.8.4#
Returns this rectangle's packed ARGB color. Colors set without an alpha byte are made opaque by the one-argument color setter, except pure black.
Returns: the color value of this rectangle.

getHeight ​

getHeight(): intSince1.8.4#
returns the absolute distance between the two y positions.
Returns: the height of this rectangle.

getParentHeight ​

getParentHeight(): int#
Returns the assigned overlay's height, or the window's GUI-scaled height when no overlay is assigned.
Returns: the height of the parent

getParentWidth ​

getParentWidth(): int#
Returns the assigned overlay's width, or the window's GUI-scaled width when no overlay is assigned.
Returns: the width of the parent

getRotation ​

getRotation(): floatSince1.8.4#
Returns this rectangle's rotation in degrees, normalized by its constructor and setRotation(double).
Returns: the rotation of this rectangle.

getScaledHeight ​

getScaledHeight(): int#
Returns this rectangle's height; rectangles have no additional scale.
Returns: the scaled height of this element

getScaledLeft ​

getScaledLeft(): int#
Returns the smaller of the two x coordinates, independent of corner order.
Returns: the position of the scaled element's left side

getScaledTop ​

getScaledTop(): int#
Returns the smaller of the two y coordinates, independent of corner order.
Returns: the position of the scaled element's top side

getScaledWidth ​

getScaledWidth(): int#
Returns this rectangle's width; rectangles have no additional scale.
Returns: the scaled width of this element

getWidth ​

getWidth(): intSince1.8.4#
returns the absolute distance between the two x positions.
Returns: the width of this rectangle.

getX1 ​

getX1(): intSince1.8.4#
Returns the x coordinate of the first corner; it is not necessarily the left edge.
Returns: the first x position of this rectangle.

getX2 ​

getX2(): intSince1.8.4#
Returns the x coordinate of the second corner; it is not necessarily the right edge.
Returns: the second x position of this rectangle.

getY1 ​

getY1(): intSince1.8.4#
Returns the y coordinate of the first corner; it is not necessarily the top edge.
Returns: the first y position of this rectangle.

getY2 ​

getY2(): intSince1.8.4#
the second y position of this rectangle, its other corner rather than an edge.
Returns: the second y position of the rectangle.

getZIndex ​

getZIndex(): int#
Returns this rectangle's overlay draw-order value; lower values draw first.
Returns: the z-index of this element

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether rotation is about the rectangle's center.
Returns: true if this rectangle should be rotated around its center, false otherwise.

moveTo ​

moveTo(int x, int y): Rect#
Moves the rectangle so (x, y) is its first corner, preserving its current width and height.

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#
Draws this rectangle through the overlay's graphics context. The 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

setAlpha ​

setAlpha(int alpha): RectSince1.1.8#
Replaces the alpha byte of this rectangle's packed color; values outside 0–255 are not clamped.

Parameters:

  • alpha: the alpha to put in the top byte
Returns: self for chaining.

setColor ​

setColor(int color): RectSince1.0.5#
Sets the packed ARGB color, making zero-alpha colors with nonzero RGB opaque; zero-alpha black stays transparent, and explicit alpha is preserved.

Parameters:

  • color: the packed colour, with the alpha in the top byte
Returns: self for chaining.
setColor(int color, int alpha): RectSince1.1.8#
sets the packed color and replaces its top byte with alpha; the value is shifted directly and is not clamped to 0–255.

Parameters:

  • color: the colour, whose top byte is replaced
  • alpha: the alpha, in the top byte
Returns: self for chaining.

setHeight ​

setHeight(int height): RectSince1.8.4#
Resizes along the y axis, anchoring the currently smaller y coordinate. If y1 <= y2, sets y2 = y1 + height; otherwise sets y1 = y2 + height. Negative heights are accepted and can reverse the corner order; getHeight() reports the absolute coordinate difference, subject to integer overflow.

Parameters:

  • height: the signed y-coordinate offset in GUI-scaled pixels
Returns: self for chaining

setParent ​

setParent(IDraw2D<?> parent): Rect#
Sets the overlay used for parent-relative dimensions and alignment; null makes those dimensions fall back to the window. Builders assign their overlay when creating the rectangle.

Parameters:

  • parent: the overlay this element is on, or null for the window
Returns: self for chaining.

setPos ​

setPos(int x1, int y1, int x2, int y2): RectSince1.1.8#
sets both corners of this rectangle.

Parameters:

  • x1: the first x position of this rectangle
  • y1: the first y position of this rectangle
  • x2: the second x position of this rectangle
  • y2: the second y position of this rectangle
Returns: self for chaining.

setPos1 ​

setPos1(int x1, int y1): RectSince1.8.4#
Sets both coordinates of the first corner, leaving the second corner unchanged.

Parameters:

  • x1: the first x position of this rectangle
  • y1: the first y position of this rectangle
Returns: self for chaining.

setPos2 ​

setPos2(int x2, int y2): RectSince1.8.4#
sets the second corner, leaving the first corner unchanged.

Parameters:

  • x2: the second x position of this rectangle
  • y2: the second y position of this rectangle
Returns: self for chaining.

setRotateCenter ​

setRotateCenter(boolean rotateCenter): RectSince1.8.4#
Sets whether rotation is about the rectangle's center rather than its first corner.

Parameters:

  • rotateCenter: whether this rectangle should be rotated around its center
Returns: self for chaining.

setRotation ​

setRotation(double rotation): RectSince1.2.6#
Sets the rotation in degrees, normalized by Mth.wrapDegrees(float).

Parameters:

  • rotation: the angle in degrees
Returns: self for chaining.

setSize ​

setSize(int width, int height): RectSince1.8.4#
Resizes both axes by applying setWidth(int) then setHeight(int). Each axis anchors its currently smaller coordinate; negative offsets are accepted and can reverse the corresponding corner order.

Parameters:

  • width: the signed x-coordinate offset in GUI-scaled pixels
  • height: the signed y-coordinate offset in GUI-scaled pixels
Returns: self for chaining

setWidth ​

setWidth(int width): RectSince1.8.4#
Resizes along the x axis, anchoring the currently smaller x coordinate. If x1 <= x2, sets x2 = x1 + width; otherwise sets x1 = x2 + width. Negative widths are accepted and can reverse the corner order; getWidth() reports the absolute coordinate difference, subject to integer overflow.

Parameters:

  • width: the signed x-coordinate offset in GUI-scaled pixels
Returns: self for chaining

setX1 ​

setX1(int x1): RectSince1.8.4#
Sets the first corner's x coordinate without changing any other coordinate.

Parameters:

  • x1: the first x position of this rectangle
Returns: self for chaining.

setX2 ​

setX2(int x2): RectSince1.8.4#
Sets the second corner's x coordinate without changing any other coordinate.

Parameters:

  • x2: the second x position of this rectangle
Returns: self for chaining.

setY1 ​

setY1(int y1): RectSince1.8.4#
Sets the first corner's y coordinate without changing any other coordinate.

Parameters:

  • y1: the first y position of this rectangle
Returns: self for chaining.

setY2 ​

setY2(int y2): RectSince1.8.4#
Sets the second corner's y coordinate without changing any other coordinate.

Parameters:

  • y2: the second y position of this rectangle
Returns: self for chaining.

setZIndex ​

setZIndex(int zIndex): RectSince1.8.4#
Sets this rectangle's overlay draw-order value; lower values draw first.

Parameters:

  • zIndex: the new z-index for this rectangle
Returns: self for chaining.