From 89b8bb427dbedba9ad8649b99ec8568142029777 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Fri, 1 Dec 2023 20:21:32 -0600 Subject: [PATCH] Changed the 1/0 for the "center" drawing parameter to be true/false. --- CHANGELOG.txt | 4 +- src/singe.c | 180 +++++++++++++++++++++++++------------------------- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 754042ec0..2ce215ae6 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -12,9 +12,9 @@ New Features sprite's center as the anchor instead of the upper right. This is highly 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 which default audio track you want (-o or --audio). For games with multiple diff --git a/src/singe.c b/src/singe.c index c441f6423..229a58d12 100644 --- a/src/singe.c +++ b/src/singe.c @@ -1949,58 +1949,58 @@ int32_t apiSpriteDraw(lua_State *L) { if ((n >= 3) && (n <= 6)) { if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 2)) { - if (lua_isnumber(L, 3)) { - d = lua_tonumber(L, 1); dest.x = (int32_t)d; - d = lua_tonumber(L, 2); dest.y = (int32_t)d; - // Centered? - if ((n == 3) || (n == 4)) { - if (n == 4) { - if (lua_isnumber(L, 4)) { - d = lua_tonumber(L, 3); center = (int32_t)d != 0; - d = lua_tonumber(L, 4); id = (int32_t)d; - } - } else { + d = lua_tonumber(L, 1); dest.x = (int32_t)d; + d = lua_tonumber(L, 2); dest.y = (int32_t)d; + // Centered? + if ((n == 3) || (n == 4)) { + if (n == 4) { + if (lua_isboolean(L, 3) && lua_isnumber(L, 4)) { + d = lua_toboolean(L, 3); center = (int32_t)d != 0; + d = lua_tonumber(L, 4); id = (int32_t)d; + } + } else { + if (lua_isnumber(L, 3)) { d = lua_tonumber(L, 3); id = (int32_t)d; } } - if ((n == 5) || (n == 6)) { - // Target is scaled - if (lua_isnumber(L, 4)) { - if (lua_isnumber(L, 5)) { - 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; - // Centered? - if (n == 6) { - if (lua_isnumber(L, 6)) { - d = lua_tonumber(L, 5); center = (int32_t)d != 0; - d = lua_tonumber(L, 6); id = (int32_t)d; - } - } else { - d = lua_tonumber(L, 5); id = (int32_t)d; - } + } + if ((n == 5) || (n == 6)) { + // Target is scaled + if (lua_isnumber(L, 4)) { + 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; + // Centered? + if (n == 6) { + if (lua_isboolean(L, 5) && lua_isnumber(L, 6)) { + d = lua_toboolean(L, 5); center = (int32_t)d != 0; + d = lua_tonumber(L, 6); id = (int32_t)d; + } + } else { + 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); - if (!sprite) luaDie(L, "spriteDraw", "No sprite at index %d in apiSpriteDraw.", id); - if ((n == 3) || (n == 4)) { - // No scaling, find width - dest.w = sprite->surface->w; - dest.h = sprite->surface->h; - } - if (center) { - // Move sprite so the drawing coordinate is the center of the sprite - dest.x -= dest.w * 0.5; - dest.y -= dest.h * 0.5; - } - if ((n == 3) || (n == 4)) { - // No scaling - SDL_BlitSurface(sprite->surface, NULL, _global.overlay, &dest); - } else { - // Scaled - SDL_BlitScaled(sprite->surface, NULL, _global.overlay, &dest); - } + } + //utilSay("spriteDraw: x=%d y=%d c=%d id=%d", dest.x, dest.y, center, id); + HASH_FIND_INT(_global.spriteList, &id, sprite); + if (!sprite) luaDie(L, "spriteDraw", "No sprite at index %d in apiSpriteDraw.", id); + if ((n == 3) || (n == 4)) { + // No scaling, find width + dest.w = sprite->surface->w; + dest.h = sprite->surface->h; + } + if (center) { + // Move sprite so the drawing coordinate is the center of the sprite + dest.x -= dest.w * 0.5; + dest.y -= dest.h * 0.5; + } + if ((n == 3) || (n == 4)) { + // No scaling + SDL_BlitSurface(sprite->surface, NULL, _global.overlay, &dest); + } else { + // 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 (lua_isnumber(L, 1)) { if (lua_isnumber(L, 2)) { - if (lua_isnumber(L, 3)) { - if (lua_isnumber(L, 4)) { - d = lua_tonumber(L, 1); id = (int32_t)d; - d = lua_tonumber(L, 2); dest.x = (int32_t)d; - d = lua_tonumber(L, 3); dest.y = (int32_t)d; - if (n == 5) { - if (lua_isnumber(L, 5)) { - 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; - } - } else { - d = lua_tonumber(L, 4); center = (int32_t)d != 0; + if (lua_isnumber(L, 3)) { + d = lua_tonumber(L, 1); id = (int32_t)d; + d = lua_tonumber(L, 2); dest.x = (int32_t)d; + d = lua_tonumber(L, 3); dest.y = (int32_t)d; + if (n == 5) { + if (lua_isnumber(L, 4) && lua_isnumber(L, 5)) { + 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; + } + } else { + if (lua_isboolean(L, 4)) { + d = lua_toboolean(L, 4); center = (int32_t)d != 0; dest.w = 0; dest.h = 0; } + } - // Get our video structure - HASH_FIND_INT(_global.videoList, &id, video); - if (!video) luaDie(L, "videoDraw", "No video at index %d in apiVideoDraw.", id); - frame = videoUpdate(video->handle, &video->texture); + // Get our video structure + HASH_FIND_INT(_global.videoList, &id, video); + if (!video) luaDie(L, "videoDraw", "No video at index %d in apiVideoDraw.", id); + frame = videoUpdate(video->handle, &video->texture); - // New Frame? - if (frame != video->lastFrame) { - // Get new frame into a surface - this is slow - if (video->surface) SDL_FreeSurface(video->surface); - SDL_QueryTexture(video->texture, NULL, NULL, &w, &h); - video->surface = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 255); - if (!video->surface) utilDie("%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_SetRenderTarget(_global.renderer, NULL) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); - } + // New Frame? + if (frame != video->lastFrame) { + // Get new frame into a surface - this is slow + if (video->surface) SDL_FreeSurface(video->surface); + SDL_QueryTexture(video->texture, NULL, NULL, &w, &h); + video->surface = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 255); + if (!video->surface) utilDie("%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_SetRenderTarget(_global.renderer, NULL) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); + } - // Render frame into overlay - if ((dest.w == 0) && (dest.h == 0)) { - surface = rotozoomSurfaceXY(video->surface, 360 - video->angle, video->scaleX, video->scaleY, video->smooth); - dest.w = surface->w; - dest.h = surface->h; - // Scaled/Rotated draw - if (center) { - // Move video so the drawing coordinate is the center of the video - dest.x -= dest.w * 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()); + // Render frame into overlay + if ((dest.w == 0) && (dest.h == 0)) { + surface = rotozoomSurfaceXY(video->surface, 360 - video->angle, video->scaleX, video->scaleY, video->smooth); + dest.w = surface->w; + dest.h = surface->h; + // Scaled/Rotated draw + if (center) { + // Move video so the drawing coordinate is the center of the video + dest.x -= dest.w * 0.5; + dest.y -= dest.h * 0.5; } - 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; } } }