From 599da39add7dc804a35f79bd1033a33d9ab048ac Mon Sep 17 00:00:00 2001 From: Ash Tyndall Date: Sat, 8 Oct 2011 15:01:40 +0800 Subject: [PATCH] Completed menu functionality, added two functions roundUp and makeSubmenuFromArray to assist with this --- scene.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scene.c b/scene.c index 602dc49..f9df3c8 100644 --- a/scene.c +++ b/scene.c @@ -246,6 +246,12 @@ void processLightEvents(int id) { } +/** + * Rounds up numbers, from http://stackoverflow.com/questions/3407012/c-rounding-up-to-the-nearest-multiple-of-a-number + * @param numToRound Number to round + * @param multiple Multiple to round up to + * @return Rounded number + */ int roundUp(int numToRound, int multiple) { if(multiple == 0) { return numToRound; @@ -257,6 +263,14 @@ int roundUp(int numToRound, int multiple) { return numToRound + multiple - remainder; } +/** + * Makes a submenu from an array of items, splitting the list into subsubmenus + * of only 10 items. + * @param menuEntries Array of menu items + * @param menuEntriesSize Size of menuEntries + * @param callback Callback function for this array of menu items + * @return Reference to menu created + */ int makeSubmenuFromArray( const char *menuEntries[], unsigned int menuEntriesSize, void *callback ) { if ( menuEntriesSize == 0 ) return -1; @@ -270,7 +284,7 @@ int makeSubmenuFromArray( const char *menuEntries[], unsigned int menuEntriesSiz if ( j == menuEntriesSize ) break; // Detect if we've reached the end of the array glutAddMenuEntry( menuEntries[j], j + 1 ); } - } + } int mainMenu = glutCreateMenu(callback); for ( int i = 0; i < menuNumber; i++ ) { -- 2.20.1