diff --git a/src/link.cpp b/src/link.cpp index 162f958..e17817b 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -85,6 +85,12 @@ const string &Link::getIcon() { return icon; } +void Link::loadIcon() { + if (icon.compare(0, 5, "skin:") == 0) { + setIconPath(gmenu2x->sc.getSkinFilePath(icon.substr(5, string::npos))); + } +} + void Link::setIcon(const string &icon) { this->icon = icon; diff --git a/src/link.h b/src/link.h index 419960d..99797ab 100644 --- a/src/link.h +++ b/src/link.h @@ -50,6 +50,7 @@ protected: Surface *iconSurface; Surface *icon_hover; + void setIconPath(const std::string &icon); void updateSurfaces(); public: @@ -59,6 +60,9 @@ public: virtual void paint(); virtual bool paintHover(); + virtual void loadIcon(); + virtual const std::string &searchIcon(); + void setSize(int w, int h); void setPosition(int x, int y); @@ -68,9 +72,7 @@ public: void setDescription(const std::string &description); const std::string &getIcon(); void setIcon(const std::string &icon); - virtual const std::string &searchIcon(); const std::string &getIconPath(); - void setIconPath(const std::string &icon); void run(); }; diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 44f1771..c31e549 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -261,6 +261,20 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, if (iconPath.empty()) searchIcon(); } +void LinkApp::loadIcon() { + if (icon.compare(0, 5, "skin:") == 0) { + string linkIcon = gmenu2x->sc.getSkinFilePath( + icon.substr(5, string::npos)); + if (!fileExists(linkIcon)) + searchIcon(); + else + setIconPath(linkIcon); + + } else if (!fileExists(icon)) { + searchIcon(); + } +} + const string &LinkApp::searchIcon() { if (!iconPath.empty()) return iconPath; diff --git a/src/linkapp.h b/src/linkapp.h index 67b629a..e78689b 100644 --- a/src/linkapp.h +++ b/src/linkapp.h @@ -70,6 +70,7 @@ public: const char* linkfile); #endif + virtual void loadIcon(); virtual const std::string &searchIcon(); #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) diff --git a/src/menu.cpp b/src/menu.cpp index 9153307..66f8ccb 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -122,21 +122,7 @@ void Menu::loadIcons() { gmenu2x->sc.add("skin:" + sectionIcon); for (Link *&link : links[i]) { - LinkApp *linkapp = dynamic_cast(link); - - //check link's icons - string linkIcon = link->getIcon(); - if (linkIcon.substr(0,5) == "skin:") { - linkIcon = gmenu2x->sc.getSkinFilePath( - linkIcon.substr(5, linkIcon.length())); - if (linkapp != NULL && !fileExists(linkIcon)) - linkapp->searchIcon(); - else - link->setIconPath(linkIcon); - - } else if (!fileExists(linkIcon)) { - if (linkapp != NULL) linkapp->searchIcon(); - } + link->loadIcon(); } i++;