00001 #include "glwx.h" 00002 00003 GUILabel::GUILabel(const std::string &ls, 00004 const std::string &callback) : GUIAlphaElement(callback) 00005 { 00006 setDimensions(40, 5); 00007 setLabelString(ls); 00008 widgetType = WT_LABEL; 00009 } 00010 00011 bool GUILabel::loadXMLSettings(const TiXmlElement *element) 00012 { 00013 if(!XMLArbiter::inspectElementInfo(element, "Label")) 00014 return Logger::writeErrorLog("Need a Label node in the xml file"); 00015 00016 return GUIAlphaElement::loadXMLSettings(element); 00017 } 00018 00019 void GUILabel::render(float clockTick) 00020 { 00021 if(!parent || !visible) 00022 return; 00023 00024 Tuple2i center = getCenter(); 00025 00026 if(label.needUpdating()) 00027 parent->forceUpdate(true); 00028 00029 switch(anchor) 00030 { 00031 case AT_CORNERLU: label.print(windowBounds.x, windowBounds.y); break; 00032 case AT_CORNERLD: label.print(windowBounds.x, windowBounds.y - label.getHeight()); break; 00033 case AT_CORNERRU: label.print(windowBounds.z, windowBounds.y); break; 00034 case AT_CORNERRD: label.print(windowBounds.z, windowBounds.y - label.getHeight()); break; 00035 default: label.printCenteredXY(center.x, center.y); 00036 } 00037 } 00038 00039 const Tuple4i &GUILabel::getWindowBounds() 00040 { 00041 if(parent && update) 00042 { 00043 int height = 0, 00044 width = 0; 00045 label.computeDimensions(); 00046 00047 if(dimensions.x > 1) 00048 width = dimensions.x < label.getWidth() ? label.getWidth() : (int)dimensions.x; 00049 else 00050 width = getWidth() < label.getWidth() ? label.getWidth() : getWidth(); 00051 00052 if(dimensions.x > 1) 00053 height = dimensions.y < label.getHeight() ? label.getHeight() : (int)dimensions.y; 00054 else 00055 height = getHeight() < label.getHeight() ? label.getHeight() : getHeight(); 00056 00057 dimensions.set(float(width), float(height)); 00058 GUIRectangle::computeWindowBounds(); 00059 } 00060 return windowBounds; 00061 }