From 91f1a0a47daebaab3410f81f8ca3ccc33a3c3f36 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 27 Sep 2021 22:18:19 +0200 Subject: [PATCH] Improved the speed of the badges code. Also made some other adjustments to the badges and flexbox logic. --- .../views/gamelist/DetailedGameListView.cpp | 2 +- .../src/views/gamelist/VideoGameListView.cpp | 2 +- es-core/src/components/BadgesComponent.cpp | 34 +- es-core/src/components/BadgesComponent.h | 12 +- es-core/src/components/FlexboxComponent.cpp | 5 +- es-core/src/components/FlexboxComponent.h | 6 +- ...badge_altemu.svg => badge_altemulator.svg} | 2 +- resources/graphics/badge_broken.svg | 323 +++++++++++++---- resources/graphics/badge_completed.svg | 325 ++++++++++++++---- resources/graphics/badge_favorite.svg | 317 +++++++++++++---- resources/graphics/badge_kidgame.svg | 320 +++++++++++++---- themes/rbsimple-DE/theme.xml | 5 +- 12 files changed, 1045 insertions(+), 308 deletions(-) rename resources/graphics/{badge_altemu.svg => badge_altemulator.svg} (99%) diff --git a/es-app/src/views/gamelist/DetailedGameListView.cpp b/es-app/src/views/gamelist/DetailedGameListView.cpp index 736f1ac76..24c1450a9 100644 --- a/es-app/src/views/gamelist/DetailedGameListView.cpp +++ b/es-app/src/views/gamelist/DetailedGameListView.cpp @@ -410,7 +410,7 @@ void DetailedGameListView::updateInfoPanel() ss << (file->metadata.get("completed").compare("true") ? "" : "completed "); ss << (file->metadata.get("kidgame").compare("true") ? "" : "kidgame "); ss << (file->metadata.get("broken").compare("true") ? "" : "broken "); - ss << (file->metadata.get("altemulator").compare("") ? "altemu " : ""); + ss << (file->metadata.get("altemulator").compare("") ? "altemulator " : ""); std::string slots = ss.str(); if (!slots.empty()) slots.pop_back(); diff --git a/es-app/src/views/gamelist/VideoGameListView.cpp b/es-app/src/views/gamelist/VideoGameListView.cpp index 49b25ddd1..acff97747 100644 --- a/es-app/src/views/gamelist/VideoGameListView.cpp +++ b/es-app/src/views/gamelist/VideoGameListView.cpp @@ -451,7 +451,7 @@ void VideoGameListView::updateInfoPanel() ss << (file->metadata.get("completed").compare("true") ? "" : "completed "); ss << (file->metadata.get("kidgame").compare("true") ? "" : "kidgame "); ss << (file->metadata.get("broken").compare("true") ? "" : "broken "); - ss << (file->metadata.get("altemulator").compare("") ? "altemu " : ""); + ss << (file->metadata.get("altemulator").compare("") ? "altemulator " : ""); std::string slots = ss.str(); if (!slots.empty()) slots.pop_back(); diff --git a/es-core/src/components/BadgesComponent.cpp b/es-core/src/components/BadgesComponent.cpp index 9a28fa3c9..1d6ebfaab 100644 --- a/es-core/src/components/BadgesComponent.cpp +++ b/es-core/src/components/BadgesComponent.cpp @@ -20,30 +20,22 @@ std::vector BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETE BadgesComponent::BadgesComponent(Window* window) : FlexboxComponent(window) { - - 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"; - mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR] = ":/graphics/badge_altemu.svg"; + mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR] = ":/graphics/badge_altemulator.svg"; - mImageComponents = std::map(); 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}); - ImageComponent mImageAltEmu = ImageComponent(window); - mImageAltEmu.setImage(mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR], false, true); - mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu}); + ImageComponent mImageAltEmulator = ImageComponent(window); + mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmulator}); } BadgesComponent::~BadgesComponent() @@ -94,13 +86,14 @@ void BadgesComponent::applyTheme(const std::shared_ptr& theme, if (!elem) return; - bool imgChanged = false; for (auto& slot : mSlots) { - if (properties & PATH && elem->has(slot) && - mBadgeIcons[slot] != elem->get(slot)) { + if (properties & PATH && elem->has(slot)) { mBadgeIcons[slot] = elem->get(slot); - mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot], false, true); - imgChanged = true; + mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot]); + } + else { + mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot]); + std::string teststring; } } @@ -123,12 +116,5 @@ void BadgesComponent::applyTheme(const std::shared_ptr& theme, // Apply theme on the flexbox component parent. FlexboxComponent::applyTheme(theme, view, element, properties); - if (imgChanged) - onSizeChanged(); -} - -std::vector BadgesComponent::getHelpPrompts() -{ - std::vector prompts; - return prompts; + onSizeChanged(); } diff --git a/es-core/src/components/BadgesComponent.h b/es-core/src/components/BadgesComponent.h index f4584ecf4..e7412233a 100644 --- a/es-core/src/components/BadgesComponent.h +++ b/es-core/src/components/BadgesComponent.h @@ -7,8 +7,8 @@ // Used by gamelist views. // -#ifndef ES_APP_COMPONENTS_BADGES_COMPONENT_H -#define ES_APP_COMPONENTS_BADGES_COMPONENT_H +#ifndef ES_CORE_COMPONENTS_BADGES_COMPONENT_H +#define ES_CORE_COMPONENTS_BADGES_COMPONENT_H #include "FlexboxComponent.h" #include "GuiComponent.h" @@ -20,7 +20,7 @@ #define SLOT_COMPLETED "completed" #define SLOT_KIDS "kidgame" #define SLOT_BROKEN "broken" -#define SLOT_ALTERNATIVE_EMULATOR "altemu" +#define SLOT_ALTERNATIVE_EMULATOR "altemulator" class TextureResource; @@ -30,6 +30,8 @@ public: BadgesComponent(Window* window); ~BadgesComponent(); + static std::shared_ptr& getInstance(); + std::string getValue() const override; // Should be a list of strings. void setValue(const std::string& value) override; @@ -39,12 +41,10 @@ public: const std::string& element, unsigned int properties) override; - virtual std::vector getHelpPrompts() override; - private: static std::vector mSlots; std::map mBadgeIcons; std::map mImageComponents; }; -#endif // ES_APP_COMPONENTS_BADGES_COMPONENT_H +#endif // ES_CORE_COMPONENTS_BADGES_COMPONENT_H diff --git a/es-core/src/components/FlexboxComponent.cpp b/es-core/src/components/FlexboxComponent.cpp index 9213ae095..ac53174df 100644 --- a/es-core/src/components/FlexboxComponent.cpp +++ b/es-core/src/components/FlexboxComponent.cpp @@ -71,8 +71,8 @@ void FlexboxComponent::computeLayout() float anchorOriginY = 0; // Translation directions when placing items. - glm::vec2 directionLine = {1, 0}; - glm::vec2 directionRow = {0, 1}; + glm::ivec2 directionLine = {1, 0}; + glm::ivec2 directionRow = {0, 1}; // Change direction. if (mDirection == DIRECTION_COLUMN) { @@ -89,6 +89,7 @@ void FlexboxComponent::computeLayout() glm::vec2 newSize = {mItemWidth, oldSize.y * (mItemWidth / oldSize.x)}; i->setSize(newSize); maxItemSize = {std::max(maxItemSize.x, newSize.x), std::max(maxItemSize.y, newSize.y)}; + i->setResize(maxItemSize.x, maxItemSize.y); } // Pre-compute layout parameters. diff --git a/es-core/src/components/FlexboxComponent.h b/es-core/src/components/FlexboxComponent.h index 731a00c8e..d5c1b3a15 100644 --- a/es-core/src/components/FlexboxComponent.h +++ b/es-core/src/components/FlexboxComponent.h @@ -7,8 +7,8 @@ // Used by gamelist views. // -#ifndef ES_APP_COMPONENTS_FLEXBOX_COMPONENT_H -#define ES_APP_COMPONENTS_FLEXBOX_COMPONENT_H +#ifndef ES_CORE_COMPONENTS_FLEXBOX_COMPONENT_H +#define ES_CORE_COMPONENTS_FLEXBOX_COMPONENT_H #include "GuiComponent.h" #include "renderers/Renderer.h" @@ -69,4 +69,4 @@ private: bool mLayoutValid; }; -#endif // ES_APP_COMPONENTS_FLEXBOX_COMPONENT_H +#endif // ES_CORE_COMPONENTS_FLEXBOX_COMPONENT_H diff --git a/resources/graphics/badge_altemu.svg b/resources/graphics/badge_altemulator.svg similarity index 99% rename from resources/graphics/badge_altemu.svg rename to resources/graphics/badge_altemulator.svg index 777ad8142..943ec1486 100644 --- a/resources/graphics/badge_altemu.svg +++ b/resources/graphics/badge_altemulator.svg @@ -15,7 +15,7 @@ version="1.1" id="svg4842" inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)" - sodipodi:docname="badge_altemu.svg"> + sodipodi:docname="badge_altemulator.svg"> - - - - - image/svg+xml - - - - - - - - - - + + + + + + + + + + image/svg+xml + + + + + + + + + + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + diff --git a/resources/graphics/badge_completed.svg b/resources/graphics/badge_completed.svg index fca3c4ac5..a4f0a107b 100644 --- a/resources/graphics/badge_completed.svg +++ b/resources/graphics/badge_completed.svg @@ -1,71 +1,260 @@ - - - - - - image/svg+xml - - - - - - - - - - + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/resources/graphics/badge_favorite.svg b/resources/graphics/badge_favorite.svg index 4d5abaeb8..0ccd06479 100644 --- a/resources/graphics/badge_favorite.svg +++ b/resources/graphics/badge_favorite.svg @@ -1,70 +1,253 @@ - - - - - - image/svg+xml - - - - - - - - - - + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/resources/graphics/badge_kidgame.svg b/resources/graphics/badge_kidgame.svg index 13f5a249a..f11131965 100644 --- a/resources/graphics/badge_kidgame.svg +++ b/resources/graphics/badge_kidgame.svg @@ -1,70 +1,256 @@ - - - - - - image/svg+xml - - - - - - - - - - + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/themes/rbsimple-DE/theme.xml b/themes/rbsimple-DE/theme.xml index 381379f96..613f51df6 100644 --- a/themes/rbsimple-DE/theme.xml +++ b/themes/rbsimple-DE/theme.xml @@ -243,16 +243,17 @@ based on: 'recalbox-multi' by the Recalbox community row start - 2 + 3 5 5 .035 - favorite completed kidgame broken altemu + favorite completed kidgame broken altemulator :/graphics/badge_favorite.svg :/graphics/badge_completed.svg :/graphics/badge_kidgame.svg :/graphics/badge_broken.svg + :/graphics/badge_altemulator.svg