From 1da38af50e4f52fdfdc173571403ad81e43fd817 Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Wed, 13 Apr 2011 17:42:11 +0000 Subject: [PATCH] copy added --- src/sdl-instead/graphics.c | 20 ++++++++++++++++ src/sdl-instead/graphics.h | 1 + src/sdl-instead/instead.c | 49 ++++++++++++++++++++++++++++++++++++++ stead/sprites.lua | 6 +++++ 4 files changed, 76 insertions(+) diff --git a/src/sdl-instead/graphics.c b/src/sdl-instead/graphics.c index 10946b2..29c35de 100644 --- a/src/sdl-instead/graphics.c +++ b/src/sdl-instead/graphics.c @@ -902,6 +902,26 @@ void gfx_draw_from(img_t p, int x, int y, int width, int height, img_t to, int x SDL_BlitSurface(pixbuf, &src, scr, &dest); } +void gfx_copy_from(img_t p, int x, int y, int width, int height, img_t to, int xx, int yy) +{ + SDL_Surface *pixbuf = (SDL_Surface *)p; + SDL_Surface *scr = (SDL_Surface *)to; + SDL_Rect dest, src; + if (!scr) + scr = screen; + src.x = x; + src.y = y; + src.w = width; + src.h = height; + dest.x = xx; + dest.y = yy; + dest.w = width; + dest.h = height; + gfx_unset_alpha(pixbuf); + SDL_BlitSurface(pixbuf, &src, scr, &dest); + gfx_set_alpha(pixbuf, 255); +} + void gfx_draw(img_t p, int x, int y) { anigif_t ag; diff --git a/src/sdl-instead/graphics.h b/src/sdl-instead/graphics.h index 9983b69..68ca670 100644 --- a/src/sdl-instead/graphics.h +++ b/src/sdl-instead/graphics.h @@ -73,6 +73,7 @@ extern int gfx_prev_mode(int *w, int *h); extern void gfx_update(int x, int y, int w, int h); extern void gfx_video_done(void); extern void gfx_clear(int x, int y, int w, int h); +extern void gfx_copy_from(img_t p, int x, int y, int width, int height, img_t to, int xx, int yy); extern void gfx_draw(img_t pixmap, int x, int y); extern void gfx_draw_wh(img_t p, int x, int y, int w, int h); extern img_t gfx_grab_screen(int x, int y, int w, int h); diff --git a/src/sdl-instead/instead.c b/src/sdl-instead/instead.c index a8c10bc..bcc526b 100644 --- a/src/sdl-instead/instead.c +++ b/src/sdl-instead/instead.c @@ -915,6 +915,54 @@ static int luaB_draw_sprite(lua_State *L) { return 1; } +static int luaB_copy_sprite(lua_State *L) { + img_t s, d; + img_t img2 = NULL; + float v; + const char *src = luaL_optstring(L, 1, NULL); + int x = luaL_optnumber(L, 2, 0); + int y = luaL_optnumber(L, 3, 0); + int w = luaL_optnumber(L, 4, 0); + int h = luaL_optnumber(L, 5, 0); + const char *dst = luaL_optstring(L, 6, NULL); + int xx = luaL_optnumber(L, 7, 0); + int yy = luaL_optnumber(L, 8, 0); + int xoff = 0, yoff = 0; + int xoff0 = 0, yoff0 = 0; + if (!src || !dst) + return 0; + + s = grab_sprite(src, &xoff0, &yoff0); + + d = grab_sprite(dst, &xoff, &yoff); + + if (!s || !d) + return 0; + + v = game_theme.scale; + + if (v != 1.0f) { + x *= v; + y *= v; + w *= v; + h *= v; + xx *= v; + yy *= v; + } + + if (!w) + w = gfx_img_w(s) - 2 * xoff0; + if (!h) + h = gfx_img_h(s) - 2 * yoff0; + + game_pict_modify(d); + + gfx_copy_from(s, x + xoff0, y + yoff0, w, h, d, xx + xoff, yy + yoff); + gfx_free_image(img2); + lua_pushboolean(L, 1); + return 1; +} + static int luaB_alpha_sprite(lua_State *L) { _spr_t *sp; @@ -1185,6 +1233,7 @@ static const luaL_Reg base_funcs[] = { {"sprite_free", luaB_free_sprite}, {"sprites_free", luaB_free_sprites}, {"sprite_draw", luaB_draw_sprite}, + {"sprite_copy", luaB_copy_sprite}, {"sprite_fill", luaB_fill_sprite}, {"sprite_dup", luaB_dup_sprite}, {"sprite_alpha", luaB_alpha_sprite}, diff --git a/stead/sprites.lua b/stead/sprites.lua index b3e586e..37b15fb 100644 --- a/stead/sprites.lua +++ b/stead/sprites.lua @@ -50,6 +50,12 @@ sprite = { end return sprite_draw(s, fx, fy, fw, fh, d, x, y, alpha); end; + copy = function(s, fx, fy, fw, fh, d, x, y, alpha) + if d == nil and x == nil and y == nil then + return sprite_copy(s, 0, 0, 0, 0, fx, fy, fw, fh); + end + return sprite_copy(s, fx, fy, fw, fh, d, x, y, alpha); + end; fill = function(d, x, y, w, h, col) if h == nil and col == nil then return sprite_fill(d, 0, 0, 0, 0, x);