X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=c9820a20543e304884e45bcfd13857a2a3ccf3b0;hb=1b0087ae8ca179df3a55922c92670c80a891b3b9;hp=f6520e79aaa7adee3bfc003edb8ec0287a7d3759;hpb=653cfb2c0e3aacd00fd53d5d03cb9d9da516eac1;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index f6520e7..c9820a2 100644 --- a/scene.c +++ b/scene.c @@ -246,7 +246,34 @@ void processLightEvents(int id) { } +int makeSubmenuFromArray( const char *menuEntries, void *callback ) { + int menuEntriesSize = sizeof(menuEntries) / sizeof(menuEntries[0]); + int menuNumber = menuEntriesSize / 10 + 1; + int submenuObjects[menuNumber-1]; + + for( int i = 0; i < menuNumber; i++ ) { + submenuObjects[i] = glutCreateMenu(callback); + int startNum = i*11 - (i-1); + for ( int j = startNum - 1; j < (startNum+9); j++ ) { + if ( j == menuEntriesSize ) break; // Detect if we've reached the end of the array + glutAddMenuEntry( menuEntries[j], j ); + } + } + + int mainMenu = glutCreateMenu(callback); + for ( int i = 0; i < menuNumber; i++ ) { + char name[10]; // buffer to hold name + int startNum = i*11 - (i-1); + int endNum = startNum + 9; + if ( i == menuNumber - 1 ) { // We're on the last one + endNum = startNum + 3; + } + sprintf(name, "%d-%d", startNum, endNum); + glutAddSubMenu( name, submenuObjects[i] ); + } + return mainMenu; +} void makeMenu() { // Construct material menu @@ -268,20 +295,21 @@ void makeMenu() { glutAddMenuEntry("R/G/B/All Light 2", LIGHT_RGBALL_LIGHT_2); // Construct add object submenus - int addObjectSubmenu[6]; - - for( int i = 0; i < 6; i++ ) { - addObjectSubmenu[i] = glutCreateMenu(processObjectEvents); - for ( int j = i; j < (i+9); j++ ) { + int addObjectMenu = makeSubmenuFromArray( objectMenuEntries, processObjectEvents ); + + // Construct texture/ground texture submenus +/* int textureMenuEntries = sizeof(textureMenuEntries) / sizeof(textureMenuEntries[0]); + int menuNumber = textureMenuEntries / 10 + 1; + int textureSubmenu[menuNumber-1]; + + for( int i = 0; i < menuNumber; i++ ) { + textureSubmenu[i] = glutCreateMenu(processTextureEvents); + int startNum = i*11 - (i-1); + for ( int j = startNum - 1; j < (startNum+9); j++ ) { + if ( j == objectMenuEntriesSize ) break; // Detect if we've reached the end of the array glutAddMenuEntry( objectMenuEntries[j], j ); } - } - - // Construct add object menu - int addObjectMenu = glutCreateMenu(processObjectEvents); - for ( int i = 0; addObjectSubmenu[i]; i++ ) { - glutAddSubMenu( (char)i, addObjectSubmenu[i] ); - } + }*/ int mainMenu = glutCreateMenu(processMainEvents);