1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 11:08:27 +02:00

Moved most Menu::loadIcons() code into Link/LinkApp classes

The code still has a lot of overlap with the other methods of Link and
LinkApp, but at least it is in the same place now.

Since this was the last outside use, setIconPath() could be declared
as 'protected'.
This commit is contained in:
Maarten ter Huurne 2013-08-02 21:20:10 +02:00
parent 40372d14ef
commit a9b5d8bd19
5 changed files with 26 additions and 17 deletions

View File

@ -85,6 +85,12 @@ const string &Link::getIcon() {
return icon; 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) { void Link::setIcon(const string &icon) {
this->icon = icon; this->icon = icon;

View File

@ -50,6 +50,7 @@ protected:
Surface *iconSurface; Surface *iconSurface;
Surface *icon_hover; Surface *icon_hover;
void setIconPath(const std::string &icon);
void updateSurfaces(); void updateSurfaces();
public: public:
@ -59,6 +60,9 @@ public:
virtual void paint(); virtual void paint();
virtual bool paintHover(); virtual bool paintHover();
virtual void loadIcon();
virtual const std::string &searchIcon();
void setSize(int w, int h); void setSize(int w, int h);
void setPosition(int x, int y); void setPosition(int x, int y);
@ -68,9 +72,7 @@ public:
void setDescription(const std::string &description); void setDescription(const std::string &description);
const std::string &getIcon(); const std::string &getIcon();
void setIcon(const std::string &icon); void setIcon(const std::string &icon);
virtual const std::string &searchIcon();
const std::string &getIconPath(); const std::string &getIconPath();
void setIconPath(const std::string &icon);
void run(); void run();
}; };

View File

@ -261,6 +261,20 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
if (iconPath.empty()) searchIcon(); 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() { const string &LinkApp::searchIcon() {
if (!iconPath.empty()) if (!iconPath.empty())
return iconPath; return iconPath;

View File

@ -70,6 +70,7 @@ public:
const char* linkfile); const char* linkfile);
#endif #endif
virtual void loadIcon();
virtual const std::string &searchIcon(); virtual const std::string &searchIcon();
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)

View File

@ -122,21 +122,7 @@ void Menu::loadIcons() {
gmenu2x->sc.add("skin:" + sectionIcon); gmenu2x->sc.add("skin:" + sectionIcon);
for (Link *&link : links[i]) { for (Link *&link : links[i]) {
LinkApp *linkapp = dynamic_cast<LinkApp*>(link); link->loadIcon();
//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();
}
} }
i++; i++;