mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 02:05:55 +02:00
LuaImage::LoadType support
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
#include "Image.h"
|
||||
#include "../../SDL.h"
|
||||
#include "../../Utility/Utils.h"
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
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_)
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <string>
|
||||
#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;
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
return 2;
|
||||
}
|
||||
#if 0
|
||||
|
||||
int LuaImage::isLoaded(lua_State *l)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user