From bac05204a224d9cabe6b7d52c00d2e0601825cb4 Mon Sep 17 00:00:00 2001 From: Diederick Niehorster Date: Wed, 6 Mar 2013 09:17:13 +0000 Subject: [PATCH] now have a default reshape callback function that is used if the user didn't set any, instead of having what to do spread out over the code git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1557 7f0cb862-5218-0410-a997-914c9d46530a --- src/fg_callbacks.c | 16 +++++++++++++++- src/fg_main.c | 8 +------- src/fg_structure.c | 4 +++- src/mswin/fg_window_mswin.c | 1 + src/x11/fg_main_x11.c | 8 +------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/fg_callbacks.c b/src/fg_callbacks.c index c83b3f0..c62d37c 100644 --- a/src/fg_callbacks.c +++ b/src/fg_callbacks.c @@ -121,7 +121,6 @@ void FGAPIENTRY glut##a##Func( FGCB##b callback ) \ #define IMPLEMENT_CALLBACK_FUNC(a) IMPLEMENT_CALLBACK_FUNC_2NAME(a,a) /* Implement all these callback setter functions... */ -IMPLEMENT_CALLBACK_FUNC(Reshape); IMPLEMENT_CALLBACK_FUNC(Position); IMPLEMENT_CALLBACK_FUNC(Keyboard); IMPLEMENT_CALLBACK_FUNC(KeyboardUp); @@ -163,6 +162,21 @@ void FGAPIENTRY glutDisplayFunc( FGCBDisplay callback ) SET_CALLBACK( Display ); } +void fghDefaultReshape(int width, int height) +{ + glViewport( 0, 0, width, height ); +} + +void FGAPIENTRY glutReshapeFunc( FGCBReshape callback ) +{ + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeFunc" ); + + if( !callback ) + callback = fghDefaultReshape; + + SET_CALLBACK( Reshape ); +} + /* * Sets the Visibility callback for the current window. * NB: the Visibility func is deprecated in favor of the WindowStatus func, diff --git a/src/fg_main.c b/src/fg_main.c index f6a94a6..9acfc31 100644 --- a/src/fg_main.c +++ b/src/fg_main.c @@ -74,13 +74,7 @@ static void fghReshapeWindow ( SFG_Window *window, int width, int height ) fgPlatformReshapeWindow ( window, width, height ); - if( FETCH_WCB( *window, Reshape ) ) - INVOKE_WCB( *window, Reshape, ( width, height ) ); - else - { - fgSetWindow( window ); - glViewport( 0, 0, width, height ); - } + INVOKE_WCB( *window, Reshape, ( width, height ) ); /* * Force a window redraw. In Windows at least this is only a partial diff --git a/src/fg_structure.c b/src/fg_structure.c index e779037..be9d1ce 100644 --- a/src/fg_structure.c +++ b/src/fg_structure.c @@ -49,6 +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); static void fghClearCallBacks( SFG_Window *window ) { @@ -77,6 +78,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, fgPlatformCreateWindow ( window ); fghClearCallBacks( window ); + SET_WCB( *window, Reshape, fghDefaultReshape); /* Initialize the object properties */ window->ID = ++fgStructure.WindowID; @@ -94,7 +96,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, window->State.Cursor = GLUT_CURSOR_INHERIT; /* Mark window as menu if a menu is to be created */ - window->IsMenu = isMenu; + window->IsMenu = isMenu; /* * Open the window now. The fgOpenWindow() function is system diff --git a/src/mswin/fg_window_mswin.c b/src/mswin/fg_window_mswin.c index 518e0d3..8342503 100644 --- a/src/mswin/fg_window_mswin.c +++ b/src/mswin/fg_window_mswin.c @@ -742,6 +742,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, void fgPlatformDisplayWindow ( SFG_Window *window ) { + /* This immediately generates a WM_PAINT message upon which we call the display callbacks to redraw the window */ RedrawWindow( window->Window.Handle, NULL, NULL, RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW diff --git a/src/x11/fg_main_x11.c b/src/x11/fg_main_x11.c index c803b2b..0bf967d 100644 --- a/src/x11/fg_main_x11.c +++ b/src/x11/fg_main_x11.c @@ -662,13 +662,7 @@ void fgPlatformProcessSingleEvent ( void ) window->State.pWState.OldWidth = width; window->State.pWState.OldHeight = height; - if( FETCH_WCB( *window, Reshape ) ) - INVOKE_WCB( *window, Reshape, ( width, height ) ); - else - { - fgSetWindow( window ); - glViewport( 0, 0, width, height ); - } + INVOKE_WCB( *window, Reshape, ( width, height ) ); glutPostRedisplay( ); if( window->IsMenu ) fgSetWindow( current_window ); -- 1.7.10.4