34 mInheritsEnabled(true),
35 mInheritsVisible(true),
42 mAlign(
Align::Default),
65 mWidgetStyle = _style;
72 #if MYGUI_DEBUG_MODE == 1
96 const WidgetInfo* root = initialiseWidgetSkinBase(skinInfo, templateInfo);
115 if (skinInfo !=
nullptr)
116 setSkinProperty(skinInfo);
120 for (VectorStringPairs::const_iterator iter = root->
properties.begin(); iter != root->
properties.end(); ++iter)
132 shutdownWidgetSkinBase();
168 shutdownWidgetSkinBase();
169 const WidgetInfo* root = initialiseWidgetSkinBase(skinInfo, templateInfo);
175 if (skinInfo !=
nullptr)
176 setSkinProperty(skinInfo);
180 for (VectorStringPairs::const_iterator iter = root->
properties.begin(); iter != root->
properties.end(); ++iter)
190 bool skinOnly =
false;
192 if (_skinInfo ==
nullptr)
195 std::string skinName;
198 for (VectorWidgetInfo::const_iterator item = data.begin(); item != data.end(); ++item)
200 if ((*item).name ==
"Root")
202 skinName = (*item).skin;
214 if (_skinInfo !=
nullptr)
230 for (MapString::const_iterator item = properties.begin(); item != properties.end(); ++item)
238 for (VectorChildSkinInfo::const_iterator iter = child.begin(); iter != child.end(); ++iter)
240 Widget* widget =
baseCreateWidget(iter->style, iter->type, iter->skin, iter->coord, iter->align, iter->layer, iter->name,
true);
242 for (MapString::const_iterator prop = iter->params.begin(); prop != iter->params.end(); ++prop)
243 widget->setUserString(prop->first, prop->second);
269 void Widget::shutdownWidgetSkinBase()
276 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
279 mWidgetChild.push_back(*iter);
282 mWidgetChildSkin.clear();
284 mWidgetClient =
nullptr;
294 mWidgetChildSkin.push_back(widget);
298 if (mWidgetClient !=
nullptr)
300 widget = mWidgetClient->
baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name, _template);
344 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
345 (*widget)->_updateView();
346 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
347 (*widget)->_updateView();
366 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
367 (*widget)->_updateView();
368 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
369 (*widget)->_updateView();
381 MYGUI_ASSERT(
nullptr != _widget,
"invalid widget pointer");
388 VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
389 if (iter != mWidgetChild.end())
395 mWidgetChild.erase(iter);
413 while (!mWidgetChild.empty())
416 Widget* widget = mWidgetChild.back();
417 mWidgetChild.pop_back();
429 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
430 if (mWidgetClient !=
nullptr)
437 if (mAlpha == _alpha)
444 void Widget::_updateAlpha()
446 if (
nullptr != mParent)
447 mRealAlpha = mAlpha * (mInheritsAlpha ? mParent->_getRealAlpha() :
ALPHA_MAX);
451 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
452 (*widget)->_updateAlpha();
453 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
454 (*widget)->_updateAlpha();
461 mInheritsAlpha = _inherits;
478 for (VectorWidgetPtr::const_reverse_iterator widget = mWidgetChild.rbegin(); widget != mWidgetChild.rend(); ++widget)
489 for (VectorWidgetPtr::const_reverse_iterator widget = mWidgetChildSkin.rbegin(); widget != mWidgetChildSkin.rend(); ++widget)
500 void Widget::_updateAbsolutePoint()
508 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
509 (*widget)->_updateAbsolutePoint();
510 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
511 (*widget)->_updateAbsolutePoint();
518 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
519 if (mWidgetClient !=
nullptr)
525 VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
526 if (iter == mWidgetChild.end())
530 for (VectorWidgetPtr::iterator widget = copy.begin(); widget != copy.end(); ++widget)
532 if ((*widget) == _widget)
533 (*widget)->setDepth(-1);
534 else if ((*widget)->getDepth() == -1)
535 (*widget)->setDepth(0);
543 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
544 if (mWidgetClient !=
nullptr)
547 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
573 const IntSize& size = _newSize;
575 bool need_move =
false;
576 bool need_size =
false;
640 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
641 (*widget)->_updateAbsolutePoint();
642 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
643 (*widget)->_updateAbsolutePoint();
676 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
677 (*widget)->_setAlign(old,
getSize());
678 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
679 (*widget)->_setAlign(old,
getSize());
694 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
695 (*widget)->_updateAbsolutePoint();
696 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
697 (*widget)->_updateAbsolutePoint();
721 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
723 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
767 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
768 (*widget)->_updateAbsolutePoint();
769 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
770 (*widget)->_updateAbsolutePoint();
785 mParent->_unlinkChildWidget(
this);
793 else if (!oldlayer.empty())
804 MYGUI_ASSERT(_parent !=
this,
"cyclic attach (attaching to self)");
821 mWidgetStyle = _style;
827 if (mParent ==
nullptr)
830 mParent->_unlinkChildWidget(
this);
833 mParent->_linkChildWidget(
this);
848 if (mParent ==
nullptr)
851 mParent->_unlinkChildWidget(
this);
854 mParent->_linkChildWidget(
this);
859 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
860 (*widget)->_updateAbsolutePoint();
861 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
862 (*widget)->_updateAbsolutePoint();
874 if (mParent ==
nullptr)
877 mParent->_unlinkChildWidget(
this);
880 mParent->_linkChildWidget(
this);
885 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
886 (*widget)->_updateAbsolutePoint();
887 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
888 (*widget)->_updateAbsolutePoint();
900 if (_style == mWidgetStyle)
929 return baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name,
false);
934 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
935 if (mWidgetClient !=
nullptr)
942 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
943 if (mWidgetClient !=
nullptr)
945 return mWidgetChild.size();
950 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
951 if (mWidgetClient !=
nullptr)
954 return mWidgetChild[_index];
967 if (mVisible == _value)
974 void Widget::_updateVisible()
977 bool value = mVisible && mInheritsVisible;
981 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
982 (*widget)->_updateVisible();
983 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
984 (*widget)->_updateVisible();
994 if (mEnabled == _value)
1001 void Widget::_updateEnabled()
1004 mInheritsEnabled = mInheritsEnabled && mEnabled;
1006 for (VectorWidgetPtr::iterator iter = mWidgetChild.begin(); iter != mWidgetChild.end(); ++iter)
1007 (*iter)->_updateEnabled();
1008 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
1009 (*iter)->_updateEnabled();
1013 if (!mInheritsEnabled)
1021 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
1022 (*widget)->setColour(_value);
1046 void Widget::_linkChildWidget(
Widget* _widget)
1048 VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
1049 MYGUI_ASSERT(iter == mWidgetChild.end(),
"widget already exist");
1053 void Widget::_unlinkChildWidget(Widget* _widget)
1055 VectorWidgetPtr::iterator iter = std::remove(mWidgetChild.begin(), mWidgetChild.end(), _widget);
1056 MYGUI_ASSERT(iter != mWidgetChild.end(),
"widget not found");
1057 mWidgetChild.erase(iter);
1071 for (MapString::const_iterator item = properties.begin(); item != properties.end(); ++item)
1077 std::string key = _key;
1078 std::string value = _value;
1082 size_t index = key.find(
"_");
1083 if (index != std::string::npos)
1086 key = key.substr(index + 1);
1097 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
1098 (*iter)->findWidgets(_name, result);
1106 _result.push_back(
this);
1108 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
1109 if (mWidgetClient !=
nullptr)
1115 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
1116 (*widget)->findWidgets(_name, _result);
1122 mWidgetChild.push_back(_widget);
1136 mWidgetClient = _widget;
1141 return baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name,
true);
1147 if (_key ==
"Position")
1148 setPosition(utility::parseValue<IntPoint>(_value));
1151 else if (_key ==
"Size")
1152 setSize(utility::parseValue<IntSize>(_value));
1155 else if (_key ==
"Coord")
1156 setCoord(utility::parseValue<IntCoord>(_value));
1159 else if (_key ==
"Visible")
1160 setVisible(utility::parseValue<bool>(_value));
1163 else if (_key ==
"Depth")
1164 setDepth(utility::parseValue<int>(_value));
1167 else if (_key ==
"Alpha")
1168 setAlpha(utility::parseValue<float>(_value));
1171 else if (_key ==
"Colour")
1172 setColour(utility::parseValue<Colour>(_value));
1175 else if (_key ==
"InheritsAlpha")
1179 else if (_key ==
"InheritsPick")
1183 else if (_key ==
"MaskPick")
1187 else if (_key ==
"NeedKey")
1191 else if (_key ==
"NeedMouse")
1195 else if (_key ==
"Enabled")
1196 setEnabled(utility::parseValue<bool>(_value));
1199 else if (_key ==
"NeedToolTip")
1203 else if (_key ==
"Pointer")
1267 return mInheritsAlpha;
1292 return mWidgetClient;
1297 return mWidgetStyle;
1307 mContainer = _value;
1325 float Widget::_getRealAlpha()
const
1332 return mInheritsEnabled;
1337 return mInheritsVisible;
1340 void Widget::resizeLayerItemView(
const IntSize& _oldView,
const IntSize& _newView)
1347 if (mDepth == _value)
1352 if (mParent !=
nullptr)
1354 mParent->_unlinkChildWidget(
this);
1355 mParent->_linkChildWidget(
this);
1365 void Widget::addWidget(
Widget* _widget)
1371 for (
size_t index = 0; index < mWidgetChild.size(); ++index)
1373 Widget* widget = mWidgetChild[index];
1376 mWidgetChild.insert(mWidgetChild.begin() + index, _widget);
1382 mWidgetChild.push_back(_widget);
1387 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
1391 (*widget)->detachFromLayerItemNode(
true);
1396 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
1401 (*widget)->_updateView();