Help end child hunger

Sub Menus

 
Prev: Popup Menus Next: Modifying a Menu
 

In the previous section we saw how to build a simple menu, and process the events generated by a user selection. Now we’re going to see how to add a cascade submenu.

A submenu is created with the same function as a menu. Therefore we use the function glutCreateMenu, see the previous section, to create submenus as well as menus. Then we must add the submenu as an entry to the menu. This is done in GLUT using glutAddSubMenu.


void glutAddSubMenu(char *entryName, int menuIndex);

Parameters:

  • entryName – The name of the submenu entry in the menu
  • menuIndex – The index of the submenu, this is the value that we get as a return value when calling glutCreateMenu for the submenu.

This function adds an entry to the end of the menu. When selected, the new entry will open a submenu.

The following piece of code illustrates the usage of the above function:

void createPopupMenus() {

	shrinkMenu = glutCreateMenu(processShrinkMenu);
	glutAddMenuEntry("Shrink",SHRINK);
	glutAddMenuEntry("NORMAL",NORMAL);

	fillMenu = glutCreateMenu(processFillMenu);
	glutAddMenuEntry("Fill",FILL);
	glutAddMenuEntry("Line",LINE);

	colorMenu = glutCreateMenu(processColorMenu);
	glutAddMenuEntry("Red",RED);
	glutAddMenuEntry("Blue",BLUE);
	glutAddMenuEntry("Green",GREEN);
	glutAddMenuEntry("Orange",ORANGE);

	mainMenu = glutCreateMenu(processMainMenu);
	glutAddSubMenu("Polygon Mode", fillMenu);
	glutAddSubMenu("Color", colorMenu);

	// attach the menu to the right button
	glutAttachMenu(GLUT_RIGHT_BUTTON);
}

Using the code above, when the user pressed the right mouse button a menu with two options would be presented: “Polygon Mode” and “Color”. Pressing on “Color”, a submenu appears with three items: “Red”, “Blue”, “Green”, and “Orange”.

 

 

Prev: Popup Menus Next: Modifying a Menu
 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: