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

View file

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