void Menu::_determineLargestTextItemWidth() { mMaxTextItemWidth = 0; float textWidth = 0; MenuTextItem* mti = NULL; for( std::list<MenuItem*>::iterator it = mItems.begin(); it != mItems.end(); ++it ) { mti = dynamic_cast<MenuTextItem*>((*it)); if(mti != NULL) { textWidth = mti->getTextWidth(); if(textWidth > mMaxTextItemWidth) mMaxTextItemWidth = textWidth; } } }
MenuItem* Menu::createItem(MenuItemDesc* d, int index) { if(d->widget_name == "") { d->widget_name = getName() + ".AutoName.MenuItem." + Ogre::StringConverter::toString(mAutoNameCounter); ++mAutoNameCounter; } // Make sure new MenuItem will maintain link to owner ToolBar d->toolBar = mDesc->toolBar; // Make sure new MenuItem will maintain link to owner ContextMenu d->contextMenu = mDesc->contextMenu; // Make sure new MenuItem will maintain link to owner Menu d->menu = this; // Determine position of MenuItem d->widget_dimensions.size.width = mMenuPanel->getClientDimensions().size.width; d->widget_dimensions.size.height = mDesc->menu_itemHeight; d->index = index; MenuItem* newMenuItem = dynamic_cast<MenuItem*>(_createWidget(d)); addChild(newMenuItem); if(mDesc->menu_autoWidenMenuPanel) { MenuTextItem* mti = dynamic_cast<MenuTextItem*>(newMenuItem); if(mti != NULL) { float textWidth = mti->getTextWidth(); if(textWidth > mMaxTextItemWidth) { mMaxTextItemWidth = textWidth; if(mMenuPanel != NULL) mMenuPanel->setWidth(mMenuPanel->getLeftRightBorderWidth() + mMaxTextItemWidth + 5); } } } return newMenuItem; }