Exemplo n.º 1
0
/**
 * @brief Compares two colours to see if they are the same.
 *
 *    @luaparam c1 Colour 1 to compare.
 *    @luaparam c2 Colour 2 to compare.
 *    @luareturn true if both colours are the same.
 * @luafunc __eq( c1, c2 )
 */
static int colL_eq( lua_State *L )
{
    LuaColour *c1, *c2;
    c1 = luaL_checkcolour(L,1);
    c2 = luaL_checkcolour(L,2);
    lua_pushboolean( L, (memcmp( &c1->col, &c2->col, sizeof(glColour) )==0) );
    return 1;
}
Exemplo n.º 2
0
/**
 * @brief Sets the alpha of a colour.
 *
 * Value is from 0. (transparent) to 1. (opaque).
 *
 * @usage col:setAlpha( 0.5 ) -- Make colour half transparent
 *
 *    @luaparam col Colour to set alpha of.
 *    @luaparam alpha Alpha value to set.
 * @luafunc setAlpha( col, alpha )
 */
static int colL_setalpha( lua_State *L )
{
    LuaColour *lc;
    lc          = luaL_checkcolour(L,1);
    lc->col.a   = luaL_checknumber(L,2);
    return 0;
}
Exemplo n.º 3
0
/**
 * @brief Gets the alpha of a colour.
 *
 * Value is from from 0. (transparent) to 1. (opaque).
 *
 * @usage colour_alpha = col:alpha()
 *
 *    @luaparam col Colour to get alpha of.
 *    @luareturn The alpha of the colour.
 * @luafunc alpha( col )
 */
static int colL_alpha( lua_State *L )
{
    LuaColour *lc;
    lc = luaL_checkcolour(L,1);
    lua_pushnumber( L, lc->col.a );
    return 1;
}
Exemplo n.º 4
0
/**
 * @brief Prints text on the screen.
 *
 * @usage gfx.print( nil, "Hello World!", 50, 50, colour.new("Red") ) -- Displays text in red at 50,50.
 * @usage gfx.print( true, "Hello World!", 50, 50, col, 100 ) -- Displays text to a maximum of 100 pixels wide.
 * @usage gfx.print( true, str, 50, 50, col, 100, true ) -- Displays centered text to a maximum of 100 pixels.
 *
 *    @luaparam small Whether or not to use a small font.
 *    @luaparam str String to print.
 *    @luaparam x X position to print at.
 *    @luaparam y Y position to print at.
 *    @luaparam col Colour to print text.
 *    @luaparam max Optional parameter to indicate maximum width to render up to.
 *    @luaparam center Optional boolean parameter indicating whether or not to center it.
 * @luafunc print( small, str, x, y, col, max, center )
 */
static int gfxL_print( lua_State *L )
{
   glFont *font;
   const char *str;
   double x, y;
   LuaColour *lc;
   int max, mid;

   /* Parse parameters. */
   font  = lua_toboolean(L,1) ? &gl_smallFont : &gl_defFont;
   str   = luaL_checkstring(L,2);
   x     = luaL_checknumber(L,3);
   y     = luaL_checknumber(L,4);
   lc    = luaL_checkcolour(L,5);
   if (lua_gettop(L) >= 6)
      max = luaL_checkinteger(L,6);
   else
      max = 0;
   mid   = lua_toboolean(L,7);

   /* Render. */
   if (mid)
      gl_printMidRaw( font, max, x, y, &lc->col, str );
   else if (max > 0)
      gl_printMaxRaw( font, max, x, y, &lc->col, str );
   else
      gl_printRaw( font, x, y, &lc->col, str );
   return 0;
}
Exemplo n.º 5
0
/**
 * @brief Sets the colours values from the RGB colourspace.
 *
 * Values are from 0. to 1.
 *
 * @usage col:setRGB( r, g, b )
 *
 *    @luaparam col Colour to set RGB values.
 *    @luaparam r Red value to set.
 *    @luaparam g Green value to set.
 *    @luaparam b Blue value to set.
 * @luafunc setRGB( col, r, g, b )
 */
static int colL_setrgb( lua_State *L )
{
    LuaColour *lc;
    lc          = luaL_checkcolour(L,1);
    lc->col.r   = luaL_checknumber(L,2);
    lc->col.g   = luaL_checknumber(L,3);
    lc->col.b   = luaL_checknumber(L,4);
    return 0;
}
Exemplo n.º 6
0
/**
 * @brief Gets the RGB values of a colour.
 *
 * Values are from 0. to 1.
 *
 * @usage r,g,b = col:rgb()
 *
 *    @luaparam col Colour to get RGB values of.
 *    @luareturn The red, green and blue values of the colour.
 * @luafunc rgb( col )
 */
static int colL_rgb( lua_State *L )
{
    LuaColour *lc;
    lc = luaL_checkcolour(L,1);
    lua_pushnumber( L, lc->col.r );
    lua_pushnumber( L, lc->col.g );
    lua_pushnumber( L, lc->col.b );
    return 3;
}
Exemplo n.º 7
0
/**
 * @brief Gets the HSV values of a colour.
 *
 * Values are from 0. to 1.
 *
 * @usage h,s,v = col:rgb()
 *
 *    @luaparam col Colour to get HSV values of.
 *    @luareturn The hue, saturation and value values of the colour.
 * @luafunc hsv( col )
 */
static int colL_hsv( lua_State *L )
{
    double h, s, v;
    LuaColour *lc;
    lc = luaL_checkcolour(L,1);
    col_rgb2hsv( &h, &s, &v, lc->col.r, lc->col.g, lc->col.b );
    lua_pushnumber( L, h );
    lua_pushnumber( L, s );
    lua_pushnumber( L, v );
    return 3;
}
Exemplo n.º 8
0
/**
 * @brief Renders a texture.
 *
 * This function has variable parameters depending on how you want to render.
 *
 * @usage gfx.renderTex( tex, 0., 0. ) -- Render tex at origin
 * @usage gfx.renderTex( tex, 0., 0., col ) -- Render tex at origin with colour col
 * @usage gfx.renderTex( tex, 0., 0., 4, 3 ) -- Render sprite at position 4,3 (top-left is 1,1)
 * @usage gfx.renderTex( tex, 0., 0., 4, 3, col ) -- Render sprite at position 4,3 (top-left is 1,1) with colour col
 *
 *    @luaparam tex Texture to render.
 *    @luaparam pos_x X position to render texture at.
 *    @luaparam pos_y Y position to render texture at.
 *    @luaparam sprite_x X sprite to render.
 *    @luaparam sprite_y Y sprite to render.
 *    @luaparam colour Colour to use when rendering.
 * @luafunc renderTex( tex, pos_x, pos_y, sprite_x, sprite_y, colour )
 */
static int gfxL_renderTex( lua_State *L )
{
   LuaTex *lt;
   LuaColour *lc;
   double x, y;
   int sx, sy;

   /* Parameters. */
   lc = NULL;
   lt = luaL_checktex( L, 1 );
   x  = luaL_checknumber( L, 2 );
   y  = luaL_checknumber( L, 3 );
   if (lua_isnumber( L, 4 )) {
      sx    = luaL_checkinteger( L, 4 ) - 1;
      sy    = luaL_checkinteger( L, 5 ) - 1;
      if (lua_iscolour(L, 6))
         lc    = luaL_checkcolour(L,6);
   }
   else {
      sx    = 0;
      sy    = 0;
      if (lua_iscolour(L, 4))
         lc    = luaL_checkcolour(L,4);
   }

   /* Some sanity checking. */
#if DEBUGGING
   if (sx >= lt->tex->sx)
      NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (X position) sprite: %d > %d.",
            lt->tex->name, sx+1, lt->tex->sx );
   if (sx >= lt->tex->sx)
      NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (Y position) sprite: %d > %d.",
            lt->tex->name, sy+1, lt->tex->sy );
#endif /* DEBUGGING */

   /* Render. */
   gl_blitStaticSprite( lt->tex, x, y, sx, sy, (lc==NULL) ? NULL : &lc->col );

   return 0;
}
Exemplo n.º 9
0
/**
 * @brief Renders a texture.
 *
 * This function has variable parameters depending on how you want to render.
 *
 * @usage gfx.renderTex( tex, 0., 0. ) -- Render tex at origin
 * @usage gfx.renderTex( tex, 0., 0., col ) -- Render tex at origin with colour col
 * @usage gfx.renderTex( tex, 0., 0., 4, 3 ) -- Render sprite at position 4,3 (top-left is 1,1)
 * @usage gfx.renderTex( tex, 0., 0., 4, 3, col ) -- Render sprite at position 4,3 (top-left is 1,1) with colour col
 *
 *    @luaparam tex Texture to render.
 *    @luaparam pos_x X position to render texture at.
 *    @luaparam pos_y Y position to render texture at.
 *    @luaparam sprite_x X sprite to render.
 *    @luaparam sprite_y Y sprite to render.
 *    @luaparam colour Colour to use when rendering.
 * @luafunc renderTex( tex, pos_x, pos_y, sprite_x, sprite_y, colour )
 */
static int gfxL_renderTex( lua_State *L )
{
    glTexture *tex;
    glColour *col;
    double x, y;
    int sx, sy;

    /* Parameters. */
    col = NULL;
    tex = luaL_checktex( L, 1 );
    x   = luaL_checknumber( L, 2 );
    y   = luaL_checknumber( L, 3 );
    if (lua_isnumber( L, 4 )) {
        sx    = luaL_checkinteger( L, 4 ) - 1;
        sy    = luaL_checkinteger( L, 5 ) - 1;
        if (lua_iscolour(L, 6))
            col = luaL_checkcolour(L,6);
    }
    else {
        sx    = 0;
        sy    = 0;
        if (lua_iscolour(L, 4))
            col = luaL_checkcolour(L,4);
    }

    /* Some sanity checking. */
#if DEBUGGING
    if (sx >= tex->sx)
        NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (X position) sprite: %d > %d.",
                    tex->name, sx+1, tex->sx );
    if (sx >= tex->sx)
        NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (Y position) sprite: %d > %d.",
                    tex->name, sy+1, tex->sy );
#endif /* DEBUGGING */

    /* Render. */
    gl_blitStaticSprite( tex, x, y, sx, sy, col );

    return 0;
}
Exemplo n.º 10
0
/**
 * @brief Sets the colours values from the HSV colourspace.
 *
 * Values are from 0. to 1.
 *
 * @usage col:setHSV( h, s, v )
 *
 *    @luaparam col Colour to set HSV values.
 *    @luaparam h Hue value to set.
 *    @luaparam s Saturation value to set.
 *    @luaparam v Value to set.
 * @luafunc setHSV( col, h, s, v )
 */
static int colL_sethsv( lua_State *L )
{
    double r, g, b, h, s, v;
    LuaColour *lc;
    lc = luaL_checkcolour(L,1);
    h  = luaL_checknumber(L,2);
    s  = luaL_checknumber(L,3);
    v  = luaL_checknumber(L,4);
    col_hsv2rgb( &r, &g, &b,  h, s, v );
    lc->col.r = r;
    lc->col.g = g;
    lc->col.b = b;
    return 0;
}
Exemplo n.º 11
0
/**
 * @brief Prints a block of text on the screen.
 *
 * @usage gfx.printText( true, 100, 50, 50, 100, 100, col ) -- Displays a 100x100 block of text
 *
 *    @luaparam small Whether or not to use a small font.
 *    @luaparam str String to print.
 *    @luaparam x X position to print at.
 *    @luaparam y Y position to print at.
 *    @luaparam w Width of the block of text.
 *    @luaparam h Height of the block of text.
 *    @luaparam col Colour to print text.
 * @luafunc printText( small, str, x, y, w, h, col )
 */
static int gfxL_printText( lua_State *L )
{
   glFont *font;
   const char *str;
   int w, h;
   double x, y;
   LuaColour *lc;

   /* Parse parameters. */
   font  = lua_toboolean(L,1) ? &gl_smallFont : &gl_defFont;
   str   = luaL_checkstring(L,2);
   x     = luaL_checknumber(L,3);
   y     = luaL_checknumber(L,4);
   w     = luaL_checkinteger(L,5);
   h     = luaL_checkinteger(L,6);
   lc    = luaL_checkcolour(L,7);

   /* Render. */
   gl_printTextRaw( font, w, h, x, y, &lc->col, str );

   return 0;
}
Exemplo n.º 12
0
/**
 * @brief Renders a rectangle.
 *
 * @usage gfx.renderRect( 10., 30,. 40., 40., col ) -- Renders a 40 side square at position 10,30 of colour col
 * @usage gfx.renderRect( 10., 30,. 40., 40., col, True ) -- Renders a 40 side empty square at position 10,30 of colour col
 *
 *    @luaparam x X position to render at.
 *    @luaparam y Y position to render at.
 *    @luaparam w Width of the rectangle.
 *    @luaparam h Height of the rectangle.
 *    @luaparam col Colour to use.
 *    @luaparam empty Optional parameter on whether or not it should be empty, defaults to true.
 * @luafunc renderRect( x, y, w, h, col, empty )
 */
static int gfxL_renderRect( lua_State *L )
{
   LuaColour *lc;
   double x,y, w,h;
   int empty;

   /* Parse parameters. */
   x     = luaL_checknumber( L, 1 );
   y     = luaL_checknumber( L, 2 );
   w     = luaL_checknumber( L, 3 );
   h     = luaL_checknumber( L, 4 );
   lc    = luaL_checkcolour( L, 5 );
   empty = lua_toboolean( L, 6 );

   /* Render. */
   if (empty)
      gl_renderRectEmpty( x, y, w, h, &lc->col );
   else
      gl_renderRect( x, y, w, h, &lc->col );

   return 0;
}