mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-16 21:19:20 +02:00
8f57afcf53
GCC 4.7.0 warns that C++11 considers doing this implicitly ill-formed.
74 lines
1.5 KiB
C++
74 lines
1.5 KiB
C++
#include "iconbutton.h"
|
|
|
|
#include "asfont.h"
|
|
#include "gmenu2x.h"
|
|
#include "surface.h"
|
|
|
|
using namespace std;
|
|
using namespace fastdelegate;
|
|
|
|
IconButton::IconButton(
|
|
GMenu2X *gmenu2x_, Touchscreen &ts_,
|
|
const string &icon, const string &label)
|
|
: Button(ts_)
|
|
, gmenu2x(gmenu2x_)
|
|
{
|
|
this->icon = icon;
|
|
this->label = label;
|
|
updateSurfaces();
|
|
}
|
|
|
|
void IconButton::updateSurfaces() {
|
|
iconSurface = gmenu2x->sc[icon];
|
|
recalcSize();
|
|
}
|
|
|
|
void IconButton::setPosition(int x, int y) {
|
|
if (rect.x != x || rect.y != y) {
|
|
Button::setPosition(x,y);
|
|
recalcSize();
|
|
}
|
|
}
|
|
|
|
void IconButton::paint() {
|
|
if (iconSurface) {
|
|
iconSurface->blit(gmenu2x->s, iconRect);
|
|
}
|
|
if (label != "") {
|
|
gmenu2x->s->write(gmenu2x->font, label, labelRect.x, labelRect.y,
|
|
ASFont::HAlignLeft, ASFont::VAlignMiddle);
|
|
}
|
|
}
|
|
|
|
bool IconButton::paintHover() {
|
|
return true;
|
|
}
|
|
|
|
void IconButton::recalcSize() {
|
|
Uint16 h = 0, w = 0;
|
|
if (iconSurface) {
|
|
w += iconSurface->width();
|
|
h += iconSurface->height();
|
|
iconRect = (SDL_Rect) { rect.x, rect.y, w, h };
|
|
} else {
|
|
iconRect = (SDL_Rect) { 0, 0, 0, 0 };
|
|
}
|
|
|
|
if (label != "") {
|
|
uint margin = iconSurface ? 2 : 0;
|
|
labelRect = (SDL_Rect) {
|
|
static_cast<Sint16>(iconRect.x + iconRect.w + margin),
|
|
static_cast<Sint16>(rect.y + h / 2),
|
|
static_cast<Uint16>(gmenu2x->font->getTextWidth(label)),
|
|
static_cast<Uint16>(gmenu2x->font->getHeight())
|
|
};
|
|
w += margin + labelRect.w;
|
|
}
|
|
|
|
setSize(w, h);
|
|
}
|
|
|
|
void IconButton::setAction(ButtonAction action) {
|
|
this->action = action;
|
|
}
|