1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-05 06:58: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;
}
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;

View File

@ -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();
};

View File

@ -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;

View File

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

View File

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