Exemple #1
0
void Menu::HandleFocusChanged(StringHash eventType, VariantMap& eventData)
{
    if (!showPopup_)
        return;
    
    using namespace FocusChanged;
    
    UIElement* element = static_cast<UIElement*>(eventData[P_ELEMENT].GetPtr());
    UIElement* root = GetRoot();
    
    // If another element was focused due to the menu button being clicked, do not hide the popup
    if (eventType == E_FOCUSCHANGED && static_cast<UIElement*>(eventData[P_CLICKEDELEMENT].GetPtr()))
        return;
    
    // If clicked emptiness or defocused, hide the popup
    if (!element)
    {
        ShowPopup(false);
        return;
    }
    
    // Otherwise see if the clicked element has either the menu item or the popup in its parent chain.
    // In that case, do not hide
    while (element)
    {
        if (element == this || element == popup_)
            return;
        if (element->GetParent() == root)
            element = static_cast<UIElement*>(element->GetVar(originHash).GetPtr());
        else
            element = element->GetParent();
    }
    
    ShowPopup(false);
}
Exemple #2
0
void ScrollView::Update(float timeStep)
{
    // Update touch scrolling here if necessary
    if (touchScrollSpeed_ == Vector2::ZERO && touchScrollSpeedMax_ == Vector2::ZERO && !barScrolling_)
        return;

    // Check if we should not scroll:
    // - ScrollView is not visible, is not enabled, or doesn't have focus
    // - The element being dragged is not a child of the ScrollView, or is one of our scrollbars
    if (!IsVisible() || !IsEnabled() || !HasFocus())
    {
        touchScrollSpeed_ = Vector2::ZERO;
        touchScrollSpeedMax_ = Vector2::ZERO;
        return;
    }

    if (GetSubsystem<UI>()->IsDragging())
    {
        Vector<UIElement*> dragElements = GetSubsystem<UI>()->GetDragElements();

        for (unsigned i = 0; i < dragElements.Size(); i++)
        {
            UIElement* dragElement = dragElements[i];
            int dragButtons = dragElement->GetDragButtonCombo();

            if (dragButtons != MOUSEB_LEFT)
                continue;

            UIElement* dragParent = dragElement->GetParent();
            bool dragElementIsChild = false;

            while (dragParent)
            {
                if (dragParent == this)
                {
                    dragElementIsChild = true;
                    break;
                }
                dragParent = dragParent->GetParent();
            }

            if (!dragElementIsChild || dragElement == horizontalScrollBar_->GetSlider() ||
                dragElement == verticalScrollBar_->GetSlider())
            {
                touchScrollSpeed_ = Vector2::ZERO;
                touchScrollSpeedMax_ = Vector2::ZERO;
                return;
            }
        }
    }

    // Update view position
    IntVector2 newPosition = viewPosition_;
    newPosition.x_ += (int)touchScrollSpeed_.x_;
    newPosition.y_ += (int)touchScrollSpeed_.y_;
    SetViewPosition(newPosition);

    // Smooth deceleration
    ScrollSmooth(timeStep);
}
Exemple #3
0
void ScrollView::Update(float timeStep)
{
    // Update touch scrolling here if necessary
    if (touchScrollSpeed_ == IntVector2::ZERO)
        return;
    
    // Check if we should not scroll:
    // - ScrollView is not visible, is not enabled, or doesn't have focus
    // - The element being dragged is not a child of the ScrollView, or is one of our scrollbars
    if (!IsVisible() || !IsEnabled() || !HasFocus())
    {
        touchScrollSpeed_ = IntVector2::ZERO;
        return;
    }
    
    UIElement* dragElement = GetSubsystem<UI>()->GetDragElement();
    if (dragElement)
    {
        UIElement* dragParent = dragElement->GetParent();
        bool dragElementIsChild = false;
        
        while (dragParent)
        {
            if (dragParent == this)
            {
                dragElementIsChild = true;
                break;
            }
            dragParent = dragParent->GetParent();
        }
        
        if (!dragElementIsChild || dragElement == horizontalScrollBar_->GetSlider() || dragElement == verticalScrollBar_->GetSlider())
        {
            touchScrollSpeed_ = IntVector2::ZERO;
            return;
        }
    }
    
    // Update view position, reset speed accumulation for next frame
    IntVector2 newPosition = viewPosition_;
    newPosition.x_ += touchScrollSpeed_.x_;
    newPosition.y_ += touchScrollSpeed_.y_;
    SetViewPosition(newPosition);
    
    /// \todo Could have smooth deceleration
    touchScrollSpeed_ = IntVector2::ZERO;
}
Exemple #4
0
void ListView::HandleItemFocusChanged(StringHash eventType, VariantMap& eventData)
{
    using namespace FocusChanged;

    UIElement* element = static_cast<UIElement*>(eventData[P_ELEMENT].GetPtr());
    while (element)
    {
        // If the focused element or its parent is in the list, scroll the list to make the item visible
        UIElement* parent = element->GetParent();
        if (parent == contentElement_)
        {
            EnsureItemVisibility(element);
            return;
        }
        element = parent;
    }
}