X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_structure.c;h=4274667efe339887404f484c8b14e2c11a5b6a57;hb=831749819dcdc1ea884c18607c2b447bbf5fca72;hp=5a6ce95ae07f1d91fd073bb0f9aa124cfd85bca1;hpb=67f242b7dd68bea7dea467f9b5265c8448b6655e;p=freeglut diff --git a/src/fg_structure.c b/src/fg_structure.c index 5a6ce95..4274667 100644 --- a/src/fg_structure.c +++ b/src/fg_structure.c @@ -49,7 +49,7 @@ SFG_Structure fgStructure = { { NULL, NULL }, /* The list of windows */ /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ extern void fgPlatformCreateWindow ( SFG_Window *window ); -extern void fghDefaultReshape(int width, int height); +extern void fghDefaultReshape(int width, int height, FGCBUserData userData); static void fghClearCallBacks( SFG_Window *window ) { @@ -57,7 +57,10 @@ static void fghClearCallBacks( SFG_Window *window ) { int i; for( i = 0; i < TOTAL_CALLBACKS; ++i ) + { window->CallBacks[ i ] = NULL; + window->CallbackDatas[ i ] = NULL; + } } } @@ -75,10 +78,15 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, /* Have the window object created */ SFG_Window *window = (SFG_Window *)calloc( 1, sizeof(SFG_Window) ); + if( !window ) + { + fgError( "Out of memory. Could not create window." ); + } + fgPlatformCreateWindow ( window ); fghClearCallBacks( window ); - SET_WCB( *window, Reshape, fghDefaultReshape); + SET_WCB( *window, Reshape, fghDefaultReshape, NULL); /* Initialize the object properties */ window->ID = ++fgStructure.WindowID; @@ -100,7 +108,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, /* * Open the window now. The fgOpenWindow() function is system - * dependant, and resides in fg_window.c. Uses fgState. + * dependent, and resides in fg_window.c. Uses fgState. */ fgOpenWindow( window, title, positionUse, x, y, sizeUse, w, h, gameMode, (GLboolean)(parent ? GL_TRUE : GL_FALSE) ); @@ -111,7 +119,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, /* * This private function creates a menu and adds it to the menus list */ -SFG_Menu* fgCreateMenu( FGCBMenu menuCallback ) +SFG_Menu* fgCreateMenu( FGCBMenuUC menuCallback, FGCBUserData userData ) { SFG_Window *current_window = fgStructure.CurrentWindow; @@ -129,10 +137,11 @@ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback ) fgSetWindow( current_window ); /* Initialize the object properties: */ - menu->ID = ++fgStructure.MenuID; - menu->Callback = menuCallback; - menu->ActiveEntry = NULL; - menu->Font = fgState.MenuFont; + menu->ID = ++fgStructure.MenuID; + menu->Callback = menuCallback; + menu->CallbackData = userData; + menu->ActiveEntry = NULL; + menu->Font = fgState.MenuFont; fgListInit( &menu->Entries ); fgListAppend( &fgStructure.Menus, &menu->Node ); @@ -168,9 +177,10 @@ void fgAddToWindowDestroyList( SFG_Window* window ) * to ensure that they are no longer called after this point. */ { - FGCBDestroy destroy = (FGCBDestroy)FETCH_WCB( *window, Destroy ); + FGCBDestroyUC destroy = (FGCBDestroyUC)FETCH_WCB( *window, Destroy ); + FGCBUserData destroyData = FETCH_USER_DATA_WCB( *window, Destroy ); fghClearCallBacks( window ); - SET_WCB( *window, Destroy, destroy ); + SET_WCB( *window, Destroy, destroy, destroyData ); } } @@ -297,7 +307,7 @@ void fgDestroyMenu( SFG_Menu* menu ) { SFG_Menu *activeMenu=fgStructure.CurrentMenu; fgStructure.CurrentMenu = menu; - menu->Destroy( ); + menu->Destroy( menu->DestroyData ); fgStructure.CurrentMenu = activeMenu; } @@ -332,7 +342,7 @@ void fgDestroyMenu( SFG_Menu* menu ) * This function should be called on glutInit(). It will prepare the internal * structure of freeglut to be used in the application. The structure will be * destroyed using fgDestroyStructure() on glutMainLoop() return. In that - * case further use of freeglut should be preceeded with a glutInit() call. + * case further use of freeglut should be preceded with a glutInit() call. */ void fgCreateStructure( void ) {