1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
/*!
@file
@author Albert Semenov
@date 10/2010
*/
#ifndef MESSAGE_BOX_STYLE_H_
#define MESSAGE_BOX_STYLE_H_
#include <MyGUI.h>
namespace MyGUI
{
struct MessageBoxStyle
{
enum Enum
{
None = MYGUI_FLAG_NONE,
Ok = MYGUI_FLAG(0),
Yes = MYGUI_FLAG(1),
No = MYGUI_FLAG(2),
Abort = MYGUI_FLAG(3),
Retry = MYGUI_FLAG(4),
Ignore = MYGUI_FLAG(5),
Cancel = MYGUI_FLAG(6),
Try = MYGUI_FLAG(7),
Continue = MYGUI_FLAG(8),
_IndexUserButton1 = 9, // индекс первой кнопки юзера
Button1 = MYGUI_FLAG(_IndexUserButton1),
Button2 = MYGUI_FLAG(_IndexUserButton1 + 1),
Button3 = MYGUI_FLAG(_IndexUserButton1 + 2),
Button4 = MYGUI_FLAG(_IndexUserButton1 + 3),
_CountUserButtons = 4, // колличество кнопок юзера
_IndexIcon1 = _IndexUserButton1 + _CountUserButtons, // индекс первой иконки
IconDefault = MYGUI_FLAG(_IndexIcon1),
IconInfo = MYGUI_FLAG(_IndexIcon1),
IconQuest = MYGUI_FLAG(_IndexIcon1 + 1),
IconError = MYGUI_FLAG(_IndexIcon1 + 2),
IconWarning = MYGUI_FLAG(_IndexIcon1 + 3),
Icon1 = MYGUI_FLAG(_IndexIcon1),
Icon2 = MYGUI_FLAG(_IndexIcon1 + 1),
Icon3 = MYGUI_FLAG(_IndexIcon1 + 2),
Icon4 = MYGUI_FLAG(_IndexIcon1 + 3),
Icon5 = MYGUI_FLAG(_IndexIcon1 + 4),
Icon6 = MYGUI_FLAG(_IndexIcon1 + 5),
Icon7 = MYGUI_FLAG(_IndexIcon1 + 6),
Icon8 = MYGUI_FLAG(_IndexIcon1 + 7)
};
MessageBoxStyle(Enum _value = None) :
mValue(_value)
{
}
MessageBoxStyle& operator |= (MessageBoxStyle const& _other)
{
mValue = Enum(int(mValue) | int(_other.mValue));
return *this;
}
friend MessageBoxStyle operator | (Enum const& a, Enum const& b)
{
return MessageBoxStyle(Enum(int(a) | int(b)));
}
MessageBoxStyle operator | (Enum const& a)
{
return MessageBoxStyle(Enum(int(mValue) | int(a)));
}
friend bool operator == (MessageBoxStyle const& a, MessageBoxStyle const& b)
{
return a.mValue == b.mValue;
}
friend bool operator != (MessageBoxStyle const& a, MessageBoxStyle const& b)
{
return a.mValue != b.mValue;
}
/*friend std::ostream& operator << (std::ostream& _stream, const MessageBoxStyle& _value)
{
//_stream << _value.print();
return _stream;
}*/
friend std::istream& operator >> (std::istream& _stream, MessageBoxStyle& _value)
{
std::string value;
_stream >> value;
_value = parse(value);
return _stream;
}
// возвращает индекс иконки
size_t getIconIndex()
{
size_t index = 0;
int num = mValue >> _IndexIcon1;
while (num != 0)
{
if ((num & 1) == 1)
return index;
++index;
num >>= 1;
}
return ITEM_NONE;
}
// возвращает индекс иконки
size_t getButtonIndex()
{
size_t index = 0;
int num = mValue;
while (num != 0)
{
if ((num & 1) == 1)
return index;
++index;
num >>= 1;
}
return ITEM_NONE;
}
// возвращает список кнопок
std::vector<MessageBoxStyle> getButtons()
{
std::vector<MessageBoxStyle> buttons;
size_t index = 0;
int num = mValue;
while (index < _IndexIcon1)
{
if ((num & 1) == 1)
{
buttons.push_back(MessageBoxStyle::Enum( MYGUI_FLAG(index)));
}
++index;
num >>= 1;
}
return buttons;
}
typedef std::map<std::string, int> MapAlign;
static MessageBoxStyle parse(const std::string& _value)
{
MessageBoxStyle result(MessageBoxStyle::Enum(0));
const MapAlign& map_names = result.getValueNames();
const std::vector<std::string>& vec = utility::split(_value);
for (size_t pos = 0; pos < vec.size(); pos++)
{
MapAlign::const_iterator iter = map_names.find(vec[pos]);
if (iter != map_names.end())
{
result.mValue = Enum(int(result.mValue) | int(iter->second));
}
else
{
MYGUI_LOG(Warning, "Cannot parse type '" << vec[pos] << "'");
}
}
return result;
}
private:
const MapAlign& getValueNames()
{
static MapAlign map_names;
if (map_names.empty())
{
MYGUI_REGISTER_VALUE(map_names, None);
MYGUI_REGISTER_VALUE(map_names, Ok);
MYGUI_REGISTER_VALUE(map_names, Yes);
MYGUI_REGISTER_VALUE(map_names, No);
MYGUI_REGISTER_VALUE(map_names, Abort);
MYGUI_REGISTER_VALUE(map_names, Retry);
MYGUI_REGISTER_VALUE(map_names, Ignore);
MYGUI_REGISTER_VALUE(map_names, Cancel);
MYGUI_REGISTER_VALUE(map_names, Try);
MYGUI_REGISTER_VALUE(map_names, Continue);
MYGUI_REGISTER_VALUE(map_names, Button1);
MYGUI_REGISTER_VALUE(map_names, Button2);
MYGUI_REGISTER_VALUE(map_names, Button3);
MYGUI_REGISTER_VALUE(map_names, Button4);
MYGUI_REGISTER_VALUE(map_names, IconDefault);
MYGUI_REGISTER_VALUE(map_names, IconInfo);
MYGUI_REGISTER_VALUE(map_names, IconQuest);
MYGUI_REGISTER_VALUE(map_names, IconError);
MYGUI_REGISTER_VALUE(map_names, IconWarning);
MYGUI_REGISTER_VALUE(map_names, Icon1);
MYGUI_REGISTER_VALUE(map_names, Icon2);
MYGUI_REGISTER_VALUE(map_names, Icon3);
MYGUI_REGISTER_VALUE(map_names, Icon4);
MYGUI_REGISTER_VALUE(map_names, Icon5);
MYGUI_REGISTER_VALUE(map_names, Icon6);
MYGUI_REGISTER_VALUE(map_names, Icon7);
MYGUI_REGISTER_VALUE(map_names, Icon8);
}
return map_names;
}
private:
Enum mValue;
};
} // namespace MyGUI
#endif // MESSAGE_BOX_STYLE_H_
|