diff --git a/RetroFE/Source/Graphics/Component/Image.cpp b/RetroFE/Source/Graphics/Component/Image.cpp index a368c5f..0668997 100644 --- a/RetroFE/Source/Graphics/Component/Image.cpp +++ b/RetroFE/Source/Graphics/Component/Image.cpp @@ -15,6 +15,7 @@ */ #include "Image.h" #include "../../SDL.h" +#include "../../Utility/Utils.h" #include Image::Image() @@ -29,23 +30,22 @@ Image::~Image() bool Image::load(std::string file) { bool retval = false; - if(!texture_) - { - SDL_LockMutex(SDL::getMutex()); - texture_ = IMG_LoadTexture(SDL::getRenderer(), file.c_str()); + unload(); + SDL_LockMutex(SDL::getMutex()); + texture_ = IMG_LoadTexture(SDL::getRenderer(), file.c_str()); - if (texture_ != NULL) - { - SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); - SDL_QueryTexture(texture_, NULL, NULL, &info.width, &info.height); - retval = true; - } - SDL_UnlockMutex(SDL::getMutex()); + if (texture_ != NULL) + { + SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); + SDL_QueryTexture(texture_, NULL, NULL, &info.width, &info.height); + retval = true; } + SDL_UnlockMutex(SDL::getMutex()); return retval; } + void Image::unload() { if(texture_) diff --git a/RetroFE/Source/Lua/LuaCollection.cpp b/RetroFE/Source/Lua/LuaCollection.cpp index 08dc6aa..b2d6bd5 100644 --- a/RetroFE/Source/Lua/LuaCollection.cpp +++ b/RetroFE/Source/Lua/LuaCollection.cpp @@ -3,9 +3,9 @@ #include #include "../Collection/Item.h" -Configuration *config; -CollectionInfoBuilder *cib; -LuaEvent *events; +static Configuration *config; +static CollectionInfoBuilder *cib; +static LuaEvent *events; void LuaCollection::initialize(Configuration *c, CollectionInfoBuilder *b, LuaEvent *e) { config = c; diff --git a/RetroFE/Source/Lua/LuaImage.cpp b/RetroFE/Source/Lua/LuaImage.cpp index 23e69f1..49bc7bc 100644 --- a/RetroFE/Source/Lua/LuaImage.cpp +++ b/RetroFE/Source/Lua/LuaImage.cpp @@ -1,11 +1,15 @@ #include "LuaImage.h" #include "../Utility/Log.h" +#include "../Utility/Utils.h" +#include "../Collection/CollectionInfo.h" -ComponentFactory *factory; +static ComponentFactory *factory = NULL; +static Configuration *config = NULL; -void LuaImage::initialize(ComponentFactory &f) +void LuaImage::initialize(Configuration *c, ComponentFactory &f) { factory = &f; + config = c; } int LuaImage::create(lua_State *l) @@ -36,18 +40,40 @@ int LuaImage::loadFile(lua_State *l) return 1; } -#if 0 int LuaImage::loadType(lua_State *l) { + bool result = false; Image *i = (Image *)luaL_checkinteger(l, 1); - stdL::string type = luaL_checkstring(l, 2); - stdL::string item = luaL_checkstring(l, 3); + CollectionInfo *ci = (CollectionInfo *)luaL_checkinteger(l, 2); + std::string type = luaL_checkstring(l, 3); + std::string name = luaL_checkstring(l, 4); - bool result = i->loadType(type, item); + std::string file; + std::vector extensions; + + extensions.push_back("png"); + extensions.push_back("PNG"); + extensions.push_back("jpg"); + extensions.push_back("JPG"); + extensions.push_back("jpeg"); + extensions.push_back("JPEG"); + + std::string path; + config->getMediaPropertyAbsolutePath(ci->name, type, false, path); + + std::string prefix = Utils::combinePath(path, name); + + if(Utils::findMatchingFile(prefix, extensions, file)) + { + result = i->load(file); + } + + lua_pushboolean(l, result); return 2; } +#if 0 int LuaImage::isLoaded(lua_State *l) { diff --git a/RetroFE/Source/Lua/LuaImage.h b/RetroFE/Source/Lua/LuaImage.h index 162850f..f3a3e62 100644 --- a/RetroFE/Source/Lua/LuaImage.h +++ b/RetroFE/Source/Lua/LuaImage.h @@ -1,11 +1,11 @@ #pragma once #include "Lua.h" +#include "../Database/Configuration.h" #include "../Graphics/Component/ComponentFactory.h" - namespace LuaImage { - void initialize(ComponentFactory &f); + void initialize(Configuration *c, ComponentFactory &f); int create(lua_State *l); int destroy(lua_State *l); int loadFile(lua_State *l); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 8b5c62e..bc0a7c6 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -55,6 +55,7 @@ const luaL_Reg RetroFE::luaImageFuncs[] = { // Creation {"create", LuaImage::create}, {"loadFile", LuaImage::loadFile}, + {"loadType", LuaImage::loadType}, {"getOriginalWidth", LuaImage::getOriginalWidth}, {"getOriginalHeight", LuaImage::getOriginalHeight}, {"getOriginalDimensions", LuaImage::getOriginalDimensions}, @@ -107,7 +108,7 @@ const luaL_Reg RetroFE::luaLogFuncs[] = { void RetroFE::initializeLua() { lua_.initialize(); - LuaImage::initialize(factory_); + LuaImage::initialize(&config_, factory_); LuaCollection::initialize(&config_, cib_, &luaEvent_); lua_newtable(lua_.state);