X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=602dc49d32203abd6c444e39b81bb16f98803289;hb=a80b904b2d8e211f02e0833183200cc3bebd40b7;hp=bd003f5705d3b1d97645bb4095f0f726e265fdc4;hpb=029de1695bc7b9f91b559a224a71e9be7aedd8a2;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index bd003f5..602dc49 100644 --- a/scene.c +++ b/scene.c @@ -246,9 +246,21 @@ void processLightEvents(int id) { } -int makeSubmenuFromArray( const char *menuEntries[], void *callback ) { - int menuEntriesSize = sizeof(menuEntries) / sizeof(menuEntries[0]); - int menuNumber = menuEntriesSize / 10 + 1; +int roundUp(int numToRound, int multiple) { + if(multiple == 0) { + return numToRound; + } + + int remainder = numToRound % multiple; + if (remainder == 0) + return numToRound; + return numToRound + multiple - remainder; +} + +int makeSubmenuFromArray( const char *menuEntries[], unsigned int menuEntriesSize, void *callback ) { + if ( menuEntriesSize == 0 ) return -1; + + int menuNumber = roundUp(menuEntriesSize, 10) / 10; int submenuObjects[menuNumber-1]; for( int i = 0; i < menuNumber; i++ ) { @@ -256,7 +268,7 @@ int makeSubmenuFromArray( const char *menuEntries[], void *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 ); + glutAddMenuEntry( menuEntries[j], j + 1 ); } } @@ -266,7 +278,7 @@ int makeSubmenuFromArray( const char *menuEntries[], void *callback ) { int startNum = i*11 - (i-1); int endNum = startNum + 9; if ( i == menuNumber - 1 ) { // We're on the last one - endNum = startNum + 3; + endNum = startNum + (menuEntriesSize - startNum); // Work out final number } sprintf(name, "%d-%d", startNum, endNum); glutAddSubMenu( name, submenuObjects[i] ); @@ -294,44 +306,28 @@ void makeMenu() { glutAddMenuEntry("Move Light 2", LIGHT_MOVE_LIGHT_2); glutAddMenuEntry("R/G/B/All Light 2", LIGHT_RGBALL_LIGHT_2); - // Construct add object submenus - 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 object menu + int objectMenuEntriesSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]); + int objectMenu = makeSubmenuFromArray( objectMenuEntries, objectMenuEntriesSize, processObjectEvents ); + // Construct texture / ground texture menus + int textureMenuEntriesSize = sizeof(textureMenuEntries) / sizeof(textureMenuEntries[0]); + int textureMenu = makeSubmenuFromArray( textureMenuEntries, textureMenuEntriesSize, processTextureEvents ); + int gTextureMenu = makeSubmenuFromArray( textureMenuEntries, textureMenuEntriesSize, processGTextureEvents ); + // Construct main menu int mainMenu = glutCreateMenu(processMainEvents); - glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA); - glutAddSubMenu("Add object", addObjectMenu); + glutAddSubMenu("Add object", objectMenu); glutAddMenuEntry("Position/Scale", POSITION_SCALE); glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE); - //material - - - - glutSetMenu(mainMenu); glutAddSubMenu("Material", materialMenu); - - //texture - //ground texture - //lights - - + glutAddSubMenu("Texture", textureMenu); + glutAddSubMenu("Ground texture", gTextureMenu); + glutAddSubMenu("Lights", lightMenu); glutAddMenuEntry("Exit", EXIT); + // Bind to right mouse button glutAttachMenu(GLUT_RIGHT_BUTTON); }