mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 10:16:50 +02:00
LuaImage::LoadType support
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "../../SDL.h"
|
#include "../../SDL.h"
|
||||||
|
#include "../../Utility/Utils.h"
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
|
||||||
Image::Image()
|
Image::Image()
|
||||||
@@ -29,23 +30,22 @@ Image::~Image()
|
|||||||
bool Image::load(std::string file)
|
bool Image::load(std::string file)
|
||||||
{
|
{
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
if(!texture_)
|
unload();
|
||||||
{
|
SDL_LockMutex(SDL::getMutex());
|
||||||
SDL_LockMutex(SDL::getMutex());
|
texture_ = IMG_LoadTexture(SDL::getRenderer(), file.c_str());
|
||||||
texture_ = IMG_LoadTexture(SDL::getRenderer(), file.c_str());
|
|
||||||
|
|
||||||
if (texture_ != NULL)
|
if (texture_ != NULL)
|
||||||
{
|
{
|
||||||
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
||||||
SDL_QueryTexture(texture_, NULL, NULL, &info.width, &info.height);
|
SDL_QueryTexture(texture_, NULL, NULL, &info.width, &info.height);
|
||||||
retval = true;
|
retval = true;
|
||||||
}
|
|
||||||
SDL_UnlockMutex(SDL::getMutex());
|
|
||||||
}
|
}
|
||||||
|
SDL_UnlockMutex(SDL::getMutex());
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Image::unload()
|
void Image::unload()
|
||||||
{
|
{
|
||||||
if(texture_)
|
if(texture_)
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "../Collection/Item.h"
|
#include "../Collection/Item.h"
|
||||||
|
|
||||||
Configuration *config;
|
static Configuration *config;
|
||||||
CollectionInfoBuilder *cib;
|
static CollectionInfoBuilder *cib;
|
||||||
LuaEvent *events;
|
static LuaEvent *events;
|
||||||
void LuaCollection::initialize(Configuration *c, CollectionInfoBuilder *b, LuaEvent *e)
|
void LuaCollection::initialize(Configuration *c, CollectionInfoBuilder *b, LuaEvent *e)
|
||||||
{
|
{
|
||||||
config = c;
|
config = c;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
#include "LuaImage.h"
|
#include "LuaImage.h"
|
||||||
#include "../Utility/Log.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;
|
factory = &f;
|
||||||
|
config = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaImage::create(lua_State *l)
|
int LuaImage::create(lua_State *l)
|
||||||
@@ -36,18 +40,40 @@ int LuaImage::loadFile(lua_State *l)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int LuaImage::loadType(lua_State *l)
|
int LuaImage::loadType(lua_State *l)
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
Image *i = (Image *)luaL_checkinteger(l, 1);
|
Image *i = (Image *)luaL_checkinteger(l, 1);
|
||||||
stdL::string type = luaL_checkstring(l, 2);
|
CollectionInfo *ci = (CollectionInfo *)luaL_checkinteger(l, 2);
|
||||||
stdL::string item = luaL_checkstring(l, 3);
|
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<std::string> 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);
|
lua_pushboolean(l, result);
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
|
||||||
int LuaImage::isLoaded(lua_State *l)
|
int LuaImage::isLoaded(lua_State *l)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Lua.h"
|
#include "Lua.h"
|
||||||
|
#include "../Database/Configuration.h"
|
||||||
#include "../Graphics/Component/ComponentFactory.h"
|
#include "../Graphics/Component/ComponentFactory.h"
|
||||||
|
|
||||||
namespace LuaImage
|
namespace LuaImage
|
||||||
{
|
{
|
||||||
void initialize(ComponentFactory &f);
|
void initialize(Configuration *c, ComponentFactory &f);
|
||||||
int create(lua_State *l);
|
int create(lua_State *l);
|
||||||
int destroy(lua_State *l);
|
int destroy(lua_State *l);
|
||||||
int loadFile(lua_State *l);
|
int loadFile(lua_State *l);
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ const luaL_Reg RetroFE::luaImageFuncs[] = {
|
|||||||
// Creation
|
// Creation
|
||||||
{"create", LuaImage::create},
|
{"create", LuaImage::create},
|
||||||
{"loadFile", LuaImage::loadFile},
|
{"loadFile", LuaImage::loadFile},
|
||||||
|
{"loadType", LuaImage::loadType},
|
||||||
{"getOriginalWidth", LuaImage::getOriginalWidth},
|
{"getOriginalWidth", LuaImage::getOriginalWidth},
|
||||||
{"getOriginalHeight", LuaImage::getOriginalHeight},
|
{"getOriginalHeight", LuaImage::getOriginalHeight},
|
||||||
{"getOriginalDimensions", LuaImage::getOriginalDimensions},
|
{"getOriginalDimensions", LuaImage::getOriginalDimensions},
|
||||||
@@ -107,7 +108,7 @@ const luaL_Reg RetroFE::luaLogFuncs[] = {
|
|||||||
void RetroFE::initializeLua()
|
void RetroFE::initializeLua()
|
||||||
{
|
{
|
||||||
lua_.initialize();
|
lua_.initialize();
|
||||||
LuaImage::initialize(factory_);
|
LuaImage::initialize(&config_, factory_);
|
||||||
LuaCollection::initialize(&config_, cib_, &luaEvent_);
|
LuaCollection::initialize(&config_, cib_, &luaEvent_);
|
||||||
|
|
||||||
lua_newtable(lua_.state);
|
lua_newtable(lua_.state);
|
||||||
|
|||||||
Reference in New Issue
Block a user