Module renderScript

RenderScript is a new technology for creating screen unit contents using Lua (also referred to as "Lua Screen Units"), rather than HTML/CSS.

In general, this technology causes less performance drops in the game, while simultaneously allowing significantly more complex animaged and interactive screens.

Render scripts are Lua scripts residing inside screen units that provide rendering instructions for the screen. To use RenderScript, simply switch the screen mode from 'HTML' to 'Lua' in the screen unit content editor interface, then start writing a render script! Render scripts work by building up layers of geometric shapes, images, and text, that are then rendered sequentially to the screen.

The short example script below demonstrates drawing a box and some text on the screen.

local layer = createLayer() -- create a new layer
local rx, ry = getResolution() -- get the resolution of the screen
local font = loadFont("Play", 20) -- load the "Play" font at size 20pain

setNextFillColor(layer, 1, 0, 0, 1) -- set the fill color (red, green, blue, alpha) for the next shape
addBox(layer, rx/4, ry/4, rx/2, ry/2) -- add a box in the center of the screen
addText(layer, font, "Hello World!", rx/3, ry/2) -- add a text string using font

Animation

It is entirely possible to create animated screens with RenderScript; in fact, the technology really shines for complex animations, where the performance of HTML/CSS is generally low.

Animations are made possible by using the requestAnimationFrame function to re-run in some number of frames, then changing the positioning of geometry within the layers, based on some variable such as time. Effectively, you will simply draw one frame of your animation at a time, but since RenderScript is fast enough to execute at 60 frames per second, the result will look smooth.

The minimal example script below demonstrates using the getTime function to animate the location of a circle on the screen:

local layer = createLayer()
local rx, ry = getResolution()
local t = getTime()
local r = math.min(rx/4, ry/4)
local x = rx/2 + r * math.cos(t)
local y = ry/2 + r * math.sin(t)

addCircle(layer, x, y, 16)
requestAnimationFrame(1)

Coordinate Space

All render script coordinates are in screen pixels, ranging from (0, 0) at the top-left of the screen, to (width, height) at the bottom-right. The width and height of the screen in pixels can be retrieved by calling getResolution.

For maximal robustness, scripts should be written so as to adapt to the resolution, as screens with different sizes or aspect ratios will use different display resolutions.

Render Cost

Since render script is intended to solve screen unit performance problems, we impose relatively harsh restrictions on content compared to HTML. This does not mean you won't be able to create amazing, detailed, high-framerate screen contents; it just means that you'll need to be aware of the budgeting mechanism.

Any render script call that draws a shape (box, circle, line, text...) adds to a cost metric that consumes some of the screen's total rendering budget. Although the exact cost metric is subject to change, roughly-speaking, the render cost incurred by any shape is proportional to the screen-space area of the shape, plus a constant factor. This means that a box of dimension 16 x 16 consumes roughly four times as much render cost as a box of 8 x 8. This is fairly intuitive when you realize that the number of pixels filled by the larger box is four times that of the smaller box.

For most render scripts, it is unlikely that the maximum cost will ever be exceeded, so most users probably don't need to worry too much about this mechanism. However, drawing lots of large text or lots of large, overlapping images may cause you to exceed the budget.

To learn more about your script's use of this budget, use the built-in API functions getRenderCost and getRenderCostMax. getRenderCost can be called at any point during a render script to see how much all the contents added so far cost.

Below is an example of how to add a simple render cost progile to your screen so that you can see cost information in real-time:

local rx, ry = getResolution()
local layer = createLayer()
local font = loadFont('FiraMono-Bold', 16)
local text = string.format('render cost: %d / %d', getRenderCost(), getRenderCostMax())
setNextFillColor(layer, 1, 1, 1, 1)
setNextTextAlign(layer, AlignH_Left, AlignV_Descender)
addText(layer, font, text, 16, ry - 8)

Render Order

When you need explicit control over the top-to-bottom ordering of rendered elements, you should use layers. As stated in the createLayer documentation, each layer that is created within a script will be rendered on top of each previous layer, such that the first layer created appears at the bottom, while the last layer created appears at the top.

Shapes that live on the same layer do not offer as much control. Among the same type of shape, instances rendered later will appear on top of those rendered before, so if you add two boxes to a layer, the last box added will appear on top. However, the situation is more complex when mixing different shapes. For rendering efficiency, all instances of a shape type on the same layer are drawn at the same time. This means that all instances of one shape will appear below or above all instances of other shapes, regardless of the relative order in which they were added to the layer. Currently, the ordering is as follows, from top to bottom:

  • Text
  • Quads
  • Triangles
  • Lines
  • Circles
  • Rounded Boxes
  • Boxes
  • Beziers
  • Images

Thus, all boxes will always render below all circles on the same layer, and text on the same layer will appear on top of both. It is not possible to control this behavior, nor is it a good idea to rely on it, as it is subject to change. If you need to rely on something appearing in front of something else, you should use multiple layers.

Additional Functions

Additional funcionality is provided in the rslib.lua library in your Dual Universe\Game\data\lua directory, accessible by calling local rslib = require('rslib').

Lua calls available within the screen renderer environment:

  • Libraries
    • table
    • string
    • math
  • Functions
    • next
    • select
    • pairs
    • ipairs
    • type
    • tostring
    • tonumber
    • pcall
    • xpcall
    • assert
    • error
    • require
    • load
    • setmetatable
    • getmetatable

See also:

Functions

addBezier (layer, x1, y1, x2, y2, x3, y3) Add a quadratic bezier curve to the given layer.
addBox (layer, x, y, width, height) Add a rectangle to the given layer with top-left corner (x,y) and dimensions width x height.
addBoxRounded (layer, x, y, width, height, radius) Add a rectangle to the given layer with top-left corner (x,y) and dimensions width x height with each corner rounded to radius.
addCircle (layer, x, y, radius) Add a circle to the given layer with center (x, y) and radius radius.
addImage (layer, image, x, y, width, height) Add image reference to layer as a rectangle with top-left corner x, y) and dimensions width x height.
addImageSub (layer, image, x, y, sx, sy, subX, subY, subSx, subSy) Add image reference to layer as a rectangle with top-left corner x, y) and dimensions width x height.
addLine (layer, x1, y1, x2, y2) Add a line to layer from (x1, y1) to (x2, y2).
addQuad (layer, x1, y1, x2, y2, x3, y3, x4, y4) Add a quadrilateral to the given layer with vertices (x1, y1), (x2, y2), (x3, y3), (x4, y4).
addText (layer, font, text, x, y) Add text to layer using font, with top-left baseline starting at (x, y).
addTriangle (layer, x1, y1, x2, y2, x3, y3) Add a triangle to the given layer with vertices (x1, y1), (x2, y2), (x3, y3).
createLayer () Create a new layer that will be rendered on top of all previously-created layers.
setLayerClipRect (layer, x, y, sx, sy) Set a clipping rectangle applied to the layer as a whole.
setLayerOrigin (layer, x, y) Set the transform origin of a layer; layer scaling and rotation are applied relative to this origin.
setLayerRotation (layer, rotation) Set a rotation applied to the layer as a whole, relative to the layer's transform origin.
setLayerScale (layer, sx, sy) Set a scale factor applied to the layer as a whole, relative to the layer's transform origin.
setLayerTranslation (layer, tx, ty) Set a translation applied to the layer as a whole.
getCursor () Return the screen location that is currently raycasted by the player in screen pixel coordinates as a (x, y) tuple.
getCursorDown () Return true if the mouse cursor is currently pressed down on the screen, false otherwise.
getCursorPressed () Return true if the mouse button changed from being released to being pressed at any point since the last update.
getCursorReleased () Return true if the mouse button changed from being pressed to being released at any point since the last update.
getDeltaTime () Returns the time, in seconds, since the screen was last updated.
getTime () Returns the time, in seconds, relative to the first execution.
getLocale () Return the locale in which the game is currently running.
getRenderCost () Return the current render cost of the script thus far, used to profile the performance of a screen.
getRenderCostMax () Return the maximum render cost limit.
getResolution () Return the current viewport resolution as a (width, height) tuple.
logMessage (message) Write message to the Lua chat if the output checkbox is checked.
loadImage (path) Return an image handle that can be used with addImage.
isImageLoaded (imageHandle) Returns true if the given imageHandle is loaded.
getImageSize (image) Returns the width and height of an image.
getAvailableFontCount () Returns the number of fonts available to be used by render script.
getAvailableFontName (index) Returns the name of the nth available font.
loadFont (name, size) Return a font handle that can be used with addText.
isFontLoaded (font) Deprecated: Returns true if the given font is loaded.
getTextBounds (font, text) Compute and return the bounding box width and height of the given text in the given font as a (width, height) tuple.
getFontMetrics (font) Compute and return the ascender and descender height of given font.
getFontSize (font) Return the currently-set size for the given font.
setFontSize (font, size) Set the size at which a font will render.
requestAnimationFrame (frames) Notify the screen manager that this screen should be redrawn in frames frames.
setBackgroundColor (r, g, b) Set the background color of the screen as red (r), green (g), blue (b) in the range [0, 1].
setDefaultFillColor (layer, shapeType, r, g, b, a) Set the default fill color for all shapeType on layer.
setDefaultRotation (layer, shapeType, radians) Set the default rotation for all shapeType on layer.
setDefaultShadow (layer, shapeType, radius, r, g, b, a) Set the default shadow for all shapeType on layer with size radius.
setDefaultStrokeColor (layer, shapeType, r, g, b, a) Set the default stroke color for all shapeType on layer.
setDefaultStrokeWidth (layer, shapeType, width) Set the default stroke width for all shapeType on layer.
setDefaultTextAlign (layer, alignH, alignV) Set the default text alignment of all subsequent text strings on the given layer.
setNextFillColor (layer, r, g, b, a) Set the fill color of the next rendered shape on layer.
setNextRotation (layer, radians) Set the rotation of the next rendered shape on layer.
setNextRotationDegrees (layer, degrees) Set the rotation of the next rendered shape on layer.
setNextShadow (layer, radius, r, g, b, a) Set the shadow of the next rendered shape on layer with size radius.
setNextStrokeColor (layer, r, g, b, a) Set the stroke color of the next rendered shape on layer.
setNextStrokeWidth (layer, width) Set the stroke width of the next rendered shape on layer.
setNextTextAlign (layer, alignH, alignV) Set the next text alignment for the next rendered shape on layer.
getInput () Return a string of input data (or an empty string, if no input has been set) that can be set via a control unit with the screen unit API function screen.setScriptInput(inputString).
setOutput (outputString) Set the script's output string to outputString, which can be retrieved via a control unit with the screen unit API function screen.getScriptOuput()

Tables

Shape Shape constants for shapeType.
AlignH Horizontal alignment constants for alignH.
AlignV Vertical alignment constants for alignV.


Functions

addBezier (layer, x1, y1, x2, y2, x3, y3)
Add a quadratic bezier curve to the given layer.

Supported properties: shadow, strokeColor, strokeWidth

Parameters:

  • layer int The id of the layer to which to add.
  • x1 float X coordinate of the first point of the curve (the starting point).
  • y1 float Y coordinate of the first point of the curve (the starting point).
  • x2 float X coordinate of the second point of the curve (the control point).
  • y2 float Y coordinate of the second point of the curve (the control point).
  • x3 float X coordinate of the third point of the curve (the ending point).
  • y3 float Y coordinate of the third point of the curve (the ending point).
addBox (layer, x, y, width, height)
Add a rectangle to the given layer with top-left corner (x,y) and dimensions width x height.

Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth

Parameters:

  • layer int The id of the layer to which to add.
  • x float The x coordinate (in pixels) of the left side of the box.
  • y float The y coordinate (in pixels) of the top side of the box.
  • width float The width of the box in pixels.
  • height float The height of the box in pixels.
addBoxRounded (layer, x, y, width, height, radius)
Add a rectangle to the given layer with top-left corner (x,y) and dimensions width x height with each corner rounded to radius.

Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth

Parameters:

  • layer int The id of the layer to which to add.
  • x float The x coordinate (in pixels) of the left side of the box.
  • y float The y coordinate (in pixels) of the top side of the box.
  • width float The width of the box in pixels.
  • height float The height of the box in pixels.
  • radius float The corner radius of the box in pixels.
addCircle (layer, x, y, radius)
Add a circle to the given layer with center (x, y) and radius radius.

Supported properties: fillColor, shadow, strokeColor, strokeWidth

Parameters:

  • layer int The id of the layer to which to add.
  • x float The x coordinate (in pixels) of the center of the circle.
  • y float The y coordinate (in pixels) of the center of the circle.
  • radius float The radius of the circle in pixels.
addImage (layer, image, x, y, width, height)
Add image reference to layer as a rectangle with top-left corner x, y) and dimensions width x height.

Supported properties: fillColor, rotation

Parameters:

  • layer int The id of the layer to which to add.
  • image int The handle for the image to add.
  • x float The x coordinate (in pixels) of the image's top-left corner.
  • y float The y coordinate (in pixels) of the image's top-left corner.
  • width float The width of the image in pixels.
  • height float The height of the image in pixels.

See also:

addImageSub (layer, image, x, y, sx, sy, subX, subY, subSx, subSy)
Add image reference to layer as a rectangle with top-left corner x, y) and dimensions width x height.

Supported properties: fillColor, rotation

Parameters:

  • layer int The id of the layer to which to add.
  • image int The id of the image to add.
  • x float The x coordinate (in pixels) of the image's top-left corner.
  • y float The y coordinate (in pixels) of the image's top-left corner.
  • sx float Width of the image.
  • sy float Height of the image.
  • subX float X coordinate of the top-left corner of the sub-region to draw.
  • subY float Y coordinate of the top-left corner of the sub-region to draw.
  • subSx float Width of the sub-region within the image to draw.
  • subSy float Height of the sub-region within the image to draw.

See also:

addLine (layer, x1, y1, x2, y2)
Add a line to layer from (x1, y1) to (x2, y2).

Supported properties: rotation, shadow, strokeColor, strokeWidth

Parameters:

  • layer int The id of the layer to which to add.
  • x1 float The x coordinate (in pixels) of the start of the line.
  • y1 float The y coordinate (in pixels) of the start of the line.
  • x2 float The x coordinate (in pixels) of the end of the line.
  • y2 float The y coordinate (in pixels) of the end of the line.
addQuad (layer, x1, y1, x2, y2, x3, y3, x4, y4)
Add a quadrilateral to the given layer with vertices (x1, y1), (x2, y2), (x3, y3), (x4, y4).

Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth

Parameters:

  • layer int The id of the layer to which to add.
  • x1 float The x coordinate (in pixels) of the first corner.
  • y1 float The y coordinate (in pixels) of the first corner.
  • x2 float The x coordinate (in pixels) of the second corner.
  • y2 float The y coordinate (in pixels) of the second corner.
  • x3 float The x coordinate (in pixels) of the third corner.
  • y3 float The y coordinate (in pixels) of the third corner.
  • x4 float The x coordinate (in pixels) of the final corner.
  • y4 float The y coordinate (in pixels) of the final corner.
addText (layer, font, text, x, y)
Add text to layer using font, with top-left baseline starting at (x, y). Note that each glyph in text counts as one shape toward the total rendered shape limit.

Supported properties: fillColor, shadow, strokeColor, strokeWidth, textAlign

Parameters:

  • layer int The id of the layer to which to add.
  • font int The id of the font to use.
  • text string The text to add.
  • x float The x coordinate (in pixels) of the top-left baseline.
  • y float The y coordinate (in pixels) of the top-left baseline.

See also:

addTriangle (layer, x1, y1, x2, y2, x3, y3)
Add a triangle to the given layer with vertices (x1, y1), (x2, y2), (x3, y3).

Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth

Parameters:

  • layer int The id of the layer to which to add.
  • x1 float The x coordinate (in pixels) of the first corner.
  • y1 float The y coordinate (in pixels) of the first corner.
  • x2 float The x coordinate (in pixels) of the second corner.
  • y2 float The y coordinate (in pixels) of the second corner.
  • x3 float The x coordinate (in pixels) of the third corner.
  • y3 float The y coordinate (in pixels) of the third corner.
createLayer ()
Create a new layer that will be rendered on top of all previously-created layers.

Returns:

    int The id that can be used to uniquely identify the layer for use with other API functions.
setLayerClipRect (layer, x, y, sx, sy)
Set a clipping rectangle applied to the layer as a whole. Layer contents that fall outside the clipping rectangle will not be rendered, and those that are partially within the rectangle will be 'clipped' against it. The clipping rectangle is applied before layer transformations. Note that clipped contents still count toward the render cost.

Parameters:

  • layer int The id of the layer for which the clipping rectangle will be set.
  • x float The X coordinate of the clipping rectangle's top-left corner.
  • y float The Y coordinate of the clipping rectangle's top-left corner.
  • sx float The width of the clipping rectangle.
  • sy float The height of the clipping rectangle.
setLayerOrigin (layer, x, y)
Set the transform origin of a layer; layer scaling and rotation are applied relative to this origin.

Parameters:

  • layer int The id of the layer for which the origin will be set.
  • x float The X coordinate of the layer's transform origin.
  • y float The Y coordinate of the layer's transform origin.
setLayerRotation (layer, rotation)
Set a rotation applied to the layer as a whole, relative to the layer's transform origin.

Parameters:

  • layer int The id of the layer for which the rotation will be set.
  • rotation float Rotation, in radians; positive is counter-clockwise, negative is clockwise.
setLayerScale (layer, sx, sy)
Set a scale factor applied to the layer as a whole, relative to the layer's transform origin. Scale factors are multiplicative, so that a scale >1 enlarges the size of the layer, 1.0 does nothing, and <1 reduces the size of the layer.

Parameters:

  • layer int The id of the layer for which the scale factor will be set.
  • sx float The scale factor along the X axis.
  • sy float The scale factor along the Y axis.
setLayerTranslation (layer, tx, ty)
Set a translation applied to the layer as a whole.

Parameters:

  • layer int The id of the layer for which the translation will be set.
  • tx float The translation along the X axis.
  • ty float The translation along the Y axis.
getCursor ()
Return the screen location that is currently raycasted by the player in screen pixel coordinates as a (x, y) tuple. Returns (-1, -1) if the current raycasted location is not inside the screen.

Returns:

    float,float The mouse (x, y) in pixels.
getCursorDown ()
Return true if the mouse cursor is currently pressed down on the screen, false otherwise. Retains its state if dragged out of the screen.

Returns:

    boolean True if the mouse is pressed on the screen, false otherwise.
getCursorPressed ()
Return true if the mouse button changed from being released to being pressed at any point since the last update. Note that it is possible for both getCursorPressed() and getCursorReleased() to return true in the same script execution, if the mouse button was both pressed and released since the last execution.

Returns:

    boolean True if the mouse was pressed since the last update, false otherwise.

See also:

getCursorReleased ()
Return true if the mouse button changed from being pressed to being released at any point since the last update. Note that it is possible for both getCursorPressed() and getCursorReleased() to return true in the same script execution, if the mouse button was both pressed and released since the last execution.

Returns:

    boolean True if the mouse was released since the last update, false otherwise.

See also:

getDeltaTime ()
Returns the time, in seconds, since the screen was last updated. Useful for timing-based animations, since screens are not guaranteed to be updated at any specific time interval, it is more reliable to update animations based on this timer than based on a frame counter.

Returns:

    float Time since last refresh in seconds.
getTime ()
Returns the time, in seconds, relative to the first execution.

Returns:

    float Time, in seconds, since the render script started running.
getLocale ()
Return the locale in which the game is currently running.

Returns:

    string The locale, currently one of "en-US", "fr-FR", or "de-DE".
getRenderCost ()
Return the current render cost of the script thus far, used to profile the performance of a screen. This can be used to abort further render instructions when close to the render maximum preventing the screen from shutting down.

Returns:

    int The current render cost.
getRenderCostMax ()
Return the maximum render cost limit. When a script exceeds this render cost in one execution, an error will be thrown and the contents will fail to render.

Returns:

    int The render cost limit.
getResolution ()
Return the current viewport resolution as a (width, height) tuple.

Returns:

    int,int resolution The resolution in the form of (width, height).
logMessage (message)
Write message to the Lua chat if the output checkbox is checked.

Parameters:

  • message string The message to print.
loadImage (path)
Return an image handle that can be used with addImage. If the image is not yet loaded, a sentinel value will be returned that will cause addImage to fail silently, so that the rendered image will not appear until it is loaded. Only images that have gone through image validation are available.

Parameters:

  • path string The path to the image to load.

Returns:

    int The handle to the newly loaded image.

See also:

isImageLoaded (imageHandle)
Returns true if the given imageHandle is loaded.

Parameters:

  • imageHandle int An image handle provided by loadImage.

Returns:

    boolean True if loaded, false otherwise.

See also:

getImageSize (image)
Returns the width and height of an image.

Parameters:

  • image int The id of the image to query.

Returns:

    float,float A tuple containing the width and height, respectively, of the image, or (0, 0) if the image is not yet loaded.
getAvailableFontCount ()
Returns the number of fonts available to be used by render script.

Returns:

    int The total number of fonts available.
getAvailableFontName (index)
Returns the name of the nth available font.

Parameters:

Returns:

    string The name of the font, which can be used with the loadFont function.
loadFont (name, size)
Return a font handle that can be used with addText. If the font is not yet loaded, a sentinel value will be returned that will cause addText to fail silently, so that the rendered text will not appear until the font is loaded.

Name must be one of the following currently-available fonts:

  • FiraMono
  • FiraMono-Bold
  • Montserrat
  • Montserrat-Bold
  • Montserrat-Light
  • Play
  • Play-Bold
  • RefrigeratorDeluxe
  • RefrigeratorDeluxe-Light
  • RobotoCondensed
  • RobotoMono
  • RobotoMono-Bold

Parameters:

  • name string The name of the font to load, chosen from the above list.
  • size float The size, in vertical pixels, at which the font will render. Note that this size can be changed during script execution with the setFontSize function.

Returns:

    int The id that can be used to uniquely identify the font for use with other API functions.

See also:

isFontLoaded (font)
Deprecated: Returns true if the given font is loaded.

Parameters:

  • font int A font handle provided by load font.

Returns:

    boolean True if loaded, false otherwise.

See also:

getTextBounds (font, text)
Compute and return the bounding box width and height of the given text in the given font as a (width, height) tuple.

Parameters:

  • font int A font handle provided by load font.
  • text string The text to calculate bounds for.

Returns:

    float,float The text bounds as (width, height) in pixels.

See also:

getFontMetrics (font)
Compute and return the ascender and descender height of given font.

Parameters:

  • font int The id of the font to query.

Returns:

    float,float A tuple containing the maximal ascender and descender, respectively, of the given font.

See also:

getFontSize (font)
Return the currently-set size for the given font.

Parameters:

  • font int The id of the font to query.

Returns:

    float The font size in vertical pixels.
setFontSize (font, size)
Set the size at which a font will render. Impacts all subsequent font-related calls, including addText, getFontMetrics, and getTextBounds.

Parameters:

  • font int The id of the font for which the size will be set.
  • size int The new size, in vertical pixels, at which the font will render.
requestAnimationFrame (frames)
Notify the screen manager that this screen should be redrawn in frames frames. A screen that requires highly-fluid animations should thus call requestAnimationFrame(1) before it returns.

Usage of this function has an obvious and significant performance impact on the screen unit system. Scripts should try to request updates as infrequently as possible for their application. A screen with unchanging (static) contents should not call this function at all.

Parameters:

  • frames int The number of frames to wait before redrawing the screen.
setBackgroundColor (r, g, b)
Set the background color of the screen as red (r), green (g), blue (b) in the range [0, 1].

Parameters:

  • r float The red component, between 0 and 1.
  • g float The green component, between 0 and 1.
  • b float The blue component, between 0 and 1.
setDefaultFillColor (layer, shapeType, r, g, b, a)
Set the default fill color for all shapeType on layer. Red (r), green (g), blue (b), and alpha (a) components are specified, respectively, in the range [0, 1]. Has no effect on shapes that don't support the fillColor property.

Parameters:

  • layer int The id of the layer for which the default will be set.
  • shapeType int The type of Shape to which the default will apply.
  • r float The red component, between 0 and 1.
  • g float The green component, between 0 and 1.
  • b float The blue component, between 0 and 1.
  • a float The alpha component, between 0 and 1.

See also:

setDefaultRotation (layer, shapeType, radians)
Set the default rotation for all shapeType on layer. Rotation is specified in CCW radians radians. Has no effect on shapes that don't support the rotation property.

Parameters:

  • layer int The id of the layer for which the default will be set.
  • shapeType int The type of Shape to which the default will apply.
  • radians float Rotation, in radians; positive is counter-clockwise, negative is clockwise.

See also:

setDefaultShadow (layer, shapeType, radius, r, g, b, a)
Set the default shadow for all shapeType on layer with size radius. Red (r), green (g), blue (b), and alpha (a) components are specified, respectively, in the range [0, 1]. Has no effect on shapes that don't support the shadow property.

Parameters:

  • layer int The id of the layer for which the default will be set.
  • shapeType int The type of Shape to which the default will apply.
  • radius float The distance that the shadow extends from the shape's border.
  • r float The red component, between 0 and 1.
  • g float The green component, between 0 and 1.
  • b float The blue component, between 0 and 1.
  • a float The alpha component, between 0 and 1.

See also:

setDefaultStrokeColor (layer, shapeType, r, g, b, a)
Set the default stroke color for all shapeType on layer. Red (r), green (g), blue (b), and alpha (a) components are specified, respectively, in the range [0, 1]. Has no effect on shapes that don't support the strokeColor property.

Parameters:

  • layer int The id of the layer for which the default will be set.
  • shapeType int The shape to apply this default to. Must be a built in constant from Shape.
  • r float The red component, between 0 and 1.
  • g float The green component, between 0 and 1.
  • b float The blue component, between 0 and 1.
  • a float The alpha component, between 0 and 1.

See also:

setDefaultStrokeWidth (layer, shapeType, width)
Set the default stroke width for all shapeType on layer. Width is specified in pixels. Positive values produce an outer stroke, while negative values produce an inner stroke. Has no effect on shapes that don't support the strokeWidth property.

Parameters:

  • layer int The id of the layer for which the default will be set.
  • shapeType int The type of Shape to which the default will apply.
  • width float Stroke width, in pixels.

See also:

setDefaultTextAlign (layer, alignH, alignV)
Set the default text alignment of all subsequent text strings on the given layer.

Parameters:

  • layer int The id of the layer for which the default will be set.
  • alignH int Controls the horizontal alignment of a text shape relative to the draw coordinates. Must be a built in constant from AlignH.
  • alignV int Controls the vertical alignment of a text shape relative to the draw coordinates. Must be a built in constant from AlignV.

See also:

setNextFillColor (layer, r, g, b, a)
Set the fill color of the next rendered shape on layer. Red (r), green (g), blue (b), and alpha (a) components are specified, respectively, in the range [0, 1]. Has no effect on shapes that don't support the fillColor property.

Parameters:

  • layer int The handle for the layer to apply this property to.
  • r float The red component, between 0 and 1.
  • g float The green component, between 0 and 1.
  • b float The blue component, between 0 and 1.
  • a float The alpha component, between 0 and 1.
setNextRotation (layer, radians)
Set the rotation of the next rendered shape on layer. Rotation is specified in CCW radians. Has no effect on shapes that don't support the rotation property.

Parameters:

  • layer int The handle for the layer to apply this property to.
  • radians float The angle (in radians) to rotate by.

See also:

setNextRotationDegrees (layer, degrees)
Set the rotation of the next rendered shape on layer. Rotation is specified in CCW degrees. Has no effect on shapes that don't support the rotation property.

Parameters:

  • layer int The handle for the layer to apply this property to.
  • degrees float The angle (in degrees) to rotate by.

See also:

setNextShadow (layer, radius, r, g, b, a)
Set the shadow of the next rendered shape on layer with size radius. Red (r), green (g), blue (b), and alpha (a) components are specified, respectively, in the range [0, 1]. Has no effect on shapes that don't support the shadow property.

Parameters:

  • layer int The handle for the layer to apply this property to.
  • radius float The radius of the shadow.
  • r float The red component, between 0 and 1.
  • g float The green component, between 0 and 1.
  • b float The blue component, between 0 and 1.
  • a float The alpha component, between 0 and 1.
setNextStrokeColor (layer, r, g, b, a)
Set the stroke color of the next rendered shape on layer. Red (r), green (g), blue (b), and alpha (a) components are specified, respectively, in the range [0, 1].

Parameters:

  • layer int The handle for the layer to apply this property to.
  • r float The red component, between 0 and 1.
  • g float The green component, between 0 and 1.
  • b float The blue component, between 0 and 1.
  • a float The alpha component, between 0 and 1.
setNextStrokeWidth (layer, width)
Set the stroke width of the next rendered shape on layer. Width is specified in pixels. Positive values produce an outer stroke, while negative values produce an inner stroke. Has no effect on shapes that don't support the strokeWidth property.

Parameters:

  • layer int The handle for the layer to apply this property to.
  • width float The width of the stroke in pixels.
setNextTextAlign (layer, alignH, alignV)
Set the next text alignment for the next rendered shape on layer.

Note that there is a subtle difference between AlignV_Ascender/AlignV_Descender and AlignV_Top/AlignV_Bottom: the ascender and descender alignment modes anchor a text string to a global top/bottom position of the font, while the top and bottom alignment modes anchor a text string relative to its own bounding box. Thus, while top/bottom are useful for aligning individual text strings with high precision, they depend on the contents of the text string that is rendered. On the other hand, ascender/descender align text in such a way that the alignment will not change depending on the text string. The correct choice will depend on your specific use case and needs.

Parameters:

  • layer int The id of the layer to apply this property to.
  • alignH int Controls the horizontal alignment of a text shape relative to the draw coordinates. Must be a built in constant from AlignH.
  • alignV int Controls the vertical alignment of a text shape relative to the draw coordinates. Must be a built in constant from AlignV.

See also:

getInput ()
Return a string of input data (or an empty string, if no input has been set) that can be set via a control unit with the screen unit API function screen.setScriptInput(inputString).

Returns:

    string The input string set by the control unit.

See also:

setOutput (outputString)
Set the script's output string to outputString, which can be retrieved via a control unit with the screen unit API function screen.getScriptOuput()

Parameters:

  • outputString string The string to output to the control unit.

See also:

Tables

Shape
Shape constants for shapeType. Used to set default properties by shape.

Note: These are constants defined directly in the screen renderer, the grouping in a table is for documentation purposes only.

Fields:

  • Shape_Bezier
  • Shape_Box
  • Shape_BoxRounded
  • Shape_Circle
  • Shape_Image
  • Shape_Line
  • Shape_Polygon Applies to both Triangle and Quad.
  • Shape_Text
AlignH
Horizontal alignment constants for alignH. Used by setNextTextAlign.

Note: These are constants defined directly in the screen renderer, the grouping in a table is for documentation purposes only.

Fields:

  • AlignH_Left (Default) Align to the start of the text.
  • AlignH_Center Align to the middle of the text.
  • AlignH_Right Align to the end of the text.
AlignV
Vertical alignment constants for alignV. Used by setNextTextAlign.

Note: These are constants defined directly in the screen renderer, the grouping in a table is for documentation purposes only.

Fields:

  • AlignV_Ascender Align to top of ascender.
  • AlignV_Top Align to height of capital characters.
  • AlignV_Middle Align to middle of characters.
  • AlignV_Baseline (Default) Align to text baseline.
  • AlignV_Bottom
  • AlignV_Descender Align to bottom of descender.
generated by LDoc 1.5.0 Last updated 2024-09-27 15:22:47