MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #ifndef __MYGUI_WIDGET_STYLE_H__ 00008 #define __MYGUI_WIDGET_STYLE_H__ 00009 00010 #include "MyGUI_Prerequest.h" 00011 #include <string.h> 00012 00013 namespace MyGUI 00014 { 00015 00016 struct MYGUI_EXPORT WidgetStyle 00017 { 00018 enum Enum 00019 { 00020 Child, 00021 Popup, 00022 Overlapped, 00023 MAX 00024 }; 00025 00026 WidgetStyle() : 00027 mValue(MAX) 00028 { 00029 } 00030 00031 WidgetStyle(Enum _value) : 00032 mValue(_value) 00033 { 00034 } 00035 00036 static WidgetStyle parse(const std::string& _value) 00037 { 00038 WidgetStyle type; 00039 int value = 0; 00040 while (true) 00041 { 00042 const char* name = type.getValueName(value); 00043 if (strcmp(name, "") == 0 || name == _value) 00044 break; 00045 value++; 00046 } 00047 type.mValue = (Enum)value; 00048 return type; 00049 } 00050 00051 friend bool operator == (WidgetStyle const& a, WidgetStyle const& b) 00052 { 00053 return a.mValue == b.mValue; 00054 } 00055 00056 friend bool operator != (WidgetStyle const& a, WidgetStyle const& b) 00057 { 00058 return a.mValue != b.mValue; 00059 } 00060 00061 friend std::ostream& operator << (std::ostream& _stream, const WidgetStyle& _value) 00062 { 00063 _stream << _value.getValueName(_value.mValue); 00064 return _stream; 00065 } 00066 00067 friend std::istream& operator >> (std::istream& _stream, WidgetStyle& _value) 00068 { 00069 std::string value; 00070 _stream >> value; 00071 _value = parse(value); 00072 return _stream; 00073 } 00074 00075 std::string print() const 00076 { 00077 return getValueName(mValue); 00078 } 00079 00080 int getValue() const 00081 { 00082 return mValue; 00083 } 00084 00085 private: 00086 const char* getValueName(int _index) const 00087 { 00088 static const char* values[MAX + 1] = { "Child", "Popup", "Overlapped", "" }; 00089 return values[(_index < MAX && _index >= 0) ? _index : MAX]; 00090 } 00091 00092 private: 00093 Enum mValue; 00094 }; 00095 00096 } // namespace MyGUI 00097 00098 #endif // __MYGUI_WIDGET_STYLE_H__