Layouts
Layouts
=====================
Contents
--------
* [Overview](#overview)
* [Squirrel Language](#squirrel)
* [Language Extensions](#squirrel_ext)
* [Frontend Binding](#binding)
* [Magic Tokens](#magic)
* [Functions](#functions)
* [`fe.add_image()`](#add_image)
* [`fe.add_artwork()`](#add_artwork)
* [`fe.add_surface()`](#add_surface)
* [`fe.add_clone()`](#add_clone)
* [`fe.add_text()`](#add_text)
* [`fe.add_listbox()`](#add_listbox)
* [`fe.add_shader()`](#add_shader)
* [`fe.add_sound()`](#add_sound)
* [`fe.add_ticks_callback()`](#add_ticks_callback)
* [`fe.add_transition_callback()`](#add_transition_callback)
* [`fe.game_info()`](#game_info)
* [`fe.get_art()`](#get_art)
* [`fe.get_input_state()`](#get_input_state)
* [`fe.get_input_pos()`](#get_input_pos)
* [`fe.signal()`](#signal)
* [`fe.set_display()`](#set_display)
* [`fe.add_signal_handler()`](#add_signal_handler)
* [`fe.remove_signal_handler()`](#remove_signal_handler)
* [`fe.do_nut()`](#do_nut)
* [`fe.load_module()`](#load_module)
* [`fe.plugin_command()`](#plugin_command)
* [`fe.plugin_command_bg()`](#plugin_command_bg)
* [`fe.path_expand()`](#path_expand)
* [`fe.path_test()`](#path_test)
* [`fe.get_config()`](#get_config)
* [`fe.get_text()`](#get_text)
* [Objects and Variables](#objects)
* [`fe.ambient_sound`](#ambient_sound)
* [`fe.layout`](#layout)
* [`fe.list`](#list)
* [`fe.image_cache`](#image_cache)
* [`fe.overlay`](#overlay)
* [`fe.obj`](#obj)
* [`fe.displays`](#displays)
* [`fe.filters`](#filters)
* [`fe.monitors`](#monitors)
* [`fe.script_dir`](#script_dir)
* [`fe.script_file`](#script_file)
* [`fe.module_dir`](#module_dir)
* [`fe.nv`](#nv)
* [Classes](#classes)
* [`fe.LayoutGlobals`](#LayoutGlobals)
* [`fe.CurrentList`](#CurrentList)
* [`fe.ImageCache`](#ImageCache)
* [`fe.Overlay`](#Overlay)
* [`fe.Display`](#Display)
* [`fe.Filter`](#Filter)
* [`fe.Monitor`](#Monitor)
* [`fe.Image`](#Image)
* [`fe.Text`](#Text)
* [`fe.ListBox`](#ListBox)
* [`fe.Sound`](#Sound)
* [`fe.Shader`](#Shader)
* [Constants](#constants)
<a name="overview" />
Overview
--------
The Attract-mode layout sets out what gets displayed to the user. Layouts
consist of a `layout.nut` script file and a collection of related resources
(images, other scripts, etc.) used by the script.
Each layout can have one or more `layout*.nut` script files. The "Toggle
Layout" command in Attract-Mode allows users to cycle between each of the
`layout*.nut` script files located in the layout's directory. Attract-Mode
remembers the last layout file toggled to for each layout and will go back
to that same file the next time the layout is loaded. This allows for
variations of a particular layout to be implemented and easily selected by
the user (for example, a layout could provide a `layout.nut` for horizontal
monitor orientations and a `layout-vert.nut` for vertical).
The Attract-Mode screen saver and intro modes are really just special case
layouts. The screensaver gets loaded after a user-configured period of
inactivity, while the intro mode gets run when the frontend first starts and
exits as soon as any action is triggered (for example if the user hits the
select button). The screen saver script is located in the `screensaver.nut`
file stored in the "screensaver" subdirectory. The intro script is located
in the `intro.nut` file stored in the "intro" subdirectory.
Plug-ins are similar to layouts in that they consist of at least one squirrel
script file and a collection of related resources. Plug-ins are stored in the
"plugins" subdirectory of the Attract-Mode config directory. Plug-ins can be a
single ".nut" file stored in this subdirectory. They can also have their own
separate subdirectory or archive file (in which case the script itself needs to
be in a file called `plugin.nut`).
<a name="squirrel" />
Squirrel Language
-----------------
[SQREFMAN]: http://www.squirrel-lang.org/doc/squirrel3.html
[SQLIBMAN]: http://www.squirrel-lang.org/doc/sqstdlib3.html
<a name="squirrel_ext" />
Language Extensions
-------------------
Supported archive formats are: .zip, .7z, .rar, .tar.gz, .tar.bz2 and .tar
<a name="binding" />
Frontend Binding
----------------
Example:
```` squirrel
fe.layout.base_rotation = RotateScreen.Right;
fe.add_image( "bg.png", 0, 0 );
local marquee = fe.add_artwork( "marquee", 256, 20, 512, 256 );
marquee.set_rgb( 100, 100, 100 );
````
<a name="magic" />
Magic Tokens
----------------
Image names, as well as the messages displayed by Text and Listbox objects, can
all contain one or more "Magic Tokens". Magic tokens are enclosed in square
brackets, and the frontend automatically updates them accordingly as the user
navigates the frontend. So for example, a Text message set to
"[Manufacturer]" will be automatically updated with the appropriate
Manufacturer's name. There are more examples below.
Examples:
```` squirrel
// Add a text that displays the filter name and list location
//
fe.add_text( "[FilterName] [[ListEntry]/[ListSize]]",
0, 0, 400, 20 );
return m;
}
fe.add_text( "[!well_formatted]", 0, 0 );
````
<a name="functions" />
Functions
---------
fe.add_image( name )
fe.add_image( name, x, y )
fe.add_image( name, x, y, w, h )
Parameters:
Return Value:
<a name="add_artwork" />
fe.add_artwork( label )
fe.add_artwork( label, x, y )
fe.add_artwork( label, x, y, w, h )
Parameters:
Return Value:
<a name="add_surface" />
fe.add_surface( w, h )
Add a surface to the end of Attract-Mode's draw list. A surface is an off-
screen texture upon which you can draw other image, artwork, text, listbox
and surface objects. The resulting texture is treated as a static image by
Attract-Mode which can in turn have image effects applied to it (scale,
position, pinch, skew, shaders, etc) when it is drawn.
Parameters:
Return Value:
<a name="add_clone" />
fe.add_clone( img )
Clone an image, artwork or surface object and add the clone to the back
of Attract-Mode's draw list. The texture pixel data of the original and
clone is shared as a result.
Parameters:
Return Value:
<a name="add_text" />
fe.add_text( msg, x, y, w, h )
Parameters:
* msg - the text to display. Magic tokens can be used here, see
[Magic Tokens](#magic) for more information.
* x - the x coordinate of the top left corner of the text (in layout
coordinates).
* y - the y coordinate of the top left corner of the text (in layout
coordinates).
* w - the width of the text (in layout coordinates).
* h - the height of the text (in layout coordinates).
Return Value:
<a name="add_listbox" />
fe.add_listbox( x, y, w, h )
Parameters:
* x - the x coordinate of the top left corner of the listbox (in layout
coordinates).
* y - the y coordinate of the top left corner of the listbox (in layout
coordinates).
* w - the width of the listbox (in layout coordinates).
* h - the height of the listbox (in layout coordinates).
Return Value:
<a name="add_shader" />
Add a GLSL shader (vertex and/or fragment) for use in the layout.
Parameters:
* type - the type of shader to add. Can be one of the following values:
- `Shader.VertexAndFragment` - add a combined vertex and fragment shader
- `Shader.Vertex` - add a vertex shader
- `Shader.Fragment` - add a fragment shader
- `Shader.Empty` - add an empty shader. An object's shader property can
be set to an empty shader to stop using a shader on that object where
one was set previously.
* file1 - the name of the shader file located in the layout/plugin directory.
For the VertexAndFragment type, this should be the vertex shader.
* file2 - This parameter is only used with the VertexAndFragment type, and
should be the name of the fragment shader file located in the layout/
plugin directory.
Return Value:
Shaders are implemented using the SFML API. For more information please see:
http://www.sfml-dev.org/tutorials/2.1/graphics-shader.php
```` glsl
void main()
{
// transform the vertex position
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
```` glsl
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
<a name="add_sound" />
Parameters:
Return Value:
<a name="add_ticks_callback" />
The single parameter passed to the tick function is the amount of time (in
milliseconds) since the layout began.
Parameters:
Return Value:
* None.
<a name="add_transition_callback" />
// do stuff...
if ( redraw_needed )
return true;
return false;
}
The value of the `var` parameter passed to the transition function depends
upon the value of `ttype`:
Parameters:
Return Value:
* None.
<a name="game_info" />
fe.game_info( id )
fe.game_info( id, index_offset )
fe.game_info( id, index_offset, filter_offset )
Parameters:
Return Value:
Notes:
<a name="get_art" />
fe.get_art( label )
fe.get_art( label, index_offset )
fe.get_art( label, index_offset, filter_offset )
fe.get_art( label, index_offset, filter_offset, flags )
Parameters:
Return Value:
<a name="get_input_state" />
fe.get_input_state( input_id )
Parameter:
* input_id - [string] the input to test. This can be a string in the same
format as used in the attract.cfg file for input mappings. For example,
"LControl" will check the left control key, "Joy0 Up" will check the up
direction on the first joystick, "Mouse MiddleButton" will check the
middle mouse button, and "select" will check for any input mapped to the
game select button...
Note that mouse moves and mouse wheel movements are not available through
this function.
Return Value:
<a name="get_input_pos" />
fe.get_input_pos( input_id )
Parameter:
Return Value:
<a name="signal" />
fe.signal( signal_str )
Return Value:
* None.
<a name="set_display" />
Change to the display at the specified index. This should align with the
index of the fe.displays array that contains the intended display.
NOTE that changing the display causes all layout and plugin scripts to reload.
Parameters:
* index - The index of the display to change to. This should correspond to
the index in the fe.displays array of the intended new display. The index for
the current display is stored in `fe.list.display_index`.
* stack_previous - [boolean] if set to `true`, the new display is stacked on
the current one, so that when the user selects the "Back" UI button the frontend
will navigate back to the earlier display. Default value is `false`.
Return Value:
* None.
<a name="add_signal_handler" />
// do stuff...
if ( no_more_processing )
return true;
return false;
}
Parameters:
* environment - the squirrel object that the function is associated with
(default value: the root table of the squirrel vm)
* function_name - a string naming the signal handler function to
be added.
Return Value:
* None.
<a name="remove_signal_handler" />
Parameters:
Return Value:
* None.
<a name="do_nut" />
fe.do_nut( name )
Parameters:
Return Value:
* None.
<a name="load_module" />
fe.load_module( name )
Return Value:
<a name="plugin_command" />
Parameters:
function callback_function( op )
{
}
If provided, this function will get called repeatedely with chunks of the
command output in `op`. NOTE: `op` is not necessarily aligned with the
start and the end of the lines of output from the command. In any one
call `op` may contain data from multiple lines and that may begin or end
in the middle of a line.
Return Value:
* None.
<a name="plugin_command_bg" />
Parameters:
* None.
<a name="path_expand" />
fe.path_expand( path )
Expand the given path name. A leading `~` or `$HOME` token will be become
the user's home directory. On Windows systems, a leading `%SYSTEMROOT%`
token will become the path to the Windows directory and a leading
`%PROGRAMFILES%` or `%PROGRAMFILESx86%` will become the path to the
applicable Windows "Program Files" directory.
Parameters:
Return Value:
<a name="path_test" />
Check whether the specified path has the status indicated by `flag`.
Parameters:
Return Value:
* (boolean) result.
<a name="get_config" />
NOTE this function will *not* return valid settings when called from a
callback function registered with fe.add_ticks_callback(),
fe.add_transition_callback() or fe.add_signal_handler()
Parameters:
* None.
Return Value:
For an example, please see one of the plug-ins included with Attract-
Mode or the "Attrac-Man" layout.
<a name="get_text" />
fe.get_text( text )
Parameters:
Return Value:
<a name="objects" />
<a name="layout" />
<a name="list" />
#### `fe.list` ####
<a name="image_cache" />
<a name="overlay" />
<a name="obj" />
<a name="displays" />
<a name="filters" />
<a name="monitors" />
<a name="script_dir" />
<a name="script_file" />
<a name="module_dir" />
<a name="nv" />
The fe.nv table can be used by layouts and plugins to store persistent values.
The values in this table get saved by Attract-Mode whenever the layout changes
and are saved to disk when Attract-Mode is shut down. Boolean, integer, float,
string, array and table values can be stored in this table.
<a name="classes" />
Classes
-------
This class is a container for global layout settings. The instance of this
class is the `fe.layout` object. This class cannot be otherwise instantiated
in a script.
Properties:
Notes:
* The actual rotation of the layout can be determined using the following
equation: `( fe.layout.base_rotation + fe.layout.toggle_rotation ) % 4`
<a name="CurrentList" />
This class is a container for status information regarding the current display.
The instance of this class is the `fe.list` object. This class cannot be
otherwise instantiated in a script.
Properties:
<a name="ImageCache" />
Properties:
Member Functions:
<a name="Overlay" />
Properties:
* `is_up` - Get whether the overlay is currently being displayed (i.e. config
mode, etc).
Member Functions:
<a name="Display" />
Properties:
<a name="Filter" />
Properties:
<a name="Monitor" />
Properties:
Member Functions:
* `add_image()` - add an image to the end of this monitor's draw list (see
[`fe.add_image()`](#add_image) for parameters and return value).
* `add_artwork()` - add an artwork to the end of this monitor's draw list
(see [`fe.add_artwork()`](#add_artwork) for parameters and return value).
* `add_clone()` - add a clone to the end of this monitor's draw list (see
[`fe.add_clone()`](#add_clone) for parameters and return value).
* `add_text()` - add a text to the end of this monitor's draw list (see
[`fe.add_text()`](#add_text) for parameters and return value).
* `add_listbox()` - add a listbox to the end of this monitor's draw list
(see [`fe.add_listbox()`](#add_listbox) for parameters and return value).
* `add_surface()` - add a surface to the end of this monitor's draw list
(see [`fe.add_surface()`](#add_surface) for parameters and return value).
Notes:
<a name="Image" />
Properties:
Member Functions:
* `set_rgb( r, g, b )` - Set the red, green and blue colour values for the
image. Range is [0 ... 255].
* `set_pos( x, y )` - Set the image position (in layout coordinates).
* `set_pos( x, y, width, height )` - Set the image position and size (in
layout coordinates).
* `swap( other_img )` - swap the texture contents of this object (and all
of its clones) with the contents of "other_img" (and all of its clones).
If an image or artwork is swapped, its video attributes (`video_flags`
and `video_playing`) will be swapped as well.
* `fix_masked_image()` - Takes the colour of the top left pixel in the image
and makes all the pixels in the image with that colour transparent.
* `load_from_archive( archive, filename )` - Load the image from the
specified archive file (.zip, etc).
* `add_image()` - [surface only] add an image to the end of this surface's
draw list (see [`fe.add_image()`](#add_image) for parameters and return
value).
* `add_artwork()` - [surface only] add an artwork to the end of this
surface's draw list (see [`fe.add_artwork()`](#add_artwork) for parameters
and return value).
* `add_clone()` - [surface only] add a clone to the end of this surface's
draw list (see [`fe.add_clone()`](#add_clone) for parameters and return
value).
* `add_text()` - [surface only] add a text to the end of this surface's draw
list (see [`fe.add_text()`](#add_text) for parameters and return value).
* `add_listbox()` - [surface only] add a listbox to the end of this
surface's draw list (see [`fe.add_listbox()`](#add_listbox) for parameters
and return value).
* `add_surface()` - [surface only] add a surface to the end of this
surface's draw list (see [`fe.add_surface()`](#add_surface) for parameters
and return value).
<a name="ImageNotes" />
Notes:
* Note that Attract-Mode defers the loading of artwork and dynamic images
(images with Magic Tokens) until after all layout and plug-in scripts have
completed running. This means that the `texture_width`, `texture_height`
and `file_name` attributes are not available when a layout or plug-in
script first adds the artwork/dynamic image resource. These attributes
are available during transition callbacks, and in particular during the
`Transition.FromOldSelection` and `Transition.ToNewList` transitions.
Example:
```` squirrel
local my_art = fe.add_artwork( "snap", 0, 0, 100, 100 );
fe.add_transition_callback( "artwork_transition" );
function artwork_transition( ttype, var, ttime )
{
if (( ttype == Transition.FromOldSelection )
|| ( ttype == Transition.ToNewList ))
{
//
// do stuff with my_art's texture_width or texture_height here...
//
// for example, flip the image vertically:
my_art.subimg_height = -1 * texture_height;
my_art.subimg_y = texture_height;
}
return false;
}
````
```` squirrel
// flip "img" vertically
function flip_y( img )
{
img.subimg_height = -1 * img.texture_height;
img.subimg_y = img.texture_height;
}
````
* To rotate an image around its centre, set the origin_x and origin_y
values to one half of the image's width and height (respectively)
and then set the 'rotation' value accordingly
```` squirrel
local img = fe.add_image( "img.png", 100, 100, 200, 200 );
img.origin_x = 100;
img.origin_y = 100;
img.rotation = 90; // rotate img around its centre
````
<a name="Text" />
Properties:
* `msg` - Get/set the text label's message. Magic tokens can be used here,
see [Magic Tokens](#magic) for more information.
* `msg_wrapped` - Get the text label's message after word wrapping.
* `x` - Get/set x position of top left corner (in layout coordinates).
* `y` - Get/set y position of top left corner (in layout coordinates).
* `width` - Get/set width of text (in layout coordinates).
* `height` - Get/set height of text (in layout coordinates).
* `visible` - Get/set whether text is visible (boolean). Default value
is `true`.
* `rotation` - Get/set rotation of text. Range is [0 ... 360]. Default
value is 0.
* `red` - Get/set red colour level for text. Range is [0 ... 255].
Default value is 255.
* `green` - Get/set green colour level for text. Range is [0 ... 255].
Default value is 255.
* `blue` - Get/set blue colour level for text. Range is [0 ... 255].
Default value is 255.
* `alpha` - Get/set alpha level for text. Range is [0 ... 255]. Default
value is 255.
* `index_offset` - Get/set offset from current game selection for text
info to display. For example, set to -1 to show text info for the
previous list entry, or 1 for the next list entry. Default value is 0.
* `filter_offset` - Get/set filter offset from current filter for the
text info to display. For example, set to -1 to show text info for
a selection in the previous filter, or 1 for the next filter, etc.
Default value is 0.
* `bg_red` - Get/set red colour level for text background. Range is
[0 ... 255]. Default value is 0.
* `bg_green` - Get/set green colour level for text background. Range is
[0 ... 255]. Default value is 0.
* `bg_blue` - Get/set blue colour level for text background. Range is
[0 ... 255]. Default value is 0.
* `bg_alpha` - Get/set alpha level for text background. Range is [0 ...
255]. Default value is 0 (transparent).
* `char_size` - Get/set the forced character size. If this is <= 0
then Attract-Mode will autosize based on `height`. Default value is -1.
* `glyph_size` - Get the height in pixels of the capital letter.
Useful if you want to set the textbox height to match the letter height.
* `char_spacing` - Get/set the spacing factor between letters. Default value is
1.0
* `line_spacing` - Get/set the spacing factor between lines. Default value is
1.0
At values 0.75 or lower letters start to overlap. For uppercase texts it's
around 0.5
It's advised to use this property with the new align modes.
* `style` - Get/set the text style. Can be a combination of one or more
of the following (i.e. `Style.Bold | Style.Italic`):
- `Style.Regular` (default)
- `Style.Bold`
- `Style.Italic`
- `Style.Underlined`
* `align` - Get/set the text alignment. Can be one of the following
values:
- `Align.Centre` (default)
- `Align.Left`
- `Align.Right`
- `Align.TopCentre`
- `Align.TopLeft`
- `Align.TopRight`
- `Align.BottomCentre`
- `Align.BottomLeft`
- `Align.BottomRight`
- `Align.MiddleCentre`
- `Align.MiddleLeft`
- `Align.MiddleRight`
The last 3 alignment modes have the same function as the first 3,
but they are more accurate. The first 3 modes are preserved for compatibility.
* `word_wrap` - Get/set whether word wrapping is enabled in this text
(boolean). Default is `false`.
* `msg_width` - Get the width of the text message, in layout coordinates.
* `font` - Get/set the name of the font used for this text. Default is
the layout font name.
* `margin` - Get/set the margin spacing in pixels to sides of the text.
Default value is `-1` which calcualtes the margin based on the .char_size.
* `shader` - Get/set the GLSL shader for this text. This can only be set to
an instance of the class `fe.Shader` (see: `fe.add_shader()`).
* `zorder` - Get/set the Text's order in the applicable draw list. Objects
with a lower zorder are drawn first, so that when objects overlap, the one
with the higher zorder is drawn on top. Default value is 0.
Member Functions:
* `set_rgb( r, g, b )` - Set the red, green and blue colour values for the
text. Range is [0 ... 255].
* `set_bg_rgb( r, g, b )` - Set the red, green and blue colour values for
the text background. Range is [0 ... 255].
* `set_pos( x, y )` - Set the text position (in layout coordinates).
* `set_pos( x, y, width, height )` - Set the text position and size (in
layout coordinates).
<a name="ListBox" />
Properties:
Member Functions:
* `set_rgb( r, g, b )` - Set the red, green and blue colour values for the
text. Range is [0 ... 255].
* `set_bg_rgb( r, g, b )` - Set the red, green and blue colour values for
the text background. Range is [0 ... 255].
* `set_sel_rgb( r, g, b )` - Set the red, green and blue colour values
for the selection text. Range is [0 ... 255].
* `set_selbg_rgb( r, g, b )` - Set the red, green and blue colour values
for the selection background. Range is [0 ... 255].
* `set_pos( x, y )` - Set the listbox position (in layout coordinates).
* `set_pos( x, y, width, height )` - Set the listbox position and size (in
layout coordinates).
<a name="Sound" />
The class representing an audio track. Instances of this class are returned
by the `fe.add_sound()` function. This is also the class for the
`fe.ambient_sound` object. Object of this class cannot be otherwise
instantiated in a script.
Properties:
Member Functions:
* `get_metadata( tag )` - Get the meta data (if available in the source
file) that corresponds to the specified tag (i.e. "artist", "album", etc.)
* `load_from_archive( archive, filename )` - Load the sound from the
specified archive file (.zip, etc).
<a name="Shader" />
The class representing a GLSL shader. Instances of this class are returned
by the `fe.add_shader()` function. This class cannot be otherwise
instantiated in a script.
Properties:
* `type` - Get the shader type. Can be one of the following values:
- `Shader.VertexAndFragment`
- `Shader.Vertex`
- `Shader.Fragment`
- `Shader.Empty`
Member Functions:
* `set_param( name, f )` - Set the float variable (float GLSL type) with
the specified name to the value of f.
* `set_param( name, f1, f2 )` - Set the 2-component vector variable (vec2
GLSL type) with the specified name to (f1,f2).
* `set_param( name, f1, f2, f3 )` - Set the 3-component vector variable
(vec3 GLSL type) with the specified name to (f1,f2,f3).
* `set_param( name, f1, f2, f3, f4 )` - Set the 4-component vector
variable (vec4 GLSL type) with the specified name to (f1,f2,f3,f4).
* `set_texture_param( name )` - Set the texture variable (sampler2D GLSL
type) with the specified name. The texture used will be the texture
for whatever object (fe.Image, fe.Text, fe.Listbox) the shader is
drawing.
* `set_texture_param( name, image )` - Set the texture variable (sampler2D
GLSL type) with the specified name to the texture contained in "image".
"image" must be an instance of the `fe.Image` class.
<a name="constants" />
Constants
---------
The Operating System that Attract-Mode is running under. Will be one of:
"Windows", "OSX", "FreeBSD", "Linux" or "Unknown".