User Tools

Site Tools


This is an old revision of the document!


Predefined Methods

This section lists all methods that the GuiSys (C++) code predefines for the GUI windows of all window classes. These methods are intended to be called from your Lua scripts for convenient access to the window details. These are the key methods for setting up and customizing the windows of your GUI.

Currently, all methods are available for all window classes (windowClass, editClass, etc.), and behave identically. Deviations from this rule are mentioned explicitly in the respective documentation below.

set(var, value)

Sets the window variable with name var to the given value.

Parameters:

Name Type Description
var string The name of the variable to set. All valid names are listed in the table below.
value See table below. The value to set the variable to.

Returns:

Nothing (nil).

Notes:

Many variables are tuples of 2 or 4 individual values. E.g. all color values have a red, green, blue and alpha component, and positions have an x- and y-component. Therefore, for many variables there is a form with which you can set all components at once, and forms with which you can set a subset of the components.

Here is a list with all variable names that you can use for var, in logically grouped order. The second column indicates how many arguments and their related types are expected.

Name Type Remarks
show boolean If this window is shown.
time number Automatically incremented on each frame, but can freely be modified.
rotAngle number The angle of rotation of this window, in degrees (0..360).
Name Type Remarks
rect number, number, number, number The (x, y) position and (width, height) dimensions of this window. The position is relative to the parent window.
pos number, number Just the first two components of rect: the (x, y) position, relative to the parent window.
size number, number Just the last two components of rect: The width and height.
pos.x number The x-position of this window (1st component of rect).
pos.y number The y-position of this window (2nd component of rect).
size.x number The width of this window (3rd component of rect).
size.y number The height of this window (4th component of rect).
Name Type Remarks
backMaterial string The name of the MatSys material to be used as the background image of this window.
backColor number, number, number, number The red, green, blue and alpha components of the background color.
backColor.r number The red component of the background color.
backColor.g number The green component of the background color.
backColor.b number The blue component of the background color.
backColor.a number The alpha component of the background color.
Name Type Remarks
borderWidth number The width of the border frame.
borderColor number, number, number, number The red, green, blue and alpha components of the border color.
borderColor.r number The red component of the border color.
borderColor.g number The green component of the border color.
borderColor.b number The blue component of the border color.
borderColor.a number The alpha component of the border color.
Name Type Remarks
font string The name of the font to render the text with.
text string The text to display in this window.
textColor number, number, number, number The red, green, blue and alpha components of the text color.
textColor.r number The red component of the text color.
textColor.g number The green component of the text color.
textColor.b number The blue component of the text color.
textColor.a number The alpha component of the text color.
textScale number The relative size of the text. 1 = 48pt, 0.5 = 24pt, etc.
textAlignHor number (integer) The horizontal text alignment mode: 0 = left (default), 1 = right, 2 = center.
textAlignVer number (integer) The vertical text alignment mode: 0 = top (default), 1 = bottom, 2 = middle.
  • Also note that all coordinates are given with regards to the “virtual screen coordinate system”, which has a resolution of 640 * 480 pixels and is automatically scaled to the true resolution.
  • Color components (red, green, blue and alpha) are always given in percent, that is, as fractional values between 0 and 1.

Example:

    function ConsoleFrame:OnInit()
        self:set("rect", 20, 20, 600, 440);
        self:set("backColor", 0.82, 0.49, 0.17, 0.2);
        self:set("borderWidth", 0.7);
        self:set("borderColor", 0.82, 0.49, 0.17, 1.0);
        self:set("text", "Hello!");
    end

get(var)

Returns the value the window variable.

Parameters:

Name Type Description
var string The name of the variable whose value should be returned.

Returns:

The value of the desired variable in the appropriate type.

As Lua supports tuples as return types, this method works with all variables listed at the set() method, except for “backMaterial” and “font”, which are write-only.

Notes:

  • Cannot be used with the variables “backMaterial” and “font”, as they are write-only.

Example:

    function RotatingWin:OnFrame()
        self:set("rotAngle", self:get("time")*50);
    end
 
    function OtherWin:OnAction()
        -- Toggle the hor. text alignment of RotatingWin.
        local newAlign=RotatingWin:get("textAlignHor")+1;
        if (newAlign>2) then newAlign=0; end
 
        RotatingWin:set("textAlignHor", newAlign);
    end

interpolate(var, s, e, t)

Interpolates the value of the given variable from start value s to end value e over time t.

Parameters:

Name Type Description
var string The name of the variable to interpolate.
s number The start value.
e number The end value.
t number The time to interpolate over, given in milliseconds.

Returns:

Nothing (nil).

Notes:

  • For var only variables of type number are allowed, see set() for a list.

Example:

    function ButtonOK:OnMouseEnter()
        self:interpolate("rotAngle", 0, 360, 250);
        self:interpolate("textScale", 0.2, 0.25, 500);
        self:interpolate("pos.y", 300, 380, 750);
    end

__tostring()

Returns a short string that describes the window.

Parameters:

None.

Returns:

A short string that describes the window.

Notes:

  • This method is not intended to be called directly. Rather, it's the metamethod for Luas tostring() method that allows the conversion of a window into a string.

Example:

This method makes the following examples work:

    s=tostring(myWin);    -- myWin is a GuiSys window object (which has the __tostring() metamethod).
    print(s);
 
    print(myWin);         -- Same as:   print(tostring(myWin));
guisys/predefined_methods.1158509032.txt.gz · Last modified: 2013-01-07 12:07 (external edit)