Exemplo n.º 1
0
DropdownButton::DropdownButton(const char* sName,Container* sParent,const std::vector<std::string>& items,const GLFont* sFont,bool sManageChild)
	:DecoratedButton(sName,sParent,sLabel,sFont,false),
	 popup(0),numItems(items.size()),itemLabels(new Label*[numItems]),
	 arrowBorderSize(0.25f),arrowSize(0.25f),
	 selectedItem(0),isPopped(false)
	{
	const GLMotif::StyleSheet& ss=*getManager()->getStyleSheet();
	
	/* Create a pop-up containing the item labels: */
	popup=new Popup("Popup",getManager());
	popup->setBorderWidth(borderWidth);
	popup->setBorderType(Widget::PLAIN);
	popup->setBorderColor(borderColor);
	popup->setBackgroundColor(backgroundColor);
	popup->setForegroundColor(foregroundColor);
	popup->setMarginWidth(0.0f);
	
	/* Create a rowcolumn container for the item labels: */
	RowColumn* items=new RowColumn("Items",popup,false);
	items->setBorderWidth(0.0f);
	items->setOrientation(RowColumn::VERTICAL);
	items->setNumMinorWidgets(1);
	items->setMarginWidth(0.0f);
	items->setSpacing(0.0f);
	
	/* Create a label for each list item: */
	for(size_t i=0;i<numItems;++i)
		{
		char itemLabelName[40];
		snprintf(itemLabelName,sizeof(itemLabelName),"ItemLabel%d",int(i));
		itemLabels[i]=new Label(itemLabelName,items[i].c_str(),sFont);
		}
	
	items->manageChild();
	
	GLfloat fontHeight=sFont->getTextHeight();
	
	/* Set the arrow sizes: */
	arrowBorderSize=fontHeight*0.125f;
	arrowSize=fontHeight*0.125f;
	
	/* Set the decoration position and size: */
	setDecorationPosition(DecoratedButton::DECORATION_RIGHT);
	GLfloat width=4.0f*(arrowSize+arrowBorderSize);
	setDecorationSize(Vector(width,width,0.0f));
	
	/* Manage me: */
	if(sManageChild)
		manageChild();
	}