X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_structure.c;h=8a5b4f5c1d573487a73dc3f27f343c1f5560c08e;hb=75ee380e8ec27aad5c793bb8d966efd927d82cba;hp=1e0565321fda2f3c18504c137f4781738515a83b;hpb=1b5ee849ba61b667aeba474a7e03406196478bee;p=freeglut diff --git a/src/fg_structure.c b/src/fg_structure.c index 1e05653..8a5b4f5 100644 --- a/src/fg_structure.c +++ b/src/fg_structure.c @@ -98,6 +98,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, window->State.IgnoreKeyRepeat = GL_FALSE; window->State.KeyRepeating = GL_FALSE; window->State.IsFullscreen = GL_FALSE; + window->State.VisualizeNormals= GL_FALSE; /* * Open the window now. The fgOpenWindow() function is system @@ -378,7 +379,7 @@ void fgDestroyStructure( void ) /* * Helper function to enumerate through all registered top-level windows */ -void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator ) +void fgEnumWindows( FGCBWindowEnumerator enumCallback, SFG_Enumerator* enumerator ) { SFG_Window *window; @@ -398,10 +399,32 @@ void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator ) } /* +* Helper function to enumerate through all registered top-level windows +*/ +void fgEnumMenus( FGCBMenuEnumerator enumCallback, SFG_Enumerator* enumerator ) +{ + SFG_Menu *menu; + + FREEGLUT_INTERNAL_ERROR_EXIT ( enumCallback && enumerator, + "Enumerator or callback missing from window enumerator call", + "fgEnumWindows" ); + + /* It's enough to check all entries in fgStructure.Menus... */ + for( menu = (SFG_Menu *)fgStructure.Menus.First; + menu; + menu = (SFG_Menu *)menu->Node.Next ) + { + enumCallback( menu, enumerator ); + if( enumerator->found ) + return; + } +} + +/* * Helper function to enumerate through all a window's subwindows * (single level descent) */ -void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback, +void fgEnumSubWindows( SFG_Window* window, FGCBWindowEnumerator enumCallback, SFG_Enumerator* enumerator ) { SFG_Window *child; @@ -485,7 +508,7 @@ static void fghcbWindowByID( SFG_Window *window, SFG_Enumerator *enumerator ) } /* - * This function is similiar to the previous one, except it is + * This function is similar to the previous one, except it is * looking for a specified (sub)window identifier. The function * is defined in freeglut_structure.c file. */ @@ -493,7 +516,7 @@ SFG_Window* fgWindowByID( int windowID ) { SFG_Enumerator enumerator; - /* Uses a method very similiar for fgWindowByHandle... */ + /* Uses a method very similar for fgWindowByHandle... */ enumerator.found = GL_FALSE; enumerator.data = ( void * )&windowID; fgEnumWindows( fghcbWindowByID, &enumerator ); @@ -503,19 +526,77 @@ SFG_Window* fgWindowByID( int windowID ) } /* - * Looks up a menu given its ID. This is easier that fgWindowByXXX + * A static helper function to look for a menu given its ID + */ +static void fghcbMenuByID( SFG_Menu *menu, + SFG_Enumerator *enumerator ) +{ + if ( enumerator->found ) + return; + + /* Check the menu's ID. */ + if( menu->ID == (int)(enumerator->data) ) + { + enumerator->found = GL_TRUE; + enumerator->data = menu; + + return; + } +} + +/* + * Looks up a menu given its ID. This is easier than fgWindowByXXX * as all menus are placed in one doubly linked list... */ SFG_Menu* fgMenuByID( int menuID ) { - SFG_Menu *menu = NULL; + SFG_Enumerator enumerator; + + /* This is easy and makes use of the menus enumeration defined above */ + enumerator.found = GL_FALSE; + enumerator.data = (void *)menuID; + fgEnumMenus( fghcbMenuByID, &enumerator ); + + if( enumerator.found ) + return( SFG_Menu *) enumerator.data; + + return NULL; +} + +/* + * A static helper function to look for an active menu + */ +static void fghcbGetActiveMenu( SFG_Menu *menu, + SFG_Enumerator *enumerator ) +{ + if ( enumerator->found ) + return; + + /* Check the menu's ID. */ + if( menu->IsActive ) + { + enumerator->found = GL_TRUE; + enumerator->data = menu; + + return; + } +} + +/* + * Returns active menu, if any. Assumption: only one menu active throughout application at any one time. + * This is easier than fgWindowByXXX as all menus are placed in one doubly linked list... + */ +SFG_Menu* fgGetActiveMenu( ) +{ + SFG_Enumerator enumerator; + + /* This is easy and makes use of the menus enumeration defined above */ + enumerator.found = GL_FALSE; + fgEnumMenus( fghcbGetActiveMenu, &enumerator ); + + if( enumerator.found ) + return( SFG_Menu *) enumerator.data; - /* It's enough to check all entries in fgStructure.Menus... */ - for( menu = (SFG_Menu *)fgStructure.Menus.First; - menu; - menu = (SFG_Menu *)menu->Node.Next ) - if( menu->ID == menuID ) - return menu; return NULL; }