Skip to content

Rect.Builder ​

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

Since1.8.4

Builder for a rectangle on an overlay. Coordinates can be supplied as two corners or as a first corner and a size. Defaults are zero coordinates, opaque white,
zero rotation, and rotation about the center; unlike directly constructed rectangles, builders rotate about the center by default.

Nested type declared in Rect.

Constructors ​

new Rect.Builder ​

new Rect.Builder(IDraw2D<?> draw2D)#
Creates a rectangle builder associated with the given overlay.

Parameters:

  • draw2D: the overlay the rectangles will be added to

Methods ​

alpha ​

alpha(int alpha): Rect.BuilderSince1.8.4#
Sets the alpha value independently of the stored color. The value is not clamped; when built, its shifted bits may also affect the color channels.

Parameters:

  • alpha: the alpha value of the color
Returns: self for chaining.

color ​

color(int color): Rect.BuilderSince1.8.4#
Sets a packed color and stores its fixed-up alpha separately; a later alpha call replaces that alpha.

Parameters:

  • color: the color of the rectangle
Returns: self for chaining.
color(int r, int g, int b): Rect.BuilderSince1.8.4#
Packs the components into the low 24 bits; the separately stored alpha is unchanged. Component values are packed without range validation.

Parameters:

  • r: the red component of the color
  • g: the green component of the color
  • b: the blue component of the color
Returns: self for chaining.
color(int r, int g, int b, int a): Rect.BuilderSince1.8.4#
Packs the RGB components into the low 24 bits and stores a separately; component values are packed without range validation.

Parameters:

  • r: the red component of the color
  • g: the green component of the color
  • b: the blue component of the color
  • a: the alpha value of the color
Returns: self for chaining.
color(int color, int alpha): Rect.BuilderSince1.8.4#
Stores the color and alpha separately, without applying the packed-color overload's alpha fix-up.

Parameters:

  • color: the color of the rectangle
  • alpha: the alpha value of the color
Returns: self for chaining.

createElement ​

createElement(): Rect#
Creates a new rectangle from the builder's current values and assigns the builder's overlay as its parent. The builder's alpha is combined with its stored RGB value when the rectangle is constructed.
Returns: the new rectangle.

getAlpha ​

getAlpha(): intSince1.8.4#
Returns the separately stored alpha value, initially 255.
Returns: the alpha value of the color.

getColor ​

getColor(): intSince1.8.4#
Returns the stored color value. Component-based color overloads store only the low 24 RGB bits; packed-color overloads retain the supplied value.
Returns: the color of the rectangle.

getHeight ​

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

getParentHeight ​

getParentHeight(): int#
Returns the height of the builder's overlay, used by parent-relative alignment.
Returns: the height of the parent

getParentWidth ​

getParentWidth(): int#
Returns the width of the builder's overlay, used by parent-relative alignment.
Returns: the width of the parent

getRotation ​

getRotation(): floatSince1.8.4#
Returns the stored rotation in degrees, without normalization.
Returns: the rotation (clockwise) of the rectangle in degrees.

getScaledHeight ​

getScaledHeight(): int#
Returns the builder's height; rectangles have no additional scale.
Returns: the scaled height

getScaledLeft ​

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

getScaledTop ​

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

getScaledWidth ​

getScaledWidth(): int#
Returns the builder's width; rectangles have no additional scale.
Returns: the scaled width

getWidth ​

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

getX1 ​

getX1(): intSince1.8.4#
Returns the first x coordinate; it starts at zero.
Returns: the first x position of the rectangle.

getX2 ​

getX2(): intSince1.8.4#
Returns the second x coordinate; size setters calculate it from the first x coordinate.
Returns: the second x position of the rectangle.

getY1 ​

getY1(): intSince1.8.4#
Returns the first y coordinate; it starts at zero.
Returns: the first y position of the rectangle.

getY2 ​

getY2(): intSince1.8.4#
Returns the second y coordinate; size setters calculate it from the first y coordinate.
Returns: the second y position of the rectangle.

getZIndex ​

getZIndex(): intSince1.8.4#
Returns the overlay ordering index to be used when building the rectangle.
Returns: the z-index of the rectangle.

height ​

height(int height): Rect.BuilderSince1.8.4#
Sets the second y coordinate to y1 + height; the value is measured from the first corner, regardless of the existing second corner.

Parameters:

  • height: the height of the rectangle
Returns: self for chaining.

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether the built rectangle rotates around its center.
Returns: true if this rectangle should be rotated around its center, false otherwise.

moveTo ​

moveTo(int x, int y): Rect.Builder#
Moves the builder 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.

pos ​

pos(int x1, int y1, int x2, int y2): Rect.BuilderSince1.8.4#
Sets both rectangle corners.

Parameters:

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

pos1 ​

pos1(int x1, int y1): Rect.BuilderSince1.8.4#
Sets the first corner coordinates.

Parameters:

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

pos2 ​

pos2(int x2, int y2): Rect.BuilderSince1.8.4#
Sets the second corner coordinates.

Parameters:

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

rotateCenter ​

rotateCenter(boolean rotateCenter): Rect.BuilderSince1.8.4#
Selects whether rotation is around the rectangle's center; builders default to true.

Parameters:

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

rotation ​

rotation(double rotation): Rect.BuilderSince1.8.4#
Sets the rotation in degrees; the builder stores the supplied value as a float without normalizing it.

Parameters:

  • rotation: the rotation (clockwise) of the rectangle in degrees
Returns: self for chaining.

size ​

size(int width, int height): Rect.BuilderSince1.8.4#
Sets the rectangle's width and height, measured from its first corner.

Parameters:

  • width: the width of the rectangle
  • height: the height of the rectangle
Returns: self for chaining.

width ​

width(int width): Rect.BuilderSince1.8.4#
Sets the second x coordinate to x1 + width; the value is measured from the first corner, regardless of the existing second corner.

Parameters:

  • width: the width of the rectangle
Returns: self for chaining.

x1 ​

x1(int x1): Rect.BuilderSince1.8.4#
Sets the first x coordinate of the rectangle.

Parameters:

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

x2 ​

x2(int x2): Rect.BuilderSince1.8.4#
Sets the second x coordinate of the rectangle.

Parameters:

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

y1 ​

y1(int y1): Rect.BuilderSince1.8.4#
Sets the first y coordinate of the rectangle.

Parameters:

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

y2 ​

y2(int y2): Rect.BuilderSince1.8.4#
Sets the second y coordinate of the rectangle.

Parameters:

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

zIndex ​

zIndex(int zIndex): Rect.BuilderSince1.8.4#
Sets the overlay ordering index; lower values are drawn first. Builders default to zero.

Parameters:

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