30 Widget::Widget() =
default;
32 Widget::~Widget() =
default;
34 void Widget::_initialise(
37 std::string_view _skinName,
39 ICroppedRectangle* _croppedParent,
40 std::string_view _name)
42 ResourceSkin* skinInfo =
nullptr;
43 ResourceLayout* templateInfo =
nullptr;
45 if (LayoutManager::getInstance().isExist(_skinName))
46 templateInfo = LayoutManager::getInstance().getByName(_skinName);
48 skinInfo = SkinManager::getInstance().getByName(_skinName);
52 mAlign = Align::Default;
53 mWidgetStyle = _style;
56 mCroppedParent = _croppedParent;
58 updateWorldHasRotation();
61#if MYGUI_DEBUG_MODE == 1
63 if (mWidgetStyle == WidgetStyle::Child)
68 else if (mWidgetStyle == WidgetStyle::Overlapped)
70 MYGUI_ASSERT((mParent ==
nullptr) == (mCroppedParent ==
nullptr),
"error cropped");
72 else if (mWidgetStyle == WidgetStyle::Popup)
74 MYGUI_ASSERT(!mCroppedParent,
"cropped must be nullptr");
80 mAbsolutePosition = _coord.point();
82 if (
nullptr != mCroppedParent)
83 mAbsolutePosition += mCroppedParent->getAbsolutePosition();
84 updateRotationTransform();
86 const WidgetInfo* root = initialiseWidgetSkinBase(skinInfo, templateInfo);
89 if (mWidgetStyle == WidgetStyle::Child)
92 mParent->addChildItem(
this);
94 else if (mWidgetStyle == WidgetStyle::Overlapped)
97 mParent->addChildNode(
this);
101 initialiseOverride();
103 if (skinInfo !=
nullptr)
104 setSkinProperty(skinInfo);
108 for (
const auto& property : root->properties)
110 setProperty(property.first, property.second);
115 void Widget::_shutdown()
117 eventWidgetDestroyed(
this);
119 setUserData(Any::Null);
124 shutdownWidgetSkinBase();
126 _destroyAllChildWidget();
128 if (mWidgetStyle == WidgetStyle::Child)
131 mParent->removeChildItem(
this);
133 else if (mWidgetStyle == WidgetStyle::Overlapped)
136 mParent->removeChildNode(
this);
140 mCroppedParent =
nullptr;
143 void Widget::changeWidgetSkin(std::string_view _skinName)
145 ResourceSkin* skinInfo =
nullptr;
146 ResourceLayout* templateInfo =
nullptr;
148 if (LayoutManager::getInstance().isExist(_skinName))
149 templateInfo = LayoutManager::getInstance().getByName(_skinName);
151 skinInfo = SkinManager::getInstance().getByName(_skinName);
157 shutdownWidgetSkinBase();
158 const WidgetInfo* root = initialiseWidgetSkinBase(skinInfo, templateInfo);
162 initialiseOverride();
164 if (skinInfo !=
nullptr)
165 setSkinProperty(skinInfo);
169 for (
const auto& property : root->properties)
171 setProperty(property.first, property.second);
176 const WidgetInfo* Widget::initialiseWidgetSkinBase(ResourceSkin* _skinInfo, ResourceLayout* _templateInfo)
178 const WidgetInfo* root =
nullptr;
179 bool skinOnly =
false;
181 if (_skinInfo ==
nullptr)
184 std::string_view skinName;
187 for (
const auto& item : data)
189 if (item.name ==
"Root")
191 skinName = item.skin;
197 _skinInfo = SkinManager::getInstance().getByName(skinName);
201 const IntSize& _size = mCoord.size();
203 if (_skinInfo !=
nullptr)
206 Widget::setSize(_skinInfo->getSize());
208 _createSkinItem(_skinInfo);
218#ifndef MYGUI_DONT_USE_OBSOLETE
219 const MapString& properties = _skinInfo->getProperties();
220 for (
const auto& property : properties)
222 if (BackwardCompatibility::isIgnoreProperty(property.first))
227 <<
" skin property is deprecated, move it to UserString in a widget in ResourceLayout"
228 << LayoutManager::getInstance().getCurrentLayout() <<
"]");
229 setUserString(property.first, property.second);
236 for (
const auto& iter : child)
238 Widget* widget = baseCreateWidget(
248 for (
const auto& prop : iter.params)
249 widget->setUserString(prop.first, prop.second);
256 Widget::setSize(root->intCoord.size());
258 for (
const auto& userString : root->userStrings)
260 setUserString(userString.first, userString.second);
263 for (
const auto& iter : root->childWidgetsInfo)
265 _templateInfo->createWidget(iter, {},
this,
true);
270 if (mCoord.size() == _size)
273 Widget::setSize(_size);
278 void Widget::shutdownWidgetSkinBase()
280 setMaskPick(MaskPickInfo{});
285 for (
auto& iter : mWidgetChildSkin)
288 mWidgetChild.push_back(iter);
289 _destroyChildWidget(iter);
291 mWidgetChildSkin.clear();
293 mWidgetClient =
nullptr;
296 Widget* Widget::baseCreateWidget(
298 std::string_view _type,
299 std::string_view _skin,
302 std::string_view _layer,
303 std::string_view _name,
306 Widget* widget =
nullptr;
310 widget = WidgetManager::getInstance().createWidget(
316 _style == WidgetStyle::Popup ?
nullptr :
this,
318 mWidgetChildSkin.push_back(widget);
322 if (mWidgetClient !=
nullptr)
325 mWidgetClient->baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name, _template);
326 onWidgetCreated(widget);
330 widget = WidgetManager::getInstance().createWidget(
336 _style == WidgetStyle::Popup ?
nullptr :
this,
338 _linkChildWidget(widget);
341 widget->setAlign(_align);
344 if (!_layer.empty() && widget->isRootWidget())
345 LayerManager::getInstance().attachToLayerNode(_layer, widget);
347 onWidgetCreated(widget);
352 Widget* Widget::createWidgetRealT(
353 std::string_view _type,
354 std::string_view _skin,
357 std::string_view _name)
359 return createWidgetT(_type, _skin, CoordConverter::convertFromRelative(_coord, getSize()), _align, _name);
362 void Widget::_updateView()
364 bool margin = mCroppedParent ? _checkMargin() : false;
369 if (_checkOutsideUnrotated())
374 _setSubSkinVisible(
false);
377 for (
auto& widget : mWidgetChild)
378 widget->_updateView();
379 for (
auto& widget : mWidgetChildSkin)
380 widget->_updateView();
388 _updateSkinItemView();
396 _setSubSkinVisible(
true);
399 for (
auto& widget : mWidgetChild)
400 widget->_updateView();
401 for (
auto& widget : mWidgetChildSkin)
402 widget->_updateView();
404 _updateSkinItemView();
407 bool Widget::_setWidgetState(std::string_view _state)
409 return _setSkinItemState(_state);
412 void Widget::_destroyChildWidget(Widget* _widget)
414 MYGUI_ASSERT(
nullptr != _widget,
"invalid widget pointer");
416 if (mParent !=
nullptr && mParent->getClientWidget() ==
this)
417 mParent->onWidgetDestroy(_widget);
419 onWidgetDestroy(_widget);
421 WidgetContainer::_destroyChildWidget(_widget);
424 IntCoord Widget::getClientCoord()
const
426 if (mWidgetClient !=
nullptr)
427 return mWidgetClient->getCoord();
428 return {0, 0, mCoord.width, mCoord.height};
431 void Widget::setAlpha(
float _alpha)
433 if (mAlpha == _alpha)
440 void Widget::_updateAlpha()
442 if (
nullptr != mParent)
443 mRealAlpha = mAlpha * (mInheritsAlpha ? mParent->_getRealAlpha() :
ALPHA_MAX);
447 for (
auto& widget : mWidgetChild)
448 widget->_updateAlpha();
449 for (
auto& widget : mWidgetChildSkin)
450 widget->_updateAlpha();
452 _setSkinItemAlpha(mRealAlpha);
455 void Widget::setInheritsAlpha(
bool _inherits)
457 if (mInheritsAlpha == _inherits)
459 mInheritsAlpha = _inherits;
463 ILayerItem* Widget::getLayerItemByPoint(
int _left,
int _top)
const
465 if (!mInheritedEnabled || !mInheritedVisible || (!getNeedMouseFocus() && !getInheritsPick()))
470 if (mRotation == 0.0f && (mCroppedParent || !mParent))
471 return getLayerItemByLocalPoint(
IntPoint(_left - mCoord.left, _top - mCoord.top));
473 return getLayerItemByRotatedPoint(_left, _top);
476 ILayerItem* Widget::getLayerItemByRotatedPoint(
int _left,
int _top)
const
478 const FloatPoint point((
float)_left, (
float)_top);
481 (mParent && !mCroppedParent) ? layerToLocal(point) : mRotationTransform.inverseTransformPoint(point);
482 return getLayerItemByLocalPoint(localPoint);
489 if (_point.left < mMargin.left || _point.top < mMargin.top || _point.left >= mCoord.width - mMargin.right ||
490 _point.top >= mCoord.height - mMargin.bottom
492 || !isMaskPickInside(
IntPoint((
int)_point.left, (
int)_point.top), mCoord))
496 int childLeft = (int)_point.left;
497 int childTop = (int)_point.top;
498 if constexpr (std::is_floating_point_v<T>)
500 childLeft = (int)std::floor(_point.left);
501 childTop = (int)std::floor(_point.top);
503 return pickChildrenOrSelf({childLeft, childTop});
506 ILayerItem* Widget::pickChildrenOrSelf(
IntPoint _point)
const
508 for (VectorWidgetPtr::const_reverse_iterator widget = mWidgetChild.rbegin(); widget != mWidgetChild.rend();
512 if ((*widget)->mWidgetStyle == WidgetStyle::Popup)
515 ILayerItem* item = (*widget)->getLayerItemByPoint(_point.left, _point.top);
520 for (VectorWidgetPtr::const_reverse_iterator widget = mWidgetChildSkin.rbegin();
521 widget != mWidgetChildSkin.rend();
524 ILayerItem* item = (*widget)->getLayerItemByPoint(_point.left, _point.top);
530 return getInheritsPick() ? nullptr :
const_cast<Widget*
>(
this);
533 void Widget::_updateGeometry(
const IntSize* _oldSize)
535 const IntPoint oldPosition = mAbsolutePosition;
536 mAbsolutePosition = mCroppedParent ? mCroppedParent->getAbsolutePosition() + mCoord.point() : mCoord.point();
537 updateRotationTransform();
539 for (
auto& widget : mWidgetChild)
540 if (_oldSize !=
nullptr)
541 widget->_setAlign(*_oldSize, getSize());
542 else if (widget->mCroppedParent !=
nullptr)
543 widget->_updateGeometry();
544 else if (widget->mWorldHasRotation)
545 widget->invalidateRotation();
546 for (
auto& widget : mWidgetChildSkin)
547 if (_oldSize !=
nullptr)
548 widget->_setAlign(*_oldSize, getSize());
549 else if (widget->mCroppedParent !=
nullptr)
550 widget->_updateGeometry();
551 else if (widget->mWorldHasRotation)
552 widget->invalidateRotation();
554 _correctSkinItemView();
556 if (mAbsolutePosition != oldPosition || (_oldSize !=
nullptr && getSize() != *_oldSize))
557 eventChangeAbsoluteCoord(
this);
560 void Widget::_forcePick(Widget* _widget)
562 if (mWidgetClient !=
nullptr)
564 mWidgetClient->_forcePick(_widget);
568 auto iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
569 if (iter == mWidgetChild.end())
572 for (
auto& widget : mWidgetChild)
574 if (widget == _widget)
576 else if (widget->getDepth() == -1)
582 Widget* Widget::findWidget(std::string_view _name)
586 if (mWidgetClient !=
nullptr)
587 return mWidgetClient->findWidget(_name);
589 for (
const auto& widget : mWidgetChild)
591 Widget* find = widget->findWidget(_name);
598 void Widget::setRealPosition(
const FloatPoint& _point)
601 mCroppedParent ==
nullptr ? RenderManager::getInstance().getViewSize() : mCroppedParent->getSize();
602 setPosition(CoordConverter::convertFromRelative(_point, parentSize));
605 void Widget::setRealSize(
const FloatSize& _size)
608 mCroppedParent ==
nullptr ? RenderManager::getInstance().getViewSize() : mCroppedParent->getSize();
609 setSize(CoordConverter::convertFromRelative(_size, parentSize));
612 void Widget::setRealCoord(
const FloatCoord& _coord)
615 mCroppedParent ==
nullptr ? RenderManager::getInstance().getViewSize() : mCroppedParent->getSize();
616 setCoord(CoordConverter::convertFromRelative(_coord, parentSize));
619 void Widget::_setAlign(
const IntSize& _oldsize,
const IntSize& _newSize)
621 auto [coord, resize, move] = CoordConverter::applyAlign(mAlign, mCoord, _newSize, _oldsize);
626 setPosition(coord.point());
628 setSize(coord.size());
631 if (mCroppedParent !=
nullptr && mAbsolutePosition != mCroppedParent->getAbsolutePosition() + mCoord.point())
637 if (mWorldHasRotation)
638 invalidateRotation();
643 void Widget::setPosition(
const IntPoint& _point)
645 if (mCoord.point() == _point)
652 eventChangeCoord(
this);
655 void Widget::setSize(
const IntSize& _size)
657 if (mCoord.size() == _size)
659 Widget::setCoord(
IntCoord(mCoord.point(), _size));
662 void Widget::setCoord(
const IntCoord& _coord)
664 if (mCoord == _coord)
672 eventChangeCoord(
this);
675 void Widget::_updateCoord(
const IntSize& _oldSize)
679 bool margin = mCroppedParent ? _checkMargin() : false;
683 if (_checkOutsideUnrotated())
689 _setSubSkinVisible(visible);
691 _updateGeometry(&_oldSize);
693 _setSkinItemAlign(_oldSize);
699 void Widget::setAlign(Align _value)
704 void Widget::setRotation(
float _radians)
706 if (mRotation == _radians)
708 const bool rotationPresenceChanged = (mRotation == 0.0f) != (_radians == 0.0f);
709 mRotation = _radians;
710 if (rotationPresenceChanged)
711 updateWorldHasRotation();
712 mRotationTransform.cosine = std::cos(_radians);
713 mRotationTransform.sine = std::sin(_radians);
714 invalidateRotation();
717 float Widget::getRotation()
const
722 void Widget::setRotationCenter(
const FloatPoint& _center)
724 if (mCustomRotationCenter && mRotationCenter == _center)
726 mRotationCenter = _center;
727 mCustomRotationCenter =
true;
728 invalidateRotation();
733 return mCustomRotationCenter ? mRotationCenter :
FloatPoint(mCoord.width * 0.5f, mCoord.height * 0.5f);
739 cosine * _point.left - sine * _point.top + offsetX,
740 sine * _point.left + cosine * _point.top + offsetY);
745 const float x = _point.
left - offsetX;
746 const float y = _point.top - offsetY;
747 return FloatPoint(cosine * x + sine * y, cosine * y - sine * x);
750 void Widget::updateRotationTransform()
753 mRotationTransform.offsetX = (float)mCoord.left;
754 mRotationTransform.offsetY = (float)mCoord.top;
755 if (mRotation == 0.0f)
757 const FloatPoint center = getRotationCenter();
758 mRotationTransform.offsetX +=
759 center.left - mRotationTransform.cosine * center.left + mRotationTransform.sine * center.top;
760 mRotationTransform.offsetY +=
761 center.top - mRotationTransform.sine * center.left - mRotationTransform.cosine * center.top;
764 void Widget::updateWorldHasRotation()
766 const bool hasRotation = mRotation != 0.0f || (mParent && mParent->mWorldHasRotation);
767 if (mWorldHasRotation == hasRotation)
769 mWorldHasRotation = hasRotation;
770 for (
auto* widget : mWidgetChild)
771 widget->updateWorldHasRotation();
772 for (
auto* widget : mWidgetChildSkin)
773 widget->updateWorldHasRotation();
776 Widget::RotationTransform Widget::getWorldRotationTransform()
const
778 if (mParent ==
nullptr)
779 return mRotationTransform;
780 const RotationTransform parent = mParent->getWorldRotationTransform();
781 FloatPoint offset(mRotationTransform.offsetX, mRotationTransform.offsetY);
784 offset -=
FloatPoint((
float)mParent->getAbsoluteLeft(), (
float)mParent->getAbsoluteTop());
785 offset = parent.transformPoint(offset);
786 RotationTransform result;
787 result.cosine = parent.cosine * mRotationTransform.cosine - parent.sine * mRotationTransform.sine;
788 result.sine = parent.sine * mRotationTransform.cosine + parent.cosine * mRotationTransform.sine;
789 result.offsetX = offset.left;
790 result.offsetY = offset.top;
796 return getWorldRotationTransform().transformPoint(_point);
799 void Widget::localToLayer(
FloatPoint* _points,
size_t _count)
const
801 const RotationTransform transform = getWorldRotationTransform();
802 for (
size_t i = 0; i < _count; ++i)
803 _points[i] = transform.transformPoint(_points[i]);
808 return getWorldRotationTransform().inverseTransformPoint(_point);
813 if (!mWorldHasRotation)
815 const RotationTransform transform = getWorldRotationTransform();
816 return transform.transformPoint(
817 _point -
FloatPoint((
float)mAbsolutePosition.left, (
float)mAbsolutePosition.top));
822 if (!mWorldHasRotation)
824 const RotationTransform transform = getWorldRotationTransform();
825 return transform.inverseTransformPoint(_point) +
826 FloatPoint((
float)mAbsolutePosition.left, (
float)mAbsolutePosition.top);
831 const RotationTransform transform = getWorldRotationTransform();
833 (
int)std::lround(transform.cosine * _vector.left + transform.sine * _vector.top),
834 (
int)std::lround(transform.cosine * _vector.top - transform.sine * _vector.left));
837 void Widget::_transformVertices(
Vertex* _vertices,
size_t _count,
const RenderTargetInfo& _info)
const
839 if (!mWorldHasRotation)
841 const RotationTransform transform = getWorldRotationTransform();
843 for (
size_t i = 0; i < _count; ++i)
845 Vertex& vertex = _vertices[i];
848 vertex.x = transformed.left;
849 vertex.y = transformed.top;
853 bool Widget::_hasRotation()
const
855 return mWorldHasRotation;
858 void Widget::invalidateRotation()
860 updateRotationTransform();
862 for (
auto* widget : mWidgetChild)
863 widget->invalidateRotation();
864 for (
auto* widget : mWidgetChildSkin)
865 widget->invalidateRotation();
868 void Widget::detachFromWidget(std::string_view _layer)
870 const bool hadRotation = mWorldHasRotation;
871 _detachFromWidget(_layer);
877 if (hadRotation != mWorldHasRotation)
878 invalidateRotation();
883 void Widget::_detachFromWidget(std::string_view _layer)
885 std::string_view oldlayer;
887 oldlayer = getLayer()->getName();
889 if (mParent !=
nullptr)
894 detachFromLayerItemNode(
true);
896 if (mWidgetStyle == WidgetStyle::Child)
898 mParent->removeChildItem(
this);
900 else if (mWidgetStyle == WidgetStyle::Overlapped)
902 mParent->removeChildNode(
this);
905 mWidgetStyle = WidgetStyle::Overlapped;
907 mCroppedParent =
nullptr;
913 Gui::getInstance()._linkChildWidget(
this);
914 mParent->_unlinkChildWidget(
this);
916 updateWorldHasRotation();
921 LayerManager::getInstance().attachToLayerNode(_layer,
this);
923 else if (!oldlayer.empty())
925 LayerManager::getInstance().attachToLayerNode(oldlayer,
this);
929 void Widget::attachToWidget(Widget* _parent, WidgetStyle _style, std::string_view _layer)
932 MYGUI_ASSERT(_parent !=
this,
"cyclic attach (attaching to self)");
935 if (_parent->getClientWidget())
936 _parent = _parent->getClientWidget();
938 Widget* parent = _parent;
939 while (parent->getParent())
942 parent = parent->getParent();
945 const bool hadRotation = mWorldHasRotation;
946 _detachFromWidget({});
948 mWidgetStyle = _style;
950 if (_style == WidgetStyle::Popup)
952 if (mParent ==
nullptr)
953 Gui::getInstance()._unlinkChildWidget(
this);
955 mParent->_unlinkChildWidget(
this);
958 updateWorldHasRotation();
959 mParent->_linkChildWidget(
this);
961 mCroppedParent =
nullptr;
965 LayerManager::getInstance().attachToLayerNode(_layer,
this);
968 else if (_style == WidgetStyle::Child)
970 LayerManager::getInstance().detachFromLayer(
this);
972 if (mParent ==
nullptr)
973 Gui::getInstance()._unlinkChildWidget(
this);
975 mParent->_unlinkChildWidget(
this);
978 updateWorldHasRotation();
979 mParent->addChildItem(
this);
980 mParent->_linkChildWidget(
this);
982 mCroppedParent = _parent;
984 else if (_style == WidgetStyle::Overlapped)
986 LayerManager::getInstance().detachFromLayer(
this);
988 if (mParent ==
nullptr)
989 Gui::getInstance()._unlinkChildWidget(
this);
991 mParent->_unlinkChildWidget(
this);
994 updateWorldHasRotation();
995 mParent->_linkChildWidget(
this);
997 mCroppedParent = _parent;
999 mParent->addChildNode(
this);
1007 if (hadRotation != mWorldHasRotation)
1008 invalidateRotation();
1013 void Widget::setWidgetStyle(WidgetStyle _style, std::string_view _layer)
1015 if (_style == mWidgetStyle)
1017 if (
nullptr == getParent())
1020 attachToWidget(mParent, _style, _layer);
1024 Widget* Widget::createWidgetT(
1025 std::string_view _type,
1026 std::string_view _skin,
1029 std::string_view _name)
1031 return baseCreateWidget(WidgetStyle::Child, _type, _skin, _coord, _align, {}, _name,
false);
1034 Widget* Widget::createWidgetT(
1035 std::string_view _type,
1036 std::string_view _skin,
1042 std::string_view _name)
1044 return createWidgetT(_type, _skin,
IntCoord(_left, _top, _width, _height), _align, _name);
1047 Widget* Widget::createWidgetRealT(
1048 std::string_view _type,
1049 std::string_view _skin,
1055 std::string_view _name)
1057 return createWidgetRealT(_type, _skin,
FloatCoord(_left, _top, _width, _height), _align, _name);
1060 Widget* Widget::createWidgetT(
1062 std::string_view _type,
1063 std::string_view _skin,
1066 std::string_view _layer,
1067 std::string_view _name)
1069 return baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name,
false);
1074 if (mWidgetClient !=
nullptr)
1075 return mWidgetClient->getChildWidgets();
1076 return mWidgetChild;
1079 size_t Widget::getChildCount()
const
1081 return getChildWidgets().size();
1084 Widget* Widget::getChildAt(
size_t _index)
const
1086 const auto& widgets = getChildWidgets();
1088 return widgets[_index];
1091 void Widget::baseUpdateEnable()
1093 if (getInheritedEnabled())
1094 _setWidgetState(
"normal");
1096 _setWidgetState(
"disabled");
1099 void Widget::setVisible(
bool _value)
1101 if (mVisible == _value)
1108 void Widget::_updateVisible()
1110 mInheritedVisible = mParent ==
nullptr || mParent->getInheritedVisible();
1111 mInheritedVisible = mVisible && mInheritedVisible;
1113 _setSkinItemVisible(mInheritedVisible);
1115 for (
auto& widget : mWidgetChild)
1116 widget->_updateVisible();
1117 for (
auto& widget : mWidgetChildSkin)
1118 widget->_updateVisible();
1120 if (!mInheritedVisible && InputManager::getInstance().getMouseFocusWidget() ==
this)
1121 InputManager::getInstance()._resetMouseFocusWidget();
1122 if (!mInheritedVisible && InputManager::getInstance().getKeyFocusWidget() ==
this)
1123 InputManager::getInstance().resetKeyFocusWidget();
1126 void Widget::setEnabled(
bool _value)
1128 if (mEnabled == _value)
1135 void Widget::_updateEnabled()
1137 mInheritedEnabled = mParent ==
nullptr || (mParent->getInheritedEnabled());
1138 mInheritedEnabled = mInheritedEnabled && mEnabled;
1140 for (
auto& iter : mWidgetChild)
1141 iter->_updateEnabled();
1142 for (
auto& iter : mWidgetChildSkin)
1143 iter->_updateEnabled();
1147 if (!mInheritedEnabled)
1148 InputManager::getInstance().unlinkWidget(
this);
1151 void Widget::setColour(
const Colour& _value)
1153 _setSkinItemColour(_value);
1155 for (
auto& widget : mWidgetChildSkin)
1156 widget->setColour(_value);
1159 IntSize Widget::getParentSize()
const
1162 return static_cast<Widget*
>(mCroppedParent)->getSize();
1164 return getLayer()->getSize();
1166 return RenderManager::getInstance().getViewSize();
1169 void Widget::_resetContainer(
bool _updateOnly)
1171 if (getNeedToolTip())
1172 ToolTipManager::getInstance()._unlinkWidget(
this);
1175 bool Widget::_checkPoint(
int _left,
int _top)
const
1178 return _getViewLeft() <= _left && _getViewTop() <= _top && _left < _getViewRight() && _top < _getViewBottom();
1181 void Widget::_linkChildWidget(Widget* _widget)
1183 WidgetContainer::_linkChildWidget(_widget);
1184 _updateChilds(
false);
1187 void Widget::shutdownOverride()
1191 void Widget::initialiseOverride()
1194 assignWidget(mWidgetClient,
"Client");
1197 void Widget::setSkinProperty(ResourceSkin* _info)
1199 const MapString& properties = _info->getProperties();
1200 for (
const auto& property : properties)
1201 setProperty(property.first, property.second);
1204 void Widget::setProperty(std::string_view _key, std::string_view _value)
1206 std::string key{_key};
1207 std::string value{_value};
1209 if (BackwardCompatibility::processDeprecatedProperty(
this, key, value))
1210 setPropertyOverride(key, value);
1213 VectorWidgetPtr Widget::getSkinWidgetsByName(std::string_view _name)
const
1217 for (
const auto& childSkin : mWidgetChildSkin)
1218 childSkin->findWidgets(_name, result);
1223 void Widget::findWidgets(std::string_view _name,
VectorWidgetPtr& _result)
1228 if (mWidgetClient !=
nullptr)
1230 mWidgetClient->findWidgets(_name, _result);
1234 for (
const auto& widget : mWidgetChild)
1235 widget->findWidgets(_name, _result);
1239 void Widget::onWidgetCreated(Widget* _widget)
1243 void Widget::onWidgetDestroy(Widget* _widget)
1247 void Widget::setWidgetClient(Widget* _widget)
1249 MYGUI_ASSERT(mWidgetClient !=
this,
"mWidgetClient can not be this widget");
1250 mWidgetClient = _widget;
1253 Widget* Widget::_getClientWidget()
1255 return getClientWidget() ==
nullptr ? this : getClientWidget();
1258 const Widget* Widget::_getClientWidget()
const
1260 return getClientWidget() ==
nullptr ? this : getClientWidget();
1263 Widget* Widget::_createSkinWidget(
1265 std::string_view _type,
1266 std::string_view _skin,
1269 std::string_view _layer,
1270 std::string_view _name)
1272 return baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name,
true);
1275 void Widget::setPropertyOverride(std::string_view _key, std::string_view _value)
1278 if (_key ==
"Rotation")
1281 else if (_key ==
"RotationCenter")
1284 else if (_key ==
"Position")
1288 else if (_key ==
"Size")
1292 else if (_key ==
"Coord")
1296 else if (_key ==
"Visible")
1300 else if (_key ==
"Depth")
1304 else if (_key ==
"Alpha")
1308 else if (_key ==
"Colour")
1312 else if (_key ==
"InheritsAlpha")
1316 else if (_key ==
"InheritsPick")
1320 else if (_key ==
"MaskPick")
1321 setMaskPick(std::string{_value});
1324 else if (_key ==
"NeedKey")
1328 else if (_key ==
"NeedMouse")
1332 else if (_key ==
"Enabled")
1336 else if (_key ==
"NeedToolTip")
1340 else if (_key ==
"Pointer")
1347 "Widget '" << getName() <<
"|" << getTypeName() <<
"' have unknown property '" << _key <<
"' "
1348 <<
" [" << LayoutManager::getInstance().getCurrentLayout() <<
"]");
1352 eventChangeProperty(
this, _key, _value);
1355 void Widget::setPosition(
int _left,
int _top)
1357 setPosition(
IntPoint(_left, _top));
1360 void Widget::setSize(
int _width,
int _height)
1362 setSize(
IntSize(_width, _height));
1365 void Widget::setCoord(
int _left,
int _top,
int _width,
int _height)
1367 setCoord(
IntCoord(_left, _top, _width, _height));
1370 void Widget::setRealPosition(
float _left,
float _top)
1375 void Widget::setRealSize(
float _width,
float _height)
1377 setRealSize(
FloatSize(_width, _height));
1380 void Widget::setRealCoord(
float _left,
float _top,
float _width,
float _height)
1382 setRealCoord(
FloatCoord(_left, _top, _width, _height));
1385 const std::string& Widget::getName()
const
1390 bool Widget::getVisible()
const
1395 Align Widget::getAlign()
const
1400 float Widget::getAlpha()
const
1405 bool Widget::getInheritsAlpha()
const
1407 return mInheritsAlpha;
1410 bool Widget::isRootWidget()
const
1412 return nullptr == mCroppedParent;
1415 Widget* Widget::getParent()
const
1420 void Widget::setEnabledSilent(
bool _value)
1425 bool Widget::getEnabled()
const
1430 Widget* Widget::getClientWidget()
1432 return mWidgetClient;
1435 const Widget* Widget::getClientWidget()
const
1437 return mWidgetClient;
1440 WidgetStyle Widget::getWidgetStyle()
const
1442 return mWidgetStyle;
1445 size_t Widget::_getItemIndex(Widget* _item)
const
1450 void Widget::_setContainer(Widget* _value)
1452 mContainer = _value;
1455 Widget* Widget::_getContainer()
const
1460 size_t Widget::_getContainerIndex(
const IntPoint& _point)
const
1465 const IntCoord& Widget::getLayerItemCoord()
const
1470 float Widget::_getRealAlpha()
const
1475 bool Widget::getInheritedEnabled()
const
1477 return mInheritedEnabled;
1480 bool Widget::getInheritedVisible()
const
1482 return mInheritedVisible;
1485 void Widget::resizeLayerItemView(
const IntSize& _oldView,
const IntSize& _newView)
1487 _setAlign(_oldView, _newView);
1490 void Widget::setDepth(
int _value)
1492 if (mDepth == _value)
1497 if (mParent !=
nullptr)
1500 mParent->_unlinkChildWidget(
this);
1501 mParent->_linkChildWidget(
this);
1502 mParent->_updateChilds(
false);
1506 int Widget::getDepth()
const
1511 void Widget::_updateChilds(
bool _fullSort)
1516 mWidgetChild.begin(),
1518 [](Widget* lhs, Widget* rhs) { return lhs->getDepth() > rhs->getDepth(); });
1520 else if (!mWidgetChild.empty())
1523 size_t index = mWidgetChild.size() - 1;
1524 while (index > 0 && mWidgetChild[index]->getDepth() > mWidgetChild[index - 1]->getDepth())
1526 std::swap(mWidgetChild[index], mWidgetChild[index - 1]);
1531 for (
auto& widget : mWidgetChild)
1533 if (widget->getWidgetStyle() == WidgetStyle::Child)
1535 widget->detachFromLayerItemNode(
false);
1536 removeChildItem(widget);
1540 for (
auto& widget : mWidgetChild)
1542 if (widget->getWidgetStyle() == WidgetStyle::Child)
1544 addChildItem(widget);
1545 widget->_updateView();
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_LOG(level, text)
void const IntCoord IntCoord & _result
FloatPoint fromRenderTarget(FloatPoint _point, const RenderTargetInfo &_info, IntPoint _origin={})
FloatPoint toRenderTarget(FloatPoint _point, const RenderTargetInfo &_info, IntPoint _origin={})
T parseValue(std::string_view value)
constexpr float ALPHA_MAX
types::TPoint< int > IntPoint
types::TCoord< float > FloatCoord
std::map< std::string, std::string, std::less<> > MapString
std::vector< WidgetInfo > VectorWidgetInfo
types::TPoint< float > FloatPoint
constexpr size_t ITEM_NONE
types::TSize< float > FloatSize
types::TCoord< int > IntCoord
types::TSize< int > IntSize
std::vector< Widget * > VectorWidgetPtr
std::vector< ChildSkinInfo > VectorChildSkinInfo