Changed the 1/0 for the "center" drawing parameter to be true/false.

This commit is contained in:
Scott Duensing 2023-12-01 20:21:32 -06:00
parent 5173a88dc8
commit 89b8bb427d
2 changed files with 92 additions and 92 deletions

View file

@ -12,9 +12,9 @@ New Features
sprite's center as the anchor instead of the upper right. This is highly sprite's center as the anchor instead of the upper right. This is highly
useful when dealing with rotated sprites. useful when dealing with rotated sprites.
- Sprite scaling and rotation! Optional separate X & Y scaling. - Sprite anti-aliasing, scaling and rotation! Optional separate X & Y scaling.
- Optional sprite anti-aliasing. - Video anti-aliasing, scaling and rotation! Optional separate X & Y scaling.
- Multiple audio track support for videos. New command line options to select - Multiple audio track support for videos. New command line options to select
which default audio track you want (-o or --audio). For games with multiple which default audio track you want (-o or --audio). For games with multiple

View file

@ -1949,58 +1949,58 @@ int32_t apiSpriteDraw(lua_State *L) {
if ((n >= 3) && (n <= 6)) { if ((n >= 3) && (n <= 6)) {
if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) { if (lua_isnumber(L, 2)) {
if (lua_isnumber(L, 3)) { d = lua_tonumber(L, 1); dest.x = (int32_t)d;
d = lua_tonumber(L, 1); dest.x = (int32_t)d; d = lua_tonumber(L, 2); dest.y = (int32_t)d;
d = lua_tonumber(L, 2); dest.y = (int32_t)d; // Centered?
// Centered? if ((n == 3) || (n == 4)) {
if ((n == 3) || (n == 4)) { if (n == 4) {
if (n == 4) { if (lua_isboolean(L, 3) && lua_isnumber(L, 4)) {
if (lua_isnumber(L, 4)) { d = lua_toboolean(L, 3); center = (int32_t)d != 0;
d = lua_tonumber(L, 3); center = (int32_t)d != 0; d = lua_tonumber(L, 4); id = (int32_t)d;
d = lua_tonumber(L, 4); id = (int32_t)d; }
} } else {
} else { if (lua_isnumber(L, 3)) {
d = lua_tonumber(L, 3); id = (int32_t)d; d = lua_tonumber(L, 3); id = (int32_t)d;
} }
} }
if ((n == 5) || (n == 6)) { }
// Target is scaled if ((n == 5) || (n == 6)) {
if (lua_isnumber(L, 4)) { // Target is scaled
if (lua_isnumber(L, 5)) { if (lua_isnumber(L, 4)) {
d = lua_tonumber(L, 3); dest.w = (int32_t)d - dest.x + 1; d = lua_tonumber(L, 3); dest.w = (int32_t)d - dest.x + 1;
d = lua_tonumber(L, 4); dest.h = (int32_t)d - dest.y + 1; d = lua_tonumber(L, 4); dest.h = (int32_t)d - dest.y + 1;
// Centered? // Centered?
if (n == 6) { if (n == 6) {
if (lua_isnumber(L, 6)) { if (lua_isboolean(L, 5) && lua_isnumber(L, 6)) {
d = lua_tonumber(L, 5); center = (int32_t)d != 0; d = lua_toboolean(L, 5); center = (int32_t)d != 0;
d = lua_tonumber(L, 6); id = (int32_t)d; d = lua_tonumber(L, 6); id = (int32_t)d;
} }
} else { } else {
d = lua_tonumber(L, 5); id = (int32_t)d; if (lua_isnumber(L, 6)) {
} d = lua_tonumber(L, 5); id = (int32_t)d;
} }
} }
} }
//utilSay("spriteDraw: x=%d y=%d c=%d id=%d", dest.x, dest.y, center, id); }
HASH_FIND_INT(_global.spriteList, &id, sprite); //utilSay("spriteDraw: x=%d y=%d c=%d id=%d", dest.x, dest.y, center, id);
if (!sprite) luaDie(L, "spriteDraw", "No sprite at index %d in apiSpriteDraw.", id); HASH_FIND_INT(_global.spriteList, &id, sprite);
if ((n == 3) || (n == 4)) { if (!sprite) luaDie(L, "spriteDraw", "No sprite at index %d in apiSpriteDraw.", id);
// No scaling, find width if ((n == 3) || (n == 4)) {
dest.w = sprite->surface->w; // No scaling, find width
dest.h = sprite->surface->h; dest.w = sprite->surface->w;
} dest.h = sprite->surface->h;
if (center) { }
// Move sprite so the drawing coordinate is the center of the sprite if (center) {
dest.x -= dest.w * 0.5; // Move sprite so the drawing coordinate is the center of the sprite
dest.y -= dest.h * 0.5; dest.x -= dest.w * 0.5;
} dest.y -= dest.h * 0.5;
if ((n == 3) || (n == 4)) { }
// No scaling if ((n == 3) || (n == 4)) {
SDL_BlitSurface(sprite->surface, NULL, _global.overlay, &dest); // No scaling
} else { SDL_BlitSurface(sprite->surface, NULL, _global.overlay, &dest);
// Scaled } else {
SDL_BlitScaled(sprite->surface, NULL, _global.overlay, &dest); // Scaled
} SDL_BlitScaled(sprite->surface, NULL, _global.overlay, &dest);
} }
} }
} }
@ -2304,58 +2304,58 @@ int32_t apiVideoDraw(lua_State *L) {
if ((n == 4) || (n == 5)) { if ((n == 4) || (n == 5)) {
if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) { if (lua_isnumber(L, 2)) {
if (lua_isnumber(L, 3)) { if (lua_isnumber(L, 3)) {
if (lua_isnumber(L, 4)) { d = lua_tonumber(L, 1); id = (int32_t)d;
d = lua_tonumber(L, 1); id = (int32_t)d; d = lua_tonumber(L, 2); dest.x = (int32_t)d;
d = lua_tonumber(L, 2); dest.x = (int32_t)d; d = lua_tonumber(L, 3); dest.y = (int32_t)d;
d = lua_tonumber(L, 3); dest.y = (int32_t)d; if (n == 5) {
if (n == 5) { if (lua_isnumber(L, 4) && lua_isnumber(L, 5)) {
if (lua_isnumber(L, 5)) { d = lua_tonumber(L, 4); dest.w = (int32_t)d - dest.x + 1;
d = lua_tonumber(L, 4); dest.w = (int32_t)d - dest.x + 1; d = lua_tonumber(L, 5); dest.h = (int32_t)d - dest.y + 1;
d = lua_tonumber(L, 5); dest.h = (int32_t)d - dest.y + 1; }
} } else {
} else { if (lua_isboolean(L, 4)) {
d = lua_tonumber(L, 4); center = (int32_t)d != 0; d = lua_toboolean(L, 4); center = (int32_t)d != 0;
dest.w = 0; dest.w = 0;
dest.h = 0; dest.h = 0;
} }
}
// Get our video structure // Get our video structure
HASH_FIND_INT(_global.videoList, &id, video); HASH_FIND_INT(_global.videoList, &id, video);
if (!video) luaDie(L, "videoDraw", "No video at index %d in apiVideoDraw.", id); if (!video) luaDie(L, "videoDraw", "No video at index %d in apiVideoDraw.", id);
frame = videoUpdate(video->handle, &video->texture); frame = videoUpdate(video->handle, &video->texture);
// New Frame? // New Frame?
if (frame != video->lastFrame) { if (frame != video->lastFrame) {
// Get new frame into a surface - this is slow // Get new frame into a surface - this is slow
if (video->surface) SDL_FreeSurface(video->surface); if (video->surface) SDL_FreeSurface(video->surface);
SDL_QueryTexture(video->texture, NULL, NULL, &w, &h); SDL_QueryTexture(video->texture, NULL, NULL, &w, &h);
video->surface = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 255); video->surface = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 255);
if (!video->surface) utilDie("%s", SDL_GetError()); if (!video->surface) utilDie("%s", SDL_GetError());
if (SDL_SetRenderTarget(_global.renderer, video->texture) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); if (SDL_SetRenderTarget(_global.renderer, video->texture) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError());
if (SDL_RenderReadPixels(_global.renderer, NULL, video->surface->format->format, video->surface->pixels, video->surface->pitch) != 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); if (SDL_RenderReadPixels(_global.renderer, NULL, video->surface->format->format, video->surface->pixels, video->surface->pitch) != 0) luaDie(L, "videoDraw", "%s", SDL_GetError());
if (SDL_SetRenderTarget(_global.renderer, NULL) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); if (SDL_SetRenderTarget(_global.renderer, NULL) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError());
} }
// Render frame into overlay // Render frame into overlay
if ((dest.w == 0) && (dest.h == 0)) { if ((dest.w == 0) && (dest.h == 0)) {
surface = rotozoomSurfaceXY(video->surface, 360 - video->angle, video->scaleX, video->scaleY, video->smooth); surface = rotozoomSurfaceXY(video->surface, 360 - video->angle, video->scaleX, video->scaleY, video->smooth);
dest.w = surface->w; dest.w = surface->w;
dest.h = surface->h; dest.h = surface->h;
// Scaled/Rotated draw // Scaled/Rotated draw
if (center) { if (center) {
// Move video so the drawing coordinate is the center of the video // Move video so the drawing coordinate is the center of the video
dest.x -= dest.w * 0.5; dest.x -= dest.w * 0.5;
dest.y -= dest.h * 0.5; dest.y -= dest.h * 0.5;
}
SDL_BlitSurface(surface, NULL, _global.overlay, &dest);
SDL_FreeSurface(surface);
} else {
// Simple/Stretched draw
if (SDL_BlitScaled(video->surface, NULL, _global.overlay, &dest) != 0) luaDie(L, "videoDraw", "%s", SDL_GetError());
} }
result = true; SDL_BlitSurface(surface, NULL, _global.overlay, &dest);
SDL_FreeSurface(surface);
} else {
// Simple/Stretched draw
if (SDL_BlitScaled(video->surface, NULL, _global.overlay, &dest) != 0) luaDie(L, "videoDraw", "%s", SDL_GetError());
} }
result = true;
} }
} }
} }