mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-18 07:05:39 +00:00
add support for default image path in themes
This commit is contained in:
parent
99c1ddb260
commit
24f1b969bf
|
@ -523,6 +523,8 @@ Can be created as an extra.
|
||||||
- Point around which the image will be rotated. Defaults to `0.5 0.5`.
|
- Point around which the image will be rotated. Defaults to `0.5 0.5`.
|
||||||
* `path` - type: PATH.
|
* `path` - type: PATH.
|
||||||
- Path to the image file. Most common extensions are supported (including .jpg, .png, and unanimated .gif).
|
- Path to the image file. Most common extensions are supported (including .jpg, .png, and unanimated .gif).
|
||||||
|
* `default` - type: PATH.
|
||||||
|
- Path to default image file. Default image will be displayed when selected game does not have an image.
|
||||||
* `tile` - type: BOOLEAN.
|
* `tile` - type: BOOLEAN.
|
||||||
- If true, the image will be tiled instead of stretched to fit its size. Useful for backgrounds.
|
- If true, the image will be tiled instead of stretched to fit its size. Useful for backgrounds.
|
||||||
* `color` - type: COLOR.
|
* `color` - type: COLOR.
|
||||||
|
|
|
@ -42,15 +42,17 @@ void SystemView::populate()
|
||||||
e.object = *it;
|
e.object = *it;
|
||||||
|
|
||||||
// make logo
|
// make logo
|
||||||
if(theme->getElement("system", "logo", "image"))
|
const ThemeData::ThemeElement* logoElem = theme->getElement("system", "logo", "image");
|
||||||
|
if(logoElem)
|
||||||
{
|
{
|
||||||
std::string path = theme->getElement("system", "logo", "image")->get<std::string>("path");
|
std::string path = logoElem->get<std::string>("path");
|
||||||
|
std::string defaultPath = logoElem->has("default") ? logoElem->get<std::string>("default") : "";
|
||||||
if(!path.empty() && ResourceManager::getInstance()->fileExists(path))
|
if((!path.empty() && ResourceManager::getInstance()->fileExists(path))
|
||||||
|
|| (!defaultPath.empty() && ResourceManager::getInstance()->fileExists(defaultPath)))
|
||||||
{
|
{
|
||||||
ImageComponent* logo = new ImageComponent(mWindow, false, false);
|
ImageComponent* logo = new ImageComponent(mWindow, false, false);
|
||||||
logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale);
|
logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale);
|
||||||
logo->applyTheme((*it)->getTheme(), "system", "logo", ThemeFlags::PATH | ThemeFlags::COLOR);
|
logo->applyTheme(theme, "system", "logo", ThemeFlags::PATH | ThemeFlags::COLOR);
|
||||||
|
|
||||||
e.data.logo = std::shared_ptr<GuiComponent>(logo);
|
e.data.logo = std::shared_ptr<GuiComponent>(logo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::
|
||||||
("rotation", FLOAT)
|
("rotation", FLOAT)
|
||||||
("rotationOrigin", NORMALIZED_PAIR)
|
("rotationOrigin", NORMALIZED_PAIR)
|
||||||
("path", PATH)
|
("path", PATH)
|
||||||
|
("default", PATH)
|
||||||
("tile", BOOLEAN)
|
("tile", BOOLEAN)
|
||||||
("color", COLOR)
|
("color", COLOR)
|
||||||
("zIndex", FLOAT)))
|
("zIndex", FLOAT)))
|
||||||
|
|
|
@ -93,12 +93,22 @@ void ImageComponent::onSizeChanged()
|
||||||
updateVertices();
|
updateVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageComponent::setDefaultImage(std::string path)
|
||||||
|
{
|
||||||
|
mDefaultPath = path;
|
||||||
|
}
|
||||||
|
|
||||||
void ImageComponent::setImage(std::string path, bool tile)
|
void ImageComponent::setImage(std::string path, bool tile)
|
||||||
{
|
{
|
||||||
if(path.empty() || !ResourceManager::getInstance()->fileExists(path))
|
if(path.empty() || !ResourceManager::getInstance()->fileExists(path))
|
||||||
|
{
|
||||||
|
if(mDefaultPath.empty() || !ResourceManager::getInstance()->fileExists(mDefaultPath))
|
||||||
mTexture.reset();
|
mTexture.reset();
|
||||||
else
|
else
|
||||||
|
mTexture = TextureResource::get(mDefaultPath, tile, mForceLoad, mDynamic);
|
||||||
|
} else {
|
||||||
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic);
|
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic);
|
||||||
|
}
|
||||||
|
|
||||||
resize();
|
resize();
|
||||||
}
|
}
|
||||||
|
@ -334,6 +344,10 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
|
||||||
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))
|
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))
|
||||||
setOrigin(elem->get<Eigen::Vector2f>("origin"));
|
setOrigin(elem->get<Eigen::Vector2f>("origin"));
|
||||||
|
|
||||||
|
if(elem->has("default")) {
|
||||||
|
setDefaultImage(elem->get<std::string>("default"));
|
||||||
|
}
|
||||||
|
|
||||||
if(properties & PATH && elem->has("path"))
|
if(properties & PATH && elem->has("path"))
|
||||||
{
|
{
|
||||||
bool tile = (elem->has("tile") && elem->get<bool>("tile"));
|
bool tile = (elem->has("tile") && elem->get<bool>("tile"));
|
||||||
|
|
|
@ -15,6 +15,8 @@ public:
|
||||||
ImageComponent(Window* window, bool forceLoad = false, bool dynamic = true);
|
ImageComponent(Window* window, bool forceLoad = false, bool dynamic = true);
|
||||||
virtual ~ImageComponent();
|
virtual ~ImageComponent();
|
||||||
|
|
||||||
|
void setDefaultImage(std::string path);
|
||||||
|
|
||||||
//Loads the image at the given filepath. Will tile if tile is true (retrieves texture as tiling, creates vertices accordingly).
|
//Loads the image at the given filepath. Will tile if tile is true (retrieves texture as tiling, creates vertices accordingly).
|
||||||
void setImage(std::string path, bool tile = false);
|
void setImage(std::string path, bool tile = false);
|
||||||
//Loads an image from memory.
|
//Loads an image from memory.
|
||||||
|
@ -77,6 +79,8 @@ private:
|
||||||
|
|
||||||
unsigned int mColorShift;
|
unsigned int mColorShift;
|
||||||
|
|
||||||
|
std::string mDefaultPath;
|
||||||
|
|
||||||
std::shared_ptr<TextureResource> mTexture;
|
std::shared_ptr<TextureResource> mTexture;
|
||||||
unsigned char mFadeOpacity;
|
unsigned char mFadeOpacity;
|
||||||
bool mFading;
|
bool mFading;
|
||||||
|
|
Loading…
Reference in a new issue