| 694 | } |
| 695 | |
| 696 | void UIMenu::findBestMenuPos( Vector2f& pos, UIWidget* menu, UIMenu* parent, UIMenuSubMenu* subMenu, |
| 697 | Node* trigger ) { |
| 698 | SceneNode* sceneNode = menu->getSceneNode(); |
| 699 | |
| 700 | if ( nullptr == sceneNode ) |
| 701 | return; |
| 702 | |
| 703 | Rectf qScreen( 0.f, 0.f, sceneNode->getPixelsSize().getWidth(), |
| 704 | sceneNode->getPixelsSize().getHeight() ); |
| 705 | Vector2f oriPos( pos ); |
| 706 | Rectf qPos( pos.x, pos.y, pos.x + menu->getPixelsSize().getWidth(), |
| 707 | pos.y + menu->getPixelsSize().getHeight() ); |
| 708 | |
| 709 | if ( nullptr != trigger ) { |
| 710 | Rectf qTrigger = trigger->getScreenRect(); |
| 711 | // Try to position below the trigger |
| 712 | pos.y = qTrigger.Bottom; |
| 713 | qPos.Top = pos.y; |
| 714 | qPos.Bottom = qPos.Top + menu->getPixelsSize().getHeight(); |
| 715 | |
| 716 | if ( !qScreen.contains( qPos ) ) { |
| 717 | // Try to position above the trigger |
| 718 | pos.y = qTrigger.Top - menu->getPixelsSize().getHeight(); |
| 719 | qPos.Top = pos.y; |
| 720 | qPos.Bottom = qPos.Top + menu->getPixelsSize().getHeight(); |
| 721 | |
| 722 | if ( !qScreen.contains( qPos ) ) { |
| 723 | // Try to position to the right of the trigger |
| 724 | pos.x = qTrigger.Right; |
| 725 | pos.y = qTrigger.Top; |
| 726 | qPos.Left = pos.x; |
| 727 | qPos.Right = qPos.Left + menu->getPixelsSize().getWidth(); |
| 728 | qPos.Top = pos.y; |
| 729 | qPos.Bottom = qPos.Top + menu->getPixelsSize().getHeight(); |
| 730 | |
| 731 | if ( !qScreen.contains( qPos ) ) { |
| 732 | // Try to position to the left of the trigger |
| 733 | pos.x = qTrigger.Left - menu->getPixelsSize().getWidth(); |
| 734 | qPos.Left = pos.x; |
| 735 | qPos.Right = qPos.Left + menu->getPixelsSize().getWidth(); |
| 736 | |
| 737 | if ( !qScreen.contains( qPos ) ) { |
| 738 | // Reset to original position if no better position found |
| 739 | pos = oriPos; |
| 740 | qPos.Left = pos.x; |
| 741 | qPos.Right = qPos.Left + menu->getPixelsSize().getWidth(); |
| 742 | qPos.Top = pos.y; |
| 743 | qPos.Bottom = qPos.Top + menu->getPixelsSize().getHeight(); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | } else if ( nullptr != parent && nullptr != subMenu ) { |
| 749 | Rectf qPrevMenu; |
| 750 | bool clipMenu = parent->getOwnerNode() && parent->getOwnerNode()->getParent() && |
| 751 | parent->getOwnerNode()->getParent()->isType( UI_TYPE_MENU ); |
| 752 | |
| 753 | Vector2f sPos = subMenu->getPixelsPosition(); |
nothing calls this directly
no test coverage detected