Skip to main content

Draw

enum DrawContextColor

DrawContextColor = {
COMMON = 0,
UPPER_LEFT = 1,
UPPER_RIGHT = 2,
BOTTOM_LEFT = 3,
BOTTOM_RIGHT = 4,
}

enum DrawContextColor

DrawList = {
--- This layer is intended for elements that need to be rendered above all other content.
--- Use this layer for overlays, tooltips, and other UI components that must remain visible on top of main content.
FOREGROUND = 0,
--- This layer is used for background elements, which are drawn first and can be overlaid by other UI components.
--- Ideal for backgrounds, images, or any foundational visuals that support the main UI elements but should not obscure them.
BACKGROUND = 1
}

enum DrawContextColor

ImDrawCornerFlags = {
NONE = 0,
TOP_LEFT = 1, -- 1 << 0, 0x1
TOP_RIGHT = 2, -- 1 << 1, 0x2
BOT_LEFT = 4, -- 1 << 2, 0x4
BOT_RIGHT = 8, -- 1 << 3, 0x8
TOP = 3, -- (1 << 0) | (1 << 1), 0x3
BOT = 12, -- (1 << 2) | (1 << 3), 0xC
LEFT = 5, -- (1 << 0) | (1 << 2), 0x5
RIGHT = 10, -- (1 << 1) | (1 << 3), 0xA
ALL = 15 -- 0xF
}

draw.is_ready

True if drawing is possible.

  • Return:

    TypeDescription
    booleanReturns True if drawing is possible.
  • Methods:

    • draw.is_ready()

draw.get_window_width

The width of the window in pixels, or 0 if the resolution cannot be retrieved.

  • Return:

    TypeDescription
    numberThe width of the window in pixels, or 0 if the resolution cannot be retrieved.
  • Methods:

    • draw.get_window_width()

draw.get_window_height

The height of the window in pixels, or 0 if the resolution cannot be retrieved.

  • Return:

    TypeDescription
    numberThe height of the window in pixels, or 0 if the resolution cannot be retrieved.
  • Methods:

    • draw.get_window_height()

draw.get_screen_width

The width of the screen in pixels, or 0 if the resolution cannot be retrieved.

  • Return:

    TypeDescription
    numberThe width of the screen in pixels, or 0 if the resolution cannot be retrieved.
  • Methods:

    • draw.get_screen_width()

draw.get_screen_height

The height of the screen in pixels, or 0 if the resolution cannot be retrieved.

  • Return:

    TypeDescription
    numberThe height of the screen in pixels, or 0 if the resolution cannot be retrieved.
  • Methods:

    • draw.get_screen_height()

draw.create_texture_from_memory

Creates a texture from memory buffer

  • Parameters:

    NameTypeDescription
    bufferstringThe message text to send. If the string is empty, the function returns false.
    lennumberIf true, the message is sent as a team message.
  • Return:

    TypeDescription
    numberA texture handle if successful, or 0 if the texture could not be created..
  • Methods:

    • draw.create_texture_from_memory(buffer, len)

draw.create_texture_from_file

Creates a texture from a file

  • Parameters:

    NameTypeDescription
    file_namestringThe path to the texture file.
  • Return:

    TypeDescription
    numberA texture handle if successful, or 0 if the texture could not be created.
  • Methods:

    • draw.create_texture_from_file(file_name)

draw.create_texture_from_base64

Creates a texture from a base64 encoded string

  • Parameters:

    NameTypeDescription
    base64stringThe base64 encoded string representing the image data.
  • Return:

    TypeDescription
    numberA texture handle if successful, or 0 if the texture could not be created.
  • Methods:

    • draw.create_texture_from_base64(base64)

draw.create_debug_texture

Creates a debug texture with a checkerboard pattern for quick testing and debugging purposes

  • Parameters:

    NameTypeDescriptionDefault
    widthnumberThe width of the texture in pixels.100
    heightnumberThe height of the texture in pixels.100
  • Return:

    TypeDescription
    numberA texture handle if successful, or 0 if the texture could not be created.
  • Methods:

    • draw.create_debug_texture(width, height)
    • draw.create_debug_texture()

draw.release_texture

Releases a previously created texture

  • Parameters:

    NameTypeDescription
    handlenumberThe texture handle to release.
  • Return:

    TypeDescription
    booleanTrue if the texture was successfully released, false otherwise.
  • Methods:

    • draw.release_texture(handle)

draw.texture

Draws a texture on the screen at the specified coordinates

  • Parameters:

    NameTypeDescription
    handlenumberThe texture handle to draw.
    xnumberThe x-coordinate on the screen.
    ynumberThe y-coordinate on the screen.
    widthnumberThe width of the image to draw (optional).
    heightnumberThe height of the image to draw (optional).
  • Return:

    TypeDescription
    booleanTrue if the texture was successfully drawn, false otherwise.
  • Methods:

    • draw.texture(handle, x, y, width, height)

draw.set_hsv

Sets the current drawing color using HSV values, with an optional alpha component

  • Parameters:

    NameTypeDescriptionDefault
    colorDrawContextColorThe drawing context color type.
    hnumberThe hue component of the color (0-1).
    snumberThe saturation component of the color (0-1).
    vnumberThe value component of the color (0-1).
    anumberThe alpha component of the color (0-1, optional).1
  • Methods:

    • draw.set_hsv(color, h, s, v, a)

draw.set_color

Sets the current drawing color. This function can be called with different sets of parameters

  • Parameters:

    NameTypeDescription
    colorEDrawContextColorThe drawing context color type.
    valuenumberA number encapsulating RGBA components in a single four-byte number.
    rnumberThe red component of the color (0-1).
    gnumberThe green component of the color (0-1).
    bnumberThe blue component of the color (0-1).
    anumberThe alpha component of the color (0-1, optional for full opacity).
  • Methods:

    • draw.set_color(color, value)
    • draw.set_color(color, r, g, b, a)
    • draw.set_color(color, r, g, b)

draw.get_colors

Retrieves the current RGBA color values for a specified drawing context

  • Parameters:

    NameTypeDescription
    colorEDrawContextColorThe specific drawing context color to retrieve.
  • Return:

    TypeDescription
    numberFour integers representing the RGBA components of the color.
  • Example:

local r, g, b, a = draw.get_colors(DrawContextColor.COMMON)
print("Current common color RGBA: ", r, g, b, a)
  • Methods:
    • draw.get_colors(color)

draw.set_thickness

Sets the line thickness for drawing operations

  • Parameters:

    NameTypeDescription
    valuenumberThe thickness to set.
  • Methods:

    • draw.set_thickness(value)

draw.get_thickness

Retrieves the current line thickness used in drawing operations

  • Return:

    TypeDescription
    numberThe current line thickness.
  • Methods:

    • draw.get_thickness()

draw.set_rounding

Sets the rounding radius for drawing operations that require rounded corners

  • Parameters:

    NameTypeDescription
    valuenumberThe rounding radius to set.
  • Methods:

    • draw.set_rounding(value)

draw.get_rounding

Retrieves the current rounding radius used in drawing operations

  • Return:

    TypeDescription
    numberThe current rounding radius.
  • Methods:

    • draw.get_rounding()

draw.set_radius

Sets the radius for drawing operations that involve circular elements

  • Parameters:

    NameTypeDescription
    valuenumberThe radius to set for circles and arcs.
  • Methods:

    • draw.set_radius(value)

draw.get_radius

Retrieves the current radius used in drawing operations for circles and arcs

  • Return:

    TypeDescription
    numberThe current radius.
  • Methods:

    • draw.get_radius()

draw.set_num_segments

Sets the number of segments used for drawing rounded elements

  • Parameters:

    NameTypeDescription
    valuenumberThe number of segments to set.
  • Methods:

    • draw.set_num_segments(value)

draw.get_num_segments

Retrieves the current number of segments used for rounded elements

  • Return:

    TypeDescription
    numberThe current number of segments.
  • Methods:

    • draw.get_num_segments()

draw.set_flags

Sets drawing flags for customizing the behavior of drawing operations. These flags are based on the ImDrawCornerFlags enum

  • Parameters:

    NameTypeDescription
    valuenumberThe flags to set, as defined by ImDrawCornerFlags.
  • Methods:

    • draw.set_flags(value)

draw.get_flags

Retrieves the current drawing flags, as defined by the ImDrawCornerFlags enum

  • Return:

    TypeDescription
    numberThe current flags.
  • Methods:

    • draw.get_flags()

draw.set_min_uv

Sets the minimum texture coordinate (UV) for texturing operations

  • Parameters:

    NameTypeDescription
    valuenumberThe minimum UV to set.
  • Methods:

    • draw.set_min_uv(value)

draw.get_min_uv

Retrieves the current minimum texture coordinate (UV) used in texturing operations

  • Return:

    TypeDescription
    numberThe current minimum UV.
  • Methods:

    • draw.get_min_uv()

draw.set_max_uv

Sets the maximum texture coordinate (UV) for texturing operations

  • Parameters:

    NameTypeDescription
    valuenumberThe maximum UV to set.
  • Methods:

    • draw.set_max_uv(value)

draw.get_max_uv

Retrieves the current maximum texture coordinate (UV) used in texturing operations

  • Return:

    TypeDescription
    numberThe current maximum UV.
  • Methods:

    • draw.get_max_uv()

draw.create_font

Queues a font for loading and invokes a callback when the font is successfully loaded

  • Overloads:

    1. draw.create_font(font_name, font_size, on_requested)
    2. draw.create_font(font_name, on_requested)
  • Parameters:

    NameTypeDescriptionDefault
    font_namestringThe name of the font file. If the path is not specified, searches in the product directory and system fonts.
    font_sizenumberThe size of the font.14
    on_requestedfun(font: ImFont*)The callback function that is invoked when the font is loaded. Receives an ImFont pointer as an argument.
  • Return:

    TypeDescription
    booleanTrue if the font is successfully queued for loading, false if there is an error.
  • Methods:

    • draw.create_font(font_name, font_size, on_requested)
    • draw.create_font(font_name, on_requested)

draw.set_font

Sets the current font for drawing operations

  • Parameters:

    NameTypeDescription
    fontImFont*The font to set for drawing.
  • Methods:

    • draw.set_font(font)

draw.get_text_size

Calculates the size of the given text using the current font

  • Parameters:

    NameTypeDescription
    textstringThe text for which to calculate the size.
  • Return:

    TypeDescription
    numberThe width of the text in pixels.
    numberThe height of the text in pixels.
  • Methods:

    • draw.get_text_size(text)

draw.get_text_size_x

Calculates the width of the given text using the current font

  • Parameters:

    NameTypeDescription
    textstringThe text for which to calculate the width.
  • Return:

    TypeDescription
    numberThe width of the text in pixels.
  • Methods:

    • draw.get_text_size_x(text)

draw.get_text_size_y

Calculates the height of the given text using the current font

  • Parameters:

    NameTypeDescription
    textstringThe text for which to calculate the height.
  • Return:

    TypeDescription
    numberThe height of the text in pixels.
  • Methods:

    • draw.get_text_size_y(text)

draw.line

Draws a line between two points

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first point.
    y1numberThe y-coordinate of the first point.
    x2numberThe x-coordinate of the second point.
    y2numberThe y-coordinate of the second point.
  • Methods:

    • draw.line(x1, y1, x2, y2)

draw.text

Draws text at a specified location

  • Parameters:

    NameTypeDescription
    xnumberThe x-coordinate where the text starts.
    ynumberThe y-coordinate where the text starts.
    textstringThe text to draw.
  • Methods:

    • draw.text(x, y, text)

draw.rect

Draws an unfilled rectangle

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first corner.
    y1numberThe y-coordinate of the first corner.
    x2numberThe x-coordinate of the opposite corner.
    y2numberThe y-coordinate of the opposite corner.
  • Methods:

    • draw.rect(x1, y1, x2, y2)

draw.rect_filled

Draws a filled rectangle

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first corner.
    y1numberThe y-coordinate of the first corner.
    x2numberThe x-coordinate of the opposite corner.
    y2numberThe y-coordinate of the opposite corner.
  • Methods:

    • draw.rect_filled(x1, y1, x2, y2)

draw.rect_filled_multi_color

Draws a filled rectangle with multiple colors

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first corner.
    y1numberThe y-coordinate of the first corner.
    x2numberThe x-coordinate of the opposite corner.
    y2numberThe y-coordinate of the opposite corner.
  • Methods:

    • draw.rect_filled_multi_color(x1, y1, x2, y2)

draw.quad

Draws an unfilled quadrilateral

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first corner.
    y1numberThe y-coordinate of the first corner.
    x2numberThe x-coordinate of the second corner.
    y2numberThe y-coordinate of the second corner.
    x3numberThe x-coordinate of the third corner.
    y3numberThe y-coordinate of the third corner.
    x4numberThe x-coordinate of the fourth corner.
    y4numberThe y-coordinate of the fourth corner.
  • Methods:

    • draw.quad(x1, y1, x2, y2, x3, y3, x4, y4)

draw.quad_filled

Draws a filled quadrilateral

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first corner.
    y1numberThe y-coordinate of the first corner.
    x2numberThe x-coordinate of the second corner.
    y2numberThe y-coordinate of the second corner.
    x3numberThe x-coordinate of the third corner.
    y3numberThe y-coordinate of the third corner.
    x4numberThe x-coordinate of the fourth corner.
    y4numberThe y-coordinate of the fourth corner.
  • Methods:

    • draw.quad_filled(x1, y1, x2, y2, x3, y3, x4, y4)

draw.triangle

Draws an unfilled triangle

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first corner.
    y1numberThe y-coordinate of the first corner.
    x2numberThe x-coordinate of the second corner.
    y2numberThe y-coordinate of the second corner.
    x3numberThe x-coordinate of the third corner.
    y3numberThe y-coordinate of the third corner.
  • Methods:

    • draw.triangle(x1, y1, x2, y2, x3, y3)

draw.triangle_filled

Draws a filled triangle

  • Parameters:

    NameTypeDescription
    x1numberThe x-coordinate of the first corner.
    y1numberThe y-coordinate of the first corner.
    x2numberThe x-coordinate of the second corner.
    y2numberThe y-coordinate of the second corner.
    x3numberThe x-coordinate of the third corner.
    y3numberThe y-coordinate of the third corner.
  • Methods:

    • draw.triangle_filled(x1, y1, x2, y2, x3, y3)

draw.circle

Draws an unfilled circle at a specified location

  • Parameters:

    NameTypeDescription
    xnumberThe x-coordinate of the circle's center.
    ynumberThe y-coordinate of the circle's center.
  • Methods:

    • draw.circle(x, y)

draw.circle_filled

Draws a filled circle at a specified location

  • Parameters:

    NameTypeDescription
    xnumberThe x-coordinate of the circle's center.
    ynumberThe y-coordinate of the circle's center.
  • Methods:

    • draw.circle_filled(x, y)

draw.set_draw_list

Sets the current draw list for drawing elements

  • Parameters:

    NameTypeDescription
    listDrawListThe draw list to be set.
  • Return:

    TypeDescription
    DrawListThe previous DrawList that was set.
  • Methods:

    • draw.set_draw_list(list)

draw.get_draw_list

Retrieves the current draw list for drawing elements

  • Return:

    TypeDescription
    DrawListThe current draw list.
  • Methods:

    • draw.get_draw_list()