1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
static int Image_blit (lua_State *L) {
int argc = lua_gettop(L);
if (argc != 4 && argc != 5 && argc != 8 && argc != 9) return luaL_error(L, "Argument error: image:blit() takes 3, 4, 7 or 8 arguments, and MUST be called with a colon.");
bool alpha = (argc==5 || argc==9)?lua_toboolean(L, -1):true;
if(argc==5 || argc==9) lua_pop(L, 1);
SETDEST
int dx = luaL_checkint(L, 1);
int dy = luaL_checkint(L, 2);
Image* source = *toImage(L, 3);
bool rect = (argc ==8 || argc == 9) ;
int sx = rect? luaL_checkint(L, 4) : 0;
int sy = rect? luaL_checkint(L, 5) : 0;
int width = rect? luaL_checkint(L, 6) : source->imageWidth;
int height = rect? luaL_checkint(L, 7) : source->imageHeight;
if (!dest) {
if (!adjustBlitRectangle(width, height, SCREEN_WIDTH, SCREEN_HEIGHT, &sx, &sy, &width, &height, &dx, &dy)) return 0;
alpha?
blitAlphaImageToScreen(sx, sy, width, height, source, dx, dy) :
blitImageToScreen(sx, sy, width, height, source, dx, dy);
} else {
if (!adjustBlitRectangle(width, height, dest->imageWidth, dest->imageHeight, &sx, &sy, &width, &height, &dx, &dy)) return 0;
alpha?
blitAlphaImageToImage(sx, sy, width, height, source, dx, dy, dest) :
blitImageToImage(sx, sy, width, height, source, dx, dy, dest);
}
return 0;
} |
Partager