[Main Page]

Attract-Mode Frontend

Layout and Plug-in Programming Reference

Contents

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.

Layouts are stored under the "layouts" subdirectory of the Attract-Mode config directory. Each layout is stored in its own separate subdirectory or archive file (Attract-Mode can read layouts and plugins directly from .zip, .7z, .rar, .tar.gz, .tar.bz2 and .tar files).

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).

Squirrel Language

Attract-Mode's layouts are scripts written in the Squirrel programming language. Squirrel's standard "Blob", "IO", "Math", "String" and "System" library functions are available for use in a script. For more information on programming in Squirrel and using its standard libraries, consult the Squirrel manuals:

Language Extensions

Attract-Mode includes the following home-brewed extensions to the squirrel language and standard libraries:

Supported archive formats are: .zip, .7z, .rar, .tar.gz, .tar.bz2 and .tar

Frontend Binding

All of the functions, objects and classes that Attract-Mode exposes to Squirrel are arranged under the fe table, which is bound to Squirrel's root table.

Example:

    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 );

The remainder of this document describes the functions, objects, classes and constants that are exposed to layout and plug-in scripts.

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:

    // Add a text that displays the filter name and list location
    //
    fe.add_text( "[FilterName] [[ListEntry]/[ListSize]]",
            0, 0, 400, 20 );

    // Add an image that will match to the first word in the
    // Manufacturer name (i.e. "Atari.png", "Nintendo.jpg")
    //
    function strip_man( ioffset )
    {
        local m = fe.game_info(Info.Manufacturer,ioffset);
        return split( m, " " )[0];
    }
    fe.add_image( "[!strip_man]", 0, 0 );

    // Add a text that will display a copyright message if both
    // the manufacturer name and a year are present.  Otherwise,
    // just show the Manufactuer name.
    //
    function well_formatted()
    {
        local m = fe.game_info( Info.Manufacturer );
        local y = fe.game_info( Info.Year );

        if (( m.len() > 0 ) && ( y.len() > 0 ))
            return "Copyright " + y + ", " + m;

        return m;
    }
    fe.add_text( "[!well_formatted]", 0, 0 );

Functions

fe.add_image()

fe.add_image( name )
fe.add_image( name, x, y )
fe.add_image( name, x, y, w, h )

Adds an image or video to the end of Attract-Mode's draw list.

Magic Tokens can be used in the supplied "name", in which case Attract-Mode will dynamically update the image in response to navigation.

Parameters:

Return Value:

fe.add_artwork()

fe.add_artwork( label )
fe.add_artwork( label, x, y )
fe.add_artwork( label, x, y, w, h )

Add an artwork to the end of Attract-Mode's draw list. The image/video displayed in an artwork is updated automatically whenever the user changes the game selection.

Parameters:

Return Value:

fe.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:

fe.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:

fe.add_text()

fe.add_text( msg, x, y, w, h )

Add a text label to the end of Attract-Mode's draw list.

Magic Tokens can be used in the supplied "msg", in which case Attract-Mode will dynamically update the msg in response to navigation.

Parameters:

Return Value:

fe.add_listbox()

fe.add_listbox( x, y, w, h )

Add a listbox to the end of Attract-Mode's draw list.

Parameters:

Return Value:

fe.add_shader()

fe.add_shader( type, file1, file2 )
fe.add_shader( type, file1 )
fe.add_shader( type )

Add a GLSL shader (vertex and/or fragment) for use in the layout.

Parameters:

Return Value:

Implementation note for GLSL shaders in Attract-Mode:

Shaders are implemented using the SFML API. For more information please see: http://www.sfml-dev.org/tutorials/2.1/graphics-shader.php

The minimal vertex shader expected is as follows:

void main()
{
    // transform the vertex position
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    // transform the texture coordinates
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

    // forward the vertex color
    gl_FrontColor = gl_Color;
}

The minimal fragment shader expected is as follows:

uniform sampler2D texture;

void main()
{
    // lookup the pixel in the texture
    vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

    // multiply it by the color
    gl_FragColor = gl_Color * pixel;
}

fe.add_sound()

fe.add_sound( name, reuse )
fe.add_sound( name )

Add an audio file that can then be played by Attract-Mode.

Parameters:

Return Value:

fe.add_ticks_callback()

fe.add_ticks_callback( environment, function_name )
fe.add_ticks_callback( function_name )

Register a function in your script to get "tick" callbacks. Tick callbacks occur continuously during the running of the frontend. The function that is registered should be in the following form:

function tick( tick_time )
{
   // do stuff...
}

The single parameter passed to the tick function is the amount of time (in milliseconds) since the layout began.

Parameters:

Return Value:

fe.add_transition_callback()

fe.add_transition_callback( environment, function_name )
fe.add_transition_callback( function_name )

Register a function in your script to get transition callbacks. Transition callbacks are triggered by certain events in the frontend. The function that is registered should be in the following form:

function transition( ttype, var, transition_time )
{
   local redraw_needed = false;

   // do stuff...

   if ( redraw_needed )
      return true;

   return false;
}

The ttype parameter passed to the transition function indicates what is happening. It will have one of the following values:

The value of the var parameter passed to the transition function depends upon the value of ttype:

The transition_time parameter passed to the transition function is the amount of time (in milliseconds) since the transition began.

The transition function must return a boolean value. It should return true if a redraw is required, in which case Attract-Mode will redraw the screen and immediately call the transition function again with an updated transition_time.

The transition function must eventually return false to notify Attract-Mode that the transition effect is done, allowing the normal operation of the frontend to proceed.

Parameters:

Return Value:

fe.game_info()

fe.game_info( id )
fe.game_info( id, index_offset )
fe.game_info( id, index_offset, filter_offset )

Get information about the selected game.

Parameters:

Return Value:

fe.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 )

Get the filename of an artwork for the selected game. If multiple files are matched, one is chosen randomly and returned.

Parameters:

Return Value:

fe.get_input_state()

fe.get_input_state( input_id )

Check if a specific keyboard key, mouse button, joystick button or joystick direction is currently pressed, or check if any input mapped to a particular frontend action is pressed.

Parameter:

Return Value:

fe.get_input_pos()

fe.get_input_pos( input_id )

Return the current position for the specified joystick axis.

Parameter:

Return Value:

fe.signal()

fe.signal( signal_str )

Signal that a particular frontend action should occur.

Parameters:

Return Value:

fe.set_display()

fe.set_display( index )

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:

Return Value:

fe.add_signal_handler()

fe.add_signal_handler( environment, function_name )
fe.add_signal_handler( function_name )

Register a function in your script to handle signals. Signals are sent whenever a mapped control is used by the user or whenever a layout or plugin script uses the fe.signal() function. The function that is registered should be in the following form:

function handler( signal_str )
{
   local no_more_processing = false;

   // do stuff...

   if ( no_more_processing )
      return true;

   return false;
}

The signal_str parameter passed to the handler function is a string that identifies the signal that has been given. This string will correspond to the signal_str parameter values of fe.signal()

The signal handler function should return a boolean value. It should return true if no more processing should be done on this signal. It should return false if signal processing is to continue, in which case this signal will be dealt with in the default manner by the frontend.

Parameters:

Return Value:

fe.remove_signal_handler()

fe.remove_signal_handler( environment, function_name )
fe.remove_signal_handler( function_name )

Remove a signal handler that has been added with the fe.add_signal_handler() function.

Parameters:

Return Value:

fe.do_nut()

fe.do_nut( name )

Execute another Squirrel script.

Parameters:

Return Value:

fe.load_module()

fe.load_module( name )

Loads a module (a "library" Squirrel script).

Parameters:

Return Value:

fe.plugin_command()

fe.plugin_command( executable, arg_string )
fe.plugin_command( executable, arg_string, environment, callback_function )
fe.plugin_command( executable, arg_string, callback_function )

Execute a plug-in command and wait until the command is done.

Parameters:

Return Value:

fe.plugin_command_bg()

fe.plugin_command_bg( executable, arg_string )

Execute a plug-in command in the background and return immediately.

Parameters:

Return Value:

fe.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% will become the path to the "Program Files" directory.

Parameters:

Return Value:

fe.get_config()

Get the user configured settings for this layout/plugin/screensaver/intro.

NOTE this function will not return valid settings when called from a callback function registered with fe.addtickscallback(), fe.addtransitioncallback() or fe.addsignalhandler()

Parameters:

Return Value:

Objects and Variables

fe.ambient_sound

fe.ambient_sound is an instance of the fe.Sound class and can be used to control the ambient sound track.

fe.layout

fe.layout is an instance of the fe.LayoutGlobals class and is where global layout settings are stored.

fe.list

fe.list is an instance of the fe.CurrentList class and is where current display settings are stored.

fe.overlay

fe.overlay is an instance of the fe.Overlay class and is where overlay functionality may be accessed.

fe.obj

fe.obj contains the Attract-Mode draw list. It is an array of fe.Image, fe.Text and fe.ListBox instances.

fe.displays

fe.displays contains information on the available displays. It is an array of fe.Display instances.

fe.filters

fe.filters contains information on the available filters. It is an array of fe.Filter instances.

fe.monitors

fe.monitors is an array of fe.Monitor instances, and provides the mechanism for interacting with the various monitors in a multi-monitor setup. There will always be at least one entry in this list, and the first entry will always be the "primary" monitor.

fe.script_dir

When Attract-Mode runs a layout or plug-in script, fe.script_dir is set to the layout or plug-in's directory.

fe.script_file

When Attract-Mode runs a layout or plug-in script, fe.script_file is set to the name of the layout or plug-in script file.

fe.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.

Classes

fe.LayoutGlobals

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:

fe.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:

fe.Overlay

This class is a container for overlay functionality. The instance of this class is the fe.overlay object. This class cannot be otherwise instantiated in a script.

Properties:

Member Functions:

fe.Display

This class is a container for information about the available displays. Instances of this class are contained in the fe.displays array. This class cannot otherwise be instantiated in a script.

Properties:

fe.Filter

This class is a container for information about the available filters. Instances of this class are contained in the fe.filters array. This class cannot otherwise be instantiated in a script.

Properties:

fe.Monitor

This class represents a monitor in Attract-Mode, and provides the interface to the extra monitors in a multi-monitor setup. Instances of this class are contained in the fe.monitors array. This class cannot otherwise be instantiated in a script.

Properties:

Member Functions:

Notes:

fe.Image

The class representing an image in Attract-Mode. Instances of this class are returned by the add_image(), add_artwork(), add_surface and add_clone() functions and also appear in the fe.obj array (the Attract-Mode draw list). This class cannot be otherwise instantiated in a script.

Properties:

Member Functions:

Notes:

```` squirrel local myart = fe.addartwork( "snap", 0, 0, 100, 100 );

fe.addtransitioncallback("artworktransition"); function artworktransition( ttype, var, ttime ) { if (( ttype == Transition.FromOldSelection ) || ( ttype == Transition.ToNewList )) { // // do stuff with myart's texturewidth or textureheight here... // // for example, flip the image vertically: myart.subimgheight = -1 * textureheight; myart.subimgy = texture_height; }

  return false;

}

````

```` squirrel

// flip "img" vertically function flipy( img ) { img.subimgheight = -1 * img.textureheight; img.subimgy = img.texture_height; } ````

fe.Text

The class representing a text label in Attract-Mode. Instances of this class are returned by the add_text() functions and also appear in the fe.obj array (the Attract-Mode draw list). This class cannot be otherwise instantiated in a script.

Properties: * msg - Get/set the text label's message. Magic tokens can be used here, see Magic Tokens for more information. * 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). * charsize - Get/set the forced character size. If this is <= 0 then Attract-Mode will autosize based on height. Default value is -1. * 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 * 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. * 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. When objects overlap, the one with the higher zorder will be drawn on top.

Member Functions:

fe.ListBox

The class representing the listbox in Attract-Mode. Instances of this class are returned by the add_listbox() functions and also appear in the fe.obj array (the Attract-Mode draw list). This class cannot be otherwise instantiated in a script.

Properties:

Member Functions:

fe.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:

fe.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:

Member Functions:

Constants

FeVersion [string]

FeVersionNum [int]

The current Attract-Mode version.

FeConfigDirectory [string]

The path to Attract-Mode's config directory.

ScreenWidth [int]

ScreenHeight [int]

The screen width and height in pixels.

ScreenSaverActive [bool]

true if the screen saver is active, false otherwise.

IntroActive [bool]

true if the intro is active, false otherwise.

OS [string]

The Operating System that Attract-Mode is running under. Will be one of: "Windows", "OSX", "FreeBSD", "Linux" or "Unknown"

ShadersAvailable [bool]

true if GLSL shaders are available on this system, false otherwise.