Fixed an issue where defining a carousel or grid defaultImage property only for the gamelist view would lead to very long startup times.

This commit is contained in:
Leon Styhre 2023-02-25 13:58:02 +01:00
parent 2188818f00
commit 8408428f61
2 changed files with 62 additions and 55 deletions

View file

@ -61,10 +61,10 @@ public:
Entry& getEntry(int index) { return mEntries.at(index); } Entry& getEntry(int index) { return mEntries.at(index); }
void onDemandTextureLoad() override; void onDemandTextureLoad() override;
const CarouselType getType() { return mType; } const CarouselType getType() { return mType; }
const std::string& getDefaultCarouselImage() const { return mDefaultImage; } const std::string& getDefaultCarouselImage() const { return mDefaultImagePath; }
const std::string& getDefaultCarouselFolderImage() const { return mDefaultFolderImage; } const std::string& getDefaultCarouselFolderImage() const { return mDefaultFolderImagePath; }
void setDefaultImage(std::string defaultImage) { mDefaultImage = defaultImage; } void setDefaultImage(std::string defaultImage) { mDefaultImagePath = defaultImage; }
void setDefaultFolderImage(std::string defaultImage) { mDefaultFolderImage = defaultImage; } void setDefaultFolderImage(std::string defaultImage) { mDefaultFolderImagePath = defaultImage; }
bool isScrolling() const override { return List::isScrolling(); } bool isScrolling() const override { return List::isScrolling(); }
const LetterCase getLetterCase() const override { return mLetterCase; } const LetterCase getLetterCase() const override { return mLetterCase; }
const LetterCase getLetterCaseAutoCollections() const override const LetterCase getLetterCaseAutoCollections() const override
@ -144,8 +144,9 @@ private:
CarouselType mType; CarouselType mType;
std::vector<std::string> mImageTypes; std::vector<std::string> mImageTypes;
std::string mDefaultImage; std::string mDefaultImagePath;
std::string mDefaultFolderImage; std::string mDefaultFolderImagePath;
std::shared_ptr<ImageComponent> mDefaultImage;
float mMaxItemCount; float mMaxItemCount;
int mItemsBeforeCenter; int mItemsBeforeCenter;
int mItemsAfterCenter; int mItemsAfterCenter;
@ -319,27 +320,29 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
} }
else if (entry.data.defaultImagePath != "" && else if (entry.data.defaultImagePath != "" &&
ResourceManager::getInstance().fileExists(entry.data.defaultImagePath)) { ResourceManager::getInstance().fileExists(entry.data.defaultImagePath)) {
auto defaultImage = std::make_shared<ImageComponent>(false, dynamic); if (mDefaultImage.get() == nullptr || !mGamelistView) {
defaultImage->setLinearInterpolation(mLinearInterpolation); mDefaultImage = std::make_shared<ImageComponent>(false, dynamic);
defaultImage->setMipmapping(true); mDefaultImage->setLinearInterpolation(mLinearInterpolation);
defaultImage->setMaxSize( mDefaultImage->setMipmapping(true);
glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); mDefaultImage->setMaxSize(
defaultImage->setImage(entry.data.defaultImagePath); glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL); mDefaultImage->setImage(entry.data.defaultImagePath);
if (mImageBrightness != 0.0) mDefaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL);
defaultImage->setBrightness(mImageBrightness); if (mImageBrightness != 0.0)
if (mImageSaturation != 1.0) mDefaultImage->setBrightness(mImageBrightness);
defaultImage->setSaturation(mImageSaturation); if (mImageSaturation != 1.0)
if (mImageColorShift != 0xFFFFFFFF) mDefaultImage->setSaturation(mImageSaturation);
defaultImage->setColorShift(mImageColorShift); if (mImageColorShift != 0xFFFFFFFF)
if (mImageColorShiftEnd != mImageColorShift) mDefaultImage->setColorShift(mImageColorShift);
defaultImage->setColorShiftEnd(mImageColorShiftEnd); if (mImageColorShiftEnd != mImageColorShift)
if (!mImageColorGradientHorizontal) mDefaultImage->setColorShiftEnd(mImageColorShiftEnd);
defaultImage->setColorGradientHorizontal(false); if (!mImageColorGradientHorizontal)
defaultImage->setRotateByTargetSize(true); mDefaultImage->setColorGradientHorizontal(false);
mDefaultImage->setRotateByTargetSize(true);
}
// For the gamelist view the default image is applied in onDemandTextureLoad(). // For the gamelist view the default image is applied in onDemandTextureLoad().
if (!mGamelistView) if (!mGamelistView)
entry.data.item = defaultImage; entry.data.item = mDefaultImage;
} }
else if (!mGamelistView) { else if (!mGamelistView) {
entry.data.imagePath = ""; entry.data.imagePath = "";

View file

@ -71,10 +71,10 @@ public:
{ {
return mLetterCaseSystemNameSuffix; return mLetterCaseSystemNameSuffix;
} }
const std::string& getDefaultGridImage() const { return mDefaultImage; } const std::string& getDefaultGridImage() const { return mDefaultImagePath; }
const std::string& getDefaultGridFolderImage() const { return mDefaultFolderImage; } const std::string& getDefaultGridFolderImage() const { return mDefaultFolderImagePath; }
void setDefaultImage(std::string defaultImage) { mDefaultImage = defaultImage; } void setDefaultImage(std::string defaultImage) { mDefaultImagePath = defaultImage; }
void setDefaultFolderImage(std::string defaultImage) { mDefaultFolderImage = defaultImage; } void setDefaultFolderImage(std::string defaultImage) { mDefaultFolderImagePath = defaultImage; }
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const glm::mat4& parentTrans) override; void render(const glm::mat4& parentTrans) override;
@ -145,8 +145,9 @@ private:
float mVerticalMargin; float mVerticalMargin;
std::vector<std::string> mImageTypes; std::vector<std::string> mImageTypes;
std::string mDefaultImage; std::string mDefaultImagePath;
std::string mDefaultFolderImage; std::string mDefaultFolderImagePath;
std::shared_ptr<ImageComponent> mDefaultImage;
glm::vec2 mItemSize; glm::vec2 mItemSize;
float mItemScale; float mItemScale;
glm::vec2 mItemSpacing; glm::vec2 mItemSpacing;
@ -309,33 +310,36 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
ResourceManager::getInstance().fileExists(entry.data.defaultImagePath)) { ResourceManager::getInstance().fileExists(entry.data.defaultImagePath)) {
if (!mGamelistView) if (!mGamelistView)
entry.data.imagePath = ""; entry.data.imagePath = "";
auto defaultImage = std::make_shared<ImageComponent>(false, dynamic);
defaultImage->setLinearInterpolation(true); if (mDefaultImage.get() == nullptr || !mGamelistView) {
defaultImage->setMipmapping(true); mDefaultImage = std::make_shared<ImageComponent>(false, dynamic);
if (mImagefit == ImageFit::CONTAIN) mDefaultImage->setLinearInterpolation(true);
defaultImage->setMaxSize(mItemSize * mImageRelativeScale); mDefaultImage->setMipmapping(true);
else if (mImagefit == ImageFit::FILL) if (mImagefit == ImageFit::CONTAIN)
defaultImage->setResize(mItemSize * mImageRelativeScale); mDefaultImage->setMaxSize(mItemSize * mImageRelativeScale);
else if (mImagefit == ImageFit::COVER) else if (mImagefit == ImageFit::FILL)
defaultImage->setCroppedSize(mItemSize * mImageRelativeScale); mDefaultImage->setResize(mItemSize * mImageRelativeScale);
defaultImage->setImage(entry.data.defaultImagePath); else if (mImagefit == ImageFit::COVER)
defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL); mDefaultImage->setCroppedSize(mItemSize * mImageRelativeScale);
if (mImageBrightness != 0.0) mDefaultImage->setImage(entry.data.defaultImagePath);
defaultImage->setBrightness(mImageBrightness); mDefaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageSaturation != 1.0) if (mImageBrightness != 0.0)
defaultImage->setSaturation(mImageSaturation); mDefaultImage->setBrightness(mImageBrightness);
if (mImageColor != 0xFFFFFFFF) if (mImageSaturation != 1.0)
defaultImage->setColorShift(mImageColor); mDefaultImage->setSaturation(mImageSaturation);
if (mImageColorEnd != mImageColor) { if (mImageColor != 0xFFFFFFFF)
defaultImage->setColorShiftEnd(mImageColorEnd); mDefaultImage->setColorShift(mImageColor);
if (!mImageColorGradientHorizontal) if (mImageColorEnd != mImageColor) {
defaultImage->setColorGradientHorizontal(false); mDefaultImage->setColorShiftEnd(mImageColorEnd);
if (!mImageColorGradientHorizontal)
mDefaultImage->setColorGradientHorizontal(false);
}
mDefaultImage->setOrigin(0.5f, 0.5f);
mDefaultImage->setRotateByTargetSize(true);
} }
defaultImage->setOrigin(0.5f, 0.5f);
defaultImage->setRotateByTargetSize(true);
// For the gamelist view the default image is applied in onDemandTextureLoad(). // For the gamelist view the default image is applied in onDemandTextureLoad().
if (!mGamelistView) if (!mGamelistView)
entry.data.item = defaultImage; entry.data.item = mDefaultImage;
} }
else if (!mGamelistView) { else if (!mGamelistView) {
entry.data.imagePath = ""; entry.data.imagePath = "";