MyGUI: MyGUI_MenuControl.cpp Source File

MyGUI 3.4.3

MyGUI_MenuControl.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_MenuControl.h"
9#include "MyGUI_ResourceSkin.h"
10#include "MyGUI_MenuItem.h"
11#include "MyGUI_ImageBox.h"
12#include "MyGUI_MenuBar.h"
13#include "MyGUI_WidgetManager.h"
14#include "MyGUI_LayerManager.h"
15#include "MyGUI_ControllerManager.h"
16#include "MyGUI_InputManager.h"
17#include "MyGUI_Gui.h"
18#include "MyGUI_RenderManager.h"
19
20namespace MyGUI
21{
22
23 const float POPUP_MENU_SPEED_COEF = 3.0f;
24
25 void MenuControl::initialiseOverride()
26 {
27 Base::initialiseOverride();
28
29 // инициализируем овнера
30 Widget* parent = getParent();
31 if (parent)
32 {
33 mOwner = parent->castType<MenuItem>(false);
34 if (!mOwner)
35 {
36 Widget* client = parent;
37 parent = client->getParent();
38 if (parent && parent->getClientWidget())
39 {
40 mOwner = parent->castType<MenuItem>(false);
41 }
42 }
43 }
44
45 // FIXME нам нужен фокус клавы
46 setNeedKeyFocus(true);
47
48 //OBSOLETE
49 if (isUserString("SkinLine"))
50 {
51 mItemNormalSkin = getUserString("SkinLine");
52 mItemPopupSkin = mItemNormalSkin;
53 }
54
55 if (isUserString("SeparatorSkin"))
56 mItemSeparatorSkin = getUserString("SeparatorSkin");
57
58 if (isUserString("NormalSkin"))
59 mItemNormalSkin = getUserString("NormalSkin");
60
61 if (isUserString("PopupSkin"))
62 mItemPopupSkin = getUserString("PopupSkin");
63
64 if (isUserString("DistanceButton"))
65 mDistanceButton = utility::parseValue<int>(getUserString("DistanceButton"));
66
67 if (isUserString("SubMenuSkin"))
68 mSubMenuSkin = getUserString("SubMenuSkin");
69
70 if (isUserString("SubMenuLayer"))
71 mSubMenuLayer = getUserString("SubMenuLayer");
72
73 // FIXME добавленно, так как шетдаун вызывается и при смене скина
74 mShutdown = false;
75 }
76
77 void MenuControl::shutdownOverride()
78 {
79 mShutdown = true;
80
81 if (mOwner != nullptr)
82 mOwner->getMenuCtrlParent()->_notifyDeletePopup(mOwner);
83
84 Base::shutdownOverride();
85 }
86
87 void MenuControl::onWidgetCreated(Widget* _widget)
88 {
89 Base::onWidgetCreated(_widget);
90
91 MenuItem* child = _widget->castType<MenuItem>(false);
92 if (child != nullptr && !mInternalCreateChild)
93 {
94 _wrapItem(child, mItemsInfo.size(), UString(), MenuItemType::Normal, std::string_view{}, Any::Null);
95 }
96 }
97
98 MenuItem* MenuControl::insertItemAt(
99 size_t _index,
100 const UString& _name,
101 MenuItemType _type,
102 std::string_view _id,
103 Any _data)
104 {
105 MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "MenuControl::insertItemAt");
106 if (_index == ITEM_NONE)
107 _index = mItemsInfo.size();
108
109 mInternalCreateChild = true;
110 MenuItem* item = _getClientWidget()->createWidget<MenuItem>(getSkinByType(_type), IntCoord(), Align::Default);
111 mInternalCreateChild = false;
112 _wrapItem(item, _index, _name, _type, _id, _data);
113
114 return item;
115 }
116
117 void MenuControl::removeItemAt(size_t _index)
118 {
119 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::removeItemAt");
120
121 if (mItemsInfo[_index].submenu)
122 {
123 WidgetManager::getInstance().destroyWidget(mItemsInfo[_index].submenu);
124 mItemsInfo[_index].submenu = nullptr;
125 }
126 WidgetManager::getInstance().destroyWidget(mItemsInfo[_index].item);
127 }
128
129 void MenuControl::removeAllItems()
130 {
131 while (!mItemsInfo.empty())
132 {
133 if (mItemsInfo.back().submenu)
134 {
135 WidgetManager::getInstance().destroyWidget(mItemsInfo.back().submenu);
136 mItemsInfo.back().submenu = nullptr;
137 }
138 WidgetManager::getInstance().destroyWidget(mItemsInfo.back().item);
139 }
140 }
141
142 const UString& MenuControl::getItemNameAt(size_t _index) const
143 {
144 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemNameAt");
145 return mItemsInfo[_index].name;
146 }
147
148 void MenuControl::update()
149 {
150 IntSize size;
151
152 if (mVerticalAlignment)
153 {
154 for (auto& iter : mItemsInfo)
155 {
156 IntSize contentSize = iter.item->_getContentSize();
157 iter.item->setCoord(0, size.height, _getClientWidget()->getWidth(), contentSize.height);
158 size.height += contentSize.height + mDistanceButton;
159
160 if (contentSize.width > size.width)
161 size.width = contentSize.width;
162 }
163 if (!mItemsInfo.empty())
164 size.height -= mDistanceButton;
165 }
166 else
167 {
168 int maxHeight = 0;
169 for (const auto& iter : mItemsInfo)
170 {
171 IntSize contentSize = iter.item->_getContentSize();
172 if (maxHeight < contentSize.height)
173 maxHeight = contentSize.height;
174 }
175
176 for (auto& iter : mItemsInfo)
177 {
178 IntSize contentSize = iter.item->_getContentSize();
179 iter.item->setCoord(size.width, 0, contentSize.width, maxHeight);
180 size.width += contentSize.width + mDistanceButton;
181 }
182
183 if (!mItemsInfo.empty())
184 size.width -= mDistanceButton;
185 }
186
187 if (mResizeToContent)
188 setSize(size + mCoord.size() - _getClientWidget()->getSize());
189 }
190
191 void MenuControl::setItemDataAt(size_t _index, Any _data)
192 {
193 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::setItemDataAt");
194 mItemsInfo[_index].data = std::move(_data);
195 }
196
197 MenuControl* MenuControl::getItemChildAt(size_t _index) const
198 {
199 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemChildAt");
200 return mItemsInfo[_index].submenu;
201 }
202
203 void MenuControl::removeItemChildAt(size_t _index)
204 {
205 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::removeItemChildAt");
206
207 if (mItemsInfo[_index].submenu != nullptr)
208 {
209 WidgetManager::getInstance().destroyWidget(mItemsInfo[_index].submenu);
210 mItemsInfo[_index].submenu = nullptr;
211 }
212
213 update();
214 }
215
216 void MenuControl::setItemNameAt(size_t _index, const UString& _name)
217 {
218 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::setItemNameAt");
219
220 mItemsInfo[_index].name = _name;
221 MenuItem* item = mItemsInfo[_index].item;
222 item->setCaption(_name);
223
224 update();
225 }
226
227 void MenuControl::setItemIdAt(size_t _index, std::string_view _id)
228 {
229 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::setItemIdAt");
230 mItemsInfo[_index].id = _id;
231 }
232
233 const std::string& MenuControl::getItemIdAt(size_t _index) const
234 {
235 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemIdAt");
236 return mItemsInfo[_index].id;
237 }
238
239 void MenuControl::_notifyDeleteItem(MenuItem* _item)
240 {
241 // дитю меняем скин
242 if (mChangeChildSkin)
243 return;
244
245 // общий шутдаун виджета
246 if (mShutdown)
247 return;
248
249 size_t index = getItemIndex(_item);
250 mItemsInfo.erase(mItemsInfo.begin() + index);
251 update();
252 }
253
254 void MenuControl::_notifyDeletePopup(MenuItem* _item)
255 {
256 size_t index = getItemIndex(_item);
257 mItemsInfo[index].submenu = nullptr;
258 }
259
260 void MenuControl::_notifyUpdateName(MenuItem* _item)
261 {
262 size_t index = getItemIndex(_item);
263 mItemsInfo[index].name = _item->getCaption();
264
265 ISubWidgetText* text = _item->getSubWidgetText();
266 mItemsInfo[index].width = text ? (text->getTextSize().width + _item->getSize().width - text->getWidth()) : 0;
267 update();
268 }
269
270 MenuItemType MenuControl::getItemTypeAt(size_t _index) const
271 {
272 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemTypeAt");
273 return mItemsInfo[_index].type;
274 }
275
276 void MenuControl::setItemTypeAt(size_t _index, MenuItemType _type)
277 {
278 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::setItemTypeAt");
279 ItemInfo& info = mItemsInfo[_index];
280 if (info.type == _type)
281 return;
282
283 // сохраняем данные
284 info.type = _type;
285
286 // при смене скина дите отпишется
287 mChangeChildSkin = true;
288 info.item->changeWidgetSkin(getSkinByType(_type));
289 mChangeChildSkin = false;
290
291 info.item->setImageName(getIconIndexByType(_type));
292 info.item->setCaption(info.name);
293
294 update();
295 }
296
297 void MenuControl::notifyMenuCtrlAccept(MenuItem* _item)
298 {
299 if (mHideByAccept)
300 {
301 setVisibleSmooth(false);
302 }
303 else
304 {
305 InputManager::getInstance().setKeyFocusWidget(nullptr);
306 }
307
308 MenuItem* parent_item = getMenuItemParent();
309 if (parent_item)
310 {
311 MenuControl* parent_ctrl = parent_item->getMenuCtrlParent();
312 if (parent_ctrl)
313 {
314 parent_ctrl->notifyMenuCtrlAccept(_item);
315 }
316 }
317
318 eventMenuCtrlAccept(this, _item);
319 }
320
321 void MenuControl::setItemChildVisibleAt(size_t _index, bool _visible)
322 {
323 _setItemChildVisibleAt(_index, _visible, true);
324 }
325
326 void MenuControl::_setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth)
327 {
328 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::setItemChildVisibleAt");
329
330 if (_visible)
331 {
332 if (mItemsInfo[_index].submenu && mItemsInfo[_index].submenu->getItemCount())
333 {
334 int offset = mItemsInfo[0].item->getAbsoluteTop() - getAbsoluteTop();
335
336 const IntCoord& coord = mItemsInfo[_index].item->getAbsoluteCoord();
337 IntPoint point(getAbsoluteRect().right, coord.top - offset);
338
339 MenuControl* menu = mItemsInfo[_index].submenu;
340
341 if (mVerticalAlignment)
342 {
343 // too wide
344 if (point.left + menu->getWidth() > menu->getParentSize().width)
345 {
346 // move to the left side if possible
347 if (point.left - menu->getWidth() - getWidth() > 0)
348 point.left -= menu->getWidth() + getWidth();
349 // or put near right parent border (window) if too wide for left side too
350 else
351 point.left = menu->getParentSize().width - menu->getWidth();
352 }
353 // too high (same logic as for too wide)
354 if (point.top + menu->getHeight() > menu->getParentSize().height)
355 {
356 // move to the top side if possible
357 if (point.top - menu->getHeight() - getHeight() > 0)
358 point.top -= menu->getHeight() + getHeight();
359 // or put near bottom parent border (window) if too high for top side too
360 else
361 point.top = menu->getParentSize().height - menu->getHeight();
362 }
363 }
364 else
365 {
366 point.set(coord.left, getAbsoluteRect().bottom);
367 }
368
369 menu->setPosition(point);
370 if (_smooth)
371 menu->setVisibleSmooth(true);
372 else
373 menu->setVisible(true);
374
375 MyGUI::LayerManager::getInstance().upLayerItem(menu);
376 }
377 }
378 else
379 {
380 if (mItemsInfo[_index].submenu)
381 {
382 if (_smooth)
383 mItemsInfo[_index].submenu->setVisibleSmooth(false);
384 else
385 mItemsInfo[_index].submenu->setVisible(false);
386 }
387 }
388 }
389
390 void MenuControl::notifyRootKeyChangeFocus(Widget* _sender, bool _focus) const
391 {
392 MenuItem* item = _sender->castType<MenuItem>();
393 if (item->getItemType() == MenuItemType::Popup)
394 {
395 if (_focus)
396 {
397 if (!mMenuDropMode || mIsMenuDrop)
398 {
399 item->setItemChildVisible(true);
400 item->setStateSelected(true);
401 }
402 }
403 else
404 {
405 item->setItemChildVisible(false);
406 item->setStateSelected(false);
407 }
408 }
409 }
410
411 Widget* MenuControl::createItemChildByType(size_t _index, std::string_view _type)
412 {
413 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::createItemChildByType");
414 removeItemChildAt(_index);
415 Widget* child = mItemsInfo[_index].item->createWidgetT(
416 WidgetStyle::Popup,
417 _type,
418 mSubMenuSkin,
419 IntCoord(),
420 Align::Default,
421 mSubMenuLayer);
422 MYGUI_ASSERT(child->isType<MenuControl>(), "child must have MenuControl base type");
423 return child;
424 }
425
426 void MenuControl::notifyMouseButtonClick(Widget* _sender)
427 {
428 MenuItem* item = _sender->castType<MenuItem>();
429 if (mMenuDropMode)
430 {
431 if (mIsMenuDrop)
432 {
433 if (item->getItemType() == MenuItemType::Popup)
434 {
435 item->setStateSelected(false);
436 item->setItemChildVisible(false);
437 mIsMenuDrop = false;
438 }
439 }
440 else
441 {
442 if (item->getItemType() == MenuItemType::Popup)
443 {
444 mIsMenuDrop = true;
445 item->setStateSelected(true);
446 item->setItemChildVisible(true);
447 InputManager::getInstance().setKeyFocusWidget(item);
448 }
449 }
450 }
451 else
452 {
453 if ((item->getItemType() == MenuItemType::Popup && mPopupAccept) ||
454 item->getItemType() == MenuItemType::Normal)
455 {
456 notifyMenuCtrlAccept(item);
457 }
458 }
459 }
460
461 void MenuControl::onKeyChangeRootFocus(bool _focus)
462 {
463 if (mMenuDropMode)
464 {
465 mIsMenuDrop = false;
466 }
467 if (!_focus && mHideByLostKey)
468 {
469 setVisibleSmooth(false);
470 eventMenuCtrlClose(this);
471 }
472 Base::onKeyChangeRootFocus(_focus);
473 }
474
475 void MenuControl::notifyMouseSetFocus(Widget* _sender, Widget* _new)
476 {
477 InputManager::getInstance().setKeyFocusWidget(_sender);
478 }
479
480 void MenuControl::_wrapItemChild(MenuItem* _item, MenuControl* _widget)
481 {
482 // заменяем
483 size_t index = getItemIndex(_item);
484 if (mItemsInfo[index].submenu != nullptr)
485 {
486 WidgetManager::getInstance().destroyWidget(mItemsInfo[index].submenu);
487 mItemsInfo[index].submenu = nullptr;
488 }
489 mItemsInfo[index].submenu = _widget;
490 // скрываем менюшку
491 mItemsInfo[index].submenu->setVisible(false);
492
493 update();
494 }
495
496 void MenuControl::_wrapItem(
497 MenuItem* _item,
498 size_t _index,
499 const UString& _name,
500 MenuItemType _type,
501 std::string_view _id,
502 Any _data)
503 {
504 _item->setAlign(mVerticalAlignment ? Align::Top | Align::HStretch : Align::Default);
505 _item->eventRootKeyChangeFocus += newDelegate(this, &MenuControl::notifyRootKeyChangeFocus);
506 _item->eventMouseButtonClick += newDelegate(this, &MenuControl::notifyMouseButtonClick);
507 _item->eventMouseSetFocus += newDelegate(this, &MenuControl::notifyMouseSetFocus);
508
509 _item->setImageName(getIconIndexByType(_type));
510
511 MenuControl* submenu = nullptr;
512
513 ItemInfo info = ItemInfo(_item, _name, _type, submenu, _id, _data);
514
515 mItemsInfo.insert(mItemsInfo.begin() + _index, std::move(info));
516
517 mChangeChildSkin = true;
518 _item->changeWidgetSkin(getSkinByType(_type));
519 mChangeChildSkin = false;
520
521 // его сет капшен, обновит размер
522 _item->setCaption(_name);
523
524 update();
525 }
526
527 void MenuControl::setVisible(bool _visible)
528 {
529 if (mAnimateSmooth)
530 {
531 ControllerManager::getInstance().removeItem(this);
532 setAlpha(ALPHA_MAX);
533 setEnabledSilent(true);
534 mAnimateSmooth = false;
535 }
536
537 if (_visible)
538 {
539 if (mOwner == nullptr && mHideByLostKey)
540 {
541 MyGUI::InputManager::getInstance().setKeyFocusWidget(this);
542 }
543 }
544
545 Base::setVisible(_visible);
546 }
547
548 void MenuControl::setVisibleSmooth(bool _visible)
549 {
550 mAnimateSmooth = true;
551 ControllerManager::getInstance().removeItem(this);
552
553 if (_visible)
554 {
555 setEnabledSilent(true);
556 if (!getVisible())
557 {
558 setAlpha(ALPHA_MIN);
559 Base::setVisible(true);
560 }
561
562 ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MAX, POPUP_MENU_SPEED_COEF, true);
563 controller->eventPostAction += newDelegate(action::actionWidgetShow);
564 ControllerManager::getInstance().addItem(this, controller);
565 }
566 else
567 {
568 setEnabledSilent(false);
569
570 ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MIN, POPUP_MENU_SPEED_COEF, false);
571 controller->eventPostAction += newDelegate(action::actionWidgetHide);
572 ControllerManager::getInstance().addItem(this, controller);
573 }
574 }
575
576 ControllerFadeAlpha* MenuControl::createControllerFadeAlpha(float _alpha, float _coef, bool _enable)
577 {
578 ControllerItem* item = ControllerManager::getInstance().createItem(ControllerFadeAlpha::getClassTypeName());
579 ControllerFadeAlpha* controller = item->castType<ControllerFadeAlpha>();
580
581 controller->setAlpha(_alpha);
582 controller->setCoef(_coef);
583 controller->setEnabled(_enable);
584
585 return controller;
586 }
587
588 MenuItem* MenuControl::insertItem(
589 MenuItem* _to,
590 const UString& _name,
591 MenuItemType _type,
592 std::string_view _id,
593 Any _data)
594 {
595 return insertItemAt(getItemIndex(_to), _name, _type, _id, _data);
596 }
597
598 MenuItem* MenuControl::addItem(const UString& _name, MenuItemType _type, std::string_view _id, Any _data)
599 {
600 return insertItemAt(ITEM_NONE, _name, _type, _id, _data);
601 }
602
603 void MenuControl::removeItem(MenuItem* _item)
604 {
605 removeItemAt(getItemIndex(_item));
606 }
607
608 MenuItem* MenuControl::getItemAt(size_t _index) const
609 {
610 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemAt");
611 return mItemsInfo[_index].item;
612 }
613
614 size_t MenuControl::getItemIndex(const MenuItem* _item) const
615 {
616 for (size_t pos = 0; pos < mItemsInfo.size(); pos++)
617 {
618 if (mItemsInfo[pos].item == _item)
619 return pos;
620 }
621 MYGUI_EXCEPT("item (" << _item << ") not found, source 'MenuControl::getItemIndex'");
622 }
623
624 MenuItem* MenuControl::findItemWith(const UString& _name)
625 {
626 for (const auto& info : mItemsInfo)
627 {
628 if (info.name == _name)
629 return info.item;
630 }
631 return nullptr;
632 }
633
634 MenuItem* MenuControl::getItemById(std::string_view _id) const
635 {
636 for (const auto& info : mItemsInfo)
637 {
638 if (info.id == _id)
639 return info.item;
640 }
641 MYGUI_EXCEPT("item id (" << _id << ") not found, source 'MenuControl::getItemById'");
642 }
643
644 size_t MenuControl::getItemIndexById(std::string_view _id) const
645 {
646 for (size_t index = 0; index < mItemsInfo.size(); index++)
647 {
648 if (mItemsInfo[index].id == _id)
649 return index;
650 }
651 MYGUI_EXCEPT("item id (" << _id << ") not found, source 'MenuControl::getItemById'");
652 }
653
654 MenuItem* MenuControl::findItemById(std::string_view _id, bool _recursive)
655 {
656 for (const auto& info : mItemsInfo)
657 {
658 if (info.id == _id)
659 return info.item;
660
661 if (_recursive && info.submenu != nullptr)
662 {
663 MenuItem* find = info.submenu->findItemById(_id, _recursive);
664 if (find != nullptr)
665 return find;
666 }
667 }
668 return nullptr;
669 }
670
671 size_t MenuControl::findItemIndexWith(const UString& _name)
672 {
673 for (size_t index = 0; index < mItemsInfo.size(); index++)
674 {
675 if (mItemsInfo[index].name == _name)
676 return index;
677 }
678 return ITEM_NONE;
679 }
680
681 size_t MenuControl::findItemIndex(MenuItem* _item)
682 {
683 for (size_t index = 0; index < mItemsInfo.size(); index++)
684 {
685 if (mItemsInfo[index].item == _item)
686 return index;
687 }
688 return ITEM_NONE;
689 }
690
691 size_t MenuControl::getItemCount() const
692 {
693 return mItemsInfo.size();
694 }
695
696 void MenuControl::setItemData(MenuItem* _item, Any _data)
697 {
698 setItemDataAt(getItemIndex(_item), _data);
699 }
700
701 void MenuControl::clearItemDataAt(size_t _index)
702 {
703 setItemDataAt(_index, Any::Null);
704 }
705
706 void MenuControl::clearItemData(MenuItem* _item)
707 {
708 clearItemDataAt(getItemIndex(_item));
709 }
710
711 void MenuControl::setItemId(MenuItem* _item, std::string_view _id)
712 {
713 setItemIdAt(getItemIndex(_item), _id);
714 }
715
716 const std::string& MenuControl::getItemId(const MenuItem* _item) const
717 {
718 return getItemIdAt(getItemIndex(_item));
719 }
720
721 void MenuControl::setItemName(MenuItem* _item, const UString& _name)
722 {
723 setItemNameAt(getItemIndex(_item), _name);
724 }
725
726 const UString& MenuControl::getItemName(const MenuItem* _item) const
727 {
728 return getItemNameAt(getItemIndex(_item));
729 }
730
731 void MenuControl::setItemChildVisible(MenuItem* _item, bool _visible)
732 {
733 setItemChildVisibleAt(getItemIndex(_item), _visible);
734 }
735
736 MenuControl* MenuControl::getItemChild(const MenuItem* _item) const
737 {
738 return getItemChildAt(getItemIndex(_item));
739 }
740
741 MenuControl* MenuControl::createItemChildAt(size_t _index)
742 {
743 return createItemChildTAt<MenuControl>(_index);
744 }
745
746 MenuControl* MenuControl::createItemChild(MenuItem* _item)
747 {
748 return createItemChildAt(getItemIndex(_item));
749 }
750
751 void MenuControl::removeItemChild(MenuItem* _item)
752 {
753 removeItemChildAt(getItemIndex(_item));
754 }
755
756 MenuItemType MenuControl::getItemType(const MenuItem* _item) const
757 {
758 return getItemTypeAt(getItemIndex(_item));
759 }
760
761 void MenuControl::setItemType(MenuItem* _item, MenuItemType _type)
762 {
763 setItemTypeAt(getItemIndex(_item), _type);
764 }
765
766 void MenuControl::setPopupAccept(bool _value)
767 {
768 mPopupAccept = _value;
769 }
770
771 bool MenuControl::getPopupAccept() const
772 {
773 return mPopupAccept;
774 }
775
776 MenuItem* MenuControl::getMenuItemParent() const
777 {
778 return mOwner;
779 }
780
781 const std::string& MenuControl::getSkinByType(MenuItemType _type) const
782 {
783 if (_type == MenuItemType::Popup)
784 return mItemPopupSkin;
785 if (_type == MenuItemType::Separator)
786 return mItemSeparatorSkin;
787 return mItemNormalSkin;
788 }
789
790 std::string_view MenuControl::getIconIndexByType(MenuItemType _type) const
791 {
792 if (_type == MenuItemType::Popup)
793 return "Popup";
794 return "None";
795 }
796
797 MenuItemType MenuControl::getItemType(bool _submenu, bool _separator) const
798 {
799 if (_submenu)
800 return MenuItemType::Popup;
801 if (_separator)
802 return MenuItemType::Separator;
803 return MenuItemType::Normal;
804 }
805
806 size_t MenuControl::_getItemCount() const
807 {
808 return getItemCount();
809 }
810
811 void MenuControl::_addItem(const MyGUI::UString& _name)
812 {
813 addItem(_name, MenuItemType::Normal);
814 }
815
816 void MenuControl::_removeItemAt(size_t _index)
817 {
818 removeItemAt(_index);
819
820 _updateSizeForEmpty();
821 }
822
823 Widget* MenuControl::_getItemAt(size_t _index) const
824 {
825 return getItemAt(_index);
826 }
827
828 void MenuControl::_setItemNameAt(size_t _index, const UString& _name)
829 {
830 setItemNameAt(_index, _name);
831 }
832
833 const UString& MenuControl::_getItemNameAt(size_t _index) const
834 {
835 return getItemNameAt(_index);
836 }
837
838 void MenuControl::_setItemSelected(IItem* _item)
839 {
840 MenuItem* item = static_cast<MenuItem*>(_item);
841 for (auto& iter : mItemsInfo)
842 {
843 if (iter.type == MenuItemType::Popup)
844 {
845 iter.item->setStateSelected(false);
846
847 if (iter.submenu != nullptr)
848 iter.submenu->setVisible(false);
849 }
850 }
851
852 if (item->getItemType() == MenuItemType::Popup)
853 {
854 item->setStateSelected(true);
855 size_t index = getItemIndex(item);
856
857 _setItemChildVisibleAt(index, true, false);
858
859 _updateItems(index);
860 }
861 }
862
863 void MenuControl::_updateItems(size_t _index)
864 {
865 if (mItemsInfo[_index].submenu != nullptr)
866 mItemsInfo[_index].submenu->_updateSizeForEmpty();
867 }
868
869 void MenuControl::_updateSizeForEmpty()
870 {
871 if (mItemsInfo.empty())
872 setSize(100, 100);
873 }
874
875 void MenuControl::setVerticalAlignment(bool _value)
876 {
877 mVerticalAlignment = _value;
878
879 update();
880 }
881
882 bool MenuControl::getVerticalAlignment() const
883 {
884 return mVerticalAlignment;
885 }
886
887 void MenuControl::setPropertyOverride(std::string_view _key, std::string_view _value)
888 {
890 if (_key == "VerticalAlignment")
891 setVerticalAlignment(utility::parseValue<bool>(_value));
892
893 else
894 {
895 Base::setPropertyOverride(_key, _value);
896 return;
897 }
898
899 eventChangeProperty(this, _key, _value);
900 }
901
902} // namespace MyGUI
MyGUI_ControllerManager.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition MyGUI_Diagnostic.h:21
MYGUI_ASSERT_RANGE_INSERT
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
Definition MyGUI_Diagnostic.h:50
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_Gui.h
MyGUI_ImageBox.h
MyGUI_InputManager.h
MyGUI_LayerManager.h
MyGUI_Precompiled.h
MyGUI_RenderManager.h
MyGUI_ResourceSkin.h
MyGUI_WidgetManager.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::Button::setImageName
void setImageName(std::string_view _name)
Definition MyGUI_Button.cpp:184
MyGUI::Button::setStateSelected
void setStateSelected(bool _check)
Set button selected state.
Definition MyGUI_Button.cpp:119
MyGUI::ControllerFadeAlpha
Definition MyGUI_ControllerFadeAlpha.h:19
MyGUI::ControllerFadeAlpha::getClassTypeName
static std::string_view getClassTypeName()
Definition MyGUI_ControllerFadeAlpha.h:20
MyGUI::ControllerFadeAlpha::setAlpha
void setAlpha(float _value)
Definition MyGUI_ControllerFadeAlpha.cpp:83
MyGUI::ControllerFadeAlpha::setCoef
void setCoef(float _value)
Definition MyGUI_ControllerFadeAlpha.cpp:88
MyGUI::ControllerFadeAlpha::setEnabled
void setEnabled(bool _value)
Definition MyGUI_ControllerFadeAlpha.cpp:93
MyGUI::ControllerItem
Definition MyGUI_ControllerItem.h:26
MyGUI::ControllerItem::eventPostAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
Definition MyGUI_ControllerItem.h:53
MyGUI::ControllerManager::createItem
ControllerItem * createItem(std::string_view _type)
Definition MyGUI_ControllerManager.cpp:71
MyGUI::ControllerManager::getInstance
static ControllerManager & getInstance()
MyGUI::ControllerManager::removeItem
void removeItem(Widget *_widget)
Definition MyGUI_ControllerManager.cpp:102
MyGUI::ControllerManager::addItem
void addItem(Widget *_widget, ControllerItem *_item)
Definition MyGUI_ControllerManager.cpp:77
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition MyGUI_ICroppedRectangle.h:245
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition MyGUI_ICroppedRectangle.h:113
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition MyGUI_ICroppedRectangle.h:118
MyGUI::ICroppedRectangle::getAbsoluteRect
IntRect getAbsoluteRect() const
Definition MyGUI_ICroppedRectangle.h:67
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition MyGUI_ICroppedRectangle.h:51
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition MyGUI_ICroppedRectangle.h:87
MyGUI::IItem
Definition MyGUI_IItem.h:18
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::ISubWidgetText
Definition MyGUI_ISubWidgetText.h:19
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_ISubWidgetText.h:122
MyGUI::InputManager::setKeyFocusWidget
void setKeyFocusWidget(Widget *_widget)
Definition MyGUI_InputManager.cpp:388
MyGUI::InputManager::getInstance
static InputManager & getInstance()
MyGUI::LayerManager::upLayerItem
void upLayerItem(Widget *_item)
Definition MyGUI_LayerManager.cpp:151
MyGUI::LayerManager::getInstance
static LayerManager & getInstance()
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText() const
Definition MyGUI_SkinItem.cpp:148
MyGUI::TextBox::getCaption
virtual const UString & getCaption() const
Definition MyGUI_TextBox.cpp:79
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
MyGUI::UserData::isUserString
bool isUserString(std::string_view _key) const
Definition MyGUI_WidgetUserData.cpp:44
MyGUI::UserData::getUserString
std::string_view getUserString(std::string_view _key) const
Definition MyGUI_WidgetUserData.cpp:20
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::getParent
Widget * getParent() const
Definition MyGUI_Widget.cpp:1352
MyGUI::Widget::setAlpha
void setAlpha(float _alpha)
Definition MyGUI_Widget.cpp:466
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::getParentSize
IntSize getParentSize() const
Definition MyGUI_Widget.cpp:1082
MyGUI::Widget::changeWidgetSkin
void changeWidgetSkin(std::string_view _skinName)
Definition MyGUI_Widget.cpp:143
MyGUI::Widget::getVisible
bool getVisible() const
Definition MyGUI_Widget.cpp:1327
MyGUI::Widget::getClientWidget
Widget * getClientWidget()
Definition MyGUI_Widget.cpp:1367
MyGUI::Widget::setAlign
virtual void setAlign(Align _value)
Definition MyGUI_Widget.cpp:775
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:94
MyGUI::Widget::setEnabledSilent
void setEnabledSilent(bool _value)
Definition MyGUI_Widget.cpp:1357
MyGUI::Widget::_getClientWidget
Widget * _getClientWidget()
If there is client widget return it, otherwise return this.
Definition MyGUI_Widget.cpp:1196
MyGUI::WidgetInput::eventMouseButtonClick
EventHandle_WidgetVoid eventMouseButtonClick
Definition MyGUI_WidgetInput.h:168
MyGUI::WidgetInput::setNeedKeyFocus
void setNeedKeyFocus(bool _value)
Definition MyGUI_WidgetInput.cpp:142
MyGUI::WidgetInput::eventMouseSetFocus
EventHandle_WidgetWidget eventMouseSetFocus
Definition MyGUI_WidgetInput.h:121
MyGUI::WidgetInput::eventRootKeyChangeFocus
EventHandle_WidgetBool eventRootKeyChangeFocus
Definition MyGUI_WidgetInput.h:219
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::WidgetManager::destroyWidget
void destroyWidget(Widget *_widget)
Definition MyGUI_WidgetManager.cpp:123
MyGUI::action::actionWidgetHide
void actionWidgetHide(Widget *_widget, ControllerItem *_controller)
Definition MyGUI_ActionController.cpp:15
MyGUI::action::actionWidgetShow
void actionWidgetShow(Widget *_widget, ControllerItem *_controller)
Definition MyGUI_ActionController.cpp:20
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::ALPHA_MAX
constexpr float ALPHA_MAX
Definition MyGUI_Macros.h:20
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::ALPHA_MIN
constexpr float ALPHA_MIN
Definition MyGUI_Macros.h:21
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::POPUP_MENU_SPEED_COEF
const float POPUP_MENU_SPEED_COEF
Definition MyGUI_MenuControl.cpp:23
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100
MyGUI::Align::HStretch
@ HStretch
Definition MyGUI_Align.h:29
MyGUI::Align::Default
@ Default
Definition MyGUI_Align.h:36
MyGUI::Align::Top
@ Top
Definition MyGUI_Align.h:31
MyGUI::WidgetStyle::Popup
@ Popup
Definition MyGUI_WidgetStyle.h:23
MyGUI::types::TCoord::top
T top
Definition MyGUI_TCoord.h:21
MyGUI::types::TCoord::left
T left
Definition MyGUI_TCoord.h:20
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:19
MyGUI::types::TSize::height
T height
Definition MyGUI_TSize.h:20