void MenuItem::MouseReleased(const MouseEvent& lEvent) { if(!IsParentMenuOpen()) { return; } Menu* lpParentMenu = (Menu* )GetParent(); // Make sure that we are inside the bounds of the parent menu if(lpParentMenu->GetPullDownMenuParent() != NULL) { int lTextHeight = m_pRenderer->GetFreeTypeTextHeight(lpParentMenu->GetPullDownMenuParent()->GetGUIFont(), "%s", lpParentMenu->GetMenuTitle().c_str()); int lMenuHeight = lTextHeight + (lpParentMenu->GetMenuItemSpacer() * 2); int lFullMenuDisplayHeight = lpParentMenu->GetPullDownMenuParent()->GetMaxNumItemsDisplayed() * lMenuHeight; Point location = lpParentMenu->GetPullDownMenuParent()->GetLocation(); for(Component* parent = lpParentMenu->GetPullDownMenuParent()->GetParent(); parent != 0;) { Point parentLocation = parent->GetLocation(); location.m_x += parentLocation.m_x; location.m_y += parentLocation.m_y; parent = parent->GetParent(); } int lMenuX = location.m_x; int lMenuY = location.m_y - lFullMenuDisplayHeight; int lMenuWidth = lpParentMenu->GetBiggestWidth()+ (lpParentMenu->GetMenuItemSpacer() * 2); if(lEvent.GetX() > lMenuX && lEvent.GetX() <= lMenuX+lMenuWidth && lEvent.GetY() > lMenuY && lEvent.GetY() <= lMenuY+lFullMenuDisplayHeight) { // Close the menu, since we have clicked this menu item lpParentMenu->CloseMenu(); SetHover(false); SetSelected(false); // Signal that we have pressed this menu item MenuItemPressed(); } } FocusManager::GetInstance()->SetFocusOwner(0); OnMouseReleased(); }
void MenuItem::MouseEntered(const MouseEvent& lEvent) { if(!IsParentMenuOpen()) { return; } Menu* lpParentMenu = (Menu* )GetParent(); // Make sure that we are inside the bounds of the parent menu if(lpParentMenu->GetPullDownMenuParent() != NULL) { int lTextHeight = m_pRenderer->GetFreeTypeTextHeight(lpParentMenu->GetPullDownMenuParent()->GetGUIFont(), "%s", lpParentMenu->GetMenuTitle().c_str()); int lMenuHeight = lTextHeight + (lpParentMenu->GetMenuItemSpacer() * 2); int lFullMenuDisplayHeight = lpParentMenu->GetPullDownMenuParent()->GetMaxNumItemsDisplayed() * lMenuHeight; Point location = lpParentMenu->GetPullDownMenuParent()->GetLocation(); for(Component* parent = lpParentMenu->GetPullDownMenuParent()->GetParent(); parent != 0;) { Point parentLocation = parent->GetLocation(); location.m_x += parentLocation.m_x; location.m_y += parentLocation.m_y; parent = parent->GetParent(); } int lMenuX = location.m_x; int lMenuY = location.m_y - lFullMenuDisplayHeight; int lMenuWidth = lpParentMenu->GetBiggestWidth()+ (lpParentMenu->GetMenuItemSpacer() * 2); if(lEvent.GetX() > lMenuX && lEvent.GetX() <= lMenuX+lMenuWidth && lEvent.GetY() > lMenuY && lEvent.GetY() <= lMenuY+lFullMenuDisplayHeight) { SetHover(true); OnMouseEnter(); } } }
void MenuItem::SetHeight(int height) { Menu* lpMenuParent = (Menu *)GetParent(); if(lpMenuParent) { height += lpMenuParent->GetMenuItemSpacer() * 2; } Component::SetHeight(height); // Also set the height of the icons m_pDefaultIcon->SetHeight(height); m_pSelectedIcon->SetHeight(height); m_pHoverIcon->SetHeight(height); m_pDisabledIcon->SetHeight(height); }
void MenuItem::SetDimensions(int x, int y, int width, int height) { int lMenuItemSpacer = 0; Menu* lpMenuParent = (Menu *)GetParent(); if(lpMenuParent) { lMenuItemSpacer = lpMenuParent->GetMenuItemSpacer(); } //width += lMenuItemSpacer * 2; height += lMenuItemSpacer * 2; Component::SetDimensions(x, y, width, height); // Also set the dimensions of the icons m_pDefaultIcon->SetDimensions(0, 0, width, height); m_pSelectedIcon->SetDimensions(0, 0, width, height); m_pHoverIcon->SetDimensions(0, 0, width, height); m_pDisabledIcon->SetDimensions(0, 0, width, height); // Also set the dimensions of the label m_label.SetLocation(3, 3 /*lMenuItemSpacer, lMenuItemSpacer*/); }