diff --git a/src/singe.c b/src/singe.c index 1004c4466..bd4fbd58c 100644 --- a/src/singe.c +++ b/src/singe.c @@ -382,9 +382,9 @@ int32_t apiSpriteDraw(lua_State *L); int32_t apiSpriteGetHeight(lua_State *L); 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 apiSpriteScale(lua_State *L); -int32_t apiSpriteSmooth(lua_State *L); int32_t apiSpriteUnload(lua_State *L); int32_t apiVideoDraw(lua_State *L); @@ -406,27 +406,28 @@ int32_t apiVldpGetPixel(lua_State *L); int32_t apiVldpGetWidth(lua_State *L); int32_t apiVldpVerbose(lua_State *L); -ConfigT *buildConfFromTable(lua_State *L); -void doIndexDisplay(int32_t percent); -void doLogos(void); -void callLua(const char *func, const char *sig, ...); -void channelFinished(int channel); -void line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, SDL_Color *c); -void luaDie(lua_State *L, char *method, char *fmt, ...); -int32_t luaError(lua_State *L); -int luaSearcher(lua_State *L); -void luaTrace(lua_State *L, char *method, char *fmt, ...); -void processKey(bool down, int keysym, int32_t scancode); -void progTrace(char *fmt, ...); -void putPixel(int32_t x, int32_t y, SDL_Color *c); -void startControllers(void); -void startLuaContext(lua_State *L); -void stopControllers(void); -void takeScreenshot(void); -void updatePauseState(void); +ConfigT *buildConfFromTable(lua_State *L); +void doIndexDisplay(int32_t percent); +void doLogos(void); +void callLua(const char *func, const char *sig, ...); +void channelFinished(int channel); +void line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, SDL_Color *c); +void luaDie(lua_State *L, char *method, char *fmt, ...); +int32_t luaError(lua_State *L); +int luaSearcher(lua_State *L); +void luaTrace(lua_State *L, char *method, char *fmt, ...); +void processKey(bool down, int keysym, int32_t scancode); +void progTrace(char *fmt, ...); +void putPixel(int32_t x, int32_t y, SDL_Color *c); +void startControllers(void); +void startLuaContext(lua_State *L); +void stopControllers(void); +SDL_Surface *surfaceCopy(SDL_Surface *source); +void takeScreenshot(void); +void updatePauseState(void); #ifdef DEBUG_TOOLS -void luaStackDump(lua_State *L); +void luaStackDump(lua_State *L); #endif int32_t apiColorBackground(lua_State *L) { @@ -1080,15 +1081,15 @@ int32_t apiFontToSprite(lua_State *L) { message = lua_tostring(L, 1); switch (_global.fontQuality) { case 1: - sprite->surface = TTF_RenderText_Solid(_global.fontCurrent->font, message, _global.colorForeground); + sprite->originalSurface = TTF_RenderText_Solid(_global.fontCurrent->font, message, _global.colorForeground); break; case 2: - sprite->surface = TTF_RenderText_Shaded(_global.fontCurrent->font, message, _global.colorForeground, _global.colorBackground); + sprite->originalSurface = TTF_RenderText_Shaded(_global.fontCurrent->font, message, _global.colorForeground, _global.colorBackground); break; case 3: - sprite->surface = TTF_RenderText_Blended(_global.fontCurrent->font, message, _global.colorForeground); + sprite->originalSurface = TTF_RenderText_Blended(_global.fontCurrent->font, message, _global.colorForeground); break; default: @@ -1096,11 +1097,11 @@ int32_t apiFontToSprite(lua_State *L) { break; } - if (!sprite->surface) { + if (!sprite->originalSurface) { luaDie(L, "fontToSprite", "Font surface is null!"); } else { - SDL_SetColorKey(sprite->surface, true, 0); - SDL_BlitSurface(sprite->surface, NULL, sprite->originalSurface, NULL); + SDL_SetColorKey(sprite->originalSurface, true, 0); + sprite->surface = surfaceCopy(sprite->originalSurface); sprite->scaleX = 1.0; sprite->scaleY = 1.0; sprite->id = _global.nextSpriteId; @@ -1888,6 +1889,7 @@ int32_t apiSpriteDraw(lua_State *L) { } } } + //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)) { @@ -1989,10 +1991,10 @@ int32_t apiSpriteLoad(lua_State *L) { sprite = (SpriteT *)calloc(1, sizeof(SpriteT)); if (!sprite) luaDie(L, "spriteLoad", "Unable to allocate new sprite."); name = lua_tostring(L, 1); - sprite->surface = IMG_Load(name); - if (!sprite->surface) luaDie(L, "spriteLoad", "%s", IMG_GetError()); - SDL_SetColorKey(sprite->surface, true, 0); - SDL_BlitSurface(sprite->surface, NULL, sprite->originalSurface, NULL); + sprite->originalSurface = IMG_Load(name); + if (!sprite->originalSurface) luaDie(L, "spriteLoad", "%s", IMG_GetError()); + SDL_SetColorKey(sprite->originalSurface, true, 0); + sprite->surface = surfaceCopy(sprite->originalSurface); sprite->scaleX = 1.0; sprite->scaleY = 1.0; sprite->id = _global.nextSpriteId; @@ -2012,6 +2014,37 @@ int32_t apiSpriteLoad(lua_State *L) { } +int32_t apiSpriteQuality(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t id = -1; + int32_t s; + double d; + SpriteT *sprite = NULL; + + if (n == 2) { + if (lua_isnumber(L, 1)) { + if (lua_isnumber(L, 2)) { + d = lua_tonumber(L, 1); s = (int32_t)d; + d = lua_tonumber(L, 2); id = (int32_t)d; + HASH_FIND_INT(_global.spriteList, &id, sprite); + if (!sprite) luaDie(L, "spriteQuality", "No sprite at index %d in apiSpriteQuality.", id); + sprite->smooth = s; + SDL_FreeSurface(sprite->surface); + sprite->surface = rotozoomSurfaceXY(sprite->originalSurface, 360 - sprite->angle, sprite->scaleX, sprite->scaleY, sprite->smooth); + } + } + } + + if (id >= 0) { + luaTrace(L, "spriteQuality", "%d %d", id, sprite->smooth); + } else { + luaDie(L, "spriteQuality", "Failed!"); + } + + return 0; +} + + int32_t apiSpriteRotate(lua_State *L) { int32_t n = lua_gettop(L); int32_t id = -1; @@ -2028,7 +2061,7 @@ int32_t apiSpriteRotate(lua_State *L) { if (!sprite) luaDie(L, "spriteRotate", "No sprite at index %d in apiSpriteRotate.", id); sprite->angle = a; SDL_FreeSurface(sprite->surface); - sprite->surface = rotozoomSurfaceXY(sprite->originalSurface, sprite->angle, sprite->scaleX, sprite->scaleY, sprite->smooth); + sprite->surface = rotozoomSurfaceXY(sprite->originalSurface, 360 - sprite->angle, sprite->scaleX, sprite->scaleY, sprite->smooth); } } } @@ -2067,7 +2100,7 @@ int32_t apiSpriteScale(lua_State *L) { sprite->scaleX = x; sprite->scaleY = y; SDL_FreeSurface(sprite->surface); - sprite->surface = rotozoomSurfaceXY(sprite->originalSurface, sprite->angle, sprite->scaleX, sprite->scaleY, sprite->smooth); + sprite->surface = rotozoomSurfaceXY(sprite->originalSurface, 360 - sprite->angle, sprite->scaleX, sprite->scaleY, sprite->smooth); } } } @@ -2082,37 +2115,6 @@ int32_t apiSpriteScale(lua_State *L) { } -int32_t apiSpriteSmooth(lua_State *L) { - int32_t n = lua_gettop(L); - int32_t id = -1; - int32_t s; - double d; - SpriteT *sprite = NULL; - - if (n == 2) { - if (lua_isnumber(L, 1)) { - if (lua_isnumber(L, 2)) { - d = lua_tonumber(L, 1); s = (int32_t)d; - d = lua_tonumber(L, 2); id = (int32_t)d; - HASH_FIND_INT(_global.spriteList, &id, sprite); - if (!sprite) luaDie(L, "spriteSmooth", "No sprite at index %d in apiSpriteSmooth.", id); - sprite->smooth = s; - SDL_FreeSurface(sprite->surface); - sprite->surface = rotozoomSurfaceXY(sprite->originalSurface, sprite->angle, sprite->scaleX, sprite->scaleY, sprite->smooth); - } - } - } - - if (id >= 0) { - luaTrace(L, "spriteSmooth", "%d %d", id, sprite->smooth); - } else { - luaDie(L, "spriteSmooth", "Failed!"); - } - - return 0; -} - - int32_t apiSpriteUnload(lua_State *L) { int32_t n = lua_gettop(L); bool result = false; @@ -3976,6 +3978,9 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) { lua_register(_global.luaContext, "spriteGetHeight", apiSpriteGetHeight); lua_register(_global.luaContext, "spriteGetWidth", apiSpriteGetWidth); lua_register(_global.luaContext, "spriteLoad", apiSpriteLoad); + lua_register(_global.luaContext, "spriteQuality", apiSpriteQuality); + lua_register(_global.luaContext, "spriteRotate", apiSpriteRotate); + lua_register(_global.luaContext, "spriteScale", apiSpriteScale); lua_register(_global.luaContext, "spriteUnload", apiSpriteUnload); lua_register(_global.luaContext, "videoDraw", apiVideoDraw); @@ -4664,6 +4669,22 @@ void stopControllers(void) { } +SDL_Surface *surfaceCopy(SDL_Surface *source) { + SDL_Surface *destination = NULL; + destination = SDL_CreateRGBSurface( + source->flags, + source->w, + source->h, + source->format->BitsPerPixel, + source->format->Rmask, + source->format->Gmask, + source->format->Bmask, + source->format->Amask); + if (destination != NULL) SDL_BlitSurface(source, NULL, destination, NULL); + return destination; +} + + void takeScreenshot(void) { int32_t x = 0; char filename[1024];