00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_ALIGN_H__
00024 #define __MYGUI_ALIGN_H__
00025
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Common.h"
00028
00029 namespace MyGUI
00030 {
00031
00032 struct MYGUI_EXPORT Align
00033 {
00034 enum Enum
00035 {
00036 HCenter = MYGUI_FLAG_NONE,
00037 VCenter = MYGUI_FLAG_NONE,
00038 Center = HCenter | VCenter,
00040 Left = MYGUI_FLAG(1),
00041 Right = MYGUI_FLAG(2),
00042 HStretch = Left | Right,
00044 Top = MYGUI_FLAG(3),
00045 Bottom = MYGUI_FLAG(4),
00046 VStretch = Top | Bottom,
00048 Stretch = HStretch | VStretch,
00049 Default = Left | Top,
00051 HRelative = MYGUI_FLAG(5),
00052 VRelative = MYGUI_FLAG(6),
00053 Relative = HRelative | VRelative
00054 };
00055
00056 Align(Enum _value = Default) : value(_value) { }
00057
00058 bool isHCenter() { return HCenter == (value & ((int)HStretch | (int)HRelative)); }
00059 bool isVCenter() { return VCenter == (value & ((int)VStretch | (int)VRelative)); }
00060 bool isCenter() { return Center == (value & ((int)Stretch | (int)Relative)); }
00061
00062 bool isLeft() { return Left == (value & ((int)HStretch | (int)HRelative)); }
00063 bool isRight() { return Right == (value & ((int)HStretch | (int)HRelative)); }
00064 bool isHStretch() { return HStretch == (value & ((int)HStretch | (int)HRelative)); }
00065
00066 bool isTop() { return Top == (value & ((int)VStretch | (int)VRelative)); }
00067 bool isBottom() { return (Bottom == (value & ((int)VStretch | (int)VRelative))); }
00068 bool isVStretch() { return (VStretch == (value & ((int)VStretch | (int)VRelative))); }
00069
00070 bool isStretch() { return (Stretch == (value & ((int)Stretch | (int)Relative))); }
00071 bool isDefault() { return (Default == (value & ((int)Stretch | (int)Relative))); }
00072
00073 bool isHRelative() { return HRelative == (value & (int)HRelative); }
00074 bool isVRelative() { return VRelative == (value & (int)VRelative); }
00075 bool isRelative() { return Relative == (value & (int)Relative); }
00076
00077 Align& operator |= (Align const& _other) { value = Enum(int(value) | int(_other.value)); return *this; }
00078 friend Align operator | (Enum const& a, Enum const& b) { return Align(Enum(int(a) | int(b))); }
00079 friend Align operator | (Align const& a, Align const& b) { return Align(Enum(int(a.value) | int(b.value))); }
00080
00081 friend bool operator == (Align const& a, Align const& b) { return a.value == b.value; }
00082 friend bool operator != (Align const& a, Align const& b) { return a.value != b.value; }
00083
00084 typedef std::map<std::string, int> MapAlign;
00085
00086 static Align parse(const std::string& _value)
00087 {
00088 Align result(Enum(0));
00089 const MapAlign& map_names = result.getValueNames();
00090 const std::vector<std::string>& vec = utility::split(_value);
00091 for (size_t pos=0; pos<vec.size(); pos++)
00092 {
00093 MapAlign::const_iterator iter = map_names.find(vec[pos]);
00094 if (iter != map_names.end())
00095 {
00096 result.value = Enum(int(result.value) | int(iter->second));
00097 }
00098 else
00099 {
00100 MYGUI_LOG(Warning, "Cannot parse type '" << vec[pos] << "'");
00101 }
00102 }
00103 return result;
00104 }
00105
00106 std::string print() const
00107 {
00108 std::string result;
00109
00110 if (value & HRelative) result = "HRelative";
00111 else if (value & Left)
00112 {
00113 if (value & Right) result = "HStretch";
00114 else result = "Left";
00115 }
00116 else if (value & Right) result = "Right";
00117 else result = "HCenter";
00118
00119 if (value & VRelative) result = "VRelative";
00120 else if (value & Top)
00121 {
00122 if (value & Bottom) result += " VStretch";
00123 else result += " Top";
00124 }
00125 else if (value & Bottom) result += " Bottom";
00126 else result += " VCenter";
00127
00128 return result;
00129 }
00130
00131 friend std::ostream& operator << ( std::ostream& _stream, const Align& _value )
00132 {
00133 _stream << _value.print();
00134 return _stream;
00135 }
00136
00137 friend std::istream& operator >> ( std::istream& _stream, Align& _value )
00138 {
00139 std::string value;
00140 _stream >> value;
00141 _value = Align::parse(value);
00142 return _stream;
00143 }
00144
00145 private:
00146 const MapAlign& getValueNames()
00147 {
00148 static MapAlign map_names;
00149
00150 if (map_names.empty())
00151 {
00152
00153 map_names["ALIGN_HCENTER"] = HCenter;
00154 map_names["ALIGN_VCENTER"] = VCenter;
00155 map_names["ALIGN_CENTER"] = Center;
00156 map_names["ALIGN_LEFT"] = Left;
00157 map_names["ALIGN_RIGHT"] = Right;
00158 map_names["ALIGN_HSTRETCH"] = HStretch;
00159 map_names["ALIGN_TOP"] = Top;
00160 map_names["ALIGN_BOTTOM"] = Bottom;
00161 map_names["ALIGN_VSTRETCH"] = VStretch;
00162 map_names["ALIGN_STRETCH"] = Stretch;
00163 map_names["ALIGN_DEFAULT"] = Default;
00164
00165 MYGUI_REGISTER_VALUE(map_names, HCenter);
00166 MYGUI_REGISTER_VALUE(map_names, VCenter);
00167 MYGUI_REGISTER_VALUE(map_names, Center);
00168 MYGUI_REGISTER_VALUE(map_names, Left);
00169 MYGUI_REGISTER_VALUE(map_names, Right);
00170 MYGUI_REGISTER_VALUE(map_names, HStretch);
00171 MYGUI_REGISTER_VALUE(map_names, Top);
00172 MYGUI_REGISTER_VALUE(map_names, Bottom);
00173 MYGUI_REGISTER_VALUE(map_names, VStretch);
00174 MYGUI_REGISTER_VALUE(map_names, Stretch);
00175 MYGUI_REGISTER_VALUE(map_names, Default);
00176 MYGUI_REGISTER_VALUE(map_names, HRelative);
00177 MYGUI_REGISTER_VALUE(map_names, VRelative);
00178 MYGUI_REGISTER_VALUE(map_names, Relative);
00179 }
00180
00181 return map_names;
00182 }
00183
00184 private:
00185 Enum value;
00186 };
00187
00188 }
00189
00190 #endif // __MYGUI_ALIGN_H__