00001 #include "gui_texture.hpp" 00002 #include "gui_out.hpp" 00003 00004 #include <xml_document.hpp> 00005 #include <utils_string.hpp> 00006 00007 namespace gui 00008 { 00009 void texture::parse_block(xml::block* pBlock) 00010 { 00011 layered_region::parse_block(pBlock); 00012 00013 parse_tex_coords_block_(pBlock); 00014 parse_color_block_(pBlock); 00015 parse_gradient_block_(pBlock); 00016 } 00017 00018 void texture::parse_attributes_(xml::block* pBlock) 00019 { 00020 layered_region::parse_attributes_(pBlock); 00021 00022 set_texture(pManager_->parse_file_name(pBlock->get_attribute("file"))); 00023 if (!pBlock->get_block("Size") && pSprite_) 00024 { 00025 set_abs_width(pSprite_->get_width()); 00026 set_abs_height(pSprite_->get_height()); 00027 } 00028 } 00029 00030 void texture::parse_tex_coords_block_(xml::block* pBlock) 00031 { 00032 xml::block* pTexCoordsBlock = pBlock->get_block("TexCoords"); 00033 if (pTexCoordsBlock) 00034 { 00035 set_tex_coord(std::array<float,4>({{ 00036 (float)utils::string_to_float(pTexCoordsBlock->get_attribute("left")), 00037 (float)utils::string_to_float(pTexCoordsBlock->get_attribute("top")), 00038 (float)utils::string_to_float(pTexCoordsBlock->get_attribute("right")), 00039 (float)utils::string_to_float(pTexCoordsBlock->get_attribute("bottom")) 00040 }})); 00041 } 00042 } 00043 00044 void texture::parse_color_block_(xml::block* pBlock) 00045 { 00046 xml::block* pColorBlock = pBlock->get_block("Color"); 00047 if (pColorBlock) 00048 { 00049 set_color(color( 00050 utils::string_to_float(pColorBlock->get_attribute("r")), 00051 utils::string_to_float(pColorBlock->get_attribute("g")), 00052 utils::string_to_float(pColorBlock->get_attribute("b")), 00053 utils::string_to_float(pColorBlock->get_attribute("a")) 00054 )); 00055 } 00056 } 00057 00058 void texture::parse_gradient_block_(xml::block* pBlock) 00059 { 00060 xml::block* pGradientBlock = pBlock->get_block("Gradient"); 00061 if (pGradientBlock) 00062 { 00063 std::string sOrientation = pGradientBlock->get_attribute("orientation"); 00064 gradient::orientation mOrient; 00065 if (sOrientation == "HORIZONTAL") 00066 mOrient = gradient::HORIZONTAL; 00067 else if (sOrientation == "VERTICAL") 00068 mOrient = gradient::VERTICAL; 00069 else 00070 { 00071 gui::out << gui::warning << pGradientBlock->get_location() << " : " 00072 "Unknown gradient orientation for "+sName_+" : \""+sOrientation+"\". " 00073 "No gradient will be shown for this texture." << std::endl; 00074 return; 00075 } 00076 00077 xml::block* pMinColorBlock = pGradientBlock->get_block("MinColor"); 00078 xml::block* pMaxColorBlock = pGradientBlock->get_block("MaxColor"); 00079 00080 set_gradient(gradient(mOrient, 00081 color( 00082 utils::string_to_float(pMinColorBlock->get_attribute("r")), 00083 utils::string_to_float(pMinColorBlock->get_attribute("g")), 00084 utils::string_to_float(pMinColorBlock->get_attribute("b")), 00085 utils::string_to_float(pMinColorBlock->get_attribute("a")) 00086 ), 00087 color( 00088 utils::string_to_float(pMaxColorBlock->get_attribute("r")), 00089 utils::string_to_float(pMaxColorBlock->get_attribute("g")), 00090 utils::string_to_float(pMaxColorBlock->get_attribute("b")), 00091 utils::string_to_float(pMaxColorBlock->get_attribute("a")) 00092 ) 00093 )); 00094 } 00095 } 00096 }