# Hud

`com.jsmacrosce.jsmacros.client.api.library.impl.FHud`

**Since:** 1.0.5

Screen, overlay, texture, and window-state APIs exposed to scripts as `Hud`.  

2D overlay coordinates and mouse positions use GUI-scaled pixels from the window's top left;  
window width and height are raw pixels. 3D overlays use world coordinates. Overlays render only
while registered; use their own `register()` and `unregister()` methods. The clear
methods remove all overlays of their respective dimension, including those registered by other
scripts.  
```js
// draw 2D text in the overlay and register it
const draw = Hud.createDraw2D();  
draw.addText("hello", 10, 10, Color.rgb(0xFF, 0xFF, 0xFF), true);  
draw.register();  
```

Accessible in scripts via the global `Hud` variable.

## Fields

### overlays {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_overlays}

```js
static overlays: Set<IDraw2D<Draw2D>>
```

Set of 2D overlays currently registered for rendering.

**Since:** 1.0.5

### renders {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_renders}

```js
static renders: Set<Draw3D>
```

Set of 3D overlays currently registered for rendering.

**Since:** 1.0.6

## Methods

### clearDraw2Ds {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_clearDraw2Ds-}

```js
clearDraw2Ds(): void
```

Unregisters all 2D overlays, including those registered by other scripts; the overlay objects and their elements remain available.

**Since:** 1.0.5

**See:**
- [IDraw2D](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IDraw2D.md)

### clearDraw3Ds {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_clearDraw3Ds-}

```js
clearDraw3Ds(): void
```

Unregisters all 3D overlays, including those registered by other scripts. This also removes
prediction markers; [FPlayer.setDrawPredictions(boolean)](FPlayer.md#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_setDrawPredictions-boolean-) can register them again.

**Since:** 1.0.6

### createDraw2D {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_createDraw2D-}

```js
createDraw2D(): Draw2D
```

Creates an unregistered 2D overlay. It renders while registered; registering runs its init
function. Coordinates use GUI-scaled pixels from the top left, as do [getMouseX()](#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getMouseX-) and
[getMouseY()](#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getMouseY-).

**Returns:** a new, unregistered overlay

**Since:** 1.0.5

**See:**
- [IDraw2D](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IDraw2D.md)

### createDraw3D {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_createDraw3D-}

```js
createDraw3D(): Draw3D
```

Creates an unregistered 3D overlay. Its elements use world-space block coordinates and
render relative to the camera only while registered; unlike a 2D overlay, it has no init
function.  
```js
// a wireframe box around a single block
const draw = Hud.createDraw3D();  
draw.addBox(0, 64, 0, 1, 65, 1, Color.rgb(0xFF, 0x00, 0x00), Color.argb(0, 0, 0, 0), false);  
draw.register();  
```

**Returns:** a new unregistered [Draw3D](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/Draw3D.md)

**Since:** 1.0.6

### createScreen {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_createScreen-String-boolean-}

```js
createScreen(String title, boolean menuBackground): ScriptScreen
```

Creates a script screen with the given title and both background effects enabled: the game's
menu background overlay is drawn and the world behind it is blurred. The title is drawn by
default; set `drawTitle` on the returned screen to disable it.

**Parameters:**
- `title`: the title shown at the top of the screen
- `menuBackground`: whether to draw the game's menu background overlay

**Returns:** the new screen, not opened automatically

**Since:** 1.0.5

### createScreen {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_createScreen-String-boolean-boolean-}

```js
createScreen(String title, boolean menuBackground, boolean blurredBackground): ScriptScreen
```

Creates a script screen with the given title and background effects. The title is drawn by
default; set `drawTitle` on the returned screen to disable it.  

The two effects are independent. The menu background is vanilla's darkened background: on
the supported versions it is a flat translucent black overlay rather than a picture, so it
only darkens what is behind the screen. The blurred background applies vanilla's menu blur
to the world behind the screen. With both off, the world is shown unmodified.

**Parameters:**
- `title`: the title shown at the top of the screen
- `menuBackground`: whether to draw the game's menu background overlay
- `blurredBackground`: whether to blur the world behind the screen

**Returns:** the new screen, not opened automatically

**Since:** 2.1.0

### createTexture {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_createTexture-int-int-String-}

```js
createTexture(int width, int height, String name): CustomImage
```

Creates a mutable blank image and registers it under `name` when non-null.

**Parameters:**
- `width`: the width of the canvas
- `height`: the height of the canvas
- `name`: the name to register the texture under, or `null` for none

**Returns:** the new mutable image

**Since:** 1.8.4

### createTexture {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_createTexture-String-String-}

```js
createTexture(String path, String name): CustomImage
```

Loads an image from a path relative to the JsMacros config folder. Logs an error and returns
`null` if reading fails or no image reader recognizes the file.

**Parameters:**
- `path`: path to an image file, relative to the JsMacros config folder
- `name`: the name to register the texture under, or `null` for none

**Returns:** the loaded image, or `null` if reading fails or the format is unsupported

**Since:** 1.8.4

### getMouseX {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getMouseX-}

```js
getMouseX(): double
```

Returns the mouse's horizontal position in GUI-scaled pixels, matching 2D overlay coordinates.  
The scaled value is not necessarily an integer.

**Returns:** the current X coordinate of the mouse

**Since:** 1.1.3

### getMouseY {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getMouseY-}

```js
getMouseY(): double
```

Returns the mouse's vertical position in GUI-scaled pixels, matching 2D overlay coordinates.  
The scaled value is not necessarily an integer.

**Returns:** the current Y coordinate of the mouse

**Since:** 1.1.3

### getOpenScreen {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getOpenScreen-}

```js
getOpenScreen(): IScreen
```

Returns the currently open screen, if any.

**Returns:** the currently open screen, or `null` if none

**Since:** 1.2.7

### getOpenScreenName {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getOpenScreenName-}

```js
getOpenScreenName(): String
```

Returns a name for the open screen: recognized screens use fixed names, other screens use
their title (or `unknown` when it is empty). Returns `null` when no screen is open.

**Returns:** the screen name, or `null` if no screen is open

**Since:** 1.0.5

**Note:** renamed from `getOpenScreen` in 1.2.7

### getRegisteredTextures {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getRegisteredTextures-}

```js
getRegisteredTextures(): Map<String, CustomImage>
```

Returns a snapshot of the registered custom textures, keyed by registration name.

**Returns:** an immutable snapshot of the registered textures

**Since:** 1.8.4

### getScaleFactor {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getScaleFactor-}

```js
getScaleFactor(): int
```

Returns the configured GUI scale option; automatic scaling is reported as `0`.

**Returns:** the configured GUI scale option

**Since:** 1.8.4

### getWindowHeight {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getWindowHeight-}

```js
getWindowHeight(): int
```

Returns the game window height in raw (unscaled) pixels.

**Returns:** the current window height.

**Since:** 1.8.4

### getWindowWidth {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_getWindowWidth-}

```js
getWindowWidth(): int
```

Returns the game window width in raw (unscaled) pixels.

**Returns:** the current window width.

**Since:** 1.8.4

### isContainer {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_isContainer-}

```js
isContainer(): boolean
```

Returns whether the current screen is a container screen.

**Returns:** `true` if the current screen is a container screen

**Since:** 1.1.2

### listDraw2Ds {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_listDraw2Ds-}

```js
listDraw2Ds(): List<IDraw2D<Draw2D>>
```

Returns a snapshot of all currently registered 2D overlays, including those registered by other scripts.

**Returns:** the currently registered overlays

**Since:** 1.0.5

**See:**
- [IDraw2D](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IDraw2D.md)

### listDraw3Ds {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_listDraw3Ds-}

```js
listDraw3Ds(): List<Draw3D>
```

Returns a snapshot of the 3D overlays currently registered for rendering, including those
registered by other scripts.

**Returns:** the currently registered [Draw3D](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/Draw3D.md) overlays

**Since:** 1.0.6

### openScreen {#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_openScreen-IScreen-}

```js
openScreen(IScreen s): void
```

Opens a screen, or closes the current screen when passed `null`. The change is queued
on the client thread, so it may not have taken effect when this method returns.

**Parameters:**
- `s`: the screen to open, or `null` to close the current one

**Since:** 1.0.5
