Date:2011-10-23 12:30:20 (12 years 5 months ago)
Author:Maarten ter Huurne
Commit:62facf4dc7bd7aeb58e50bf9ebf1278c4932a18f
Message: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.
Files: src/iconbutton.cpp (3 diffs)
src/iconbutton.h (3 diffs)

Change Details

src/iconbutton.cpp
1111    , gmenu2x(gmenu2x_)
1212{
1313    this->icon = icon;
14    labelPosition = IconButton::DISP_RIGHT;
15    labelMargin = 2;
16    this->setLabel(label);
14    this->label = label;
1715    updateSurfaces();
1816}
1917
20void IconButton::updateSurfaces()
21{
18void IconButton::updateSurfaces() {
2219    iconSurface = gmenu2x->sc[icon];
2320    recalcSize();
2421}
...... 
3229
3330void IconButton::paint() {
3431    if (iconSurface) {
35        iconSurface->blit(gmenu2x->s,iconRect);
32        iconSurface->blit(gmenu2x->s, iconRect);
3633    }
3734    if (label != "") {
3835        gmenu2x->s->write(gmenu2x->font, label, labelRect.x, labelRect.y,
39                labelHAlign, labelVAlign);
36                ASFont::HAlignLeft, ASFont::VAlignMiddle);
4037    }
4138}
4239
...... 
4643
4744void IconButton::recalcSize() {
4845    uint h = 0, w = 0;
49    uint margin = labelMargin;
50
51    if (iconSurface == NULL || label == "")
52        margin = 0;
53
54    if (iconSurface != NULL) {
46    if (iconSurface) {
5547        w += iconSurface->width();
5648        h += iconSurface->height();
57        iconRect.w = w;
58        iconRect.h = h;
59        iconRect.x = rect.x;
60        iconRect.y = rect.y;
49        iconRect = (SDL_Rect) { rect.x, rect.y, w, h };
6150    } else {
62        iconRect.x = 0;
63        iconRect.y = 0;
64        iconRect.w = 0;
65        iconRect.h = 0;
51        iconRect = (SDL_Rect) { 0, 0, 0, 0 };
6652    }
6753
6854    if (label != "") {
69        labelRect.w = gmenu2x->font->getTextWidth(label);
70        labelRect.h = gmenu2x->font->getHeight();
71        if (labelPosition == IconButton::DISP_LEFT || labelPosition == IconButton::DISP_RIGHT) {
72            w += margin + labelRect.w;
73            //if (labelRect.h > h) h = labelRect.h;
74            labelHAlign = ASFont::HAlignLeft;
75            labelVAlign = ASFont::VAlignMiddle;
76        } else {
77            h += margin + labelRect.h;
78            //if (labelRect.w > w) w = labelRect.w;
79            labelHAlign = ASFont::HAlignCenter;
80            labelVAlign = ASFont::VAlignTop;
81        }
82
83        switch (labelPosition) {
84            case IconButton::DISP_BOTTOM:
85                labelRect.x = iconRect.x + iconRect.w/2;
86                labelRect.y = iconRect.y + iconRect.h + margin;
87            break;
88            case IconButton::DISP_TOP:
89                labelRect.x = iconRect.x + iconRect.w/2;
90                labelRect.y = rect.y;
91                iconRect.y += labelRect.h + margin;
92            break;
93            case IconButton::DISP_LEFT:
94                labelRect.x = rect.x;
95                labelRect.y = rect.y+h/2;
96                iconRect.x += labelRect.w + margin;
97            break;
98            default:
99                labelRect.x = iconRect.x + iconRect.w + margin;
100                labelRect.y = rect.y+h/2;
101            break;
102        }
55        uint margin = iconSurface ? 2 : 0;
56        labelRect = (SDL_Rect) {
57            iconRect.x + iconRect.w + margin,
58            rect.y + h / 2,
59            gmenu2x->font->getTextWidth(label),
60            gmenu2x->font->getHeight()
61        };
62        w += margin + labelRect.w;
10363    }
104    setSize(w, h);
105}
10664
107const string &IconButton::getLabel() {
108    return label;
109}
110
111void IconButton::setLabel(const string &label) {
112    this->label = label;
113}
114
115void IconButton::setLabelPosition(int pos, int margin) {
116    labelPosition = pos;
117    labelMargin = margin;
118    recalcSize();
119}
120
121const string &IconButton::getIcon() {
122    return icon;
123}
124
125void IconButton::setIcon(const string &icon) {
126    this->icon = icon;
127    updateSurfaces();
65    setSize(w, h);
12866}
12967
13068void IconButton::setAction(ButtonAction action) {
src/iconbutton.h
1515protected:
1616    GMenu2X *gmenu2x;
1717    string icon, label;
18    int labelPosition, labelMargin;
19    ASFont::HAlign labelHAlign;
20    ASFont::VAlign labelVAlign;
2118    void recalcSize();
2219    SDL_Rect iconRect, labelRect;
2320
...... 
2623    void updateSurfaces();
2724
2825public:
29    static const int DISP_RIGHT = 0;
30    static const int DISP_LEFT = 1;
31    static const int DISP_TOP = 2;
32    static const int DISP_BOTTOM = 3;
33
3426    IconButton(GMenu2X *gmenu2x, const string &icon, const string &label="");
3527    virtual ~IconButton() {};
3628
...... 
3931
4032    virtual void setPosition(int x, int y);
4133
42    const string &getLabel();
43    void setLabel(const string &label);
44    void setLabelPosition(int pos, int margin);
45
46    const string &getIcon();
47    void setIcon(const string &icon);
48
4934    void setAction(ButtonAction action);
5035};
5136

Archive Download the corresponding diff file



interactive