# Line

`com.jsmacrosce.jsmacros.client.api.classes.render.components.Line`

**Since:** 1.8.4

A line is defined by two endpoints, a stroke thickness, and a rotation. The
 endpoint differences determine its scaled width and height; `width` is the
 stroke thickness. Nonpositive or non-finite thickness is not rendered. Positive
 fractional thickness and length are drawn as stored rather than rounded,  
 although the renderer raises thickness to at least one physical pixel and does
 not antialias the strip's edges. Rotation is about the first endpoint by
 default, or the midpoint when `rotateCenter` is true. Constructors and
 [setRotation(double)](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setRotation-double-) normalize finite angles to `[-180, 180)`.  
 
 ```js
const draw = Hud.createDraw2D();  
const line = draw.addLine(0, 0, 50, 50, Color.rgb(0xFF, 0xFF, 0xFF), 0, 2);  
draw.register();  
Chat.log(`${line.getWidth()} thick, reaching ${line.getScaledWidth()} across`);  
 ```

Available in scripts as `RenderElements.Line`.

## Nested types

- [Builder](Line.Builder.md)

## Constructors

### new Line {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_constructor-int-int-int-int-int-float-float-int-}

```js
new Line(int x1, int y1, int x2, int y2, int color, float rotation, float width, int zIndex)
```

Creates a line between two endpoints.  
 
 Finite rotations are normalized to `[-180, 180)`. The color is processed by
 [setColor(int)](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setColor-int-); a zero-alpha color becomes opaque except for pure black.

**Parameters:**
- `x1`: the x position of the start of the line
- `y1`: the y position of the start of the line
- `x2`: the x position of the end of the line
- `y2`: the y position of the end of the line
- `color`: the color, with the alpha in the top byte
- `rotation`: the rotation in degrees
- `width`: the thickness of the line
- `zIndex`: the z-index against the other elements on the overlay

## Fields

### color {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_color}

```js
color: int
```

The packed ARGB color. Colors with a zero alpha byte are made opaque except for pure black.

### parent {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_parent}

```js
parent: IDraw2D<?>
```

The overlay this line belongs to, or `null` if it is not attached to one.  
 Parent dimensions then fall back to the GUI-scaled window dimensions.

### rotateCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_rotateCenter}

```js
rotateCenter: boolean
```

Whether rotation is about the midpoint rather than the first endpoint. Directly
 constructed lines default to `false`; builder-created lines default to `true`.

### rotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_rotation}

```js
rotation: float
```

The rotation in degrees. Constructors and [setRotation(double)](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setRotation-double-) normalize
 finite angles to `[-180, 180)`; direct field writes do not.

### width {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_width}

```js
width: float
```

The stroke thickness in screen pixels. The value is stored as a float; the builder
 defaults to one, and the 2D renderer draws fractional widths as stored, clamped to
 at least one physical pixel.

### x1 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_x1}

```js
x1: int
```

The x coordinate of the first endpoint. Endpoint order is caller-defined.

### x2 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_x2}

```js
x2: int
```

The x coordinate of the second endpoint.

### y1 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_y1}

```js
y1: int
```

The y coordinate of the first endpoint.

### y2 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_y2}

```js
y2: int
```

The y coordinate of the second endpoint.

### zIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_zIndex}

```js
zIndex: int
```

Draw-order value relative to other elements on the overlay; lower values are drawn first.

## Methods

### getAlpha {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getAlpha-}

```js
getAlpha(): int
```

Returns the top byte of the packed color, from 0 (transparent) to 255 (opaque).

**Returns:** the alpha value of the line's color.

**Since:** 1.8.4

### getColor {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getColor-}

```js
getColor(): int
```

Returns the packed ARGB color currently stored on the line.

**Returns:** the color of the line.

**Since:** 1.8.4

### getParentHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getParentHeight-}

```js
getParentHeight(): int
```

Returns the parent overlay's height, or the GUI-scaled window height if no parent is set.

**Returns:** the height of the parent

### getParentWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getParentWidth-}

```js
getParentWidth(): int
```

Returns the parent overlay's width, or the GUI-scaled window width when no parent is set.

**Returns:** the width of the parent

### getRotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getRotation-}

```js
getRotation(): float
```

Returns the stored rotation in degrees. Constructors and setters normalize finite
 angles; direct writes to the public field do not.

**Returns:** the rotation (clockwise) of the line.

**Since:** 1.8.4

### getScaledHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getScaledHeight-}

```js
getScaledHeight(): int
```

Returns the absolute difference between the line's two y coordinates.

**Returns:** the scaled height

### getScaledLeft {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getScaledLeft-}

```js
getScaledLeft(): int
```

Returns the smaller of the line's two x coordinates.

**Returns:** the position of the scaled element's left side

### getScaledTop {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getScaledTop-}

```js
getScaledTop(): int
```

Returns the smaller of the line's two y coordinates.

**Returns:** the position of the scaled element's top side

### getScaledWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getScaledWidth-}

```js
getScaledWidth(): int
```

Returns the absolute difference between the line's x coordinates.

**Returns:** the scaled width

### getWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getWidth-}

```js
getWidth(): float
```

Returns the line's stroke thickness in screen pixels.

**Returns:** the width of the line.

**Since:** 1.8.4

### getX1 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getX1-}

```js
getX1(): int
```

Returns the x coordinate of the first endpoint, which need not be the leftmost.

**Returns:** the x position of the start of the line.

**Since:** 1.8.4

### getX2 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getX2-}

```js
getX2(): int
```

Returns the x coordinate of the second endpoint, which need not be the rightmost.

**Returns:** the x position of the end of the line.

**Since:** 1.8.4

### getY1 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getY1-}

```js
getY1(): int
```

Returns the y coordinate of the first endpoint, which need not be the topmost.

**Returns:** the y position of the start of the line.

**Since:** 1.8.4

### getY2 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getY2-}

```js
getY2(): int
```

Returns the y coordinate of the line's second endpoint.

**Returns:** the y position of the end of the line.

**Since:** 1.8.4

### getZIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getZIndex-}

```js
getZIndex(): int
```

Returns this line's draw-order value.

**Returns:** the z-index of this element

### isRotatingCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_isRotatingCenter-}

```js
isRotatingCenter(): boolean
```

Returns whether rotation is about this line's midpoint.

**Returns:** `true` if this line should be rotated around its center, `false`
 otherwise.

**Since:** 1.8.4

### moveTo {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_moveTo-int-int-}

```js
moveTo(int x, int y): Line
```

Moves the line so its minimum x and y coordinates match the requested position,  
 translating both endpoints without changing their relative positions.

**Parameters:**
- `x`: the new x position
- `y`: the new y position

**Returns:** self for chaining.

### render {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_render-GuiGraphics-int-int-float-}

```js
render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void
```

Draws the line as a filled strip between its endpoints, applying the element's
 rotation and endpoint orientation. Nonpositive and non-finite widths skip drawing.  
 The strip is a unit rectangle scaled by the line's length and thickness, so
 fractional widths keep their stored size instead of being rounded. Thickness is
 raised to at least one physical pixel so very thin lines still appear, and the
 GUI renderer does not antialias the strip's edges. The mouse coordinates and
 frame delta are unused. The graphics pose is pushed and popped on normal
 completion.

**Parameters:**
- `drawContext`: the graphics context receiving the strip
- `mouseX`: unused mouse x coordinate
- `mouseY`: unused mouse y coordinate
- `delta`: unused frame delta

### setAlpha {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setAlpha-int-}

```js
setAlpha(int alpha): Line
```

Sets the alpha byte without changing the RGB channels. Values are not clamped.

**Parameters:**
- `alpha`: the alpha value of the line's color

**Returns:** self for chaining.

**Since:** 1.8.4

### setColor {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setColor-int-}

```js
setColor(int color): Line
```

Sets the packed ARGB color. A zero alpha byte with nonzero RGB is treated as opaque;  
 pure black remains transparent.

**Parameters:**
- `color`: the color of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setColor {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setColor-int-int-}

```js
setColor(int color, int alpha): Line
```

Sets the RGB color and alpha separately. The alpha replaces the top byte and is
 not clamped; only its low eight bits are returned by [getAlpha()](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_getAlpha-).

**Parameters:**
- `color`: the color of the line
- `alpha`: the alpha of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setParent {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setParent-IDraw2D-}

```js
setParent(IDraw2D<?> parent): Line
```

Sets the overlay used for parent-relative dimensions and alignment. Passing
 `null` makes parent dimensions fall back to the window.

**Parameters:**
- `parent`: the overlay this element is on, or `null` for the window

**Returns:** self for chaining.

### setPos {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setPos-int-int-int-int-}

```js
setPos(int x1, int y1, int x2, int y2): Line
```

Sets both endpoints of the line.

**Parameters:**
- `x1`: the x position of the start of the line
- `y1`: the y position of the start of the line
- `x2`: the x position of the end of the line
- `y2`: the y position of the end of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setPos1 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setPos1-int-int-}

```js
setPos1(int x1, int y1): Line
```

Sets both coordinates of the first endpoint without changing the second.

**Parameters:**
- `x1`: the x position of the start of the line
- `y1`: the y position of the start of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setPos2 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setPos2-int-int-}

```js
setPos2(int x2, int y2): Line
```

Sets the second endpoint, leaving the first unchanged.

**Parameters:**
- `x2`: the x position of the end of the line
- `y2`: the y position of the end of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setRotateCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setRotateCenter-boolean-}

```js
setRotateCenter(boolean rotateCenter): Line
```

Selects whether rotation is about the line's midpoint or its first endpoint.

**Parameters:**
- `rotateCenter`: whether this line should be rotated around its center

**Returns:** self for chaining.

**Since:** 1.8.4

### setRotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setRotation-double-}

```js
setRotation(double rotation): Line
```

Sets the rotation in degrees, normalized by Minecraft's degree-wrapping function.  
 Rotation is about the midpoint when `rotateCenter` is true, otherwise about
 the first endpoint.

**Parameters:**
- `rotation`: the rotation (clockwise) of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setWidth-double-}

```js
setWidth(double width): Line
```

Sets the line's stroke thickness in screen pixels. Values are stored as floats;  
 non-positive and non-finite widths are not rendered, and positive fractional
 widths keep their size when drawn, clamped to at least one physical pixel.

**Parameters:**
- `width`: the width of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setX1 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setX1-int-}

```js
setX1(int x1): Line
```

Sets the first endpoint's x coordinate without changing the other coordinates.

**Parameters:**
- `x1`: the x position of the start of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setX2 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setX2-int-}

```js
setX2(int x2): Line
```

Sets the second endpoint's x coordinate without changing the other coordinates.

**Parameters:**
- `x2`: the x position of the end of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setY1 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setY1-int-}

```js
setY1(int y1): Line
```

Sets the first endpoint's y coordinate without changing the other coordinates.

**Parameters:**
- `y1`: the y position of the start of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setY2 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setY2-int-}

```js
setY2(int y2): Line
```

Sets the second endpoint's y coordinate without changing the other coordinates.

**Parameters:**
- `y2`: the y position of the end of the line

**Returns:** self for chaining.

**Since:** 1.8.4

### setZIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Line_setZIndex-int-}

```js
setZIndex(int zIndex): Line
```

Sets this line's draw-order value relative to other elements in its overlay;  
 lower values are drawn first. Equal values retain insertion order in the overlay.

**Parameters:**
- `zIndex`: the z-index of the line

**Returns:** self for chaining.

**Since:** 1.8.4
