[译]GLUT教程 - 子菜单

Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Sub Menus

 

上一节我们介绍了如何创建普通菜单和如果绑定用户选定的菜单到处理事件.下面来介绍分层子菜单.

子菜单的创建和菜单用的是同一个函数.创建后插入到菜单的函数glutAddSubMenu原型如下:

 

void glutAddSubMenu(char *entryName, int menuIndex);

entryName - 子菜单名

menuIndex - 子菜单的索引值,该参数的值是从调用glutCreateMenu函数创建子菜单时得到.

 

 

该函数会添加一个项到菜单的尾部.当鼠标移到该菜单项时会自动弹出子菜单.

下面代码段演示了上述函数的用法:

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);
}

 

运行上面代码,当用户按鼠标右键时会弹出两个选项: "多维模式"和"颜色". 点击"颜色"按钮时会弹出子菜单: "红","蓝","绿"和"橙".

 

posted @ 2013-10-28 12:26  Clotho_Lee  阅读(1558)  评论(0编辑  收藏  举报