scale added

This commit is contained in:
p.kosyh@gmail.com 2011-04-12 04:50:03 +00:00
parent e2b5e39868
commit 3a9e98e0fa
2 changed files with 43 additions and 0 deletions

View file

@ -947,6 +947,45 @@ err:
return 0;
}
static int luaB_scale_sprite(lua_State *L) {
_spr_t *sp;
img_t s;
img_t img2 = NULL;
const char *key;
char sname[sizeof(unsigned long) * 2 + 16];
const char *src = luaL_optstring(L, 1, NULL);
float xs = luaL_optnumber(L, 2, 1.0f);
float ys = luaL_optnumber(L, 3, 1.0f);
const char *desc = luaL_optstring(L, 4, NULL);
if (!src)
return 0;
s = cache_lookup(gfx_image_cache(), src);
if (!s)
return 0;
img2 = gfx_scale(s, xs, ys);
if (!img2)
return 0;
if (!desc || sprite_lookup(desc)) {
key = sname;
sprite_name(src, sname, sizeof(sname));
} else
key = desc;
sp = sprite_new(key, img2);
if (!sp)
goto err;
lua_pushstring(L, sname);
return 1;
err:
gfx_free_image(img2);
return 0;
}
static int luaB_fill_sprite(lua_State *L) {
img_t d;
@ -1047,6 +1086,7 @@ static const luaL_Reg base_funcs[] = {
{"sprite_fill", luaB_fill_sprite},
{"sprite_alpha", luaB_alpha_sprite},
{"sprite_size", luaB_sprite_size},
{"sprite_scale", luaB_scale_sprite},
{"sprite_text_size", luaB_text_size},
{NULL, NULL}
};

View file

@ -26,6 +26,9 @@ sprite = {
alpha = function(name, alpha)
return sprite_alpha(name, alpha);
end;
scale = function(name, xs, ys)
return sprite_scale(name, xs, ys);
end;
text = function(font, text, col, style)
return sprite_text(font, text, col, style);
end;