diff --git a/THEMES.md b/THEMES.md index e6845c852..504730ce8 100644 --- a/THEMES.md +++ b/THEMES.md @@ -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. diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index b6f409062..f2ef3da1a 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -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("path"); - - if(!path.empty() && ResourceManager::getInstance()->fileExists(path)) + std::string path = logoElem->get("path"); + std::string defaultPath = logoElem->has("default") ? logoElem->get("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(logo); } diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index dc5c6deae..5cecba10d 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -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))) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index 7ab8f9c90..d39f5916c 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -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& theme, const s if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin")) setOrigin(elem->get("origin")); + if(elem->has("default")) { + setDefaultImage(elem->get("default")); + } + if(properties & PATH && elem->has("path")) { bool tile = (elem->has("tile") && elem->get("tile")); diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index 2ed005fc2..98087ba0e 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -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 mTexture; unsigned char mFadeOpacity; bool mFading;