00001 #include "gui_fontstring.hpp" 00002 #include "gui_out.hpp" 00003 00004 #include <xml_document.hpp> 00005 00006 namespace gui 00007 { 00008 void font_string::parse_block(xml::block* pBlock) 00009 { 00010 layered_region::parse_block(pBlock); 00011 00012 parse_color_block_(pBlock); 00013 parse_shadow_block_(pBlock); 00014 } 00015 00016 void font_string::parse_attributes_(xml::block* pBlock) 00017 { 00018 layered_region::parse_attributes_(pBlock); 00019 00020 set_font( 00021 pManager_->parse_file_name(pBlock->get_attribute("font")), 00022 utils::string_to_uint(pBlock->get_attribute("fontHeight")) 00023 ); 00024 00025 if (pBlock->is_provided("text") || !bInherits_) 00026 set_text(pBlock->get_attribute("text")); 00027 if (pBlock->is_provided("nonspacewrap") || !bInherits_) 00028 set_non_space_wrap(utils::string_to_bool(pBlock->get_attribute("nonspacewrap"))); 00029 if (pBlock->is_provided("spacing") || !bInherits_) 00030 set_spacing(utils::string_to_float(pBlock->get_attribute("spacing"))); 00031 00032 if (pBlock->is_provided("outline") || !bInherits_) 00033 { 00034 const std::string& sOutline = pBlock->get_attribute("outline"); 00035 if (sOutline == "NORMAL" || sOutline == "THICK") 00036 set_outlined(true); 00037 else if (sOutline == "NONE") 00038 set_outlined(false); 00039 else 00040 { 00041 gui::out << gui::warning << pBlock->get_location() << " : " 00042 << "Unknown outline type for " << sName_ << " : \"" 00043 << sOutline << "\"." << std::endl; 00044 } 00045 } 00046 00047 if (pBlock->is_provided("justifyH") || !bInherits_) 00048 { 00049 const std::string& sJustifyH = pBlock->get_attribute("justifyH"); 00050 if (sJustifyH == "LEFT") 00051 set_justify_h(text::ALIGN_LEFT); 00052 else if (sJustifyH == "CENTER") 00053 set_justify_h(text::ALIGN_CENTER); 00054 else if (sJustifyH == "RIGHT") 00055 set_justify_h(text::ALIGN_RIGHT); 00056 else 00057 { 00058 gui::out << gui::warning << pBlock->get_location() << " : " 00059 << "Unknown horizontal justify behavior for " << sName_ 00060 << " : \"" << sJustifyH << "\"." << std::endl; 00061 } 00062 } 00063 00064 if (pBlock->is_provided("justifyV") || !bInherits_) 00065 { 00066 const std::string& sJustifyV = pBlock->get_attribute("justifyV"); 00067 if (sJustifyV == "TOP") 00068 set_justify_v(text::ALIGN_TOP); 00069 else if (sJustifyV == "MIDDLE") 00070 set_justify_v(text::ALIGN_MIDDLE); 00071 else if (sJustifyV == "BOTTOM") 00072 set_justify_v(text::ALIGN_BOTTOM); 00073 else 00074 { 00075 gui::out << gui::warning << pBlock->get_location() << " : " 00076 << "Unknown vertical justify behavior for " << sName_ 00077 << " : \"" << sJustifyV << "\"." << std::endl; 00078 } 00079 } 00080 } 00081 00082 void font_string::parse_color_block_(xml::block* pBlock) 00083 { 00084 xml::block* pColorBlock = pBlock->get_block("Color"); 00085 if (pColorBlock) 00086 { 00087 set_text_color(color( 00088 utils::string_to_float(pColorBlock->get_attribute("r")), 00089 utils::string_to_float(pColorBlock->get_attribute("g")), 00090 utils::string_to_float(pColorBlock->get_attribute("b")), 00091 utils::string_to_float(pColorBlock->get_attribute("a")) 00092 )); 00093 } 00094 } 00095 00096 void font_string::parse_shadow_block_(xml::block* pBlock) 00097 { 00098 xml::block* pShadowBlock = pBlock->get_block("Shadow"); 00099 if (pShadowBlock) 00100 { 00101 set_shadow(true); 00102 xml::block* pColorBlock = pShadowBlock->get_block("Color"); 00103 if (pColorBlock) 00104 { 00105 set_shadow_color(color( 00106 utils::string_to_float(pColorBlock->get_attribute("r")), 00107 utils::string_to_float(pColorBlock->get_attribute("g")), 00108 utils::string_to_float(pColorBlock->get_attribute("b")), 00109 utils::string_to_float(pColorBlock->get_attribute("a")) 00110 )); 00111 } 00112 00113 xml::block* pOffsetBlock = pShadowBlock->get_block("Offset"); 00114 if (pOffsetBlock) 00115 { 00116 set_shadow_offsets( 00117 utils::string_to_int(pOffsetBlock->get_attribute("x")), 00118 utils::string_to_int(pOffsetBlock->get_attribute("y")) 00119 ); 00120 } 00121 } 00122 } 00123 }