void Ui::_updateHovered( const Point& mousePos ) { WidgetPtr lastHovered = _d->hovered.current; WidgetPtr lastHoveredNoSubelement = _d->hovered.noSubelement; _d->hovered.lastMousePos = mousePos; // Get the real Hovered _d->hovered.current = rootWidget()->getElementFromPoint( mousePos ); if( _d->tooltip.element.isValid() && _d->hovered.current == _d->tooltip.element ) { // When the mouse is over the ToolTip we remove that so it will be re-created at a new position. // Note that ToolTip.EnterTime does not get changed here, so it will be re-created at once. _d->tooltip.element->deleteLater(); _d->tooltip.element->hide(); _d->tooltip.element = WidgetPtr(); _d->hovered.current = rootWidget()->getElementFromPoint( mousePos ); } // for tooltips we want the element itself and not some of it's subelements if( _d->hovered.current != rootWidget() ) { _d->hovered.noSubelement = _d->hovered.current; while ( _d->hovered.noSubelement.isValid() && _d->hovered.noSubelement->isSubElement() ) { _d->hovered.noSubelement = _d->hovered.noSubelement->parent(); } } else { _d->hovered.noSubelement = 0; } if( _d->hovered.current != lastHovered ) { if( lastHovered.isValid() ) { lastHovered->onEvent( NEvent::Gui( lastHovered.object(), 0, guiElementLeft ) ); } if( _d->hovered.current.isValid() ) { _d->hovered.current->onEvent( NEvent::Gui( _d->hovered.current.object(), _d->hovered.current.object(), guiElementHovered ) ); } } if ( lastHoveredNoSubelement != _d->hovered.noSubelement ) { if( _d->tooltip.element.isValid() ) { _d->tooltip.element->deleteLater(); _d->tooltip.element = WidgetPtr(); } if( _d->hovered.noSubelement.isValid() ) { _d->tooltip.enterTime = DateTime::elapsedTime(); } } }
void BasicContainer::ShowWidgetPart( WidgetPtr widget, Rectangle area ) { Rectangle widgetArea = getChildrenArea(); area.x += widget->GetX(); area.y += widget->GetY(); if (area.x + area.width > widgetArea.width) { widget->SetX(widget->GetX() - area.x - area.width + widgetArea.width); } if (area.y + area.height > widgetArea.height) { widget->SetY(widget->GetY() - area.y - area.height + widgetArea.height); } if (area.x < 0) { widget->SetX(widget->GetX() - area.x); } if (area.y < 0) { widget->SetY(widget->GetY() - area.y); } }
void ItemBox::_redrawAllVisible() { int count = mCountLineVisible * mCountItemInLine + mTopIndex; size_t iwid = 0; // индекс виджета for (int pos = mTopIndex; pos<count; ++pos, ++iwid) { // дальше нет айтемов if (pos >= mCountItems) break; WidgetPtr widget = getItemWidget(iwid); widget->show(); redrawItem(widget, (size_t)pos); } // все виджеты еще есть, то их надо бы скрыть while (iwid < mVectorItems.size()) { mVectorItems[iwid]->hide(); iwid ++; } //MYGUI_OUT(mVectorItems.size()); }
bool ControllerFadeAlpha::addTime(WidgetPtr _widget, float _time) { float alpha = _widget->getAlpha(); // проверяем нужно ли к чему еще стремиться if (mAlpha > alpha) { alpha += _time * mCoef; if (mAlpha > alpha) { _widget->setAlpha(alpha); eventUpdateAction(_widget); return true; } else { _widget->setAlpha(mAlpha); } } else if (mAlpha < alpha) { alpha -= _time * mCoef; if (mAlpha < alpha) { _widget->setAlpha(alpha); eventUpdateAction(_widget); return true; } else { _widget->setAlpha(mAlpha); } } // вызываем пользовательский делегат пост обработки eventPostAction(_widget); return false; }
void Stack::AddChild( WidgetPtr child ) { int x = 0; int y = 0; if (mWidgets.size() > 0) { WidgetPtr last = mWidgets.back(); if (mOrientation == OrientationVertical) { y = last->GetY() + last->GetHeight() + mSpacing; } else { x = last->GetX() + last->GetWidth() + mSpacing; } } child->SetPosition(x, y); BasicContainer::Add(child); if (mOrientation == OrientationVertical) { SetSize(std::max(GetWidth(), child->GetWidth()), y + child->GetHeight()); } else { SetSize(x + child->GetWidth(), std::max(GetHeight(), child->GetHeight())); } }
// поправить на виджет и проверять на рутовость void LayerManager::attachToLayerKeeper(const std::string& _name, WidgetPtr _item) { MYGUI_ASSERT(_item->isRootWidget(), "attached widget must be root"); // сначала отсоединяем detachFromLayerKeeper(_item); // а теперь аттачим for (VectorLayerKeeper::iterator iter=mLayerKeepers.begin(); iter!=mLayerKeepers.end(); ++iter) { if (_name == (*iter)->getName()) { // запоминаем в рутовом виджете хранитель лееров _item->mLayerKeeper = (*iter); // достаем из хранителя леер для себя _item->mLayerItemKeeper = (*iter)->getItem(); // подписываемся на пиккинг _item->mLayerItemKeeper->_addPeekItem(_item); // физически подсоединяем иерархию _item->_attachToLayerItemKeeper(_item->mLayerItemKeeper); return; } } MYGUI_EXCEPT("Layer '" << _name << "' is not found"); }
void WidgetRender::Render(ContainerWidget* w) { m_render->PushSate(); if (w->GetBackColor().a > 0.0f) { m_render->SetColor(w->GetBackColor()); m_render->SetAlpha(w->GetBackColor().a); if (w->GetStyle()->IsEnabledTextures()) { m_render->SetTexture(w->GetBackTexture()); m_render->DrawTexturedQuad(w->GetLocalX(), w->GetLocalY(), w->GetWidth(), w->GetHeight()); } else { m_render->DrawQuad(w->GetLocalX(), w->GetLocalY(), w->GetWidth(), w->GetHeight()); } } m_render->Translate(w->GetLocalX(), w->GetLocalY()); for (ContainerWidget::ChildrenCollection::iterator it = w->GetChildren().begin(); it != w->GetChildren().end(); ++it) { WidgetPtr child = (*it).second; child->Repaint(this); } m_render->PopState(); }
bool Widget::dispatchTouchEvent(TouchEvent &event) { auto curr = event.getCurrPoint(); bool handled = false; // 靠前的控件先接受事件 int size = getNode()->getChildren().size(); for (int i = size - 1; i >= 0; --i) { auto child = getNode()->getChildren()[i]; WidgetPtr childWidget = child->getComponent<Widget>(); if (!childWidget) { continue; } Vec2 p = childWidget->getComponent<Transform2D>()->convertParentToLocalSpace(curr); event.setCurrPoint(p); // 有控件处理了事件就阻止传递 if (childWidget->onTouchEvent(event)) { handled = true; break; } } return handled; }
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; }
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); }
WidgetPtr Gui::GetKeyEventSource() { WidgetPtr widget = mFocusHandler->GetFocused(); while (widget->_getInternalFocusHandler() && widget->_getInternalFocusHandler()->GetFocused()) { widget = widget->_getInternalFocusHandler()->GetFocused(); } return widget; }
WidgetPtr Gui::GetMouseEventSource(int x, int y) { WidgetPtr widget = GetWidgetAt(x, y); if (mFocusHandler->GetModalMouseInputFocused() && !widget->isModalMouseInputFocused()) { return mFocusHandler->GetModalMouseInputFocused(); } return widget; }
void FocusHandler::distributeFocusGainedEvent(const Event& focusEvent) { WidgetPtr sourceWidget = focusEvent.GetSource(); std::list<FocusListener*> focusListeners = sourceWidget->_getFocusListeners(); // Send the event to all focus listeners of the widget. for (std::list<FocusListener*>::iterator it = focusListeners.begin(); it != focusListeners.end(); ++it) { (*it)->focusGained(focusEvent); } }
void WidgetFactory::Widget_Caption(WidgetPtr _widget, const Ogre::String &_key, const Ogre::String &_value) { // change '\n' on char 10 size_t pos = _value.find("\\n"); if (pos == std::string::npos) _widget->setCaption(_value); else { std::string value(_value); while (pos != std::string::npos) { value[pos++] = '\n'; value.erase(pos, 1); pos = value.find("\\n"); } _widget->setCaption(value); } }
void ControllerFadeAlpha::prepareItem(WidgetPtr _widget) { // подготовка виджета, блокируем если только нужно if (!mEnabled) _widget->setEnabledSilent(mEnabled); if ((ALPHA_MIN != mAlpha) && (false == _widget->isVisible())) { _widget->setAlpha(ALPHA_MIN); _widget->setVisible(true); } // отписываем его от ввода if (false == mEnabled) InputManager::getInstance()._unlinkWidget(_widget); // вызываем пользовательский делегат для подготовки eventPreAction(_widget); }
void BasicContainer::Add(WidgetPtr widget) { mWidgets.push_back(widget); if (mInternalFocusHandler == NULL) { widget->_setFocusHandler(_getFocusHandler()); } else { widget->_setFocusHandler(mInternalFocusHandler); } widget->_setParent(shared_from_this()); widget->addDeathListener(this); }
void Gui::handleModalFocusReleased() { // Check all widgets below the mouse to see if they are // present in the "widget with mouse" queue. If a widget // is not then it should be added and an entered event should // be sent to it. WidgetPtr widget = GetMouseEventSource(mLastMouseX, mLastMouseY); WidgetPtr parent = widget; while (parent != NULL) { parent = widget->GetParent(); // Check if the widget is present in the "widget with mouse" queue. bool widgetIsPresentInQueue = false; std::deque<WidgetPtr>::iterator iter; for (iter = mWidgetWithMouseQueue.begin(); iter != mWidgetWithMouseQueue.end(); iter++) { if (*iter == widget) { widgetIsPresentInQueue = true; break; } } // Widget is not present, send an entered event and add // it to the "widget with mouse" queue. if (!widgetIsPresentInQueue && Widget::widgetExists(widget)) { distributeMouseEvent(widget, MouseEvent::ENTERED, mLastMousePressButton, mLastMouseX, mLastMouseY, false, true); mWidgetWithMouseQueue.push_front(widget); } WidgetPtr swap = widget; widget = parent; parent = swap->GetParent(); } }
WidgetPtr Gui::GetWidgetAt(int x, int y) { // If the widget's parent has no child then we have found the widget.. WidgetPtr parent = mTop; WidgetPtr child = mTop; while (child != NULL) { WidgetPtr swap = child; int parentX, parentY; parent->getAbsolutePosition(parentX, parentY); child = parent->GetWidgetAt(x - parentX, y - parentY); parent = swap; } return parent; }
void BasicContainer::Remove(WidgetPtr widget) { WidgetListIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) { if (*iter == widget) { mWidgets.erase(iter); widget->_setFocusHandler(FocusHandlerPtr()); widget->_setParent(WidgetPtr()); widget->removeDeathListener(this); return; } } throw GCN_EXCEPTION("There is no such widget in this container."); }
void Gui::handleMouseReleased(const MouseInput& mouseInput) { WidgetPtr sourceWidget = GetMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->GetDraggedWidget()) { if (sourceWidget != mFocusHandler->GetLastWidgetPressed()) { mFocusHandler->SetLastWidgetPressed(WidgetPtr()); } sourceWidget = mFocusHandler->GetDraggedWidget(); } int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); distributeMouseEvent(sourceWidget, MouseEvent::RELEASED, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); if (mouseInput.getButton() == mLastMousePressButton && mFocusHandler->GetLastWidgetPressed() == sourceWidget) { distributeMouseEvent(sourceWidget, MouseEvent::CLICKED, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); mFocusHandler->SetLastWidgetPressed(WidgetPtr()); } else { mLastMousePressButton = 0; mClickCount = 0; } if (mFocusHandler->GetDraggedWidget()) { mFocusHandler->SetDraggedWidget(WidgetPtr()); } }
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); }
void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput) { WidgetPtr sourceWidget = GetMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->GetDraggedWidget() != NULL) { sourceWidget = mFocusHandler->GetDraggedWidget(); } int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); distributeMouseEvent(sourceWidget, MouseEvent::WHEEL_MOVED_UP, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); }
FloatCoord Gui::convertIntToRelative(const IntCoord& _coord, WidgetPtr _parent) { const FloatSize& size = getViewSize(); if (null == _parent) { return FloatCoord(_coord.left / size.width, _coord.top / size.height, _coord.width / size.width, _coord.height / size.height); } const IntCoord& coord = _parent->getClientCoord(); return FloatCoord(1.*_coord.left / coord.width, 1.*_coord.top / coord.height, 1.*_coord.width / coord.width, 1.*_coord.height / coord.height); }
IntCoord Gui::convertRelativeToInt(const FloatCoord& _coord, WidgetPtr _parent) { const FloatSize& size = getViewSize(); if (null == _parent) { return IntCoord(_coord.left * size.width, _coord.top * size.height, _coord.width * size.width, _coord.height * size.height); } const IntCoord& coord = _parent->getClientCoord(); return IntCoord(_coord.left * coord.width, _coord.top * coord.height, _coord.width * coord.width, _coord.height * coord.height); }
void Gui::handleMousePressed(const MouseInput& mouseInput) { WidgetPtr sourceWidget = GetMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->GetDraggedWidget()) { sourceWidget = mFocusHandler->GetDraggedWidget(); } int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); if ((mFocusHandler->GetModalFocused() != NULL && sourceWidget->isModalFocused()) || mFocusHandler->GetModalFocused() == NULL) { sourceWidget->requestFocus(); } if (mouseInput.getTimeStamp() - mLastMousePressTimeStamp < 250 && mLastMousePressButton == mouseInput.getButton()) { mClickCount++; } else { mClickCount = 1; } distributeMouseEvent(sourceWidget, MouseEvent::PRESSED, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); mFocusHandler->SetLastWidgetPressed(sourceWidget); mFocusHandler->SetDraggedWidget(sourceWidget); mLastMouseDragButton = mouseInput.getButton(); mLastMousePressButton = mouseInput.getButton(); mLastMousePressTimeStamp = mouseInput.getTimeStamp(); }
void Canvas::RealizeControl( Inspect::Control* control ) { HELIUM_ASSERT( IsMainThread() ); if ( this != control ) { WidgetPtr widget; if ( control->GetMetaClass() == Reflect::GetMetaClass< Container >() && HasFlags<Inspect::UIHints>( Reflect::AssertCast< Container >( control )->GetUIHints(), Inspect::UIHint::Popup ) ) { // Create a drawerWidget widget = new DrawerWidget( Reflect::AssertCast< Container >( control ) ); } else { WidgetCreators::const_iterator found = m_WidgetCreators.find( control->GetMetaClass() ); HELIUM_ASSERT( found != m_WidgetCreators.end() ); widget = found->second( control ); } HELIUM_ASSERT( widget ); // associate the widget with the control control->SetWidget( widget ); // find the window pointer for the parent window Inspect::Container* parent = control->GetParent(); HELIUM_ASSERT( parent ); Widget* parentWidget = Reflect::AssertCast< Widget >( parent->GetWidget() ); HELIUM_ASSERT( parentWidget ); wxWindow* parentWindow = parentWidget->GetWindow(); HELIUM_ASSERT( parentWindow ); // this will cause the widget to allocate its corresponding window (since it has the parent pointer) widget->CreateWindow( parentWindow ); DrawerWidget* drawerWidget = Reflect::SafeCast< DrawerWidget >( widget ); if ( drawerWidget && GetDrawerManager() ) { GetDrawerManager()->AddDrawer( drawerWidget->GetDrawer() ); } } }
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 InputManager::setKeyFocusWidget(WidgetPtr _widget) { // ищем рутовый фокус WidgetPtr root = _widget; if (root != null) { while (root->_getOwner() != null) root = root->_getOwner(); } // если рутовый фокус поменялся, то оповещаем if (mWidgetRootKeyFocus != root) { if (mWidgetRootKeyFocus != null) mWidgetRootKeyFocus->_onKeyChangeRootFocus(false); if (root != null) root->_onKeyChangeRootFocus(true); mWidgetRootKeyFocus = root; } // а вот тут уже проверяем обыкновенный фокус if (_widget == mWidgetKeyFocus) return; if (isFocusKey()) mWidgetKeyFocus->_onKeyLostFocus(_widget); if (_widget != null) { if (_widget->isNeedKeyFocus()) { _widget->_onKeySetFocus(mWidgetKeyFocus); mWidgetKeyFocus = _widget; return; } } mWidgetKeyFocus = null; }