X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=inline;f=scene.c;h=bd003f5705d3b1d97645bb4095f0f726e265fdc4;hb=029de1695bc7b9f91b559a224a71e9be7aedd8a2;hp=2733cf8820f58b9a163a8c063f6fdbd2569278ec;hpb=17cb701324fd442c5c9cc9ea6b662bf829d92ff2;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 2733cf8..bd003f5 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,23 +295,20 @@ void makeMenu() { glutAddMenuEntry("R/G/B/All Light 2", LIGHT_RGBALL_LIGHT_2); // Construct add object submenus - int addObjectSubmenu[6]; - int objectMenuEntriesSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]); - int menuNumber = objectMenuEntriesSize / 10 + 1; + 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++ ) { - addObjectSubmenu[i] = glutCreateMenu(processObjectEvents); - for ( int j = i; j < (i+9); j++ ) { - if ( !objectMenuEntries[j] ) break; // Detect if we've reached the end of the array + 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); - glutAddSubMenu( "test", addObjectSubmenu[0] ); - /*for ( int i = 0; addObjectSubmenu[i]; i++ ) { - glutAddSubMenu( (char)i, addObjectSubmenu[i] ); }*/