00001 #ifndef GUI_ANCHOR_HPP
00002 #define GUI_ANCHOR_HPP
00003
00004 #include <utils.hpp>
00005 #include <string>
00006
00007 namespace gui
00008 {
00009 class uiobject;
00010
00011 enum anchor_type
00012 {
00013 ANCHOR_ABS,
00014 ANCHOR_REL
00015 };
00016
00017 enum anchor_point
00018 {
00019 ANCHOR_TOPLEFT,
00020 ANCHOR_TOP,
00021 ANCHOR_TOPRIGHT,
00022 ANCHOR_RIGHT,
00023 ANCHOR_BOTTOMRIGHT,
00024 ANCHOR_BOTTOM,
00025 ANCHOR_BOTTOMLEFT,
00026 ANCHOR_LEFT,
00027 ANCHOR_CENTER
00028 };
00029
00030 enum constraint
00031 {
00032 CONSTRAINT_NONE,
00033 CONSTRAINT_X,
00034 CONSTRAINT_Y
00035 };
00036
00038 class anchor
00039 {
00040 public :
00041
00043 anchor();
00044
00046 anchor(uiobject* pObj, anchor_point mPoint, const std::string& pParent, anchor_point mParentPoint);
00047
00049
00051 int get_abs_x() const;
00052
00054
00056 int get_abs_y() const;
00057
00059
00061 const uiobject* get_object() const;
00062
00064
00066 const uiobject* get_parent() const;
00067
00069
00071 const std::string& get_parent_raw_name() const;
00072
00074
00076 anchor_point get_point() const;
00077
00079
00081 anchor_point get_parent_point() const;
00082
00084
00086 anchor_type get_type() const;
00087
00089
00091 int get_abs_offset_x() const;
00092
00094
00096 int get_abs_offset_y() const;
00097
00099
00101 float get_rel_offset_x() const;
00102
00104
00106 float get_rel_offset_y() const;
00107
00109
00111 void set_object(uiobject* pObj);
00112
00114
00116 void set_parent_raw_name(const std::string& sName);
00117
00119
00121 void set_point(anchor_point mPoint);
00122
00124
00126 void set_parent_point(anchor_point mParentPoint);
00127
00129
00132 void set_abs_offset(int iX, int iY);
00133
00135
00138 void set_rel_offset(float fX, float fY);
00139
00141
00144 std::string serialize(const std::string& sTab) const;
00145
00147 void update_parent() const;
00148
00150
00152 static std::string get_string_point(anchor_point mPoint);
00153
00155
00157 static anchor_point get_anchor_point(const std::string& sPoint);
00158
00159 private :
00160
00161 const uiobject* pObj_;
00162 anchor_point mParentPoint_;
00163 anchor_point mPoint_;
00164 anchor_type mType_;
00165
00166 int iAbsOffX_, iAbsOffY_;
00167 float fRelOffX_, fRelOffY_;
00168
00169 mutable int iParentWidth_, iParentHeight_;
00170
00171 mutable const uiobject* pParent_;
00172 mutable std::string sParent_;
00173 mutable bool bParentUpdated_;
00174 };
00175 }
00176
00177 #endif