Rect
com.jsmacrosce.jsmacros.client.api.classes.render.components.Rect
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 rectangley1: the first y position of this rectanglex2: the second x position of this rectangley2: the second y position of this rectanglecolor: the colour, with the alpha in the top byterotation: the rotation in degreeszIndex: 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 rectangley1: the first y position of this rectanglex2: the second x position of this rectangley2: the second y position of this rectanglecolor: the colour, whose top byte is replaced by the alphaalpha: the value shifted into the top byterotation: the rotation in degreeszIndex: 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
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
Returns the alpha byte of this rectangle's packed color, from 0 (transparent) to 255 (opaque).
Returns: the alpha value of this rectangle.
getColor
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
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
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
returns the absolute distance between the two x positions.
Returns: the width of this rectangle.
getX1
Returns the x coordinate of the first corner; it is not necessarily the left edge.
Returns: the first x position of this rectangle.
getX2
Returns the x coordinate of the second corner; it is not necessarily the right edge.
Returns: the second x position of this rectangle.
getY1
Returns the y coordinate of the first corner; it is not necessarily the top edge.
Returns: the first y position of this rectangle.
getY2
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
Returns whether rotation is about the rectangle's center.
Returns:
true if this rectangle should be rotated around its center, false otherwise.moveTo
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 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
setAlpha
setColor
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.
setHeight
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
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, ornullfor the window
Returns: self for chaining.
setPos
setPos1
setPos2
setRotateCenter
setRotation
Sets the rotation in degrees, normalized by Mth.wrapDegrees(float).
Parameters:
rotation: the angle in degrees
Returns: self for chaining.
setSize
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 pixelsheight: the signed y-coordinate offset in GUI-scaled pixels
Returns: self for chaining
setWidth
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