00001 #include "glwx.h"
00002
00003 GUIAlphaElement::GUIAlphaElement(const std::string &callback) : GUIRectangle(callback)
00004 {
00005 setColor(225.0f, 225.0f, 225.0f);
00006 alphaFadeScale = 1.0f;
00007 minAlpha = 0.6f;
00008 color.w = minAlpha;
00009 }
00010
00011 bool GUIAlphaElement::loadXMLSettings(const TiXmlElement *element)
00012 {
00013 if(!element)
00014 return false;
00015
00016 setAlphaFadeScale(XMLArbiter::fillComponents1f(element, "alphaFadeScale", alphaFadeScale));
00017 setMinAlpha(XMLArbiter::fillComponents1f(element, "minAlpha", minAlpha));
00018
00019 for(const TiXmlElement *child = element->FirstChildElement();
00020 child;
00021 child = child->NextSiblingElement() )
00022 {
00023 const char * value = child->Value();
00024
00025 if(value)
00026 {
00027 if(!strcmp(value, "Color"))
00028 XMLArbiter::fillComponents4f(child, color);
00029
00030 if(!strcmp(value, "Text"))
00031 label.loadXMLSettings(child);
00032 }
00033 }
00034
00035 setColor(color.x, color.y, color.z);
00036 return GUIRectangle::loadXMLSettings(element);
00037 }
00038
00039 void GUIAlphaElement::setColor(const Tuple3f& color)
00040 {
00041 setColor(color.x, color.y, color.z);
00042 }
00043
00044 void GUIAlphaElement::setColor(float r, float g, float b)
00045 {
00046 color.set(clamp(r, 0.0f, 255.0f),
00047 clamp(g, 0.0f, 255.0f),
00048 clamp(b, 0.0f, 255.0f),
00049 clamp(color.w, 0.0f, 1.0f));
00050
00051 color.x /= (color.x > 1.0) ? 255.0f : 1.0f;
00052 color.y /= (color.y > 1.0) ? 255.0f : 1.0f;
00053 color.z /= (color.z > 1.0) ? 255.0f : 1.0f;
00054 }
00055
00056 const Tuple4f &GUIAlphaElement::getColor()
00057 {
00058 return color;
00059 }
00060
00061 void GUIAlphaElement::setLabelString(const std::string &labelArg)
00062 {
00063 label = labelArg;
00064 }
00065
00066 GUIText * GUIAlphaElement::getLabel()
00067 {
00068 return &label;
00069 }
00070
00071 const std::string &GUIAlphaElement::getLabelString()
00072 {
00073 return label.getString();
00074 }
00075
00076 void GUIAlphaElement::setAlpha(float alphaArg)
00077 {
00078 color.w = clamp(alphaArg, minAlpha, 1.0f);
00079 }
00080
00081 float GUIAlphaElement::getAlpha()
00082 {
00083 return color.w;
00084 }
00085
00086 void GUIAlphaElement::setAlphaFadeScale(float duration)
00087 {
00088 alphaFadeScale = clamp(duration, 0.0f, 10.0f);
00089 }
00090
00091 float GUIAlphaElement::getAlphaFadeScale()
00092 {
00093 return alphaFadeScale;
00094 }
00095
00096 void GUIAlphaElement::setMinAlpha(float minAlphaArg)
00097 {
00098 minAlpha = clamp(minAlphaArg, 0.2f, 1.0f);
00099 }
00100
00101 float GUIAlphaElement::getMinAlpha()
00102 {
00103 return minAlpha;
00104 }
00105
00106 void GUIAlphaElement::modifyCurrentAlpha(float clockTick)
00107 {
00108 if(!mouseOver && !pressed)
00109 setAlpha(color.w - clockTick * alphaFadeScale);
00110 else
00111 setAlpha(color.w + clockTick * alphaFadeScale);
00112 }
00113