Skip to main content

RenderSurface Element

RenderSurface is a module that provides a drawing surface for custom rendering.
It supports text rendering, mouse interaction, and redraw handling.

RenderSurface Element
Element
LuaRT Element

Constructor

RenderSurface.new()
Function

RenderSurface.new(RenderSurfaceProperties)

  • Creates a new RenderSurface element,actually a Canvas object.

You can just create your RenderSurface with bgcolor and visible properties. Other properties will be set to default values. If you want more than one RenderSurface, remember you may need to set the zIndex manually,also align,size and position properties.

Parameters:

  • IsRenderSurface

    true

    • READONLY: Used internally by Weo for parent checking.
  • RenderElements

    table

    • READONLY: Managed internally by Weo.
  • parent

    Window

    • READONLY: Parent window of the RenderSurface. Mostly it's a Window.
  • x

    number?

    • Horizontal position of the RenderSurface.
  • y

    number?

    • Vertical position of the RenderSurface.
  • width

    number?

    • Width of the RenderSurface.
  • height

    number?

    • Height of the RenderSurface.
  • align

    string?

    • Alignment relative to parent. Automatically set to "all" by Weo.
  • enabled

    boolean?

    • Whether the RenderSurface responds to input.
  • visible

    boolean?

    • Controls visibility of the RenderSurface.
  • color

    string?

    • Current drawing color.
  • bgcolor

    number?
    LinearGradient?
    RadialGradient?

    • Background color of the RenderSurface.
  • font

    string?

    • Current font (from Windows system fonts).
  • fontsize

    number?

    • Font size.
  • fontweight

    number?

    • Font weight (1–999).
  • fontstretch

    number?

    • Font stretch (1–9).
  • fontstyle

    Enum.FontStyle?

    • Font style.
  • window

    Window

    • The window to which the RenderSurface is attached.
  • cursor

    Enum.CursorStyle?

    • The cursor to display when the mouse is over the RenderSurface.

Weo uses this property to set the cursor when the mouse is over the other elements,like Button.

Methods

(RenderSurface):LinearGradient()
Method

  • Please use Color.LinearGradient instead.

(RenderSurface):RadialGradient()
Method

  • Please use Color.RadialGradient instead.

(RenderSurface):show()
Method

  • Shows the RenderSurface.

(RenderSurface):hide()
Method

  • Hides the RenderSurface.

(RenderSurface):measure()
Method

(RenderSurface):measure(text)

  • Measures text size.

Parameters:

  • text
    string

Returns:

  • { width: number, height: number }

(RenderSurface):Refresh()
Method

(RenderSurface):Refresh(force)

  • Forces redraw of the RenderSurface.

This is for a bug in LuaRT 2.0.1 x64. After hiding (Window) and showing it again, the RenderSurface will not be redrawn.
This method calls (RenderSurface):onPaint() to redraw via UpdateService,performance is not guaranteed.

Parameters:

  • force
    boolean

(RenderSurface):print()
Method

(RenderSurface):print(text, x, y, color)

  • Prints text at a position.

Parameters:

  • text
    string
  • x
    number
  • y
    number
  • color
    number?
    LinearGradient?
    RadialGradient?

Please use Label instead.

(RenderSurface):rotate()
Method

(RenderSurface):rotate(angle, x, y)

  • Rotates the RenderSurface.

Parameters:

  • angle
    number
  • x
    number?
    — Optional. Default is the center of the RenderSurface.
  • y
    number?
    — Optional. Default is the center of the RenderSurface.

(RenderSurface):scale()
Method

(RenderSurface):scale(x, y,centerx, centery)

  • Scales the RenderSurface.

Parameters:

  • x
    number
  • y
    number
  • centerx
    number?
    — Optional. Default is the center of the RenderSurface.
  • centery
    number?
    — Optional. Default is the center of the RenderSurface.

(RenderSurface):translate()
Method

(RenderSurface):translate(x, y)

  • Translates the RenderSurface.

Parameters:

  • x
    number
  • y
    number

(RenderSurface):identity()
Method

(RenderSurface):identity()

  • Resets the transformation matrix of the RenderSurface.

Signals

(RenderSurface).Shown
Signal

  • Fires when the RenderSurface is shown.

(RenderSurface).Hidden
Signal

  • Fires when the RenderSurface is hidden.

(RenderSurface).Created
Signal

  • Fires when the RenderSurface is created.

(RenderSurface).MouseButton1Click
Signal

  • Fires when the RenderSurface is clicked.

Parameters:

  • position
    Vector2

(RenderSurface).MouseButton2Click
Signal

  • Fires when the RenderSurface is right-clicked.

Parameters:

  • position
    Vector2

(RenderSurface).MouseHover
Signal

  • Fires when the mouse hovers over the RenderSurface.

Parameters:

  • position
    Vector2

(RenderSurface).MouseButtonDown
Signal

  • Fires when a mouse button is pressed down.

Parameters:

  • position
    Vector2
  • buttons
    table
    — mouse buttons state
    • Table containing mouse button states:
      • left — Left mouse button state.
      • middle — Middle mouse button state.
      • right — Right mouse button state.
      • control — Control key state.
      • shift — Shift key state.

(RenderSurface).MouseButtonUp
Signal

  • Fires when a mouse button is released.

Parameters:

  • position
    Vector2
  • buttons
    table
    — mouse buttons state
    • Table containing mouse button states:
      • left — Left mouse button state.
      • middle — Middle mouse button state.
      • right — Right mouse button state.
      • control — Control key state.
      • shift — Shift key state.

Does not work on LuaRT 2.0.1 x64. Use (buttons.left, buttons.right) from MouseButtonDown instead.

(RenderSurface).MouseWheel
Signal

  • Fires when the mouse wheel is scrolled.

Parameters:

  • delta
    number
  • buttons
    table
    — mouse buttons state
    • Table containing mouse button states:
      • left — Left mouse button state.
      • middle — Middle mouse button state.
      • right — Right mouse button state.
      • control — Control key state.
      • shift — Shift key state.

(RenderSurface).MouseLeave
Signal

  • Fires when the mouse leaves the RenderSurface.

Example

-- Creating a RenderSurface
local Render = RenderSurface.new(window, {
bgcolor = Color.fromHEX("#7E0202FF"),
visible = true,
})

-- Creating a Frame,which renders on the RenderSurface
local MyFrame = Frame.new(Render, {
position = UDim2.new(0, 300, 0, 300),
size = UDim2.new(0, 100, 0, 100),
bgcolor = Color.fromHEX("#1593CEFF"),
visible = true,
borderRadius = 15,
zIndex = 0,
})

Notes

  • See LuaRT Canvas Documentation for details.
  • RenderSurface stops updating :onPaint() after the window hidden and shown again. It's a known bug in LuaRT 2.0.1 x64 and not an issue of Weo.
    • You can force (RenderSurface):Refresh(force : boolean) to update RenderSurface with UpdateService.Heartbeat, but performance is not guaranteed since this is a workaround for the issue.