00001 #include "glwx.h" 00002 00003 Tuple2i textureGUIDimensions(256,256); 00004 00005 void GUITexCoordDescriptor::setTextureWidth(int width) 00006 { 00007 textureGUIDimensions.x = clamp(width, 8, 1024); 00008 } 00009 00010 void GUITexCoordDescriptor::setTextureHeight(int height) 00011 { 00012 textureGUIDimensions.y = clamp(height, 8, 1024); 00013 } 00014 00015 GUITexCoordDescriptor::GUITexCoordDescriptor(int widgetTypeArg) 00016 { 00017 texCoords.set(0.0f,0.0f,1.0f,1.0f); 00018 widgetType = widgetTypeArg; 00019 } 00020 00021 GUITexCoordDescriptor::GUITexCoordDescriptor(const GUITexCoordDescriptor ©) 00022 { 00023 this->operator=(copy); 00024 } 00025 00026 GUITexCoordDescriptor &GUITexCoordDescriptor::operator =(const GUITexCoordDescriptor ©) 00027 { 00028 00029 if(this != ©) 00030 { 00031 texCoords = copy.texCoords; 00032 widgetType = copy.widgetType; 00033 } 00034 return *this; 00035 } 00036 00037 void GUITexCoordDescriptor::setType(int type) 00038 { 00039 switch(type) 00040 { 00041 case WT_SLIDER : 00042 case WT_BUTTON: 00043 case WT_CHECK_BOX: 00044 case WT_CHECK_BOX_MARK: 00045 case WT_RADIO_BUTTON: 00046 case WT_CHECK_RB_MARK: 00047 widgetType = type; 00048 break; 00049 default: widgetType = WT_UNKNOWN; 00050 } 00051 } 00052 00053 void GUITexCoordDescriptor::setType(const std::string &type) 00054 { 00055 if(!type.size()) 00056 { 00057 Logger::writeErrorLog("NULL GUITexCoordDescriptor type"); 00058 return; 00059 } 00060 00061 if(type == "MATERIAL_SURFACE"){ widgetType = WT_MATERIAL_SURFACE; return; } 00062 if(type == "CHECK_BOX_MARK") { widgetType = WT_CHECK_BOX_MARK; return; } 00063 if(type == "CHECK_RB_MARK") { widgetType = WT_CHECK_RB_MARK; return; } 00064 if(type == "RADIO_BUTTON") { widgetType = WT_RADIO_BUTTON; return; } 00065 if(type == "SEPARATOR") { widgetType = WT_SEPARATOR; return; } 00066 if(type == "CHECK_BOX") { widgetType = WT_CHECK_BOX; return; } 00067 if(type == "TEXT_AREA") { widgetType = WT_TEXT_AREA; return; } 00068 if(type == "BUTTON") { widgetType = WT_BUTTON; return; } 00069 if(type == "SLIDER") { widgetType = WT_SLIDER; return; } 00070 if(type == "PANEL") { widgetType = WT_PANEL; return; } 00071 if(type == "LABEL") { widgetType = WT_LABEL; return; } 00072 00073 Logger::writeErrorLog(std::string("Unknow GUITexCoordDescriptor type -> ") + type); 00074 widgetType = WT_UNKNOWN; 00075 } 00076 00077 int GUITexCoordDescriptor::getType() 00078 { 00079 return widgetType; 00080 } 00081 00082 void GUITexCoordDescriptor::loadXMLSettings(const TiXmlElement *element) 00083 { 00084 if(!XMLArbiter::inspectElementInfo(element, "TexCoordsDesc")) 00085 return; 00086 00087 std::string name; 00088 int xStart = 0, 00089 yStart = 0, 00090 xEnd = 0, 00091 yEnd = 0; 00092 00093 xStart = XMLArbiter::fillComponents1i(element, "xStart", xStart); 00094 yStart = XMLArbiter::fillComponents1i(element, "yStart", yStart); 00095 00096 xEnd = XMLArbiter::fillComponents1i(element, "xEnd", xEnd); 00097 yEnd = XMLArbiter::fillComponents1i(element, "yEnd", yEnd); 00098 00099 setTexCoords(xStart/float(textureGUIDimensions.x), yStart/float(textureGUIDimensions.y), 00100 xEnd /float(textureGUIDimensions.x), yEnd /float(textureGUIDimensions.y)); 00101 setType(element->Attribute("type")); 00102 } 00103 00104 int GUITexCoordDescriptor::getTextureWidth() 00105 { 00106 return textureGUIDimensions.x; 00107 } 00108 00109 int GUITexCoordDescriptor::getTextureHeight() 00110 { 00111 return textureGUIDimensions.y; 00112 } 00113 00114 void GUITexCoordDescriptor::setTexCoords(float x, float y, float z, float w) 00115 { 00116 texCoords.set(clamp(x,0.0f, 1.0f), clamp(y,0.0f, 1.0f), 00117 clamp(z,0.0f, 1.0f), clamp(w,0.0f, 1.0f)); 00118 } 00119 00120 void GUITexCoordDescriptor::setTexCoords(const Tuple4f& texCoordsArg) 00121 { 00122 texCoords = texCoordsArg; 00123 }; 00124 00125 const Tuple4f &GUITexCoordDescriptor::getTexCoords() 00126 { 00127 return texCoords; 00128 }