mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-17 22:55:38 +00:00
Merge pull request #256 from jrassa/default-image
add support for default image path in themes
This commit is contained in:
commit
5f7aec71dc
|
@ -523,6 +523,8 @@ Can be created as an extra.
|
|||
- Point around which the image will be rotated. Defaults to `0.5 0.5`.
|
||||
* `path` - type: PATH.
|
||||
- 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.
|
||||
- If true, the image will be tiled instead of stretched to fit its size. Useful for backgrounds.
|
||||
* `color` - type: COLOR.
|
||||
|
|
|
@ -42,15 +42,17 @@ void SystemView::populate()
|
|||
e.object = *it;
|
||||
|
||||
// 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");
|
||||
|
||||
if(!path.empty() && ResourceManager::getInstance()->fileExists(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))
|
||||
|| (!defaultPath.empty() && ResourceManager::getInstance()->fileExists(defaultPath)))
|
||||
{
|
||||
ImageComponent* logo = new ImageComponent(mWindow, false, false);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::
|
|||
("rotation", FLOAT)
|
||||
("rotationOrigin", NORMALIZED_PAIR)
|
||||
("path", PATH)
|
||||
("default", PATH)
|
||||
("tile", BOOLEAN)
|
||||
("color", COLOR)
|
||||
("zIndex", FLOAT)))
|
||||
|
|
|
@ -93,12 +93,22 @@ void ImageComponent::onSizeChanged()
|
|||
updateVertices();
|
||||
}
|
||||
|
||||
void ImageComponent::setDefaultImage(std::string path)
|
||||
{
|
||||
mDefaultPath = path;
|
||||
}
|
||||
|
||||
void ImageComponent::setImage(std::string path, bool tile)
|
||||
{
|
||||
if(path.empty() || !ResourceManager::getInstance()->fileExists(path))
|
||||
mTexture.reset();
|
||||
else
|
||||
{
|
||||
if(mDefaultPath.empty() || !ResourceManager::getInstance()->fileExists(mDefaultPath))
|
||||
mTexture.reset();
|
||||
else
|
||||
mTexture = TextureResource::get(mDefaultPath, tile, mForceLoad, mDynamic);
|
||||
} else {
|
||||
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic);
|
||||
}
|
||||
|
||||
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"))
|
||||
setOrigin(elem->get<Eigen::Vector2f>("origin"));
|
||||
|
||||
if(elem->has("default")) {
|
||||
setDefaultImage(elem->get<std::string>("default"));
|
||||
}
|
||||
|
||||
if(properties & PATH && elem->has("path"))
|
||||
{
|
||||
bool tile = (elem->has("tile") && elem->get<bool>("tile"));
|
||||
|
|
|
@ -15,6 +15,8 @@ public:
|
|||
ImageComponent(Window* window, bool forceLoad = false, bool dynamic = true);
|
||||
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).
|
||||
void setImage(std::string path, bool tile = false);
|
||||
//Loads an image from memory.
|
||||
|
@ -77,6 +79,8 @@ private:
|
|||
|
||||
unsigned int mColorShift;
|
||||
|
||||
std::string mDefaultPath;
|
||||
|
||||
std::shared_ptr<TextureResource> mTexture;
|
||||
unsigned char mFadeOpacity;
|
||||
bool mFading;
|
||||
|
|
Loading…
Reference in a new issue