Added spriteRotateAndScale()

This commit is contained in:
Scott Duensing 2023-11-26 21:53:02 -06:00
parent e9eade1d2f
commit ca8c4c04ce
3 changed files with 58 additions and 12 deletions

View file

@ -47,6 +47,8 @@ Fixes
- USB controllers now work in games launched from the included menu.
- Default controller DEAD_ZONE increased.
- Framework.singe was missing keyboard mode constants. MODE_NORMAL and
MODE_FULL are now included.

View file

@ -74,9 +74,6 @@ if [[ 1 == 1 ]]; then
..
make install
popd
#if [[ "${OS}" == "windows" ]]; then
# mv ${G_TARGET}/lib/libjxl_dec-static.a ${G_TARGET}/lib/libjxl_dec.a
#fi
pushd thirdparty/SDL2_mixer
clearAndEnterBuild
@ -130,9 +127,6 @@ if [[ 1 == 1 ]]; then
--static
make install
popd
#if [[ "${OS}" == "windows" ]]; then
# mv ${G_TARGET}/lib/libzlibstatic.a ${G_TARGET}/lib/libz.a
#fi
pushd thirdparty/zstd
clearAndEnterBuild
@ -484,10 +478,11 @@ sudo apt-get install -y \
upx-ucl
buildAll linux x86_64 2>&1 | tee linux-x86_64.log
buildAll windows x86_64 2>&1 | tee windows-x86_64.log
#buildAll linux x86
#buildAll linux x86_64 2>&1 | tee linux-x86_64.log
#buildAll macos aarch64
#buildAll macos x86 #***TODO*** Needs older SDL2
#buildAll macos x86_64 #***TODO*** Needs older SDL2
#buildAll windows x86
buildAll windows x86_64 2>&1 | tee windows-x86_64.log

View file

@ -384,6 +384,7 @@ int32_t apiSpriteGetWidth(lua_State *L);
int32_t apiSpriteLoad(lua_State *L);
int32_t apiSpriteQuality(lua_State *L);
int32_t apiSpriteRotate(lua_State *L);
int32_t apiSpriteRotateAndScale(lua_State *L);
int32_t apiSpriteScale(lua_State *L);
int32_t apiSpriteUnload(lua_State *L);
@ -2076,6 +2077,51 @@ int32_t apiSpriteRotate(lua_State *L) {
}
int32_t apiSpriteRotateAndScale(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t id = -1;
double d;
double a;
double x;
double y;
SpriteT *sprite = NULL;
if ((n == 3) || (n == 4)) {
if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) {
if (lua_isnumber(L, 3)) {
d = lua_tonumber(L, 1); a = fmod(d, 360.0);
d = lua_tonumber(L, 2); x = d;
if (n == 3) {
y = x;
d = lua_tonumber(L, 3); id = (int32_t)d;
} else {
if (lua_isnumber(L, 4)) {
d = lua_tonumber(L, 4); id = (int32_t)d;
}
}
HASH_FIND_INT(_global.spriteList, &id, sprite);
if (!sprite) luaDie(L, "spriteRotateAndScale", "No sprite at index %d in apiSpriteRotateAndScale.", id);
sprite->angle = a;
sprite->scaleX = x;
sprite->scaleY = y;
SDL_FreeSurface(sprite->surface);
sprite->surface = rotozoomSurfaceXY(sprite->originalSurface, 360 - sprite->angle, sprite->scaleX, sprite->scaleY, sprite->smooth);
}
}
}
}
if (id >= 0) {
luaTrace(L, "spriteRotateAndScale", "%d %f %f %f", id, sprite->angle, sprite->scaleX, sprite->scaleY);
} else {
luaDie(L, "spriteRotateAndScale", "Failed!");
}
return 0;
}
int32_t apiSpriteScale(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t id = -1;
@ -2092,9 +2138,11 @@ int32_t apiSpriteScale(lua_State *L) {
y = x;
d = lua_tonumber(L, 2); id = (int32_t)d;
} else {
if (lua_isnumber(L, 3)) {
d = lua_tonumber(L, 2); y = d;
d = lua_tonumber(L, 3); id = (int32_t)d;
}
}
HASH_FIND_INT(_global.spriteList, &id, sprite);
if (!sprite) luaDie(L, "spriteScale", "No sprite at index %d in apiSpriteScale.", id);
sprite->scaleX = x;
@ -3980,6 +4028,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) {
lua_register(_global.luaContext, "spriteLoad", apiSpriteLoad);
lua_register(_global.luaContext, "spriteQuality", apiSpriteQuality);
lua_register(_global.luaContext, "spriteRotate", apiSpriteRotate);
lua_register(_global.luaContext, "spriteRotateAndScale", apiSpriteRotateAndScale);
lua_register(_global.luaContext, "spriteScale", apiSpriteScale);
lua_register(_global.luaContext, "spriteUnload", apiSpriteUnload);