3
GUIButton::GUIButton(const std::string &callback) : GUIAlphaElement(callback), GUIClippedRectangle()
5
setBordersColor(0.0f, 0.0f, 0.0f);
8
setColor(100, 150, 190);
10
widgetType = WT_BUTTON;
12
drawBackground = true;
17
bool GUIButton::loadXMLSettings(const TiXmlElement *element)
19
if(!XMLArbiter::inspectElementInfo(element, "Button"))
20
return Logger::writeErrorLog("Need a Button node in the xml file");
22
enableBounce(XMLArbiter::analyzeBooleanAttr(element, "bounce", true));
23
return GUIAlphaElement::loadXMLSettings(element) &&
24
GUIClippedRectangle::loadXMLClippedRectangleInfo(element);
27
void GUIButton::enableBounce(bool bounce_){ bounce = bounce_; }
28
bool GUIButton::bounceEnabled() { return bounce; }
30
void GUIButton::render(float clockTick)
32
if(!parent || !visible)
35
modifyCurrentAlpha(clockTick);
38
Tuple3f tempColor = label.getColor();
39
float displacement = 2.0f*(pressed || clicked)*bounce;
40
int xCenter = (windowBounds.x + windowBounds.z)/2,
41
yCenter = (windowBounds.y + windowBounds.w)/2;
43
glTranslatef(displacement, displacement, 0.0);
44
renderClippedBounds();
45
label.printCenteredXY(xCenter, yCenter);
46
glTranslatef(-displacement, -displacement, 0.0f);
49
const void GUIButton::computeWindowBounds()
53
GUIRectangle::computeWindowBounds();
54
label.computeDimensions();
56
int width = windowBounds.z - windowBounds.x,
57
height = windowBounds.w - windowBounds.y;
59
if(width <= label.getWidth() + 2*clipSize)
61
if(anchor == AT_CENTER)
63
width = (label.getWidth() - width)/2 + clipSize + 2;
64
windowBounds.x -=width;
65
windowBounds.z +=width;
67
if((anchor == AT_CORNERLU) || (anchor == AT_CORNERLD))
69
width = (label.getWidth() - width)/2 + clipSize + 2;
70
windowBounds.z +=2*width;
74
if(height + 2*clipSize < label.getHeight())
77
height = (label.getHeight() - height)/2 + clipSize + 2;
78
windowBounds.y -= height;
79
windowBounds.w += height;
82
computeClippedBounds(windowBounds);