1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-02 18:05:26 +03:00

IconButton: removed unused functionality.

Labels were always right-aligned: this was the default and no other alignment
was ever selected.
Also removed unused getter and setter methods.
This commit is contained in:
Maarten ter Huurne 2011-10-23 12:30:20 +02:00
parent abe9130de9
commit 62facf4dc7
2 changed files with 16 additions and 93 deletions

View File

@ -11,14 +11,11 @@ IconButton::IconButton(GMenu2X *gmenu2x_, const string &icon,
, gmenu2x(gmenu2x_)
{
this->icon = icon;
labelPosition = IconButton::DISP_RIGHT;
labelMargin = 2;
this->setLabel(label);
this->label = label;
updateSurfaces();
}
void IconButton::updateSurfaces()
{
void IconButton::updateSurfaces() {
iconSurface = gmenu2x->sc[icon];
recalcSize();
}
@ -32,11 +29,11 @@ void IconButton::setPosition(int x, int y) {
void IconButton::paint() {
if (iconSurface) {
iconSurface->blit(gmenu2x->s,iconRect);
iconSurface->blit(gmenu2x->s, iconRect);
}
if (label != "") {
gmenu2x->s->write(gmenu2x->font, label, labelRect.x, labelRect.y,
labelHAlign, labelVAlign);
ASFont::HAlignLeft, ASFont::VAlignMiddle);
}
}
@ -46,87 +43,28 @@ bool IconButton::paintHover() {
void IconButton::recalcSize() {
uint h = 0, w = 0;
uint margin = labelMargin;
if (iconSurface == NULL || label == "")
margin = 0;
if (iconSurface != NULL) {
if (iconSurface) {
w += iconSurface->width();
h += iconSurface->height();
iconRect.w = w;
iconRect.h = h;
iconRect.x = rect.x;
iconRect.y = rect.y;
iconRect = (SDL_Rect) { rect.x, rect.y, w, h };
} else {
iconRect.x = 0;
iconRect.y = 0;
iconRect.w = 0;
iconRect.h = 0;
iconRect = (SDL_Rect) { 0, 0, 0, 0 };
}
if (label != "") {
labelRect.w = gmenu2x->font->getTextWidth(label);
labelRect.h = gmenu2x->font->getHeight();
if (labelPosition == IconButton::DISP_LEFT || labelPosition == IconButton::DISP_RIGHT) {
w += margin + labelRect.w;
//if (labelRect.h > h) h = labelRect.h;
labelHAlign = ASFont::HAlignLeft;
labelVAlign = ASFont::VAlignMiddle;
} else {
h += margin + labelRect.h;
//if (labelRect.w > w) w = labelRect.w;
labelHAlign = ASFont::HAlignCenter;
labelVAlign = ASFont::VAlignTop;
}
switch (labelPosition) {
case IconButton::DISP_BOTTOM:
labelRect.x = iconRect.x + iconRect.w/2;
labelRect.y = iconRect.y + iconRect.h + margin;
break;
case IconButton::DISP_TOP:
labelRect.x = iconRect.x + iconRect.w/2;
labelRect.y = rect.y;
iconRect.y += labelRect.h + margin;
break;
case IconButton::DISP_LEFT:
labelRect.x = rect.x;
labelRect.y = rect.y+h/2;
iconRect.x += labelRect.w + margin;
break;
default:
labelRect.x = iconRect.x + iconRect.w + margin;
labelRect.y = rect.y+h/2;
break;
}
uint margin = iconSurface ? 2 : 0;
labelRect = (SDL_Rect) {
iconRect.x + iconRect.w + margin,
rect.y + h / 2,
gmenu2x->font->getTextWidth(label),
gmenu2x->font->getHeight()
};
w += margin + labelRect.w;
}
setSize(w, h);
}
const string &IconButton::getLabel() {
return label;
}
void IconButton::setLabel(const string &label) {
this->label = label;
}
void IconButton::setLabelPosition(int pos, int margin) {
labelPosition = pos;
labelMargin = margin;
recalcSize();
}
const string &IconButton::getIcon() {
return icon;
}
void IconButton::setIcon(const string &icon) {
this->icon = icon;
updateSurfaces();
}
void IconButton::setAction(ButtonAction action) {
this->action = action;
}

View File

@ -15,9 +15,6 @@ class IconButton : public Button {
protected:
GMenu2X *gmenu2x;
string icon, label;
int labelPosition, labelMargin;
ASFont::HAlign labelHAlign;
ASFont::VAlign labelVAlign;
void recalcSize();
SDL_Rect iconRect, labelRect;
@ -26,11 +23,6 @@ protected:
void updateSurfaces();
public:
static const int DISP_RIGHT = 0;
static const int DISP_LEFT = 1;
static const int DISP_TOP = 2;
static const int DISP_BOTTOM = 3;
IconButton(GMenu2X *gmenu2x, const string &icon, const string &label="");
virtual ~IconButton() {};
@ -39,13 +31,6 @@ public:
virtual void setPosition(int x, int y);
const string &getLabel();
void setLabel(const string &label);
void setLabelPosition(int pos, int margin);
const string &getIcon();
void setIcon(const string &icon);
void setAction(ButtonAction action);
};