mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2025-04-01 02:17:28 +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:
parent
abe9130de9
commit
62facf4dc7
@ -11,14 +11,11 @@ IconButton::IconButton(GMenu2X *gmenu2x_, const string &icon,
|
|||||||
, gmenu2x(gmenu2x_)
|
, gmenu2x(gmenu2x_)
|
||||||
{
|
{
|
||||||
this->icon = icon;
|
this->icon = icon;
|
||||||
labelPosition = IconButton::DISP_RIGHT;
|
this->label = label;
|
||||||
labelMargin = 2;
|
|
||||||
this->setLabel(label);
|
|
||||||
updateSurfaces();
|
updateSurfaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconButton::updateSurfaces()
|
void IconButton::updateSurfaces() {
|
||||||
{
|
|
||||||
iconSurface = gmenu2x->sc[icon];
|
iconSurface = gmenu2x->sc[icon];
|
||||||
recalcSize();
|
recalcSize();
|
||||||
}
|
}
|
||||||
@ -32,11 +29,11 @@ void IconButton::setPosition(int x, int y) {
|
|||||||
|
|
||||||
void IconButton::paint() {
|
void IconButton::paint() {
|
||||||
if (iconSurface) {
|
if (iconSurface) {
|
||||||
iconSurface->blit(gmenu2x->s,iconRect);
|
iconSurface->blit(gmenu2x->s, iconRect);
|
||||||
}
|
}
|
||||||
if (label != "") {
|
if (label != "") {
|
||||||
gmenu2x->s->write(gmenu2x->font, label, labelRect.x, labelRect.y,
|
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() {
|
void IconButton::recalcSize() {
|
||||||
uint h = 0, w = 0;
|
uint h = 0, w = 0;
|
||||||
uint margin = labelMargin;
|
if (iconSurface) {
|
||||||
|
|
||||||
if (iconSurface == NULL || label == "")
|
|
||||||
margin = 0;
|
|
||||||
|
|
||||||
if (iconSurface != NULL) {
|
|
||||||
w += iconSurface->width();
|
w += iconSurface->width();
|
||||||
h += iconSurface->height();
|
h += iconSurface->height();
|
||||||
iconRect.w = w;
|
iconRect = (SDL_Rect) { rect.x, rect.y, w, h };
|
||||||
iconRect.h = h;
|
|
||||||
iconRect.x = rect.x;
|
|
||||||
iconRect.y = rect.y;
|
|
||||||
} else {
|
} else {
|
||||||
iconRect.x = 0;
|
iconRect = (SDL_Rect) { 0, 0, 0, 0 };
|
||||||
iconRect.y = 0;
|
|
||||||
iconRect.w = 0;
|
|
||||||
iconRect.h = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label != "") {
|
if (label != "") {
|
||||||
labelRect.w = gmenu2x->font->getTextWidth(label);
|
uint margin = iconSurface ? 2 : 0;
|
||||||
labelRect.h = gmenu2x->font->getHeight();
|
labelRect = (SDL_Rect) {
|
||||||
if (labelPosition == IconButton::DISP_LEFT || labelPosition == IconButton::DISP_RIGHT) {
|
iconRect.x + iconRect.w + margin,
|
||||||
w += margin + labelRect.w;
|
rect.y + h / 2,
|
||||||
//if (labelRect.h > h) h = labelRect.h;
|
gmenu2x->font->getTextWidth(label),
|
||||||
labelHAlign = ASFont::HAlignLeft;
|
gmenu2x->font->getHeight()
|
||||||
labelVAlign = ASFont::VAlignMiddle;
|
};
|
||||||
} else {
|
w += margin + labelRect.w;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setSize(w, h);
|
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) {
|
void IconButton::setAction(ButtonAction action) {
|
||||||
this->action = action;
|
this->action = action;
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,6 @@ class IconButton : public Button {
|
|||||||
protected:
|
protected:
|
||||||
GMenu2X *gmenu2x;
|
GMenu2X *gmenu2x;
|
||||||
string icon, label;
|
string icon, label;
|
||||||
int labelPosition, labelMargin;
|
|
||||||
ASFont::HAlign labelHAlign;
|
|
||||||
ASFont::VAlign labelVAlign;
|
|
||||||
void recalcSize();
|
void recalcSize();
|
||||||
SDL_Rect iconRect, labelRect;
|
SDL_Rect iconRect, labelRect;
|
||||||
|
|
||||||
@ -26,11 +23,6 @@ protected:
|
|||||||
void updateSurfaces();
|
void updateSurfaces();
|
||||||
|
|
||||||
public:
|
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="");
|
IconButton(GMenu2X *gmenu2x, const string &icon, const string &label="");
|
||||||
virtual ~IconButton() {};
|
virtual ~IconButton() {};
|
||||||
|
|
||||||
@ -39,13 +31,6 @@ public:
|
|||||||
|
|
||||||
virtual void setPosition(int x, int y);
|
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);
|
void setAction(ButtonAction action);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user