Skip to content

Image.Builder ​

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

Since1.8.4

Builds an image element for an overlay. Destination dimensions and texture-region dimensions are configured independently; texture dimensions default to 256 by 256.
Position and destination dimensions default to zero, tint to opaque white, rotation to zero, and rotation about the center to true. Without an identifier, the built image has no texture to draw.

js
const draw = Hud.createDraw2D();  
draw.imageBuilder("minecraft:item/diamond").pos(10, 10).size(16, 16).buildAndAdd();  
draw.register();

Nested type declared in Image.

Constructors ​

new Image.Builder ​

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

Parameters:

  • draw2D: the overlay the images will be added to

Methods ​

alpha ​

alpha(int alpha): Image.BuilderSince1.8.4#
Sets alpha separately without clamping; when the image is built, it is shifted into the top byte.

Parameters:

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

color ​

color(int color): Image.BuilderSince1.8.4#
Sets the packed tint and derives alpha from its top byte after applying the renderer's zero-alpha rule.

Parameters:

  • color: the color of the image
Returns: self for chaining.
color(int r, int g, int b): Image.BuilderSince1.8.4#
Packs the RGB components into the low 24 bits and leaves the builder's alpha unchanged.

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): Image.BuilderSince1.8.4#
Packs RGB into the low 24 bits and stores a separately as alpha.

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 component of the color
Returns: self for chaining.
color(int color, int alpha): Image.BuilderSince1.8.4#
Stores the tint and alpha separately without adjusting either value.

Parameters:

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

createElement ​

createElement(): Image#
Creates a new image from the builder's current values and binds it to its overlay. Each call creates a distinct image; adding it to the overlay is a separate operation. The separate alpha replaces the tint's top byte.
Returns: the new image.

fromCustomImage ​

fromCustomImage(CustomImage customImage): Image.BuilderSince1.8.4#
Uses the custom image's identifier and dimensions for the texture, full region, and destination size, and resets the position to zero. Other builder settings are unchanged.

Parameters:

  • customImage: the custom image to use
Returns: self for chaining.

getAlpha ​

getAlpha(): intSince1.8.4#
Returns the separately stored alpha, initially opaque; RGB and RGBA component setters leave it unchanged.
Returns: the alpha value of the color.

getColor ​

getColor(): intSince1.8.4#
Returns the stored tint; component overloads store RGB in the low 24 bits, while packed overloads store the supplied color.
Returns: the color of the image.

getHeight ​

getHeight(): intSince1.8.4#
Returns the configured destination height (zero by default), not the texture-region height.
Returns: the height of the image.

getIdentifier ​

getIdentifier(): StringSince1.8.4#
Returns the identifier set on this builder, or null if none was set.
Returns: the identifier of the used image or null if no image is used.

getImageX ​

getImageX(): intSince1.8.4#
Returns the horizontal source offset in pixels (zero by default).
Returns: the x position in the image texture to start drawing from.

getImageY ​

getImageY(): intSince1.8.4#
Returns the vertical source offset in pixels (zero by default).
Returns: the y position in the image texture to start drawing from.

getParentHeight ​

getParentHeight(): int#
the height of the overlay this builder was made from, which is what the parent-relative align methods measure against.
Returns: the height of the parent

getParentWidth ​

getParentWidth(): int#
Returns the width of the overlay this builder was created from, used by parent-relative alignment.
Returns: the width of the parent

getRegionHeight ​

getRegionHeight(): intSince1.8.4#
Returns the configured source-region height (zero by default), used by 3D rendering and distinct from the destination height.
Returns: the height of the region to draw.

getRegionWidth ​

getRegionWidth(): intSince1.8.4#
Returns the configured source-region width (zero by default), used by 3D rendering and distinct from the destination width.
Returns: the width of the region to draw.

getRotation ​

getRotation(): floatSince1.8.4#
Returns the builder's stored rotation in degrees, before the built image normalizes finite values to [-180, 180).
Returns: the rotation (clockwise) of the image in degrees.

getScaledHeight ​

getScaledHeight(): int#
Returns the image height as drawn; images have no additional scale.
Returns: the scaled height

getScaledLeft ​

getScaledLeft(): int#
the x position this builder will build the image at.
Returns: the position of the scaled element's left side

getScaledTop ​

getScaledTop(): int#
the y position this builder will build the image at.
Returns: the position of the scaled element's top side

getScaledWidth ​

getScaledWidth(): int#
Returns the image width as drawn; images have no additional scale.
Returns: the scaled width

getTextureHeight ​

getTextureHeight(): intSince1.8.4#
Returns the texture height used to normalize texture-region coordinates; defaults to 256.
Returns: the height of the used texture.

getTextureWidth ​

getTextureWidth(): intSince1.8.4#
Returns the configured texture width used to normalize source offsets (256 by default).
Returns: the width of the used texture.

getWidth ​

getWidth(): intSince1.8.4#
Returns the configured destination width (zero by default), not the texture-region width.
Returns: the width of the image.

getX ​

getX(): intSince1.8.4#
Returns the configured x position, initially zero. fromCustomImage resets it to zero.
Returns: the x position of the image.

getY ​

getY(): intSince1.8.4#
Returns the configured y position, initially zero. fromCustomImage resets it to zero.
Returns: the y position of the image.

getZIndex ​

getZIndex(): intSince1.8.4#
Returns this builder's overlay ordering value, initially zero.
Returns: the z-index of the image.

height ​

height(int height): Image.BuilderSince1.8.4#
Sets the destination height, independently of the texture region. The default is zero; values, including negative values, are stored without validation.

Parameters:

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

identifier ​

identifier(String identifier): Image.BuilderSince1.8.4#
Sets the identifier of the texture to draw. Other builder settings are unchanged.

Parameters:

  • identifier: the identifier of the image to use
Returns: self for chaining.

imagePos ​

imagePos(int imageX, int imageY): Image.BuilderSince1.8.4#
Sets the source offset on both axes, in pixels from the texture's top-left.

Parameters:

  • imageX: the x position in the image texture to start drawing from
  • imageY: the y position in the image texture to start drawing from
Returns: self for chaining.

imageX ​

imageX(int imageX): Image.BuilderSince1.8.4#
Sets the horizontal source offset in pixels. It is converted to a texture coordinate using the configured texture width (256 by default).

Parameters:

  • imageX: the x position in the image texture to start drawing from
Returns: self for chaining.

imageY ​

imageY(int imageY): Image.BuilderSince1.8.4#
Sets the vertical source offset in pixels. It is converted to a texture coordinate using the configured texture height (256 by default).

Parameters:

  • imageY: the y position in the image texture to start drawing from
Returns: self for chaining.

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether the image built by this builder will rotate about its center; builders default to true.
Returns: true if this image should be rotated around its center, false otherwise.

moveTo ​

moveTo(int x, int y): Image.Builder#
Sets the image position without changing its destination size.

Parameters:

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

pos ​

pos(int x, int y): Image.BuilderSince1.8.4#
Sets the image position without changing its size or texture coordinates.

Parameters:

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

regionHeight ​

regionHeight(int regionHeight): Image.BuilderSince1.8.4#
Sets the source-region height. It affects 3D rendering; 2D overlays derive the sampled extent from destination and texture dimensions instead.

Parameters:

  • regionHeight: the height of the region to draw
Returns: self for chaining.

regions ​

regions(int x, int y, int width, int height): Image.BuilderSince1.8.4#
Sets the source offset and region dimensions. Texture dimensions are unchanged (256 by 256 by default); set them separately for textures of another size.

Parameters:

  • x: the x position in the image texture to start drawing from
  • y: the y position in the image texture to start drawing from
  • width: the width of the region to draw
  • height: the height of the region to draw
Returns: self for chaining.
regions(int x, int y, int width, int height, int textureWidth, int textureHeight): Image.BuilderSince1.8.4#
Sets the source offset, region dimensions, and texture dimensions. Supply the actual texture dimensions so pixel offsets are normalized correctly.

Parameters:

  • x: the x position in the image texture to start drawing from
  • y: the y position in the image texture to start drawing from
  • width: the width of the region to draw
  • height: the height of the region to draw
  • textureWidth: the width of the used texture
  • textureHeight: the height of the used texture
Returns: self for chaining.

regionSize ​

regionSize(int regionWidth, int regionHeight): Image.BuilderSince1.8.4#
Sets the source-region width and height. These dimensions affect 3D rendering; 2D overlays derive the sampled extent from destination and texture dimensions.

Parameters:

  • regionWidth: the width of the region to draw
  • regionHeight: the height of the region to draw
Returns: self for chaining.

regionWidth ​

regionWidth(int regionWidth): Image.BuilderSince1.8.4#
Sets the source-region width. It affects 3D rendering; 2D overlays derive the sampled extent from destination and texture dimensions instead.

Parameters:

  • regionWidth: the width of the region to draw
Returns: self for chaining.

rotateCenter ​

rotateCenter(boolean rotateCenter): Image.BuilderSince1.8.4#
Sets whether the built image rotates about its center or its position. Builders default to rotating about the center; images made directly default to the position.

Parameters:

  • rotateCenter: whether the image should be rotated around its center
Returns: self for chaining.

rotation ​

rotation(double rotation): Image.BuilderSince1.8.4#
Sets the image rotation in degrees; the builder stores the supplied value, while the built image normalizes it to [-180, 180).

Parameters:

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

size ​

size(int width, int height): Image.BuilderSince1.8.4#
Sets the destination width and height, independently of the texture region.

Parameters:

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

textureHeight ​

textureHeight(int textureHeight): Image.BuilderSince1.8.4#
Sets the texture height used to normalize texture-region coordinates; defaults to 256.

Parameters:

  • textureHeight: the height of the used texture
Returns: self for chaining.

textureSize ​

textureSize(int textureWidth, int textureHeight): Image.BuilderSince1.8.4#
Sets the texture dimensions used to normalize texture-region coordinates; both default to 256.

Parameters:

  • textureWidth: the width of the used texture
  • textureHeight: the height of the used texture
Returns: self for chaining.

textureWidth ​

textureWidth(int textureWidth): Image.BuilderSince1.8.4#
Sets the texture width used to normalize the horizontal source offset; the default is 256.

Parameters:

  • textureWidth: the width of the used texture
Returns: self for chaining.

width ​

width(int width): Image.BuilderSince1.8.4#
Sets the destination width, independently of the texture region. The default is zero; values, including negative values, are stored without validation.

Parameters:

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

x ​

x(int x): Image.BuilderSince1.8.4#
Sets the x position without changing the y position or other builder settings.

Parameters:

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

y ​

y(int y): Image.BuilderSince1.8.4#
Sets the y position without changing the x position or other builder settings.

Parameters:

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

zIndex ​

zIndex(int zIndex): Image.BuilderSince1.8.4#
Sets this image's overlay ordering value; lower values are drawn first. A builder defaults to zero.

Parameters:

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