32 mWidgetClient(nullptr),
34 mInheritedEnabled(true),
35 mInheritedVisible(true),
42 mAlign(
Align::Default),
61 mWidgetStyle = _style;
68#if MYGUI_DEBUG_MODE == 1
92 const WidgetInfo* root = initialiseWidgetSkinBase(skinInfo, templateInfo);
111 if (skinInfo !=
nullptr)
112 setSkinProperty(skinInfo);
116 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 if (mWidgetClient !=
nullptr)
436 if (mAlpha == _alpha)
443 void Widget::_updateAlpha()
445 if (
nullptr != mParent)
446 mRealAlpha = mAlpha * (mInheritsAlpha ? mParent->_getRealAlpha() :
ALPHA_MAX);
450 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
451 (*widget)->_updateAlpha();
452 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
453 (*widget)->_updateAlpha();
460 mInheritsAlpha = _inherits;
468 || !mInheritedVisible
477 for (VectorWidgetPtr::const_reverse_iterator widget = mWidgetChild.rbegin(); widget != mWidgetChild.rend(); ++widget)
488 for (VectorWidgetPtr::const_reverse_iterator widget = mWidgetChildSkin.rbegin(); widget != mWidgetChildSkin.rend(); ++widget)
499 void Widget::_updateAbsolutePoint()
507 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
508 (*widget)->_updateAbsolutePoint();
509 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
510 (*widget)->_updateAbsolutePoint();
517 if (mWidgetClient !=
nullptr)
523 VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
524 if (iter == mWidgetChild.end())
528 for (VectorWidgetPtr::iterator widget = copy.begin(); widget != copy.end(); ++widget)
530 if ((*widget) == _widget)
531 (*widget)->setDepth(-1);
532 else if ((*widget)->getDepth() == -1)
533 (*widget)->setDepth(0);
541 if (mWidgetClient !=
nullptr)
544 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
570 const IntSize& size = _newSize;
572 bool need_move =
false;
573 bool need_size =
false;
637 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
638 (*widget)->_updateAbsolutePoint();
639 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
640 (*widget)->_updateAbsolutePoint();
673 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
674 (*widget)->_setAlign(old,
getSize());
675 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
676 (*widget)->_setAlign(old,
getSize());
691 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
692 (*widget)->_updateAbsolutePoint();
693 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
694 (*widget)->_updateAbsolutePoint();
718 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
720 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
764 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
765 (*widget)->_updateAbsolutePoint();
766 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
767 (*widget)->_updateAbsolutePoint();
782 mParent->_unlinkChildWidget(
this);
790 else if (!oldlayer.empty())
801 MYGUI_ASSERT(_parent !=
this,
"cyclic attach (attaching to self)");
818 mWidgetStyle = _style;
824 if (mParent ==
nullptr)
827 mParent->_unlinkChildWidget(
this);
830 mParent->_linkChildWidget(
this);
845 if (mParent ==
nullptr)
848 mParent->_unlinkChildWidget(
this);
851 mParent->_linkChildWidget(
this);
856 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
857 (*widget)->_updateAbsolutePoint();
858 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
859 (*widget)->_updateAbsolutePoint();
871 if (mParent ==
nullptr)
874 mParent->_unlinkChildWidget(
this);
877 mParent->_linkChildWidget(
this);
882 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
883 (*widget)->_updateAbsolutePoint();
884 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
885 (*widget)->_updateAbsolutePoint();
897 if (_style == mWidgetStyle)
926 return baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name,
false);
931 if (mWidgetClient !=
nullptr)
938 if (mWidgetClient !=
nullptr)
940 return mWidgetChild.size();
945 if (mWidgetClient !=
nullptr)
948 return mWidgetChild[_index];
961 if (mVisible == _value)
968 void Widget::_updateVisible()
971 mInheritedVisible = mVisible && mInheritedVisible;
975 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
976 (*widget)->_updateVisible();
977 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
978 (*widget)->_updateVisible();
988 if (mEnabled == _value)
995 void Widget::_updateEnabled()
998 mInheritedEnabled = mInheritedEnabled && mEnabled;
1000 for (VectorWidgetPtr::iterator iter = mWidgetChild.begin(); iter != mWidgetChild.end(); ++iter)
1001 (*iter)->_updateEnabled();
1002 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
1003 (*iter)->_updateEnabled();
1007 if (!mInheritedEnabled)
1015 for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
1016 (*widget)->setColour(_value);
1040 void Widget::_linkChildWidget(
Widget* _widget)
1042 VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
1043 MYGUI_ASSERT(iter == mWidgetChild.end(),
"widget already exist");
1047 void Widget::_unlinkChildWidget(Widget* _widget)
1049 VectorWidgetPtr::iterator iter = std::remove(mWidgetChild.begin(), mWidgetChild.end(), _widget);
1050 MYGUI_ASSERT(iter != mWidgetChild.end(),
"widget not found");
1051 mWidgetChild.erase(iter);
1067 for (MapString::const_iterator item = properties.begin(); item != properties.end(); ++item)
1073 std::string key = _key;
1074 std::string value = _value;
1078 size_t index = key.find(
"_");
1079 if (index != std::string::npos)
1082 key = key.substr(index + 1);
1093 for (
const auto& childSkin : mWidgetChildSkin)
1094 childSkin->findWidgets(_name, result);
1102 _result.push_back(
this);
1104 if (mWidgetClient !=
nullptr)
1110 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
1111 (*widget)->findWidgets(_name, _result);
1125 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
1126 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 mWidgetClient;
1302 return mWidgetStyle;
1312 mContainer = _value;
1330 float Widget::_getRealAlpha()
const
1337 return mInheritedEnabled;
1342 return mInheritedVisible;
1345 void Widget::resizeLayerItemView(
const IntSize& _oldView,
const IntSize& _newView)
1352 if (mDepth == _value)
1357 if (mParent !=
nullptr)
1359 mParent->_unlinkChildWidget(
this);
1360 mParent->_linkChildWidget(
this);
1370 void Widget::addWidget(
Widget* _widget)
1376 for (
size_t index = 0; index < mWidgetChild.size(); ++index)
1378 Widget* widget = mWidgetChild[index];
1381 mWidgetChild.insert(mWidgetChild.begin() + index, _widget);
1387 mWidgetChild.push_back(_widget);
1392 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
1396 (*widget)->detachFromLayerItemNode(
false);
1401 for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
1406 (*widget)->_updateView();
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_EXCEPT(dest)
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_LOG(level, text)
static bool isIgnoreProperty(const std::string &_key)
static bool checkProperty(Widget *_owner, std::string &_key, std::string &_value)
static IntCoord convertFromRelative(const FloatCoord &_coord, const IntSize &_view)
void _unlinkChildWidget(Widget *_widget)
void _linkChildWidget(Widget *_widget)
static Gui & getInstance()
const IntPoint & getAbsolutePosition() const
bool _checkOutside() const
ICroppedRectangle * mCroppedParent
IntPoint mAbsolutePosition
const IntCoord & getCoord() const
int _getViewRight() const
int _getViewBottom() const
const std::string & getName() const
virtual const IntSize & getSize() const =0
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const =0
void removeChildNode(LayerItem *_item)
void detachFromLayerItemNode(bool _deep)
void addChildItem(LayerItem *_item)
void addChildNode(LayerItem *_item)
void removeChildItem(LayerItem *_item)
ILayer * getLayer() const
void detachFromLayer(Widget *_item)
static LayerManager & getInstance()
void attachToLayerNode(const std::string &_name, Widget *_item)
const std::string & getCurrentLayout() const
static LayoutManager & getInstance()
ResourceLayout * getByName(const std::string &_name, bool _throw=true) const
virtual const IntSize & getViewSize() const =0
static RenderManager & getInstance()
const VectorWidgetInfo & getLayoutData() const
Widget * createWidget(const WidgetInfo &_widgetInfo, const std::string &_prefix="", Widget *_parent=nullptr, bool _template=false)
const IntSize & getSize() const
const MapString & getProperties() const
const VectorChildSkinInfo & getChild() const
void _correctSkinItemView()
void _setSkinItemAlpha(float _value)
void _createSkinItem(ResourceSkin *_info)
void _setSkinItemColour(const Colour &_value)
bool _setSkinItemState(const std::string &_state)
void _updateSkinItemView()
void _setSubSkinVisible(bool _visible)
void _setSkinItemAlign(const IntSize &_size)
void _setSkinItemVisible(bool _value)
static SkinManager & getInstance()
ResourceSkin * getByName(const std::string &_name) const
void setUserData(Any _data)
void setUserString(const std::string &_key, const std::string &_value)
types::TSize< float > FloatSize
std::map< std::string, std::string > MapString
types::TCoord< float > FloatCoord
std::vector< WidgetInfo > VectorWidgetInfo
types::TCoord< int > IntCoord
std::vector< ChildSkinInfo > VectorChildSkinInfo
std::vector< Widget * > VectorWidgetPtr
types::TPoint< float > FloatPoint
types::TSize< int > IntSize
types::TPoint< int > IntPoint
TPoint< T > point() const