Improved the speed of the badges code.
Also made some other adjustments to the badges and flexbox logic.
|  | @ -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(); | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -20,30 +20,22 @@ std::vector<std::string> BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETE | |||
| BadgesComponent::BadgesComponent(Window* window) | ||||
|     : FlexboxComponent(window) | ||||
| { | ||||
| 
 | ||||
|     mBadgeIcons = std::map<std::string, std::string>(); | ||||
|     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<std::string, ImageComponent>(); | ||||
|     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<ThemeData>& theme, | |||
|     if (!elem) | ||||
|         return; | ||||
| 
 | ||||
|     bool imgChanged = false; | ||||
|     for (auto& slot : mSlots) { | ||||
|         if (properties & PATH && elem->has(slot) && | ||||
|             mBadgeIcons[slot] != elem->get<std::string>(slot)) { | ||||
|         if (properties & PATH && elem->has(slot)) { | ||||
|             mBadgeIcons[slot] = elem->get<std::string>(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<ThemeData>& theme, | |||
|     // Apply theme on the flexbox component parent.
 | ||||
|     FlexboxComponent::applyTheme(theme, view, element, properties); | ||||
| 
 | ||||
|     if (imgChanged) | ||||
|         onSizeChanged(); | ||||
| } | ||||
| 
 | ||||
| std::vector<HelpPrompt> BadgesComponent::getHelpPrompts() | ||||
| { | ||||
|     std::vector<HelpPrompt> prompts; | ||||
|     return prompts; | ||||
|     onSizeChanged(); | ||||
| } | ||||
|  |  | |||
|  | @ -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<BadgesComponent>& 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<HelpPrompt> getHelpPrompts() override; | ||||
| 
 | ||||
| private: | ||||
|     static std::vector<std::string> mSlots; | ||||
|     std::map<std::string, std::string> mBadgeIcons; | ||||
|     std::map<std::string, ImageComponent> mImageComponents; | ||||
| }; | ||||
| 
 | ||||
| #endif // ES_APP_COMPONENTS_BADGES_COMPONENT_H
 | ||||
| #endif // ES_CORE_COMPONENTS_BADGES_COMPONENT_H
 | ||||
|  |  | |||
|  | @ -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.
 | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -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"> | ||||
|   <defs | ||||
|      id="defs4836" /> | ||||
|   <sodipodi:namedview | ||||
| Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB | 
| Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 24 KiB | 
| Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 24 KiB | 
| Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 23 KiB | 
| Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 24 KiB | 
|  | @ -243,16 +243,17 @@ based on: 'recalbox-multi' by the Recalbox community | |||
|             <!-- flexbox properties --> | ||||
|             <direction>row</direction> | ||||
|             <align>start</align> | ||||
|             <itemsPerLine>2</itemsPerLine> | ||||
|             <itemsPerLine>3</itemsPerLine> | ||||
|             <itemMargin>5 5</itemMargin> | ||||
|             <itemWidth>.035</itemWidth> | ||||
| 
 | ||||
|             <!-- badges properties --> | ||||
|             <slots>favorite completed kidgame broken altemu</slots> | ||||
|             <slots>favorite completed kidgame broken altemulator</slots> | ||||
|             <customBadgeIcon badge="favorite">:/graphics/badge_favorite.svg</customBadgeIcon> | ||||
|             <customBadgeIcon badge="completed">:/graphics/badge_completed.svg</customBadgeIcon> | ||||
|             <customBadgeIcon badge="kidgame">:/graphics/badge_kidgame.svg</customBadgeIcon> | ||||
|             <customBadgeIcon badge="broken">:/graphics/badge_broken.svg</customBadgeIcon> | ||||
|             <customBadgeIcon badge="altemulator">:/graphics/badge_altemulator.svg</customBadgeIcon> | ||||
|         </badges> | ||||
|         <!-- This block prevents additional elements from interfering when mixing layouts. --> | ||||
|         <image name="backframe4" extra="false"></image> | ||||
|  |  | |||
 Leon Styhre
						Leon Styhre