Exemplo n.º 1
0
void Menu::OnHover(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor)
{
    Button::OnHover(position, screenPosition, buttons, qualifiers, cursor);

    Menu* sibling = parent_->GetChildStaticCast<Menu>(VAR_SHOW_POPUP, true);
    if (popup_ && !showPopup_)
    {
        // Check if popup is shown by one of the siblings
        if (sibling)
        {
            // "Move" the popup from sibling menu to this menu
            sibling->ShowPopup(false);
            ShowPopup(true);
            return;
        }

        if (autoPopup_)
        {
            // Show popup when parent menu has its popup shown
            Menu* parentMenu = static_cast<Menu*>(parent_->GetVar(VAR_ORIGIN).GetPtr());
            if (parentMenu && parentMenu->showPopup_)
                ShowPopup(true);
        }
    }
    else
    {
        // Hide child menu popup when its parent is no longer being hovered
        if (sibling && sibling != this)
            sibling->ShowPopup(false);
    }
}
Exemplo n.º 2
0
void Menu::ShowPopup(bool enable)
{
    if (!popup_)
        return;

    if (enable)
    {
        OnShowPopup();

        popup_->SetVar(VAR_ORIGIN, this);
        static_cast<Window*>(popup_.Get())->SetModal(true);

        popup_->SetPosition(GetScreenPosition() + popupOffset_);
        popup_->SetVisible(true);
        // BringToFront() is unreliable in this case as it takes into account only input-enabled elements.
        // Rather just force priority to max
        popup_->SetPriority(M_MAX_INT);
    }
    else
    {
        OnHidePopup();

        // If the popup has child menus, hide their popups as well
        PODVector<UIElement*> children;
        popup_->GetChildren(children, true);
        for (PODVector<UIElement*>::ConstIterator i = children.Begin(); i != children.End(); ++i)
        {
            Menu* menu = dynamic_cast<Menu*>(*i);
            if (menu)
                menu->ShowPopup(false);
        }

        static_cast<Window*>(popup_.Get())->SetModal(false);
        const_cast<VariantMap&>(popup_->GetVars()).Erase(VAR_ORIGIN);

        popup_->SetVisible(false);
        popup_->Remove();
    }
    SetVar(VAR_SHOW_POPUP, enable);

    showPopup_ = enable;
    selected_ = enable;
}
Exemplo n.º 3
0
void Menu::ShowPopup(bool enable)
{
    if (!popup_)
        return;
    
    if (enable)
    {
        // Find the UI root element for showing the popup
        UIElement* root = GetRoot();
        if (!root)
            return;
        
        OnShowPopup();
        
        if (popup_->GetParent() != root)
            root->AddChild(popup_);
        popup_->SetPosition(GetScreenPosition() + popupOffset_);
        popup_->SetVisible(true);
        popup_->SetVar(originHash, (void*)this);
        popup_->BringToFront();
    }
    else
    {
        // If the popup has child menus, hide their popups as well
        PODVector<UIElement*> children;
        popup_->GetChildren(children, true);
        for (PODVector<UIElement*>::ConstIterator i = children.Begin(); i != children.End(); ++i)
        {
            Menu* menu = dynamic_cast<Menu*>(*i);
            if (menu)
                menu->ShowPopup(false);
        }
        
        popup_->SetVar(originHash, Variant::EMPTY);
        popup_->SetVisible(false);
        popup_->Remove();
    }
    
    showPopup_ = enable;
    selected_ = enable;
}
Exemplo n.º 4
0
void Menu::ShowPopup(bool enable)
{
    if (!popup_)
        return;

    if (enable)
    {
        OnShowPopup();

        popup_->SetVar(VAR_ORIGIN, (void*)this);
        static_cast<Window*>(popup_.Get())->SetModal(true);

        popup_->SetPosition(GetScreenPosition() + popupOffset_);
        popup_->SetVisible(true);
        popup_->BringToFront();
    }
    else
    {
        // If the popup has child menus, hide their popups as well
        PODVector<UIElement*> children;
        popup_->GetChildren(children, true);
        for (PODVector<UIElement*>::ConstIterator i = children.Begin(); i != children.End(); ++i)
        {
            Menu* menu = dynamic_cast<Menu*>(*i);
            if (menu)
                menu->ShowPopup(false);
        }

        static_cast<Window*>(popup_.Get())->SetModal(false);
        const_cast<VariantMap&>(popup_->GetVars()).Erase(VAR_ORIGIN);

        popup_->SetVisible(false);
        popup_->Remove();
    }
    SetVar(VAR_SHOW_POPUP, enable);

    showPopup_ = enable;
    selected_ = enable;
}