From edc761c4f9cfc152c61f94c08fbfb801877e1e8f Mon Sep 17 00:00:00 2001 From: Sophia Hadash Date: Sun, 26 Sep 2021 19:45:05 +0200 Subject: [PATCH] fix the startup slowdown --- es-core/src/components/BadgesComponent.cpp | 53 ++++++++++++---------- es-core/src/components/BadgesComponent.h | 14 +++--- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/es-core/src/components/BadgesComponent.cpp b/es-core/src/components/BadgesComponent.cpp index a7a6adc50..9c28733a8 100644 --- a/es-core/src/components/BadgesComponent.cpp +++ b/es-core/src/components/BadgesComponent.cpp @@ -13,32 +13,37 @@ #include "ThemeData.h" #include "resources/TextureResource.h" -BadgesComponent::BadgesComponent(Window* window) - : FlexboxComponent(window) -{ - // Define the slots. - mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN}; +// Available slot definitions. +const std::vector BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN}; +std::map BadgesComponent::mBadgeIcons = std::map(); +std::map BadgesComponent::mImageComponents = std::map(); + +BadgesComponent::BadgesComponent(Window *window) + : FlexboxComponent(window) { + if (mBadgeIcons.empty()) { + mBadgeIcons[SLOT_FAVORITE] = ":/graphics/badge_favorite.svg"; + mBadgeIcons[SLOT_COMPLETED] = ":/graphics/badge_completed.svg"; + mBadgeIcons[SLOT_KIDS] = ":/graphics/badge_kidgame.svg"; + mBadgeIcons[SLOT_BROKEN] = ":/graphics/badge_broken.svg"; + } - mBadgeIcons = std::map(); - mBadgeIcons[SLOT_FAVORITE] = ":/graphics/badge_favorite.svg"; - mBadgeIcons[SLOT_COMPLETED] = ":/graphics/badge_completed.svg"; - mBadgeIcons[SLOT_KIDS] = ":/graphics/badge_kidgame.svg"; - mBadgeIcons[SLOT_BROKEN] = ":/graphics/badge_broken.svg"; // Create the child ImageComponent for every badge. - mImageComponents = std::map(); - ImageComponent mImageFavorite = ImageComponent(window); - mImageFavorite.setImage(mBadgeIcons[SLOT_FAVORITE], false, false); - mImageComponents.insert({SLOT_FAVORITE, mImageFavorite}); - ImageComponent mImageCompleted = ImageComponent(window); - mImageCompleted.setImage(mBadgeIcons[SLOT_COMPLETED], false, false); - mImageComponents.insert({SLOT_COMPLETED, mImageCompleted}); - ImageComponent mImageKids = ImageComponent(window); - mImageKids.setImage(mBadgeIcons[SLOT_KIDS], false, false); - mImageComponents.insert({SLOT_KIDS, mImageKids}); - ImageComponent mImageBroken = ImageComponent(window); - mImageBroken.setImage(mBadgeIcons[SLOT_BROKEN], false, false); - mImageComponents.insert({SLOT_BROKEN, mImageBroken}); + if (mImageComponents.empty()) { + ImageComponent mImageFavorite = ImageComponent(window); + mImageFavorite.setImage(mBadgeIcons[SLOT_FAVORITE], false, true); + mImageComponents.insert({SLOT_FAVORITE, mImageFavorite}); + ImageComponent mImageCompleted = ImageComponent(window); + mImageCompleted.setImage(mBadgeIcons[SLOT_COMPLETED], false, true); + mImageComponents.insert({SLOT_COMPLETED, mImageCompleted}); + ImageComponent mImageKids = ImageComponent(window); + mImageKids.setImage(mBadgeIcons[SLOT_KIDS], false, true); + mImageComponents.insert({SLOT_KIDS, mImageKids}); + ImageComponent mImageBroken = ImageComponent(window); + mImageBroken.setImage(mBadgeIcons[SLOT_BROKEN], false, true); + mImageComponents.insert({SLOT_BROKEN, mImageBroken}); + } + } void BadgesComponent::setValue(const std::string& value) @@ -84,7 +89,7 @@ void BadgesComponent::applyTheme(const std::shared_ptr& theme, for (auto& slot : mSlots) { if (properties & PATH && elem->has(slot)) { mBadgeIcons[slot] = elem->get(slot); - mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot]); + mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot], false, true); imgChanged = true; } } diff --git a/es-core/src/components/BadgesComponent.h b/es-core/src/components/BadgesComponent.h index badaa57c7..79b49fc8a 100644 --- a/es-core/src/components/BadgesComponent.h +++ b/es-core/src/components/BadgesComponent.h @@ -30,19 +30,19 @@ public: std::string getValue() const override; // Should be a list of strings. - void setValue(const std::string& value) override; + void setValue(const std::string &value) override; - virtual void applyTheme(const std::shared_ptr& theme, - const std::string& view, - const std::string& element, + virtual void applyTheme(const std::shared_ptr &theme, + const std::string &view, + const std::string &element, unsigned int properties) override; virtual std::vector getHelpPrompts() override; private: - std::vector mSlots; - std::map mBadgeIcons; - std::map mImageComponents; + static const std::vector mSlots; + static std::map mBadgeIcons; + static std::map mImageComponents; }; #endif // ES_APP_COMPONENTS_BADGES_COMPONENT_H