naev 0.12.5
nlua_colour.c File Reference

Handles colours. More...

#include "nlua_colour.h"
#include "nluadef.h"
Include dependency graph for nlua_colour.c:

Go to the source code of this file.

Functions

static int colL_eq (lua_State *L)
 Compares two colours to see if they are the same.
static int colL_tostring (lua_State *L)
 Converts a colour to a string.
static int colL_new (lua_State *L)
 Creates a new colour. Colours are assumed to be in gamma colourspace by default and are converted to linear unless specified.
static int colL_newHSV (lua_State *L)
 Creates a new colour from HSV values. Colours are assumed to be in gamma colourspace by default and are converted to linear unless specified.
static int colL_alpha (lua_State *L)
 Gets the alpha of a colour.
static int colL_rgb (lua_State *L)
 Gets the RGB values of a colour.
static int colL_rgba (lua_State *L)
 Gets the RGBA values of a colour.
static int colL_hsv (lua_State *L)
 Gets the HSV values of a colour.
static int colL_setrgb (lua_State *L)
 Sets the colours values from the RGB colourspace.
static int colL_sethsv (lua_State *L)
 Sets the colours values from the HSV colourspace.
static int colL_setalpha (lua_State *L)
 Sets the alpha of a colour.
static int colL_linearToGamma (lua_State *L)
 Converts a colour from linear to gamma corrected.
static int colL_gammaToLinear (lua_State *L)
 Converts a colour from gamma corrected to linear.
int nlua_loadCol (nlua_env env)
 Loads the colour library.
glColour * lua_tocolour (lua_State *L, int ind)
 Lua bindings to interact with colours.
glColour * luaL_checkcolour (lua_State *L, int ind)
 Gets colour at index or raises error if there is no colour at index.
glColour * lua_pushcolour (lua_State *L, glColour colour)
 Pushes a colour on the stack.
int lua_iscolour (lua_State *L, int ind)
 Checks to see if ind is a colour.

Variables

static const luaL_Reg colL_methods []

Detailed Description

Handles colours.

Definition in file nlua_colour.c.

Function Documentation

◆ colL_alpha()

int colL_alpha ( lua_State * L)
static

Gets the alpha of a colour.

Value is from from 0. (transparent) to 1. (opaque).

Lua usage parameter: colour_alpha = col:alpha()

Lua function parameter: Colour col Colour to get alpha of. Lua return parameter: number The alpha of the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: alpha

Definition at line 285 of file nlua_colour.c.

◆ colL_eq()

int colL_eq ( lua_State * L)
static

Compares two colours to see if they are the same.

Lua function parameter: Colour c1 Colour 1 to compare. Lua function parameter: Colour c2 Colour 2 to compare. Lua return parameter: boolean true if both colours are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 151 of file nlua_colour.c.

◆ colL_gammaToLinear()

int colL_gammaToLinear ( lua_State * L)
static

Converts a colour from gamma corrected to linear.

Lua function parameter: Colour col Colour to change from gamma corrected to linear. Lua return parameter: Colour Modified colour.

Definition at line 477 of file nlua_colour.c.

◆ colL_hsv()

int colL_hsv ( lua_State * L)
static

Gets the HSV values of a colour.

Values are from 0 to 1 except hue which is 0 to 360.

Lua usage parameter: h,s,v = col:rgb()

Lua function parameter: Colour col Colour to get HSV values of. Lua function parameter:[opt=false] boolean gamma Whether or not to get the gamma-corrected value or not. Lua return parameter: number The hue of the colour (0-360 value). Lua return parameter: number The saturation of the colour (0-1 value). Lua return parameter: number The value of the colour (0-1 value).

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: hsv

Definition at line 369 of file nlua_colour.c.

◆ colL_linearToGamma()

int colL_linearToGamma ( lua_State * L)
static

Converts a colour from linear to gamma corrected.

Lua function parameter: Colour col Colour to change from linear to gamma. Lua return parameter: Colour Modified colour.

Definition at line 459 of file nlua_colour.c.

◆ colL_new()

int colL_new ( lua_State * L)
static

Creates a new colour. Colours are assumed to be in gamma colourspace by default and are converted to linear unless specified.

Lua usage parameter: colour.new( "Red" ) – Gets colour by name Lua usage parameter: colour.new( "Red", 0.5 ) – Gets colour by name with alpha 0.5 Lua usage parameter: colour.new() – Creates a white (blank) colour Lua usage parameter: colour.new( 1., 0., 0. ) – Creates a bright red colour Lua usage parameter: colour.new( 1., 0., 0., 0.5 ) – Creates a bright red colour with alpha 0.5

Lua function parameter: number r Red value of the colour. Lua function parameter: number g Green value of the colour. Lua function parameter: number b Blue value of the colour. Lua function parameter:[opt=1.] number a Alpha value of the colour. Lua function parameter:[opt=false] gamma Whether to load the colour in the gamma colourspace. Lua return parameter: Colour A newly created colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 197 of file nlua_colour.c.

◆ colL_newHSV()

int colL_newHSV ( lua_State * L)
static

Creates a new colour from HSV values. Colours are assumed to be in gamma colourspace by default and are converted to linear unless specified.

Lua usage parameter: colour.new( 0., 0.5, 0.5 ) – Creates a colour with 0 hue, 0.5 saturation and 0.5 value.

Lua function parameter: number h Hue of the colour (0-360 value). Lua function parameter: number s Saturation of the colour (0-1 value). Lua function parameter: number v Value of the colour (0-1 value). Lua function parameter:[opt=1.] number a Alpha value of the colour. Lua function parameter:[opt=false] gamma Whether to load the colour in the gamma colourspace. Lua return parameter: Colour A newly created colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: newHSV

Definition at line 251 of file nlua_colour.c.

◆ colL_rgb()

int colL_rgb ( lua_State * L)
static

Gets the RGB values of a colour.

Values are from 0. to 1.

Lua usage parameter: r,g,b = col:rgb()

Lua function parameter: Colour col Colour to get RGB values of. Lua function parameter:[opt=false] boolean gamma Whether or not to get the gamma-corrected value or not. Defaults to internal value that is linear. Lua return parameter: number The red value of the colour. Lua return parameter: number The green value of the colour. Lua return parameter: number The blue value of the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: rgb

Definition at line 307 of file nlua_colour.c.

◆ colL_rgba()

int colL_rgba ( lua_State * L)
static

Gets the RGBA values of a colour.

Values are from 0. to 1.

Lua usage parameter: r,g,b,a = col:rgba()

Lua function parameter: Colour col Colour to get RGB values of. Lua function parameter:[opt=false] boolean gamma Whether or not to get the gamma-corrected value or not. Lua return parameter: number The red value of the colour. Lua return parameter: number The green value of the colour. Lua return parameter: number The blue value of the colour. Lua return parameter: number The alpha value of the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: rgba

Definition at line 338 of file nlua_colour.c.

◆ colL_setalpha()

int colL_setalpha ( lua_State * L)
static

Sets the alpha of a colour.

Value is from 0. (transparent) to 1. (opaque).

Lua usage parameter: col:setAlpha( 0.5 ) – Make colour half transparent

Lua function parameter: Colour col Colour to set alpha of. Lua function parameter: number alpha Alpha value to set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setAlpha

Definition at line 446 of file nlua_colour.c.

◆ colL_sethsv()

int colL_sethsv ( lua_State * L)
static

Sets the colours values from the HSV colourspace.

Values are from 0. to 1.

Lua usage parameter: col:setHSV( h, s, v )

Lua function parameter: Colour col Colour to set HSV values. Lua function parameter: number h Hue value to set. Lua function parameter: number s Saturation value to set. Lua function parameter: number v Value to set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setHSV

Definition at line 424 of file nlua_colour.c.

◆ colL_setrgb()

int colL_setrgb ( lua_State * L)
static

Sets the colours values from the RGB colourspace.

Values are from 0. to 1.

Lua usage parameter: col:setRGB( r, g, b )

Lua function parameter: Colour col Colour to set RGB values. Lua function parameter: number r Red value to set. Lua function parameter: number g Green value to set. Lua function parameter: number b Blue value to set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setRGB

Definition at line 402 of file nlua_colour.c.

◆ colL_tostring()

int colL_tostring ( lua_State * L)
static

Converts a colour to a string.

Lua function parameter: Colour col Colour to get string from. Lua return parameter: string A string representing the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __tostring

Definition at line 167 of file nlua_colour.c.

◆ lua_iscolour()

int lua_iscolour ( lua_State * L,
int ind )

Checks to see if ind is a colour.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a colour.

Definition at line 127 of file nlua_colour.c.

◆ lua_pushcolour()

glColour * lua_pushcolour ( lua_State * L,
glColour colour )

Pushes a colour on the stack.

Parameters
LLua state to push colour into.
colourColour to push.
Returns
Newly pushed colour.

Definition at line 112 of file nlua_colour.c.

◆ lua_tocolour()

glColour * lua_tocolour ( lua_State * L,
int ind )

Lua bindings to interact with colours.

An example would be:

col1 = colour.new( "Red" ) -- Get by name
col2 = colour.new( 0.5, 0.5, 0.5, 0.3 ) -- Create with RGB values
col3 = colour.new() -- White by default
col2:setHSV( col1:hsv() ) -- Set colour 2 with colour 1's HSV values

Colours are assumed to be given as gamma-corrected values and are stored internally in linear colourspace by default. Most functions have a boolean parameter that allows controlling this behaviour.

Lua module: colour

Gets colour at index.

Parameters
LLua state to get colour from.
indIndex position to find the colour.
Returns
Colour found at the index in the state.

Definition at line 87 of file nlua_colour.c.

◆ luaL_checkcolour()

glColour * luaL_checkcolour ( lua_State * L,
int ind )

Gets colour at index or raises error if there is no colour at index.

Parameters
LLua state to get colour from.
indIndex position to find colour.
Returns
Colour found at the index in the state.

Definition at line 98 of file nlua_colour.c.

◆ nlua_loadCol()

int nlua_loadCol ( nlua_env env)

Loads the colour library.

Parameters
envEnvironment to load colour library into.
Returns
0 on success.

Definition at line 57 of file nlua_colour.c.

Variable Documentation

◆ colL_methods

const luaL_Reg colL_methods[]
static
Initial value:
= {
{ "__eq", colL_eq },
{ "__tostring", colL_tostring },
{ "new", colL_new },
{ "newHSV", colL_newHSV },
{ "alpha", colL_alpha },
{ "rgb", colL_rgb },
{ "rgba", colL_rgba },
{ "hsv", colL_hsv },
{ "setRGB", colL_setrgb },
{ "setHSV", colL_sethsv },
{ "setAlpha", colL_setalpha },
{ "linearToGamma", colL_linearToGamma },
{ "gammaToLinear", colL_gammaToLinear },
{ 0, 0 } }
static int colL_new(lua_State *L)
Creates a new colour. Colours are assumed to be in gamma colourspace by default and are converted to ...
static int colL_rgb(lua_State *L)
Gets the RGB values of a colour.
static int colL_setrgb(lua_State *L)
Sets the colours values from the RGB colourspace.
static int colL_eq(lua_State *L)
Compares two colours to see if they are the same.
static int colL_hsv(lua_State *L)
Gets the HSV values of a colour.
static int colL_tostring(lua_State *L)
Converts a colour to a string.
static int colL_sethsv(lua_State *L)
Sets the colours values from the HSV colourspace.
static int colL_linearToGamma(lua_State *L)
Converts a colour from linear to gamma corrected.
static int colL_newHSV(lua_State *L)
Creates a new colour from HSV values. Colours are assumed to be in gamma colourspace by default and a...
static int colL_setalpha(lua_State *L)
Sets the alpha of a colour.
static int colL_rgba(lua_State *L)
Gets the RGBA values of a colour.
static int colL_gammaToLinear(lua_State *L)
Converts a colour from gamma corrected to linear.
static int colL_alpha(lua_State *L)
Gets the alpha of a colour.

Colour metatable methods.

Definition at line 35 of file nlua_colour.c.