Superficial cleanup of the code. Mostly taking lines such as:

...

  /*
   * <Enslish recapituation of the single following C statement>
   */
  <single C statement>

...and rewrote as:

  ...
  <single C statement>


freeglut_main.c still has a lot of that in it, but it looks a bit
better, now.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@241 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-10-26 05:38:12 +00:00
parent 14801c8908
commit 9464f61d1f

View File

@ -70,7 +70,6 @@
* Calls a window's redraw method. This is used when * Calls a window's redraw method. This is used when
* a redraw is forced by the incoming window messages. * a redraw is forced by the incoming window messages.
*/ */
static void fghRedrawWindowByHandle static void fghRedrawWindowByHandle
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
( Window handle ) ( Window handle )
@ -78,38 +77,14 @@ static void fghRedrawWindowByHandle
( HWND handle ) ( HWND handle )
#endif #endif
{ {
/*
* Find the window we have to redraw...
*/
SFG_Window* window = fgWindowByHandle( handle ); SFG_Window* window = fgWindowByHandle( handle );
freeglut_return_if_fail( window != NULL ); freeglut_return_if_fail( window != NULL );
/*
* Check if there is a display callback hooked to it
*/
freeglut_return_if_fail( window->Callbacks.Display != NULL ); freeglut_return_if_fail( window->Callbacks.Display != NULL );
/*
* Return if the window is not visible
*/
freeglut_return_if_fail( window->State.Visible == TRUE ); freeglut_return_if_fail( window->State.Visible == TRUE );
/*
* Set the window as the current one.
*/
fgSetWindow( window ); fgSetWindow( window );
/*
* Do not exagerate with the redisplaying
*/
window->State.Redisplay = FALSE; window->State.Redisplay = FALSE;
/*
* Have the callback executed now. The buffers should
* be swapped by the glutSwapBuffers() execution inside
* the callback itself.
*/
window->Callbacks.Display(); window->Callbacks.Display();
} }
@ -125,50 +100,27 @@ static void fghReshapeWindowByHandle
( HWND handle, int width, int height ) ( HWND handle, int width, int height )
#endif #endif
{ {
SFG_Window *current_window = fgStructure.Window ; SFG_Window *current_window = fgStructure.Window ;
/*
* Find the window that received the reshape event
*/
SFG_Window* window = fgWindowByHandle( handle ); SFG_Window* window = fgWindowByHandle( handle );
freeglut_return_if_fail( window != NULL ); freeglut_return_if_fail( window != NULL );
/*
* Remember about setting the current window...
*/
fgSetWindow( window ); fgSetWindow( window );
/*
* Check if there is a reshape callback hooked
*/
if( window->Callbacks.Reshape != NULL ) if( window->Callbacks.Reshape != NULL )
{
/*
* OKi, have it called immediately
*/
window->Callbacks.Reshape( width, height ); window->Callbacks.Reshape( width, height );
}
else else
{
/*
* Otherwise just resize the viewport
*/
glViewport( 0, 0, width, height ); glViewport( 0, 0, width, height );
}
/* /*
* Force a window redraw. In Windows at least this is only a partial solution: if the * Force a window redraw. In Windows at least this is only a partial
* window is increasing in size in either dimension, the already-drawn part does not get * solution: if the window is increasing in size in either dimension,
* drawn again and things look funny. But without this we get this bad behaviour whenever * the already-drawn part does not get drawn again and things look funny.
* we resize the window. * But without this we get this bad behaviour whenever we resize the
* window.
*/ */
window->State.Redisplay = TRUE ; window->State.Redisplay = TRUE ;
/*
* If this is a menu, restore the active window
*/
if ( window->IsMenu ) if ( window->IsMenu )
fgSetWindow ( current_window ) ; fgSetWindow ( current_window ) ;
} }
/* /*
@ -177,38 +129,20 @@ static void fghReshapeWindowByHandle
static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator ) static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
{ {
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Check if there is an idle callback hooked
*/
if( (window->Callbacks.Display != NULL) && if( (window->Callbacks.Display != NULL) &&
(window->State.Redisplay == TRUE) && (window->State.Redisplay == TRUE) &&
(window->State.Visible == TRUE) ) (window->State.Visible == TRUE) )
{ {
SFG_Window *current_window = fgStructure.Window ; SFG_Window *current_window = fgStructure.Window ;
/*
* OKi, this is the case: have the window set as the current one
*/
fgSetWindow( window ); fgSetWindow( window );
/*
* Do not exagerate with the redisplaying
*/
window->State.Redisplay = FALSE; window->State.Redisplay = FALSE;
/*
* And execute the display callback immediately after
*/
window->Callbacks.Display(); window->Callbacks.Display();
fgSetWindow ( current_window ) ; fgSetWindow ( current_window ) ;
} }
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* Do we need to explicitly resize the window?
*/
if( window->State.NeedToResize ) if( window->State.NeedToResize )
{ {
SFG_Window *current_window = fgStructure.Window ; SFG_Window *current_window = fgStructure.Window ;
@ -221,26 +155,15 @@ static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
glutGet( GLUT_WINDOW_HEIGHT ) glutGet( GLUT_WINDOW_HEIGHT )
); );
/*
* Never ever do that again:
*/
window->State.NeedToResize = FALSE; window->State.NeedToResize = FALSE;
fgSetWindow ( current_window ) ; fgSetWindow ( current_window ) ;
} }
/*
* This is done in a bit different way under Windows
*/
if( (window->Callbacks.Display != NULL) && if( (window->Callbacks.Display != NULL) &&
(window->State.Redisplay == TRUE) && (window->State.Redisplay == TRUE) &&
(window->State.Visible == TRUE) ) (window->State.Visible == TRUE) )
{ {
/*
* Do not exagerate with the redisplaying
*/
window->State.Redisplay = FALSE; window->State.Redisplay = FALSE;
RedrawWindow( RedrawWindow(
window->Window.Handle, NULL, NULL, window->Window.Handle, NULL, NULL,
RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
@ -249,9 +172,6 @@ static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
#endif #endif
/*
* Process this window's children (if any)
*/
fgEnumSubWindows( window, fghcbDisplayWindow, enumerator ); fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
} }
@ -262,15 +182,8 @@ static void fghDisplayAll( void )
{ {
SFG_Enumerator enumerator; SFG_Enumerator enumerator;
/*
* Uses a method very similiar for fgWindowByHandle...
*/
enumerator.found = FALSE; enumerator.found = FALSE;
enumerator.data = NULL; enumerator.data = NULL;
/*
* Start the enumeration now:
*/
fgEnumWindows( fghcbDisplayWindow, &enumerator ); fgEnumWindows( fghcbDisplayWindow, &enumerator );
} }
@ -281,25 +194,11 @@ static void fghcbCheckJoystickPolls( SFG_Window *window, SFG_Enumerator *enumera
{ {
long int checkTime = fgElapsedTime(); long int checkTime = fgElapsedTime();
/*
* Check if actually need to do the poll for the currently enumerated window:
*/
if( window->State.JoystickLastPoll + window->State.JoystickPollRate <= checkTime ) if( window->State.JoystickLastPoll + window->State.JoystickPollRate <= checkTime )
{ {
/*
* Yeah, that's it. Poll the joystick...
*/
fgJoystickPollWindow( window ); fgJoystickPollWindow( window );
/*
* ...and reset the polling counters:
*/
window->State.JoystickLastPoll = checkTime; window->State.JoystickLastPoll = checkTime;
} }
/*
* Process this window's children (if any)
*/
fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator ); fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
} }
@ -310,15 +209,8 @@ static void fghCheckJoystickPolls( void )
{ {
SFG_Enumerator enumerator; SFG_Enumerator enumerator;
/*
* Uses a method very similiar for fgWindowByHandle...
*/
enumerator.found = FALSE; enumerator.found = FALSE;
enumerator.data = NULL; enumerator.data = NULL;
/*
* Start the enumeration now:
*/
fgEnumWindows( fghcbCheckJoystickPolls, &enumerator ); fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
} }
@ -336,19 +228,14 @@ static void fghCheckTimers( void )
/* /*
* For every timer that is waiting for triggering * For every timer that is waiting for triggering
*/ */
for( timer = (SFG_Timer *)fgState.Timers.First; timer; timer = (SFG_Timer *)next ) for( timer = (SFG_Timer *)fgState.Timers.First;
timer;
timer = (SFG_Timer *)next )
{ {
next = (SFG_Timer *)timer->Node.Next; next = (SFG_Timer *)timer->Node.Next;
/*
* Check for the timeout:
*/
if( timer->TriggerTime <= checkTime ) if( timer->TriggerTime <= checkTime )
{ {
/* fgListRemove( &fgState.Timers, &timer->Node );
* Add the timer to the timed out timers list
*/
fgListRemove( &fgState.Timers, &timer->Node );
fgListAppend( &timedOut, &timer->Node ); fgListAppend( &timedOut, &timer->Node );
} }
} }
@ -359,10 +246,10 @@ static void fghCheckTimers( void )
*/ */
while ( (timer = (SFG_Timer *)timedOut.First) ) while ( (timer = (SFG_Timer *)timedOut.First) )
{ {
if( timer->Callback != NULL ) if( timer->Callback != NULL )
timer->Callback( timer->ID ); timer->Callback( timer->ID );
fgListRemove( &timedOut, &timer->Node ); fgListRemove( &timedOut, &timer->Node );
free( timer ); free( timer );
} }
} }
@ -373,17 +260,17 @@ static void fghCheckTimers( void )
long fgElapsedTime( void ) long fgElapsedTime( void )
{ {
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
struct timeval now; struct timeval now;
long elapsed; long elapsed;
gettimeofday( &now, NULL ); gettimeofday( &now, NULL );
elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000; return( elapsed );
elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
return( elapsed );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
return (timeGetTime() - fgState.Time.Value); return (timeGetTime() - fgState.Time.Value);
#endif #endif
} }
@ -545,27 +432,18 @@ void FGAPIENTRY glutMainLoopEvent( void )
/* /*
* This code was repeated constantly, so here it goes into a definition: * This code was repeated constantly, so here it goes into a definition:
*/ */
# define GETWINDOW(a) window = fgWindowByHandle( event.a.window );if( window == NULL ) break; # define GETWINDOW(a) \
# define GETMOUSE(a) window->State.MouseX = event.a.x; window->State.MouseY = event.a.y; window = fgWindowByHandle( event.a.window ); \
if( window == NULL ) \
break;
# define GETMOUSE(a) \
window->State.MouseX = event.a.x; \
window->State.MouseY = event.a.y;
/*
* Make sure the display has been created etc.
*/
freeglut_assert_ready; freeglut_assert_ready;
/*
* Do we have any event messages pending?
*/
while( XPending( fgDisplay.Display ) ) while( XPending( fgDisplay.Display ) )
{ {
/*
* Grab the next event to be processed...
*/
XNextEvent( fgDisplay.Display, &event ); XNextEvent( fgDisplay.Display, &event );
/*
* Check the event's type
*/
switch( event.type ) switch( event.type )
{ {
case DestroyNotify: case DestroyNotify: