| src/iconbutton.cpp |
| 1 | 1 | #include "iconbutton.h" |
| 2 | 2 | #include "gmenu2x.h" |
| 3 | #include "surface.h" |
| 3 | 4 | |
| 4 | 5 | using namespace std; |
| 5 | 6 | using namespace fastdelegate; |
| ... | ... | |
| 10 | 11 | labelPosition = IconButton::DISP_RIGHT; |
| 11 | 12 | labelMargin = 2; |
| 12 | 13 | this->setLabel(label); |
| 14 | updateSurfaces(); |
| 15 | } |
| 16 | |
| 17 | void IconButton::updateSurfaces() |
| 18 | { |
| 19 | iconSurface = gmenu2x->sc[icon]; |
| 20 | recalcSize(); |
| 13 | 21 | } |
| 14 | 22 | |
| 15 | 23 | void IconButton::setPosition(int x, int y) { |
| ... | ... | |
| 21 | 29 | |
| 22 | 30 | void IconButton::paint() { |
| 23 | 31 | uint margin = labelMargin; |
| 24 | | if (gmenu2x->sc[icon] == NULL || label == "") |
| 32 | if (iconSurface == NULL || label == "") |
| 25 | 33 | margin = 0; |
| 26 | | if (gmenu2x->sc[icon] != NULL) |
| 27 | | gmenu2x->sc[icon]->blit(gmenu2x->s,iconRect); |
| 34 | if (iconSurface != NULL) |
| 35 | iconSurface->blit(gmenu2x->s,iconRect); |
| 28 | 36 | if (label != "") |
| 29 | 37 | gmenu2x->s->write(gmenu2x->font, label, labelRect.x, labelRect.y, labelHAlign, labelVAlign); |
| 30 | 38 | } |
| ... | ... | |
| 37 | 45 | uint h = 0, w = 0; |
| 38 | 46 | uint margin = labelMargin; |
| 39 | 47 | |
| 40 | | if (gmenu2x->sc[icon] == NULL || label == "") |
| 48 | if (iconSurface == NULL || label == "") |
| 41 | 49 | margin = 0; |
| 42 | 50 | |
| 43 | | if (gmenu2x->sc[icon] != NULL) { |
| 44 | | w += gmenu2x->sc[icon]->raw->w; |
| 45 | | h += gmenu2x->sc[icon]->raw->h; |
| 51 | if (iconSurface != NULL) { |
| 52 | w += iconSurface->raw->w; |
| 53 | h += iconSurface->raw->h; |
| 46 | 54 | iconRect.w = w; |
| 47 | 55 | iconRect.h = h; |
| 48 | 56 | iconRect.x = rect.x; |
| ... | ... | |
| 113 | 121 | |
| 114 | 122 | void IconButton::setIcon(const string &icon) { |
| 115 | 123 | this->icon = icon; |
| 116 | | recalcSize(); |
| 124 | updateSurfaces(); |
| 117 | 125 | } |
| 118 | 126 | |
| 119 | 127 | void IconButton::setAction(ButtonAction action) { |