29 mHideByLostKey(false),
30 mResizeToContent(true),
32 mVerticalAlignment(true),
36 mAnimateSmooth(false),
37 mChangeChildSkin(false),
38 mInternalCreateChild(false)
44 Base::initialiseOverride();
69 mItemPopupSkin = mItemNormalSkin;
82 mDistanceButton = utility::parseValue<int>(
getUserString(
"DistanceButton"));
98 if (mOwner !=
nullptr)
101 Base::shutdownOverride();
106 Base::onWidgetCreated(_widget);
109 if (child !=
nullptr && !mInternalCreateChild)
118 if (_index ==
ITEM_NONE) _index = mItemsInfo.size();
120 mInternalCreateChild =
true;
122 mInternalCreateChild =
false;
123 _wrapItem(item, _index, _name, _type, _id, _data);
132 if (mItemsInfo[_index].submenu)
135 mItemsInfo[_index].submenu =
nullptr;
142 while (!mItemsInfo.empty())
144 if (mItemsInfo.back().submenu)
147 mItemsInfo.back().submenu =
nullptr;
156 return mItemsInfo[_index].name;
159 void MenuControl::update()
163 if (mVerticalAlignment)
165 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
167 IntSize contentSize = iter->item->_getContentSize();
174 if (!mItemsInfo.empty())
175 size.
height -= mDistanceButton;
180 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
182 IntSize contentSize = iter->item->_getContentSize();
183 if (maxHeight < contentSize.height)
184 maxHeight = contentSize.
height;
187 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
189 IntSize contentSize = iter->item->_getContentSize();
190 iter->item->setCoord(size.
width, 0, contentSize.width, maxHeight);
191 size.
width += contentSize.width + mDistanceButton;
194 if (!mItemsInfo.empty())
195 size.
width -= mDistanceButton;
205 mItemsInfo[_index].data = _data;
211 return mItemsInfo[_index].submenu;
218 if (mItemsInfo[_index].submenu !=
nullptr)
221 mItemsInfo[_index].submenu =
nullptr;
231 mItemsInfo[_index].name = _name;
232 MenuItem* item = mItemsInfo[_index].item;
241 mItemsInfo[_index].id = _id;
247 return mItemsInfo[_index].id;
253 if (mChangeChildSkin)
261 mItemsInfo.erase(mItemsInfo.begin() + index);
268 mItemsInfo[index].submenu =
nullptr;
284 return mItemsInfo[_index].type;
290 ItemInfo& info = mItemsInfo[_index];
291 if (info.
type == _type)
298 mChangeChildSkin =
true;
300 mChangeChildSkin =
false;
308 void MenuControl::notifyMenuCtrlAccept(
MenuItem* _item)
322 MenuControl* parent_ctrl = parent_item->getMenuCtrlParent();
325 parent_ctrl->notifyMenuCtrlAccept(_item);
334 _setItemChildVisibleAt(_index, _visible,
true);
337 void MenuControl::_setItemChildVisibleAt(
size_t _index,
bool _visible,
bool _smooth)
343 if (mItemsInfo[_index].submenu && mItemsInfo[_index].submenu->getItemCount())
345 int offset = mItemsInfo[0].item->getAbsoluteTop() -
getAbsoluteTop();
347 const IntCoord& coord = mItemsInfo[_index].item->getAbsoluteCoord();
352 if (mVerticalAlignment)
391 if (mItemsInfo[_index].submenu)
394 mItemsInfo[_index].submenu->setVisibleSmooth(
false);
396 mItemsInfo[_index].submenu->setVisible(
false);
401 void MenuControl::notifyRootKeyChangeFocus(Widget* _sender,
bool _focus)
const
403 MenuItem* item = _sender->castType<MenuItem>();
410 item->setItemChildVisible(
true);
411 item->setStateSelected(
true);
416 item->setItemChildVisible(
false);
417 item->setStateSelected(
false);
422 Widget* MenuControl::createItemChildByType(
size_t _index,
const std::string& _type)
431 void MenuControl::notifyMouseButtonClick(Widget* _sender)
433 MenuItem* item = _sender->castType<MenuItem>();
440 item->setStateSelected(
false);
441 item->setItemChildVisible(
false);
450 item->setStateSelected(
true);
451 item->setItemChildVisible(
true);
461 notifyMenuCtrlAccept(item);
477 Base::onKeyChangeRootFocus(_focus);
480 void MenuControl::notifyMouseSetFocus(
Widget* _sender,
Widget* _new)
489 if (mItemsInfo[index].submenu !=
nullptr)
492 mItemsInfo[index].submenu =
nullptr;
494 mItemsInfo[index].submenu = _widget;
496 mItemsInfo[index].submenu->setVisible(
false);
512 ItemInfo info = ItemInfo(_item, _name, _type, submenu, _id, _data);
514 mItemsInfo.insert(mItemsInfo.begin() + _index, info);
516 mChangeChildSkin =
true;
518 mChangeChildSkin =
false;
533 mAnimateSmooth =
false;
544 Base::setVisible(_visible);
549 mAnimateSmooth =
true;
558 Base::setVisible(
true);
575 ControllerFadeAlpha* MenuControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
605 return mItemsInfo[_index].item;
610 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
612 if (mItemsInfo[pos].item == _item)
615 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'MenuControl::getItemIndex'");
620 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
622 if (mItemsInfo[pos].name == _name)
623 return mItemsInfo[pos].item;
630 for (
size_t index = 0; index < mItemsInfo.size(); index++)
632 if (mItemsInfo[index].
id == _id)
633 return mItemsInfo[index].item;
635 MYGUI_EXCEPT(
"item id (" << _id <<
") not found, source 'MenuControl::getItemById'");
640 for (
size_t index = 0; index < mItemsInfo.size(); index++)
642 if (mItemsInfo[index].
id == _id)
645 MYGUI_EXCEPT(
"item id (" << _id <<
") not found, source 'MenuControl::getItemById'");
650 for (
size_t index = 0; index < mItemsInfo.size(); index++)
652 if (mItemsInfo[index].
id == _id)
653 return mItemsInfo[index].item;
655 if (_recursive && mItemsInfo[index].submenu !=
nullptr)
657 MenuItem* find = mItemsInfo[index].submenu->findItemById(_id, _recursive);
667 for (
size_t index = 0; index < mItemsInfo.size(); index++)
669 if (mItemsInfo[index].name == _name)
677 for (
size_t index = 0; index < mItemsInfo.size(); index++)
679 if (mItemsInfo[index].item == _item)
687 return mItemsInfo.size();
737 return createItemChildTAt<MenuControl>(_index);
762 mPopupAccept = _value;
775 const std::string& MenuControl::getSkinByType(
MenuItemType _type)
const
778 return mItemPopupSkin;
780 return mItemSeparatorSkin;
781 return mItemNormalSkin;
784 std::string MenuControl::getIconIndexByType(MenuItemType _type)
const
835 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
841 if ((*iter).submenu !=
nullptr)
842 (*iter).submenu->setVisible(
false);
851 _setItemChildVisibleAt(index,
true,
false);
859 if (mItemsInfo[_index].submenu !=
nullptr)
860 mItemsInfo[_index].submenu->_updateSizeForEmpty();
865 if (mItemsInfo.empty())
871 mVerticalAlignment = _value;
878 return mVerticalAlignment;
884 if (_key ==
"VerticalAlignment")
889 Base::setPropertyOverride(_key, _value);
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_EXCEPT(dest)
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
#define MYGUI_ASSERT_RANGE(index, size, owner)
static const std::string & getClassTypeName()
void setAlpha(float _value)
void setCoef(float _value)
void setEnabled(bool _value)
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
ControllerItem * createItem(const std::string &_type)
static ControllerManager & getInstance()
void removeItem(Widget *_widget)
void addItem(Widget *_widget, ControllerItem *_item)
IntRect getAbsoluteRect() const
int getAbsoluteTop() const
Type * castType(bool _throw=true)
virtual IntSize getTextSize() const
void upLayerItem(Widget *_item)
static LayerManager & getInstance()
ISubWidgetText * getSubWidgetText() const
virtual const UString & getCaption() const
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
bool isUserString(const std::string &_key) const
const std::string & getUserString(const std::string &_key) const
void actionWidgetHide(Widget *_widget, ControllerItem *_controller)
void actionWidgetShow(Widget *_widget, ControllerItem *_controller)
types::TCoord< int > IntCoord
const float POPUP_MENU_SPEED_COEF
types::TSize< int > IntSize
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))