xstart Script API 0.3.1

> GLOBAL

> Object

> Array

> List

> Map

> File

> Date

> Data

> XMLDocument

> XMLNode

> Frame

> Event

> Handler

> Node

> NodeEx

> Texture

> Canvas

> Text

> Mesh

> Box

> Shader

> Framebuffer

> Recorder

> Bitmap

> Font

> Vector

> Color

> Rect

> Detector

> Socket

> Listener

> HttpServer

> AudioDevice

> AudioDeviceInfo

> AudioFile

> AudioFilter

> AudioPitch

> AudioDelay

> Video

> Midi

> Sound

> Serial

> ADDevice

> Dmx

> Camera


GLOBAL

GLOBAL

Functions:

version

string version()

Returns the version string.

exit

exit()

Terminates the program immediately.

throw

throw((optional) string message)

Throws a script error.

ascii

string ascii(int ascii)

Returns the string character for the given ascii code number.

system

string system(string command)

Executes a command and redirects output via pipe so you can catch the output of the command.

start

bool start(string command)

Executes a command without waiting for it to finish, thus returning immediately.

random

float (or) int random( (optional) float (or) int max)

Returns a random number between 0 and 'max', including 'max'. For example: random(2) may give 0, 1 or 2. If 'max' is a floating point number, the result is a floating point number too, otherwise its an integer.

time

float time((optional) float time)

Gets or sets the internal timer (in seconds).

print

print(string)

Outputs the string on the console, no newline is added.

println

println(string)

Outputs the string on the console, a newline is added.

log

log(string message)

Writes a log message to the console.

warning

warning(string error)

Reports a warning on the console.

error

error(string error)

Reports a error on the console.

fatal

fatal(string error)

Reports a fatal error on the console and terminates the program immediately!

popup

popup(string info)

Opens a message box with the given information.

ask

string ask(string question)

Prompts the user for a line of input on the console.

redirect

redirect(string file)

Redirects the console output to a file of the given name.

load

string get(string key)

Loads a config string from 'config.ini'.

save

save(string key, string value)

Saves a config string into 'config.ini'. If it does not exist, the file will be created.

instance

object instance(string class)

Creates an instance from a class type name. Used for introspection.

markdown

markdown(string fileIn, string fileOut)

Loads a markdown file and saves the HTML to another file.

pause

pause( float s)

Pauses the execution of the whole process for the given time in seconds. Reduces CPU usage of real-time applications.

eval

eval(string code)

Execute given code on the same script context, meaning, it has access to global functions and variables.

callstack

string callstack()

Returns the current callback as string.

debug

debug(int level)

Enable/Disable console debug messages.

colors

colors(int enable)

Enable/Disable console colors.

arg

string arg(int number)

Get command-line arguments.

sound

sound(string file)

Plays a sound file. (This is a simple and inefficient way to play a sound file)

askFile

string askFile()

Opens a dialog where the user can select a file.

monitor

Rect monitor(int index)

Gets the rectangle area of the given monitor in virtual screen space.

yield

yield()

Gives control to the script-runtime and the next thread/coroutine. It is important to yield in a main-loop and in threads/coroutines otherwise the applications may not run correctly and garbage-collection will never take place.

sleep

sleep(float time)

Same as yield() but continues the current thread/coroutine only after the given time, effectively let the thread/coroutine sleep.

type

string type(any any)

Returns the name of the type of the given parameter.

format

string format(string format, ...)

Like printf() in C. Formats a string by using %d, %s, %f, %c, %b, %x, %e and multiple input parameters.

abs, floor, ceil, round, cos, sin, tan, acos, asin, deg2rad, rad2deg

float cos(float p)

Common math functions with one parameters.

sqrt, power, atan, atan2, log, min, max

float cos(float x, float y)

Common math functions two parameters.

clamp

float clamp(float min, float value, float max)

Returns the clamped value.

string.length

int string.length()

Returns the length of the given string, use dot notation on the string: local len = myString.length();

string.upper

string string.upper()

Returns a upper case copy of the string, use dot notation on the string: local myUpper = myString.upper();

string.lower

string string.lower()

Returns a lower case copy of the string, use dot notation on the string: local myLower = myString.lower();

string.find

int string.find(string search, int startIndex)

Returns the index of the first occurance of the search-string or -1. Use dot notation on string to call this function.

string.getAt, string.setAt

string string.setAt(int index, int set)

Gets or sets the character at the given index. Use dot notation on string to call this function.

string.trimLeft, string.trimRight

string string.trimLeft(string str)

Returns a trimmed copy of original string. Use dot notation on string to call this function.


Object

Object((optional) string id)

Object base class. Like an object in JavaScript it has a user table for its members.

Functions:

string

string string()

Get a string representation of the object.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Array

Array((optional) string id)

Dynamic array class for storing a linear array of objects, native types or a mix of that.

Example:

ar = Array();
ar.add("A");
ar.add("B");
ar.add(3);
obj = ar.add("Four");

foreach(e in ar) {print(e + " "); }
print("\n"+obj+" is at index "+ar.find(obj)+"\n");

Functions:

string

string string()

Get a string representation of the object.

add

Object add(Object object)

Adds an object to the end of the array. The added object is returned.

remove

this remove(int index)

Removes the element at the given index from the array.

find

int find(Object object)

Finds the index of the given object, returns -1 if the object is not in the array.

length

int length()

Returns the length of the array.

parse

this parse(string json)

EXPERIMENTAL, UNFINISHED. Parses a JSON representation to an object.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


List

List((optional) string id)

Double linked list for fast insertion and removal of objects or natives.

Example:

global l = List();

l.push(1);
l.push(2);
l.push("abc");
l.push(12.3);
l.push(45.5);
l.pop();
log("removed: "+l.remove(1));
log("");
log("count:  "+l.count());
log("first:  "+l.first());
log("last:   "+l.last());
log("1:      "+l[1]);
log("");

foreach(e in l) { log(""+e); }

Functions:

string

string string()

Get a string representation of the object.

count

int count()

Counts number of items in the list.

clear

this clear()

Clears the list by removing all items from the list.

first

Object first()

Gets the first item from the list.

last

Object last()

Gets the last item from the list.

pop

this pop()

Removes the first item from list.

popFirst

this popFirst()

Removes the first item from list.

popLast

this popLast()

Removes the last item from list.

remove

Object remove(int index)

Removes the item at the given index from list.

push

this push(Object object)

Pushes the given object at the end of the list.

pushBack

this pushBack(Object object)

Pushes the given object at the end of the list.

pushFront

this pushFront(Object object)

Pushes the given object at the start of the list.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Map

Map((optional) string id)

Map class for mapping a list of values and/or object to strings indices. Supports foreach iteration, the order of the insertions/changes is preserved. For convenience the dot . and index operators can be used to modify and add to the map.

Example:

m = Map();
m.set("this", "This!");
m.set("is", "IS!");
m.set("a", " A ");
m.set("test", "Test!");
m.set("number", 1.23);
m.set("a", null);

foreach(e in m) {
	print(" " + m[e]);
}

Functions:

string

string string()

Get a string representation of the object.

get

Object get(string key)

Gets the mapped object for the given key. If the key does not exist, the value null is returned.

set

this set(string key, object value)

Sets the value for the key or creates a new key with the given value. If value is null the given key is removed.

length

int length()

Returns the number of entries in the map.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


File

File((optional)string file, (optional)string mode="rb")

Opens a file for reading or writing.

Example:

// write a text to text.txt
File("test.txt","wb").write("Hello World!\n").close();

// read and print text
print(File("test.txt","rb").read());

Functions:

string

string string()

Get a string representation of the object.

open

this open(string fileName, string mode)

Opens a file in the given mode ("r" = read, "w" = write, "rb" = read binary, "wb" = write binary, "a" = append, "ab" = append binary).

close

close()

Closes the file. This is also done by garbage collecting the object.

write

this write(string data, (optional) int length)

Subject to change. Write string to file.

read

string read( (optional) int length)

Subject to change. Reads 'length' of bytes from file or the whole file if length is not specified.

exists

int exists(string fileName)

Checks if a given file name exists. Returns zero on failure or non-zero if the file exists.

delete

bool delete(string fileName)

Deletes the given file. Returns false only aif the file exists and can not be removed.

rename

bool rename(string source, string destination)

Renames a file.

seek

this seek(int position)

Moves the file cursor to the given position. No error checking performed.

tell

int tell()

Returns the current file cursor position.

size

int size()

Returns the file size in bytes.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int bytes

Number of bytes read by last read operation.


Date

Date((optional) string id)

Date and time conversion.

Example:

d = Date().now();
print("\nNow is " + d.format("%d %B %Y - %H:%M:%S (UTC)") + "\n");
ts = d.getUnix();
print("The current unix timestamp is " + ts + "\n");
d.setUnix(ts);
print("Now is " + d.format("%d %B %Y - %H:%M:%S (UTC)") + "\n\n");

d = Date().today();
print("Today is " + d.format("%d %B %Y - %H:%M:%S (UTC)") + "\n");
ts = d.getUnix();
print("The current unix timestamp is " + ts + "\n");
d.setUnix(ts);
print("Today is " + d.format("%d %B %Y - %H:%M:%S (UTC)") + "\n\n");

Functions:

string

string string()

Get a string representation of the object.

now

no help found

today

no help found

isExpired

no help found

getUnix

no help found

setUnix

no help found

adjust

no help found

format

no help found

parse

no help found

toHijri

no help found

toGregorian

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int year

int month

int day

int hour

int minute

int second


Data

Data((optional) string id)

Functions:

string

string string()

Get a string representation of the object.

loadRaw

this loadRaw(string file)

Loads the given file into data memory as is.

saveRaw

this saveRaw(string file)

Saves the data into a file as is.

appendRaw

this appendRaw(string file)

Appends the data to an existing file as is.

peek

int peek(int addr)

Reads a single byte from the given address.

poke

this poke(int addr, int value)

Writes a single byte to the given address.

resize

int resize(int newsize)

Resizes the data array length.

copyFrom

this copyFrom(Data source)

Makes a copy of the source data. Any old data in this object will be lost.

insert

this insert(Data source, int position)

Copies the source data to the given position. The data may be resized to fit the added content.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int size

(readonly) Size of data array.

bool loop

Set to true to wrap the read and write cursor when they reach the end of the stream.

int readCursor

Read cursor.

int writeCursor

Write cursor.


XMLDocument

XMLDocument((optional) string id)

XML document class.

Functions:

string

string string()

Get a string representation of the object.

load

no help found

save

no help found

toXML

no help found

setRoot

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

object root


XMLNode

XMLNode((optional) string id)

XML node class.

Functions:

string

string string()

Get a string representation of the object.

add

Object add(Object object)

Adds an object to the end of the array. The added object is returned.

remove

this remove(int index)

Removes the element at the given index from the array.

find

int find(Object object)

Finds the index of the given object, returns -1 if the object is not in the array.

length

int length()

Returns the length of the array.

parse

this parse(string json)

EXPERIMENTAL, UNFINISHED. Parses a JSON representation to an object.

getChild

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

string name

string content

int isCDATA

object attributes


Frame

Frame(string id, int pos_x, int pos_y, int width, int height, (optional) string color)

Window frame for rendering output. The frame uses a scene-graph to draw its content, see root member.

Functions:

string

string string()

Get a string representation of the object.

close

this close()

Closes the window. Please note that any textures, shaders and other assets may be internally destroyed if no other window has a valid context on these.

render

bool render()

Immediately renders the frames scene graph.

toggle

this toggle()

Toggles the frame from/to frameless mode.

cursor

this cursor(int show)

Shows or hides the cursor when its over the frame window.

setDimensions

this setDimensions(int width, int height)

(Experimental) Sets the virtual dimensions of the frame. If not set, the frames dimensions is used instead.

flip

no help found

select

no help found

clear

no help found

maximize

no help found

minimize

no help found

show

no help found

activate

no help found

getMultitouchCount

no help found

getMultitouchPoint

no help found

onClose

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

Node root

Scene graph node, initially set to an empty Node object, see Node.

float width

(Experimental) Virtual frame width.

float height

(Experimental) Virtual frame height.

int mirrorX

(Experimental) Set to non-zero Mirror screen horizontal.

int mirrorY

(Experimental) Set to non-zero Mirror screen vertically.


Event

Event((optional) string id)

Event object that is received by all events as the first parameter. Handler is the base class for all objects that can receive events. The id on this, is set to the event name.

Common events are: Close, MouseMove, MouseDown, MouseUp, MouseEnter, MouseLeave, KeyDown, KeyUp.
These are received by setting these event handlers on the receiver object: onClose, onMouseMove, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onKeyDown, onKeyUp. Mouse events are send to all elements under them, if an event handler returns true, the event is not send further down the scene-tree hierarchy - however, you should then avoid using sleep() or yield() in the event handler.

Example:

global eventHandler = function(e) {
	log("Frame: " + this.string() + " - Received event: "+e.string());
	log("    key: " + e.key + "   text: " + e.text + "  x: " + e.x + "  y: " + e.y + "  button: " + e.button + "\n");
	if(e.id == "Close") { exit(); }
};

frame = Frame("main", 50, 50, 640, 480, "#ffffff").toggle().cursor(true);
frame.root["texture"] = Texture("images/texture.png", 50, 50, 640-100, 480-100);
frame.root["texture"].onKeyDown = eventHandler;
frame.root["texture"].onKeyUp = eventHandler;
frame.root["texture"].onMouseDown = eventHandler;
frame.root["texture"].onMouseUp = eventHandler;
//frame.root["texture"].onMouseMove = eventHandler;
frame.root["texture"].onMouseEnter = eventHandler;
frame.root["texture"].onMouseLeave = eventHandler;

while(true) { frame.render(); yield(); }

Functions:

string

string string()

Get a string representation of the object.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

Object node

Receiving node of the event, this is set to the object on which the event was rised.

int key

For keyboard events, this is set to the keycode.

string text

EXPERIMENTAL Text representation of input key.

int button

For mouse events, this is set to the button index.

float x

For mouse move events, this is the mouse x-coordinate.

float y

For mouse move events, this is the mouse y-coordinate.

float prevX

For mouse move events, the previous mouse x-coordinate.

float prevY

For mouse move events, the previous mouse y-coordinate.


Handler

Handler((optional) string id)

MAY NOT BE OF USE IN SCRIPTS. Base class for all Node objects that receive events of type Event.

Functions:

string

string string()

Get a string representation of the object.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Node

Node((optional) string id, (optional) float pos_x, (optional) float pos_y, (optional) float width, (optional) float height)

Empty scene node.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z


NodeEx

NodeEx((optional) string id, (optional) float pos_x, (optional) float pos_y, (optional) float width, (optional) float height)

Generic extended scene node for shader support.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.


Texture

Texture((optional) string file, (optional) float pos_x, (optional) float pos_y, (optional) float width, (optional) float height), (optional) string clearColor

Texture node class.

Example:

global frame = Frame("main", 50, 50, 640, 480, "#ffffff").toggle().cursor(true);
frame.root["texture"] = Texture("images/earth-bg.jpg", 0, 0, 640, 480);
frame.root["texture"].onMouseDown = function(evt) { evt.node.rotate += 0.1; };

while(frame.render()) { yield(); }

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

setBitmap

int setBitmap(Bitmap bitmap)

no help found

getBitmap

Bitmap getBitmap()

no help found

load

this load(string file)

Loads an image file and uses it. Returns null on failure.

save

this save(string file

Saves the current content to a PNG image file.

create

int create(int width, int height)

(Re-)creates the texture with the given dimensions. Returns non-zero on success.

duplicate

Texture duplicate()

Creates and returns a duplicate of the texture. The returned texture object has its own texture memory.

clear

this clear((optional) string color)

Fills the texture with the given or set clear color.

pick

string pick(int x, int y)

Returns the color on the given texel position. The string has the format RRGGBBAA with hexadigital numbers. The Color can be used afterwards to translate or modify the color.

resize

this resize(int width, int height, (optional) int bilinear)

Resizes the texture to the given size. Optionally a bilinear filter applies. On some hardware & platform combinates (especially embedded hardware) the actual dimension may differ due to power-of-two and size restrictions.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.

string clearColor

Color that is used to clear or create the texture.

float opacity

Opacity of the texture while rendering.


Canvas

Canvas((optional) string file, (optional) float pos_x, (optional) float pos_y, (optional) float width, (optional) float height), (optional) string clearColor

A texture-based node object that can be drawn onto.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

setBitmap

int setBitmap(Bitmap bitmap)

no help found

getBitmap

Bitmap getBitmap()

no help found

load

this load(string file)

Loads an image file and uses it. Returns null on failure.

save

this save(string file

Saves the current content to a PNG image file.

create

int create(int width, int height)

(Re-)creates the texture with the given dimensions. Returns non-zero on success.

duplicate

Texture duplicate()

Creates and returns a duplicate of the texture. The returned texture object has its own texture memory.

clear

this clear()

Clears the canvas with the set clear color.

pick

string pick(int x, int y)

Returns the color on the given texel position. The string has the format RRGGBBAA with hexadigital numbers. The Color can be used afterwards to translate or modify the color.

resize

this resize(int width, int height, (optional) int bilinear)

Resizes the texture to the given size. Optionally a bilinear filter applies. On some hardware & platform combinates (especially embedded hardware) the actual dimension may differ due to power-of-two and size restrictions.

setSolid

this setSolid(string color)

Sets the fill and stroke colors to a solid color.

setLinear2

this setLinear2(string color1, string color2, (optional) float horizonalScale, (optional) float verticalScale)

Sets the fill and stroke colors to a linear color pattern, the direction is taken from the scale parameter.

newPath

this newPath()

no help found

closePath

this closePath()

no help found

fill

this fill()

Fills the last path with the set color or pattern.

stroke

this stroke(float lineWidth)

Outlines the last path with the set color or pattern.

moveTo

this moveTo(float x, float y)

Moves the path cursor to the given position.

lineTo

this lineTo(float x, float y)

Draws a line from the current position to the given position.

curveTo

this curveTo(float x1, float y1, float x2, float y2, float x3, float y3)

Draws a curve from the current position to the given position.

rectangle

this rectangle(float x, float y, float width, float height)

Draws a rectangle.

roundedRectangle

this roundedRectangle(float x, float y, float width, float height, float cornerRadius)

no help found

arc

this arc(float centerX, float centerY, float radius, float angle1, float angle2)

Draws an arc or a circle.

clear

this clear()

Clears the canvas with the set clear color.

drawText

this drawText(Font font, string text, int x, int y, string solidColor, (optional) int outlineWidth, (optional) string outlineColor)

Draws text on the canvas.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.

string clearColor

Color that is used to clear or create the texture.

float opacity

Opacity of the texture while rendering.


Text

Text(string text, string font, int x, int y, string color)

Text node class for font text rendering and caching.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

setBitmap

int setBitmap(Bitmap bitmap)

no help found

getBitmap

Bitmap getBitmap()

no help found

load

this load(string file)

Loads an image file and uses it. Returns null on failure.

save

this save(string file

Saves the current content to a PNG image file.

create

int create(int width, int height)

(Re-)creates the texture with the given dimensions. Returns non-zero on success.

duplicate

Texture duplicate()

Creates and returns a duplicate of the texture. The returned texture object has its own texture memory.

clear

this clear((optional) string color)

Fills the texture with the given or set clear color.

pick

string pick(int x, int y)

Returns the color on the given texel position. The string has the format RRGGBBAA with hexadigital numbers. The Color can be used afterwards to translate or modify the color.

resize

this resize(int width, int height, (optional) int bilinear)

Resizes the texture to the given size. Optionally a bilinear filter applies. On some hardware & platform combinates (especially embedded hardware) the actual dimension may differ due to power-of-two and size restrictions.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

string color

string clearColor

Color that is used to clear or create the texture.

float opacity

Opacity of the texture while rendering.

object font

string text

string color

int outline

int password

int passwordLength

string outlineColor


Mesh

Mesh((optional) string id, (optional) float pos_x, (optional) float pos_y, (optional) float width, (optional) float height)

3D mesh.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

loadObj

this loadObj(string file)

no help found

setPosition

this setPosition(int index, float x, float y, float z)

no help found

setTexCoord

this setTexCoord(int index, float u, float v, float w)

no help found

setNormal

this setNormal(int index)

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.

object texture

object texture0

object texture1

object texture2

object texture3


Box

Box(Texture texture, float width, float height)

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

loadObj

this loadObj(string file)

no help found

setPosition

this setPosition(int index, float x, float y, float z)

no help found

setTexCoord

this setTexCoord(int index, float u, float v, float w)

no help found

setNormal

this setNormal(int index)

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.

object texture

object texture0

object texture1

object texture2

object texture3


Shader

Shader(string vertexShaderFile, string fragmentShaderFile)

GLSL shader node class. All childs of this node are rendered with this shader. If active is set to zero all shaders are disabled at this point.

Example:

global DIM_X = 800;
global DIM_Y = 600;
global BLUR = 2;

global OnKeyDown = function(e) {
    global BLUR;
    log("key: "+e.key);
	if((e.key == 187 || e.key == 107 || e.key == 35 || e.key == 86) && BLUR < 5) { BLUR += 1; SHADER.setInt("FILTER_SIZE", BLUR); }
	if((e.key == 189 || e.key == 109 || e.key == 61 || e.key == 82) && BLUR > 0) { BLUR -= 1; SHADER.setInt("FILTER_SIZE", BLUR); }
	FRAME.root["info"].text = "Blur: "+BLUR;
};

global FRAME = Frame("Shader Example", 200, 100, DIM_X, DIM_Y).toggle().showCursor(true);
FRAME.onKeyDown = OnKeyDown;

global SHADER = Shader("shaders/basic.vs", "shaders/blur.fs");
SHADER.setInt("FILTER_SIZE", BLUR);
SHADER.setFloat2("FILTER_SCALE", 1.0 / DIM_X * 2.0, 1.0 / DIM_Y * 2.0);

FRAME.root["shader"] = SHADER;
FRAME.root["shader"]["image"] = Texture("images/earth-bg.jpg", 0, 0, DIM_X, DIM_Y);

FRAME.root["help"] = Text("Press + and - to adjust blur filter size.", Font("fonts/liberation/LiberationSerif-Bold.ttf", 20));
FRAME.root["info"] = Text("Blur: "+BLUR, Font("fonts/liberation/LiberationMono-Bold.ttf", 20), 0, 30);

while(1) {
    FRAME.render();
    yield();
}

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

load

int load(string vertexShaderFile, string fragmentShaderFile), (optional) int fromFiles

Loads the vertex and fragment shaders from the given files or directly from the strings (if the third parameter is set to zero). Returns non-zero on success.

setFloat

this setFloat(float x)

Sets float uniform in shader.

setFloat2

this setFloat2(float x, float y)

Sets float vec2 uniform in shader.

setFloat3

this setFloat3(float x, float y, float z)

Sets float vec3 uniform in shader.

setFloat4

this setFloat4(float x, float y, float z, float w)

Sets float vec4 uniform in shader.

setInt

this setInt(int n)

Sets integer uniform in shader.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

int active

Sets if the childs are rendered with or without this shader.


Framebuffer

Framebuffer((optional) string file, (optional) float pos_x, (optional) float pos_y, (optional) float width, (optional) float height), (optional) string clearColor

Framebuffer for off-screen, special-effects or capture rendering. All childs are rendered into the framebuffer. Then framebuffer itself can be then be rendered too.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

setBitmap

int setBitmap(Bitmap bitmap)

no help found

getBitmap

Bitmap getBitmap()

no help found

load

this load(string file)

Loads an image file and uses it. Returns null on failure.

save

this save(string file

Saves the current content to a PNG image file.

create

int create(int width, int height)

(Re-)creates the texture with the given dimensions. Returns non-zero on success.

duplicate

Texture duplicate()

Creates and returns a duplicate of the texture. The returned texture object has its own texture memory.

clear

this clear((optional) string color)

Fills the texture with the given or set clear color.

pick

string pick(int x, int y)

Returns the color on the given texel position. The string has the format RRGGBBAA with hexadigital numbers. The Color can be used afterwards to translate or modify the color.

resize

this resize(int width, int height, (optional) int bilinear)

Resizes the texture to the given size. Optionally a bilinear filter applies. On some hardware & platform combinates (especially embedded hardware) the actual dimension may differ due to power-of-two and size restrictions.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.

string clearColor

Color that is used to clear or create the texture.

float opacity

Opacity of the texture while rendering.

int enabled

Enables or disables framebuffer update. When disabled (enabled = false), updating and child-rendering is skipped and the current content is reused when rendering the node.


Recorder

Recorder((optional) string id, (optional) float pos_x, (optional) float pos_y, (optional) float width, (optional) float height)

A Recorder node can store a sequence of frames of its childs in a ringbuffer of textures. However, it must be noted that for realtime purpose, the storage is limited by the OpenGL texture memory.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Force this node to update its contents and states. May be needed if the node is changed by the script after initialization.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

save

this save(string folder

Saves the stored sequence into the given folder.

getFrame

Texture getFrame(int index)

Gets the Nth frame texture of the stored sequence.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

int numFrames

Number to frames in sequence to store.

int currentFrame

The current frame that gets rendered into.

int enabled

int record

Set to non-zero to record frames.

int recordWidth

Width of the record resolution.

int recordHeight

Height of the record resolution.


Bitmap

Bitmap(string imageFile)

The bitmap class can load, save, store and manipulate one bitmap image. This is NOT a scene node, consider using a Texture to render a bitmap. Bitmaps can transfer from and to Texture.

Functions:

string

string string()

Get a string representation of the object.

create

this create(int width, int height)

Creates a bitmap image or the given size.

load

int load(string file)

Loads the given image into the image bitmap. Width and height is taken from the image. If a different resolution is needed, the bitmap must be resized afterwards.

save

int save(string file)

Saves the bitmap as a PNG image.

clear

this clear(string color)

Clears the image with the given color.

flipX

this flipX()

Flips the bitmap image horizontally.

flipY

this flipY()

Flips the bitmap image vertically.

swapRB

this swapRB()

Swaps the red and blue components of all pixels in the bitmap. This might be useful for images captured by a camera, since captured images may have a BGRA format.

resize

this resize(int width, int height, int bilinear

no help found

duplicate

Bitmap duplicate()

Returns a duplicate of the whole bitmap as a new object.

cut

Bitmap cut(int x, int y, int width, int height)

Returns a copy of the given area.

paste

paste(Bitmap, int x, int y

Paste a given bitmap on the given coordinates.

softenEdge

softenEdge(int width)

Does a rectangular alpha-blending on the bitmap edges.

multiplyMask

multiply(Bitmap mask, float offset, float scale)

Multiplies the bitmap with the given bitmap mask.

saturateMask

saturateMask(Bitmap mask, float offset, float scale)

Changes saturation based on the given mask.

getWidth

int getWidth()

Gets the current width of the bitmap.

getHeight

int getHeight()

Gets the current height of the bitmap.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Font

Font(string fontFile, (optional) int fontSize), (optional) int righToLeft

Creates a font object for rendering text.

Functions:

string

string string()

Get a string representation of the object.

load

this load(string fontFile, int fontSize)

Loads the font file with the given font size.

measure

Vector measure(string text, (optional) int outlineWidth)

Measures the texture size of the text if rendered with this font. Only x and y of the Vector object will be set.

drawText

int drawText(Texture texture, string text, string color, int x, int y), (optional) int outlineWidth, string outlineColor

Subject to change. Draws a text directly in a given texture.

drawBitmap

Bitmap drawBitmap(Bitmap bitmap, string text, string color, int x, int y), (optional) int outlineWidth, string outlineColor

Subject to change. Draws a text directly in a given bitmap.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int rightToLeft


Vector

Vector((optional) float x, (optional) float y, (optional) float z) or (Vector copy)

3D vector class.

Functions:

string

string string()

Get a string representation of the object.

set

this set(float x, float y, float z

no help found

length

no help found

add

no help found

subtract

no help found

scale

no help found

divide

no help found

distance

no help found

normalize

no help found

normal

no help found

radians2D

no help found

rotate2D

no help found

cross2D

no help found

dot2D

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

float x

float y

float z


Color

Color((optional) string id)

Color class to help computatation and conversions. Individual values range from 0.0 to 1.0. YCbCr is full range.

Functions:

string

string string()

Get a string representation of the object.

fromStringRGBA

this fromStringRGBA(string rgba)

Parse a color string and save the values in the members r,g,b,a and y,cb,cr as floats.

toStringRGBA

string toStringRGBA()

Gets a string representation (#RRGGBBAA) of the stored r,g,b,a and a values.

updateYCbCrFromRGB

this updateYCbCr()

Updates the y,cb,cr values from the r,g,b values.

updateRGBFromYCbCr

this updateRGB()

Updates the r,g,b,a values from the y,cb,cr values.

updateHSVFromRGB

no help found

updateRGBFromHSV

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

float r

Red.

float g

Green.

float b

Blue.

float a

Alpha.

float y

Luma.

float cb

Blue difference chroma.

float cr

Red difference chroma.

float h

Hue.

float s

Saturation.

float v

Value.


Rect

Rect((optional) string id)

Object base class. Like an object in JavaScript it has a user table for its members.

Functions:

string

string string()

Get a string representation of the object.

enclose

no help found

set

no help found

hitTest

no help found

getWidth

no help found

getHeight

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

float left

float top

float right

float bottom


Detector

Detector((optional) string file)

Haar-Cascade detector. Can detect objects, persons, faces, etc. on a given bitmap image.

Example:

global FRAME = Frame("main", 0, 0, 640, 480, "#ff00ff").toggle().showCursor(true);
FRAME.onKeyDown = function(e) {   if(e.key == 'C') { e.sender.root["camera"].config(); }   };
FRAME.root["camera"] = Camera(0, 0, 0, 640, 480, 0);
FRAME.root["found"] = Texture("images/face_detect.png", 0,0, 0,0);

global DETECTOR = Detector("haar/haarcascade_frontalface_default.xml");

while(1) {
    FRAME.root["camera"].update();
	local numFindings = DETECTOR.detect(FRAME.root["camera"].snapshotBitmap().flipY().flipX(), 200);
	
	local i = 0;
	local finding = 0;
	FRAME.root["found"].visible = false;
	
	while(1) {
		finding = DETECTOR.getFinding(i);
		if(!finding) { break; }
		i += 1;
		
		FRAME.root["found"].x = finding.left;
		FRAME.root["found"].y = finding.top;
		FRAME.root["found"].width = finding.right - finding.left;
		FRAME.root["found"].height = finding.bottom - finding.top;
		
		FRAME.root["found"].visible = true;
	}
	
    FRAME.render();
	yield();
}

Functions:

string

string string()

Get a string representation of the object.

loadHaarCascade

int loadHaarCascade(sting file)

Loads a haar-cascade file.

detect

int detect(Bitmap bitmap, int minSize)

Run haar-cascade detection on the given bitmap. Returns the number of findings in the bitmap.

getFinding

Rect getFinding(int index)

Gets the finding with the given index. Returns a Rect object with the coordinates on the source bitmap.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Socket

Socket((optional) string id)

Socket class.

Functions:

string

string string()

Get a string representation of the object.

open

no help found

openUDP

no help found

close

no help found

send

no help found

receive

no help found

setTimeout

this setTimeout(int seconds)

Sets the timeout (in seconds) to wait for data while receiving. A value of 0 sets the socket to non-blocking.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

Data data

Received data buffer. You may use toString() on this to get a string representation.


Listener

Listener((optional) string id)

Listener class.

Functions:

string

string string()

Get a string representation of the object.

bind

no help found

bindUDP

no help found

listen

no help found

listenUDP

no help found

accept

no help found

receive

no help found

send

no help found

close

no help found

setTimeout

this setTimeout(int seconds)

Sets the timeout (in seconds) to wait for data while receiving. A value of 0 sets the socket to non-blocking.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

Data data

Received data buffer. You may use toString() on this to get a string representation.

string client

String of IP address of the last accepted client.


HttpServer

HttpServer(string port, (optional) string docroot, (optional) bool dirListing)

Spawns a HTTP server. Note that bindung to port 80 may need root privileges. It is neccessary to call the poll() method since there is no background thread handling the requests.

Example:

global SERVER = HttpServer("8080", ".", true);
SERVER.onRequest = function(url, get, post, auth) {
    if(auth != "xstart:asdf") { this.sendAuthRequest("Login"); return; }
    SERVER.sendFile();
};
SERVER._admin = function(url, get, post, auth) {
    if(auth != "xstart:asdf") { this.sendAuthRequest("Login"); return; }
    this.send("hi master");
};
SERVER._source = function(url, get, post, auth) {
    if(auth != "xstart:asdf") { this.sendAuthRequest("Login"); return; }
    SERVER.sendFile("httpserver.gm");
};
start("explorer http://127.0.0.1:8080/");
while(true) {
    SERVER.poll(1.0);
    yield();
}

Functions:

string

string string()

Get a string representation of the object.

poll

this poll(float timeoutSeconds)

Polls for incoming http requests.

onRequest

onRequest(string url, string get, string post, string auth)

Request handler/callback, the default request handler sends a 404 http error code to all request. Override this handler to your own logic.

sendFile

sendFile((optional)string file)

When called inside the request-handler, it send a file to the client. If the file parameter is omitted, it sends the requested file from the URI.

send

this send(string data)

When called inside the request-handler, it sends a string back to the client.

send404

this send404()

When called inside the request-handler, it sends a a 404 error back to the client.

sendAuthRequest

this sendAuthRequest(string message)

When called inside the request-handler, it sends a authorizsation request ('401 Access Denied') back to the client.

parseForm

Map parseForm(string getOrPostVars)

Parses vars in an get or post string to a Map object.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


AudioDevice

AudioDevice(int sampleRate, int channels, int bufferSize, int deviceInIndex, int deviceOutIndex)

Audio device for recording, playing and processing audio.

Example:

// enumerate audio devices
global ADEVICE_ENUM = AudioDeviceInfo();
for(i=0; true; i+=1) {
	ADEVICE_ENUM.getDevice(i);
	if(ADEVICE_ENUM.index == -1) { break; }
	log("Found audio-device: "+ADEVICE_ENUM.name);
}

// play some sound
global DEVICE = AudioDevice(22050, 2, 512, -1, 3);
global SOUND = AudioFile("misc/snap.wav").convert(22050,16);
DEVICE.play(SOUND);
sleep(2.0);
DEVICE.close();

Functions:

string

string string()

Get a string representation of the object.

open

this open(int sampleRate, int channels, int bufferSize, int deviceInIndex, int deviceOutIndex)

Opens the audio device with the given settings. If the device is already open it will be closed first.

close

this close()

Closes the audio device.

pause

this pause()

Pauses the audio stream.

unpause

this unpause()

Unpauses the audio stream.

play

this play(AudioData source)

no help found

stop

this stop(AudioData buffer

no help found

process

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

object input

object output


AudioDeviceInfo

AudioDeviceInfo(int index, (optional) string name, (optional) string api, (optional) int minOutputChannels, (optional) int minInputChannels)

Audio device information. Find and enumerate audio devices.

Functions:

string

string string()

Get a string representation of the object.

getDevice

this getDevice(int index, (optional) string name, (optional) string api, (optional) int minInputChannels, (optional) int minOutputChannels)

Gets the device that matches the name. Only the given length will be compared, case is ignored. If no devices matches, the index is set to -1.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int numDevices

int index

string name

int apiIndex

string api

int inputChannels

int outputChannels

float sampleRate

float lowInputLatency

float lowOutputLatency

float highInputLatency

float highOutputLatency


AudioFile

AudioFile(string file)

Functions:

string

string string()

Get a string representation of the object.

loadRaw

this loadRaw(string file)

Loads the given file into data memory as is.

saveRaw

this saveRaw(string file)

Saves the data into a file as is.

appendRaw

this appendRaw(string file)

Appends the data to an existing file as is.

peek

int peek(int addr)

Reads a single byte from the given address.

poke

this poke(int addr, int value)

Writes a single byte to the given address.

resize

int resize(int newsize)

Resizes the data array length.

copyFrom

this copyFrom(Data source)

Makes a copy of the source data. Any old data in this object will be lost.

insert

this insert(Data source, int position)

Copies the source data to the given position. The data may be resized to fit the added content.

convert

this convert(int sampleRate, int bitsPerSample

no help found

load

this load(string fileName)

Loads the given RIFF/WAV file into a audio buffer in memory.

save

this save(string fileName)

Saves the current audio buffer to a RIFF/WAV file.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int size

(readonly) Size of data array.

bool loop

Set to true to wrap the read and write cursor when they reach the end of the stream.

int readCursor

Read cursor.

int writeCursor

Write cursor.

int multiplay

Allow to duplicate this audiobuffer for playing multiple instances simultaneously.

int playing

Audiobuffer is currently playing.

float volume

Volume of audio playback for this buffer. Ranges from 0.0 to 1.0.

int bytesAvailable


AudioFilter

AudioFilter(AudioData source)

Functions:

string

string string()

Get a string representation of the object.

loadRaw

this loadRaw(string file)

Loads the given file into data memory as is.

saveRaw

this saveRaw(string file)

Saves the data into a file as is.

appendRaw

this appendRaw(string file)

Appends the data to an existing file as is.

peek

int peek(int addr)

Reads a single byte from the given address.

poke

this poke(int addr, int value)

Writes a single byte to the given address.

resize

int resize(int newsize)

Resizes the data array length.

copyFrom

this copyFrom(Data source)

Makes a copy of the source data. Any old data in this object will be lost.

insert

this insert(Data source, int position)

Copies the source data to the given position. The data may be resized to fit the added content.

convert

this convert(int sampleRate, int bitsPerSample

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int size

(readonly) Size of data array.

bool loop

Set to true to wrap the read and write cursor when they reach the end of the stream.

int readCursor

Read cursor.

int writeCursor

Write cursor.

int multiplay

Allow to duplicate this audiobuffer for playing multiple instances simultaneously.

int playing

Audiobuffer is currently playing.

float volume

Volume of audio playback for this buffer. Ranges from 0.0 to 1.0.

int bytesAvailable

int enabled

int seconds

Number of seconds for the history buffer.

AudioData source

Source for streaming audio data to a device.

AudioData history

Audio buffer for story the history of the sound.

string outputFile


AudioPitch

AudioPitch(AudioData source)

Functions:

string

string string()

Get a string representation of the object.

loadRaw

this loadRaw(string file)

Loads the given file into data memory as is.

saveRaw

this saveRaw(string file)

Saves the data into a file as is.

appendRaw

this appendRaw(string file)

Appends the data to an existing file as is.

peek

int peek(int addr)

Reads a single byte from the given address.

poke

this poke(int addr, int value)

Writes a single byte to the given address.

resize

int resize(int newsize)

Resizes the data array length.

copyFrom

this copyFrom(Data source)

Makes a copy of the source data. Any old data in this object will be lost.

insert

this insert(Data source, int position)

Copies the source data to the given position. The data may be resized to fit the added content.

convert

this convert(int sampleRate, int bitsPerSample

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int size

(readonly) Size of data array.

bool loop

Set to true to wrap the read and write cursor when they reach the end of the stream.

int readCursor

Read cursor.

int writeCursor

Write cursor.

int multiplay

Allow to duplicate this audiobuffer for playing multiple instances simultaneously.

int playing

Audiobuffer is currently playing.

float volume

Volume of audio playback for this buffer. Ranges from 0.0 to 1.0.

int bytesAvailable

int enabled

int seconds

Number of seconds for the history buffer.

AudioData source

Source for streaming audio data to a device.

AudioData history

Audio buffer for story the history of the sound.

string outputFile

float pitch


AudioDelay

AudioDelay(AudioData source)

Functions:

string

string string()

Get a string representation of the object.

loadRaw

this loadRaw(string file)

Loads the given file into data memory as is.

saveRaw

this saveRaw(string file)

Saves the data into a file as is.

appendRaw

this appendRaw(string file)

Appends the data to an existing file as is.

peek

int peek(int addr)

Reads a single byte from the given address.

poke

this poke(int addr, int value)

Writes a single byte to the given address.

resize

int resize(int newsize)

Resizes the data array length.

copyFrom

this copyFrom(Data source)

Makes a copy of the source data. Any old data in this object will be lost.

insert

this insert(Data source, int position)

Copies the source data to the given position. The data may be resized to fit the added content.

convert

this convert(int sampleRate, int bitsPerSample

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int size

(readonly) Size of data array.

bool loop

Set to true to wrap the read and write cursor when they reach the end of the stream.

int readCursor

Read cursor.

int writeCursor

Write cursor.

int multiplay

Allow to duplicate this audiobuffer for playing multiple instances simultaneously.

int playing

Audiobuffer is currently playing.

float volume

Volume of audio playback for this buffer. Ranges from 0.0 to 1.0.

int bytesAvailable

int enabled

int seconds

Number of seconds for the history buffer.

AudioData source

Source for streaming audio data to a device.

AudioData history

Audio buffer for story the history of the sound.

string outputFile

float delay

Delay in seconds.

float delayVolume

Volume of delayed audio.


Video

Video(string file, int pos_x, int pos_y, int width, int height)

EXPERIMENTAL, SUBJECT TO CHANGE. Video playback node.

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Captures the video frame into texture.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

setBitmap

int setBitmap(Bitmap bitmap)

no help found

getBitmap

Bitmap getBitmap()

no help found

load

this load(string file)

Loads an image file and uses it. Returns null on failure.

save

this save(string file

Saves the current content to a PNG image file.

create

int create(int width, int height)

(Re-)creates the texture with the given dimensions. Returns non-zero on success.

duplicate

Texture duplicate()

Creates and returns a duplicate of the texture. The returned texture object has its own texture memory.

clear

this clear((optional) string color)

Fills the texture with the given or set clear color.

pick

string pick(int x, int y)

Returns the color on the given texel position. The string has the format RRGGBBAA with hexadigital numbers. The Color can be used afterwards to translate or modify the color.

resize

this resize(int width, int height, (optional) int bilinear)

Resizes the texture to the given size. Optionally a bilinear filter applies. On some hardware & platform combinates (especially embedded hardware) the actual dimension may differ due to power-of-two and size restrictions.

open

int open(string file)

Opens a video for playback. The video is not started here.

start

this start()

Starts the video. Some video codecs may need manual timing and will not render beyond the first frame by itself.

stop

this stop()

Stops the video.

pause

this pause()

Pauses the video.

setPosition

this setPosition(float position)

Sets the frame position (in seconds) of the video.

getPosition

float getPosition()

Gets the frame position (in seconds) of the video.

getDuration

float getDuration()

Gets the total duration (in seconds) of the video.

setSpeed

this setSpeed(float speed)

Sets the playback rate of the video. With 1.0 meaning normal speed and 0.5 meaning half-speed and so on.

update

this update()

Captures the video frame into texture.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.

string clearColor

Color that is used to clear or create the texture.

float opacity

Opacity of the texture while rendering.


Midi

Midi

Functions:

string

string string()

Get a string representation of the object.

load

no help found

getTrackCount

no help found

getEventCount

no help found

getEvent

no help found

joinTracks

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Sound

Sound(string file)

A sound.

Functions:

string

string string()

Get a string representation of the object.

open

int open(string file)

no help found

close

this close()

no help found

play

this play(int loop)

no help found

stop

this stop()

no help found

isPlaying

int isPlaying()

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Serial

Serial((optional) string id)

Serial class

Functions:

string

string string()

Get a string representation of the object.

open

this open((optional) string port, (optional) int baudrate)

no help found

close

this close()

no help found

flush

this flush()

NOT SUPPORTED ON WINDOWS!

peek

int peek()

NOT SUPPORTED ON WINDOWS!

write

this write(string data)

no help found

writeData

this writeData(Data data)

no help found

read

string read(float timeoutSeconds)

no help found

readEx

string read(int maxChar, int endChar, float timeoutSeconds)

no help found

readData

Data readData(int maxChar, float timeoutSeconds)

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


ADDevice

ADDevice((optional) string deviceId)

USB-AD and USB-PIO device interface. Requires the libad4.dll in the working directory or in path to work!

Functions:

string

string string()

Get a string representation of the object.

connect

int connect((optional) string deviceId)

Connect to a AD device by device id. Returns the non-zero on success.

disconnect

this disconnect()

Disconnect currently connected AD device.

findAnalogRange

int findAnalogRange(int channel, float volt)

Finds the best volt range match for the given volt.

getAnalogValue

int getAnalogValue(int channel, int range)

Gets the current raw analog value of the given channel.

getAnalogVolt

float getAnalogVolt(int channel, int range)

Gets the current analog voltage of the given channel.

setAnalogVolt

this setAnalogVolt(int channel, float volt)

Sets the voltage of the given channel.

getDigitalBits

int getDigitalBits(int channel)

Get the bitmask of the given digital channel.

setDigitalBits

this setDigitalBits(int channel, int bits)

Set the bitmask of the given digital channel.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int handle

Internal libAD device handle, if the device is not connected the handle is -1.

string device

The device id, should look like "usb-pio", "usb-ad:1", "usb-pio:012345" or similar.

int connected

Non-zero if the device is currently successfully connected.


Dmx

Dmx((optional) string id)

USB-DMX (DMX-512) device connection through DasHard DLL. Allows optional mapping of channel to X,Y coordinates (setMapping, setPixel), or direct access (setChannel). Initialization happens on object creation, no parameters are needed.

Functions:

string

string string()

Get a string representation of the object.

open

no help found

close

no help found

clearTo

no help found

setOffset

no help found

setChannel

no help found

setMapping

no help found

setPixel

no help found

update

no help found

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.


Camera

Camera(sting (or) int device, int pos_x, int pos_y, int width, int height, int bits

Camera node that displays the image from the given camera and/or saves it.

Example:

global WIDTH = 640; global HEIGHT = 480;
global FRAME = Frame("Camera Test", 50, 50, WIDTH, HEIGHT, "#ff00ff").toggle().cursor(true);
FRAME.onKeyDown = function(e) {   if(e.key == 'C') { e.sender.root["camera"].config(); }   };
FRAME.root["camera"] = Camera(0, 0, 0, 640, 480, 0);
pause(3.0);  // wait for camera to be ready

while(true) {
    FRAME.root["camera"].update();
    FRAME.render();
	yield();
}

Functions:

string

string string()

Get a string representation of the object.

update

this update()

Does a manual update of the camera texture, may need to be called in sync with the cameras framerate.

render

this render()

Renders the node and all its childs inside the selected frame.

hit

int hit(float x, float y)

Does a hit-test on the node, returns 1 if the coordinates hit the node on the screen.

setClipRegion

this setClipRegion(float left, float top, float right, float bottom)

Sets the scissor clip region, everything inside will clip to that region.

getChild

Node getChild(int index)

no help found

left

this left()

Aligns the left of the node to the pivot.

center

this center()

Aligns the horizontal center of the node to the pivot.

right

this right()

Aligns the right of the node to the pivot.

top

this top()

Aligns the top of the node to the pivot.

middle

this middle()

Aligns the vertical center of the node to the pivot.

bottom

this bottom()

Aligns the bottom of the node to the pivot.

setBitmap

int setBitmap(Bitmap bitmap)

no help found

getBitmap

Bitmap getBitmap()

no help found

load

this load(string file)

Loads an image file and uses it. Returns null on failure.

save

this save(string file

Saves the current content to a PNG image file.

create

int create(int width, int height)

(Re-)creates the texture with the given dimensions. Returns non-zero on success.

duplicate

Texture duplicate()

Creates and returns a duplicate of the texture. The returned texture object has its own texture memory.

clear

this clear((optional) string color)

Fills the texture with the given or set clear color.

pick

string pick(int x, int y)

Returns the color on the given texel position. The string has the format RRGGBBAA with hexadigital numbers. The Color can be used afterwards to translate or modify the color.

resize

this resize(int width, int height, (optional) int bilinear)

Resizes the texture to the given size. Optionally a bilinear filter applies. On some hardware & platform combinates (especially embedded hardware) the actual dimension may differ due to power-of-two and size restrictions.

open

int open(sting (or) int device, int width, int height, int bits)

Opens the camera with the given settings, the 'device' can either be an index, the device name or part of the beginning of the device name. Returns non-zero on success.

update

this update()

Does a manual update of the camera texture, may need to be called in sync with the cameras framerate.

config

this config()

Opens a DirectShow configuration dialog for the device. Some changes on that dialog should then be stored for this application (not reset on reboot). But this needs to be tested, since it is driver-dependend.

setFocus

this setFocus(int focus)

Sets the focus for the device or enables the auto-focus when the value is zero or below.

setZoom

this setZoom(int zoom)

Sets the zoom for the device.

setExposure

this setExposure(int exposure)

Sets the exposure for the device.

setWhiteBalance

this setWhiteBalance(int balance)

Set white-balance for the device.

setBrightness

this setBrightness(int brightness)

Set brightness for the device.

setContrast

this setContrast(int contrast)

Set contrast for the device.

setSaturation

this setSaturation(int saturation)

Set saturation for the device.

setPowerlineFrequency

this setPowerlineFrequency(int frequency)

Set the frequency of the powerline to match the camera.

snapshot

Texture snapshot()

Makes a snapshot of the current camera image and returns it as a texture.

snapshotBitmap

Bitmap snapshotBitmap((optional)Bitmap dst)

Makes a snapshot of the current camera image and returns it as a bitmap.

Members:

string id

Idenfication string of the object, initially set to class name but can be changed in script.

int visible

Visibility of the node and its child.

Vector position

Position of the node on the frame.

Vector pivot

Relative pivot/anchor of the node for positioning, rotation, etc.

Vector dimension

Rendering dimensions.

Vector rotation

Rotation around the center .

Vector scaling

Scaling of the node.

float scale

Alias to scaling .z

float x

Alias to position .x

float y

Alias to position .y

float z

Alias to position .z

float width

Alias to dimension .x

float height

Alias to dimension .y

float depth

Alias to dimension .z

float rotate

Alias to rotation .z

Shader shader

A shader used for rendering this node and its childs.

int useShader

Enable/Disable shader on node level.

Color color

Experimental. The color used while rendering.

string clearColor

Color that is used to clear or create the texture.

float opacity

Opacity of the texture while rendering.