void LayerManager::upLayerItem(WidgetPtr _item) { if (null == _item) return; // добираемся до рута while (_item->getParent() != null) _item = _item->getParent(); // если приаттачены, то поднимаем if (null != _item->mLayerKeeper) _item->mLayerKeeper->upItem(_item->mLayerItemKeeper); }
void ContainerWidget::addChild(const WidgetPtr& child) { auto oldParent = child->getParent(); if(oldParent) oldParent->removeChild(child); children.push_back(child); child->setParent(sharedFromThis()); }
// преобразует точку на виджете в глобальную позицию IntPoint WidgetManager::convertToGlobal(const IntPoint& _point, WidgetPtr _widget) { IntPoint ret = _point; WidgetPtr wid = _widget; while (wid != null) { ret += wid->getPosition(); wid = wid->getParent(); } return ret; }
bool Widget::isAncestorOf(const WidgetPtr &o) const { auto currentParent = o->getParent(); for (; currentParent; currentParent = currentParent->getParent()) { if (currentParent.get() == this) return true; } return false; }
void InputManager::addWidgetModal(WidgetPtr _widget) { if (null == _widget) return; MYGUI_ASSERT(null == _widget->getParent(), "Modal widget must be root"); resetMouseFocusWidget(); removeWidgetModal(_widget); mVectorModalRootWidget.push_back(_widget); setKeyFocusWidget(_widget); LayerManager::getInstance().upLayerItem(_widget); }
void WidgetManager::destroyWidget(WidgetPtr _widget) { // иначе возможен бесконечный цикл MYGUI_ASSERT(_widget != null, "widget is deleted"); // отписываем от всех VectorWidgetPtr childs = _widget->getChilds(); for (VectorWidgetPtr::iterator iter = childs.begin(); iter != childs.end(); ++iter) unlinkFromUnlinkers(*iter); unlinkFromUnlinkers(_widget); // делегирует удаление отцу виджета WidgetPtr parent = _widget->getParent(); if (parent == null) Gui::getInstance()._destroyChildWidget(_widget); else parent->_destroyChildWidget(_widget); }
bool InputManager::injectMousePress(int _absx, int _absy, MouseButton _id) { // если мы щелкнули не на гуй if (false == isFocusMouse()) { resetKeyFocusWidget(); return false; } // если активный элемент заблокирован if (false == mWidgetMouseFocus->isEnabled()) return true; // захватываем только по левой клавише и только если виджету надо if (MB_Left == _id) { // захват окна mIsWidgetMouseCapture = true; // запоминаем место нажатия mLastLeftPressed.set(_absx, _absy); } // ищем вверх тот виджет который может принимать фокус WidgetPtr focus = mWidgetMouseFocus; while ((focus != null) && (false == focus->isNeedKeyFocus())) focus = focus->getParent(); // устанавливаем перед вызовом т.к. возможно внутри ктонить поменяет фокус под себя setKeyFocusWidget(focus); if (mWidgetMouseFocus != null) { mWidgetMouseFocus->_onMouseButtonPressed(_absx, _absy, _id); //mWidgetMouseFocus->_onMouseButtonPressed(_id); // поднимаем виджет LayerManager::getInstance().upLayerItem(mWidgetMouseFocus); } return true; }