void MainMenu::recalculateSize_() { Rect parentRect = getParent()->getClientRect(); // client rect of parent //AbstractSkin* skin = getEnvironment()->getSkin(); Font font = Font::create( FONT_2_WHITE ); int height = std::max<int>( DEFAULT_MENU_HEIGHT, getHeight() ); setGeometry( Rect( parentRect.UpperLeftCorner.getX(), parentRect.UpperLeftCorner.getY(), parentRect.LowerRightCorner.getX(), parentRect.UpperLeftCorner.getY() + height ) ); Rect rect; rect.UpperLeftCorner = parentRect.UpperLeftCorner; height = std::max<int>( font.getSize("A").getHeight(), height ); //if (skin && height < skin->getSize ( EGDS_MENU_HEIGHT )) // height = skin->getSize(EGDS_MENU_HEIGHT); int width = rect.UpperLeftCorner.getX(); int i; for( i=0; i<(int)getItemCount(); ++i) { ContextMenuItem* refItem = getItem( i ); if ( refItem->isSeparator() ) { refItem->setDim( Size( 16, getHeight() ) ); } else { Size itemSize = font.getSize( refItem->getText() ) + Size( 20, 0 ); itemSize.setHeight( getHeight() ); refItem->setDim( itemSize ); } refItem->setOffset( width ); width += refItem->getDim().getWidth(); } // recalculate submenus for (i=0; i<(int)getItemCount(); ++i) { ContextMenuItem* refItem = getItem( i ); Rect rectangle( refItem->getOffset(), 0, refItem->getOffset() + refItem->getDim().getWidth(), height ); refItem->setGeometry( rectangle ); if (refItem->getSubMenu()) { // move submenu Size itemSize = refItem->getSubMenu()->getAbsoluteRect().getSize(); refItem->getSubMenu()->setGeometry( Rect( refItem->getOffset(), height, refItem->getOffset() + itemSize.getWidth()-5, height+itemSize.getHeight() )); } } }
ContextMenuItem* MainMenu::addItem(const std::string& text, int commandId, bool enabled, bool hasSubMenu, bool checked, bool autoChecking) { ContextMenuItem* ret = ContextMenu::addItem( text, commandId, enabled, hasSubMenu, checked, autoChecking ); if( ret && ret->getSubMenu() ) { //ret->getSubMenu()->setStyle( getStyle().getSubStyle( NES_SUBMENU ).getName() ); ret->setFlag( ContextMenuItem::drawSubmenuSprite, false ); ret->setBackgroundMode( Label::bgNone ); } //refItem.alignEnabled = true; //refItem.horizontal = EGUIA_CENTER; //refItem.vertical = EGUIA_CENTER; return ret; }