1 /* 2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 3 * Distributed under the MIT License 4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 5 */ 6 7 #ifndef MYGUI_WIDGET_STYLE_H_ 8 #define MYGUI_WIDGET_STYLE_H_ 9 10 #include "MyGUI_Prerequest.h" 11 #include <string> 12 #include <cstring> 13 #include <iostream> 14 15 namespace MyGUI 16 { 17 18 struct MYGUI_EXPORT WidgetStyle 19 { 20 enum Enum 21 { 22 Child, /**< child widget, cropped by parent widget borders, no overlapping (used by default for child widgets) */ 23 Popup, /**< popup widget, have parent widget, but not cropped on its borders */ 24 Overlapped, /**< child widget, cropped by parent widget borders, can overlap (used by default for root widgets) */ 25 MAX 26 }; 27 WidgetStyleWidgetStyle28 WidgetStyle() : 29 mValue(MAX) 30 { 31 } 32 WidgetStyleWidgetStyle33 WidgetStyle(Enum _value) : 34 mValue(_value) 35 { 36 } 37 parseWidgetStyle38 static WidgetStyle parse(const std::string& _value) 39 { 40 WidgetStyle type; 41 int value = 0; 42 while (true) 43 { 44 const char* name = type.getValueName(value); 45 if (strcmp(name, "") == 0 || name == _value) 46 break; 47 value++; 48 } 49 type.mValue = (Enum)value; 50 return type; 51 } 52 53 friend bool operator == (WidgetStyle const& a, WidgetStyle const& b) 54 { 55 return a.mValue == b.mValue; 56 } 57 58 friend bool operator != (WidgetStyle const& a, WidgetStyle const& b) 59 { 60 return a.mValue != b.mValue; 61 } 62 63 friend std::ostream& operator << (std::ostream& _stream, const WidgetStyle& _value) 64 { 65 _stream << _value.getValueName(_value.mValue); 66 return _stream; 67 } 68 69 friend std::istream& operator >> (std::istream& _stream, WidgetStyle& _value) 70 { 71 std::string value; 72 _stream >> value; 73 _value = parse(value); 74 return _stream; 75 } 76 printWidgetStyle77 std::string print() const 78 { 79 return getValueName(mValue); 80 } 81 getValueWidgetStyle82 int getValue() const 83 { 84 return mValue; 85 } 86 87 private: getValueNameWidgetStyle88 const char* getValueName(int _index) const 89 { 90 static const char* values[MAX + 1] = { "Child", "Popup", "Overlapped", "" }; 91 return values[(_index < MAX && _index >= 0) ? _index : MAX]; 92 } 93 94 private: 95 Enum mValue; 96 }; 97 98 } // namespace MyGUI 99 100 #endif // MYGUI_WIDGET_STYLE_H_ 101