mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 11:46:14 +02:00
Cache current icon surface. By doing so we safe a huge number of hash map
lookups.
This commit is contained in:
parent
667fb05a35
commit
a794a1c01a
11
src/link.cpp
11
src/link.cpp
@ -33,12 +33,14 @@ Link::Link(GMenu2X *gmenu2x) : Button(gmenu2x, true) {
|
||||
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png");
|
||||
iconX = 0;
|
||||
padding = 0;
|
||||
|
||||
updateSurfaces();
|
||||
}
|
||||
|
||||
void Link::run() {}
|
||||
|
||||
void Link::paint() {
|
||||
gmenu2x->sc[getIconPath()]->blit(gmenu2x->s, iconX, rect.y+padding, 32,32);
|
||||
iconSurface->blit(gmenu2x->s, iconX, rect.y+padding, 32,32);
|
||||
gmenu2x->s->write( gmenu2x->font, getTitle(), iconX+16, rect.y+gmenu2x->skinConfInt["linkHeight"]-padding, SFontHAlignCenter, SFontVAlignBottom );
|
||||
}
|
||||
|
||||
@ -50,6 +52,11 @@ bool Link::paintHover() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Link::updateSurfaces()
|
||||
{
|
||||
iconSurface = gmenu2x->sc[getIconPath()];
|
||||
}
|
||||
|
||||
string Link::getTitle() {
|
||||
return title;
|
||||
}
|
||||
@ -89,6 +96,7 @@ void Link::setIcon(string icon) {
|
||||
|
||||
this->icon = icon;
|
||||
edited = true;
|
||||
updateSurfaces();
|
||||
}
|
||||
|
||||
string Link::searchIcon() {
|
||||
@ -106,6 +114,7 @@ void Link::setIconPath(string icon) {
|
||||
iconPath = icon;
|
||||
else
|
||||
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png");
|
||||
updateSurfaces();
|
||||
}
|
||||
|
||||
void Link::setSize(int w, int h) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "button.h"
|
||||
#include "surface.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -42,7 +43,11 @@ protected:
|
||||
bool edited;
|
||||
string title, description, icon, iconPath;
|
||||
|
||||
Surface *iconSurface;
|
||||
Surface *icon_hover;
|
||||
|
||||
void recalcCoordinates();
|
||||
void updateSurfaces();
|
||||
|
||||
public:
|
||||
Link(GMenu2X *gmenu2x);
|
||||
|
Loading…
Reference in New Issue
Block a user