00001
00002
00003
00004
00005
00006 #include "gui_uiobject.hpp"
00007
00008 #include "gui_anchor.hpp"
00009 #include "gui_out.hpp"
00010
00011 #include <xml_document.hpp>
00012 #include <utils_string.hpp>
00013
00014 namespace gui
00015 {
00016 void uiobject::parse_size_block_(xml::block* pBlock)
00017 {
00018 xml::block* pSizeBlock = pBlock->get_block("Size");
00019 if (pSizeBlock)
00020 {
00021 xml::block* pDimBlock = pSizeBlock->get_radio_block();
00022 if (pDimBlock->get_name() == "AbsDimension")
00023 {
00024 if (pDimBlock->is_provided("x"))
00025 set_abs_width(utils::string_to_uint(pDimBlock->get_attribute("x")));
00026 if (pDimBlock->is_provided("y"))
00027 set_abs_height(utils::string_to_uint(pDimBlock->get_attribute("y")));
00028 }
00029 else if (pDimBlock->get_name() == "RelDimension")
00030 {
00031 if (pDimBlock->is_provided("x"))
00032 set_rel_width(utils::string_to_float(pDimBlock->get_attribute("x")));
00033 if (pDimBlock->is_provided("y"))
00034 set_rel_height(utils::string_to_float(pDimBlock->get_attribute("y")));
00035 }
00036 }
00037 }
00038
00039 void uiobject::parse_anchor_block_(xml::block* pBlock)
00040 {
00041 xml::block* pAnchorsBlock = pBlock->get_block("Anchors");
00042 if (pAnchorsBlock)
00043 {
00044 std::vector<std::string> lFoundPoints;
00045 xml::block* pAnchorBlock;
00046 foreach_block (pAnchorBlock, pAnchorsBlock)
00047 {
00048 std::string sPoint = pAnchorBlock->get_attribute("point");
00049 std::string sParent = pAnchorBlock->get_attribute("relativeTo");
00050 std::string sRelativePoint = pAnchorBlock->get_attribute("relativePoint");
00051
00052 if (utils::find(lFoundPoints, sPoint) != lFoundPoints.end())
00053 {
00054 gui::out << gui::warning << pAnchorsBlock->get_location() << " : "
00055 << "anchor point \"" << sPoint << "\" has already been defined "
00056 "for \"" << sName_ << "\". anchor skipped." << std::endl;
00057 }
00058 else
00059 {
00060 if (sRelativePoint.empty())
00061 sRelativePoint = sPoint;
00062
00063 if (utils::has_no_content(sParent))
00064 {
00065 if (pParent_ || is_virtual())
00066 sParent = "$parent";
00067 else
00068 sParent = "";
00069 }
00070
00071 anchor mAnchor(
00072 this,
00073 anchor::get_anchor_point(sPoint),
00074 sParent,
00075 anchor::get_anchor_point(sRelativePoint)
00076 );
00077
00078 xml::block* pOffsetBlock = pAnchorBlock->get_block("Offset");
00079 if (pOffsetBlock)
00080 {
00081 xml::block* pDimBlock = pOffsetBlock->get_radio_block();
00082 if (pDimBlock->get_name() == "AbsDimension")
00083 {
00084 mAnchor.set_abs_offset(
00085 utils::string_to_int(pDimBlock->get_attribute("x")),
00086 utils::string_to_int(pDimBlock->get_attribute("y"))
00087 );
00088 }
00089 else if (pDimBlock->get_name() == "RelDimension")
00090 {
00091 mAnchor.set_rel_offset(
00092 utils::string_to_float(pDimBlock->get_attribute("x")),
00093 utils::string_to_float(pDimBlock->get_attribute("y"))
00094 );
00095 }
00096 }
00097
00098 set_point(mAnchor);
00099 }
00100 }
00101 }
00102 }
00103 }