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 | ||
---|---|---|
11 | 11 | , gmenu2x(gmenu2x_) |
12 | 12 | { |
13 | 13 | this->icon = icon; |
14 | labelPosition = IconButton::DISP_RIGHT; | |
15 | labelMargin = 2; | |
16 | this->setLabel(label); | |
14 | this->label = label; | |
17 | 15 | updateSurfaces(); |
18 | 16 | } |
19 | 17 | |
20 | void IconButton::updateSurfaces() | |
21 | { | |
18 | void IconButton::updateSurfaces() { | |
22 | 19 | iconSurface = gmenu2x->sc[icon]; |
23 | 20 | recalcSize(); |
24 | 21 | } |
... | ... | |
32 | 29 | |
33 | 30 | void IconButton::paint() { |
34 | 31 | if (iconSurface) { |
35 | iconSurface->blit(gmenu2x->s,iconRect); | |
32 | iconSurface->blit(gmenu2x->s, iconRect); | |
36 | 33 | } |
37 | 34 | if (label != "") { |
38 | 35 | gmenu2x->s->write(gmenu2x->font, label, labelRect.x, labelRect.y, |
39 | labelHAlign, labelVAlign); | |
36 | ASFont::HAlignLeft, ASFont::VAlignMiddle); | |
40 | 37 | } |
41 | 38 | } |
42 | 39 | |
... | ... | |
46 | 43 | |
47 | 44 | void IconButton::recalcSize() { |
48 | 45 | 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) { | |
55 | 47 | w += iconSurface->width(); |
56 | 48 | 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 }; | |
61 | 50 | } 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 }; | |
66 | 52 | } |
67 | 53 | |
68 | 54 | 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; | |
103 | 63 | } |
104 | setSize(w, h); | |
105 | } | |
106 | 64 | |
107 | const string &IconButton::getLabel() { | |
108 | return label; | |
109 | } | |
110 | ||
111 | void IconButton::setLabel(const string &label) { | |
112 | this->label = label; | |
113 | } | |
114 | ||
115 | void IconButton::setLabelPosition(int pos, int margin) { | |
116 | labelPosition = pos; | |
117 | labelMargin = margin; | |
118 | recalcSize(); | |
119 | } | |
120 | ||
121 | const string &IconButton::getIcon() { | |
122 | return icon; | |
123 | } | |
124 | ||
125 | void IconButton::setIcon(const string &icon) { | |
126 | this->icon = icon; | |
127 | updateSurfaces(); | |
65 | setSize(w, h); | |
128 | 66 | } |
129 | 67 | |
130 | 68 | void IconButton::setAction(ButtonAction action) { |
src/iconbutton.h | ||
---|---|---|
15 | 15 | protected: |
16 | 16 | GMenu2X *gmenu2x; |
17 | 17 | string icon, label; |
18 | int labelPosition, labelMargin; | |
19 | ASFont::HAlign labelHAlign; | |
20 | ASFont::VAlign labelVAlign; | |
21 | 18 | void recalcSize(); |
22 | 19 | SDL_Rect iconRect, labelRect; |
23 | 20 | |
... | ... | |
26 | 23 | void updateSurfaces(); |
27 | 24 | |
28 | 25 | public: |
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 | ||
34 | 26 | IconButton(GMenu2X *gmenu2x, const string &icon, const string &label=""); |
35 | 27 | virtual ~IconButton() {}; |
36 | 28 | |
... | ... | |
39 | 31 | |
40 | 32 | virtual void setPosition(int x, int y); |
41 | 33 | |
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 | ||
49 | 34 | void setAction(ButtonAction action); |
50 | 35 | }; |
51 | 36 |
Branches:
install_locations
master
opkrun
packages