From 3a9e98e0fafc50bd9c3cd6f5b1b16f53ed1a1d54 Mon Sep 17 00:00:00 2001
From: "p.kosyh@gmail.com"
Date: Tue, 12 Apr 2011 04:50:03 +0000
Subject: [PATCH] scale added
---
src/sdl-instead/instead.c | 40 +++++++++++++++++++++++++++++++++++++++
stead/sprites.lua | 3 +++
2 files changed, 43 insertions(+)
diff --git a/src/sdl-instead/instead.c b/src/sdl-instead/instead.c
index a425a71..3df65a3 100644
--- a/src/sdl-instead/instead.c
+++ b/src/sdl-instead/instead.c
@@ -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}
};
diff --git a/stead/sprites.lua b/stead/sprites.lua
index 7be6717..22956ea 100644
--- a/stead/sprites.lua
+++ b/stead/sprites.lua
@@ -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;