/* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
/*
- * Calls a window's redraw method. This is used when
- * a redraw is forced by the incoming window messages.
- *
- * XXX We can/should make a "unified" window handle type so that
- * XXX the function headers don't need this silly #ifdef junk.
- * XXX Make the type, say, {fgWindow}. On UNIX_X11, this is
- * XXX {Window}. On WIN32, it is {HWND}. Then do the #ifdef
- * XXX junk *once* in "freeglut_internal.h".
- */
-static void fghRedrawWindowByHandle
-#if TARGET_HOST_UNIX_X11
- ( Window handle )
-#elif TARGET_HOST_WIN32
- ( HWND handle )
-#endif
-{
- SFG_Window* window = fgWindowByHandle( handle );
- freeglut_return_if_fail( window != NULL );
-
- /*
- * XXX Other than clearing the Redisplay flag or not,
- * XXX we may as well rely on the INVOK_WCB() doing this
- * XXX pointer-check.
- * XXX
- * XXX If we do not invoke the display because the pointer
- * XXX is not defined (should never happen, really), then
- * XXX we may enter an infinite busy-loop trying to update
- * XXX the window. Similarly, if we skip because the window
- * XXX is not visible. However, if the window becomes visible
- * XXX at a later time, the window should get its callback
- * XXX invoked. I would recommend removing the first check,
- * XXX and making the second check only affect whether the
- * XXX callback is invoked---but always clear the flag, if
- * XXX the {window} pointer is defined.
- */
- freeglut_return_if_fail( FETCH_WCB( *window, Display ) );
- freeglut_return_if_fail( window->State.Visible );
-
- window->State.Redisplay = GL_FALSE;
- INVOKE_WCB( *window, Display, ( ) );
-}
-
-/*
* Handle a window configuration change. When no reshape
* callback is hooked, the viewport size is updated to
* match the new window size.
*/
-static void fghReshapeWindowByHandle
-#if TARGET_HOST_UNIX_X11
- ( Window handle, int width, int height )
-#elif TARGET_HOST_WIN32
- ( HWND handle, int width, int height )
-#endif
+static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
+ int width, int height )
{
SFG_Window *current_window = fgStructure.Window;
SFG_Window* window = fgWindowByHandle( handle );
freeglut_return_if_fail( window != NULL );
+
+#if TARGET_HOST_UNIX_X11
+
+ XResizeWindow( fgDisplay.Display, window->Window.Handle,
+ width, height );
+ XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
+
+#elif TARGET_HOST_WIN32
+
+ {
+ RECT winRect;
+ int x, y;
+
+ GetWindowRect( window->Window.Handle, &winRect );
+ x = winRect.left;
+ y = winRect.top;
+
+ if ( window->Parent == NULL )
+ {
+ /*
+ * Adjust the size of the window to allow for the size of the
+ * frame, if we are not a menu
+ */
+ if ( ! window->IsMenu )
+ {
+ width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
+ height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
+ GetSystemMetrics( SM_CYCAPTION );
+ }
+ }
+ else
+ {
+ GetWindowRect( window->Parent->Window.Handle,
+ &winRect );
+ x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME );
+ y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) +
+ GetSystemMetrics( SM_CYCAPTION );
+ }
+
+ MoveWindow(
+ window->Window.Handle,
+ x,
+ y,
+ width,
+ height,
+ TRUE
+ );
+ }
+
+#endif
+
if( !( FETCH_WCB( *window, Reshape ) ) )
{
fgSetWindow( window );
}
/*
- * A static helper function to execute display callback for a window
+ * Calls a window's redraw method. This is used when
+ * a redraw is forced by the incoming window messages.
*/
-static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
+static void fghRedrawWindowByHandle ( SFG_WindowHandleType handle )
{
-#if TARGET_HOST_UNIX_X11
- /*
- * XXX Do we need/want to check the callback pointer here?
- * XXX INVOKE_WCB() will check for us. Arguably, the
- * XXX Redisplay status flag should be cleared regardless
- * XXX of any concern but that {window} is a valid pointer
- * XXX (which this function is assuming anyway).
- * XXX Especially since old GLUT wouldn't even enter its main
- * XXX loop if you didn't have a display callback defined...
- */
- if( ( FETCH_WCB( *window, Display ) ) &&
- window->State.Redisplay &&
- window->State.Visible )
- {
- SFG_Window *current_window = fgStructure.Window;
+ SFG_Window* window = fgWindowByHandle( handle );
+ freeglut_return_if_fail( window );
+ freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
- window->State.Redisplay = GL_FALSE;
- INVOKE_WCB( *window, Display, ( ) );
- fgSetWindow( current_window );
- }
+ window->State.Redisplay = GL_FALSE;
-#elif TARGET_HOST_WIN32
+ freeglut_return_if_fail( window->State.Visible );
if( window->State.NeedToResize )
{
fghReshapeWindowByHandle(
window->Window.Handle,
- glutGet( GLUT_WINDOW_WIDTH ),
- glutGet( GLUT_WINDOW_HEIGHT )
+ window->State.Width,
+ window->State.Height
);
window->State.NeedToResize = GL_FALSE;
fgSetWindow ( current_window );
}
- /*
- * XXX See above comment about the Redisplay flag...
- */
- if( ( FETCH_WCB( *window, Display ) ) &&
- window->State.Redisplay &&
+ INVOKE_WCB( *window, Display, ( ) );
+}
+
+/*
+ * A static helper function to execute display callback for a window
+ */
+static void fghcbDisplayWindow( SFG_Window *window,
+ SFG_Enumerator *enumerator )
+{
+ if( window->State.Redisplay &&
window->State.Visible )
{
+ if( window->State.NeedToResize )
+ {
+ SFG_Window *current_window = fgStructure.Window;
+
+ fgSetWindow( window );
+
+ fghReshapeWindowByHandle(
+ window->Window.Handle,
+ window->State.Width,
+ window->State.Height
+ );
+
+ window->State.NeedToResize = GL_FALSE;
+ fgSetWindow ( current_window );
+ }
+
window->State.Redisplay = GL_FALSE;
+#if TARGET_HOST_UNIX_X11
+ {
+ SFG_Window *current_window = fgStructure.Window;
+
+ INVOKE_WCB( *window, Display, ( ) );
+ fgSetWindow( current_window );
+ }
+#elif TARGET_HOST_WIN32
RedrawWindow(
window->Window.Handle, NULL, NULL,
RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
);
- }
-
#endif
+ }
fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
}
SFG_Enumerator enumerator;
enumerator.found = GL_FALSE;
- enumerator.data = NULL;
+ enumerator.data = NULL;
fgEnumWindows( fghcbDisplayWindow, &enumerator );
}
SFG_Enumerator enumerator;
enumerator.found = GL_FALSE;
- enumerator.data = NULL;
+ enumerator.data = NULL;
fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
}
*/
long fgElapsedTime( void )
{
- if (fgState.Time.Set)
+ if ( fgState.Time.Set )
{
#if TARGET_HOST_UNIX_X11
struct timeval now;
long elapsed;
-
+
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;
+ elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
+
return elapsed;
#elif TARGET_HOST_WIN32
- return timeGetTime( ) - fgState.Time.Value;
+ return timeGetTime() - fgState.Time.Value;
#endif
}
else
#if TARGET_HOST_UNIX_X11
gettimeofday( &fgState.Time.Value, NULL );
#elif TARGET_HOST_WIN32
- fgState.Time.Value = timeGetTime( );
+ fgState.Time.Value = timeGetTime ();
#endif
- fgState.Time.Set = GL_TRUE;
+ fgState.Time.Set = GL_TRUE ;
+
+ return 0 ;
}
}
va_start( ap, fmt );
- fprintf( stderr, "freeglut " );
+ fprintf( stderr, "freeglut ");
if( fgState.ProgramName )
- fprintf( stderr, "(%s): ", fgState.ProgramName );
+ fprintf (stderr, "(%s): ", fgState.ProgramName);
vfprintf( stderr, fmt, ap );
fprintf( stderr, "\n" );
va_end( ap );
- if ( fgState.Initalized )
- fgDeinitialize( );
+ if ( fgState.Initialised )
+ fgDeinitialize ();
exit( 1 );
}
va_start( ap, fmt );
- fprintf( stderr, "freeglut " );
+ fprintf( stderr, "freeglut ");
if( fgState.ProgramName )
fprintf( stderr, "(%s): ", fgState.ProgramName );
vfprintf( stderr, fmt, ap );
* an opaque wall.
*
*/
-static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e )
+static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
{
if( FETCH_WCB( *w, Joystick ) )
{
fgEnumWindows( fgCheckJoystickCallback, &enumerator );
return !!enumerator.data;
}
-static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e )
+static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
{
if( w->State.Redisplay )
{
}
fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
}
-static int fgHavePendingRedisplays( void )
+static int fgHavePendingRedisplays (void)
{
SFG_Enumerator enumerator;
enumerator.found = GL_FALSE;
/*
* Indicates whether there are any outstanding timers.
*/
+#if 0 /* Not used */
static int fgHaveTimers( void )
{
return !!fgState.Timers.First;
}
+#endif
/*
* Returns the number of GLUT ticks (milliseconds) till the next timer event.
*/
static long fgNextTimer( void )
{
- long now = fgElapsedTime( );
+ long now = fgElapsedTime();
long ret = INT_MAX;
SFG_Timer *timer;
- for( timer = ( SFG_Timer * )fgState.Timers.First;
+ for( timer = (SFG_Timer *)fgState.Timers.First;
timer;
- timer = ( SFG_Timer * )timer->Node.Next )
+ timer = (SFG_Timer *)timer->Node.Next )
ret = MIN( ret, MAX( 0, timer->TriggerTime - now ) );
return ret;
if( fgHaveJoystick( ) )
msec = MIN( msec, 10 );
- wait.tv_sec = msec / 1000;
- wait.tv_usec = ( msec % 1000 ) * 1000;
+ wait.tv_sec = msec / 1000;
+ wait.tv_usec = (msec % 1000) * 1000;
err = select( socket+1, &fdset, NULL, NULL, &wait );
if( -1 == err )
- fgWarning( "freeglut select() error: %d\n", errno );
+ fgWarning ( "freeglut select() error: %d\n", errno );
#elif TARGET_HOST_WIN32
#endif
*/
case CreateNotify:
case ConfigureNotify:
- fghReshapeWindowByHandle(
- event.xconfigure.window,
- event.xconfigure.width,
- event.xconfigure.height
- );
+ GETWINDOW( xconfigure );
+ window->State.NeedToResize = GL_TRUE ;
+ window->State.Width = event.xconfigure.width ;
+ window->State.Height = event.xconfigure.height;
break;
case DestroyNotify:
window->ActiveMenu->Window->State.MouseY =
event.xmotion.y_root - window->ActiveMenu->Y;
}
- window->ActiveMenu->Window->State.Redisplay = GL_TRUE;
+ window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
fgSetWindow( window->ActiveMenu->ParentWindow );
break;
*/
#define BUTTON_MASK \
( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
- if( event.xmotion.state & BUTTON_MASK )
+ if ( event.xmotion.state & BUTTON_MASK )
INVOKE_WCB( *window, Motion, ( event.xmotion.x,
event.xmotion.y ) );
else
int button;
if( event.type == ButtonRelease )
- pressed = GL_FALSE;
+ pressed = GL_FALSE ;
/*
* A mouse button has been pressed or released. Traditionally,
! FETCH_WCB( *window, MouseWheel ) )
break;
- /*
- * XXX Why don't we use {window}? Other code here does...
- */
fgState.Modifiers = fgGetXModifiers( &event );
/*
* XXX Note that {button} has already been decremeted
* XXX in mapping from X button numbering to GLUT.
*/
- int wheel_number = ( button - 3 ) / 2;
+ int wheel_number = (button - 3) / 2;
int direction = -1;
if( button % 2 )
direction = 1;
* Execute the callback (if one has been specified),
* given that the special code seems to be valid...
*/
- if( special_cb && ( special != -1 ) )
+ if( special_cb && (special != -1) )
{
fgSetWindow( window );
fgState.Modifiers = fgGetXModifiers( &event );
break; /* XXX Should disable this event */
default:
- fgWarning( "Unknown X event type: %d", event.type );
+ fgWarning ("Unknown X event type: %d", event.type);
break;
}
}
while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
- fgState.ExecState = GLUT_EXEC_STATE_STOP;
+ fgState.ExecState = GLUT_EXEC_STATE_STOP ;
TranslateMessage( &stMsg );
DispatchMessage( &stMsg );
void FGAPIENTRY glutMainLoop( void )
{
#if TARGET_HOST_WIN32
- SFG_Window *window = (SFG_Window *)fgStructure.Windows.First;
+ SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
#endif
freeglut_assert_ready;
*/
while( window )
{
- if( FETCH_WCB( *window, Visibility ) )
+ if ( FETCH_WCB( *window, Visibility ) )
{
- SFG_Window *current_window = fgStructure.Window;
+ SFG_Window *current_window = fgStructure.Window ;
INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
fgSetWindow( current_window );
}
- window = (SFG_Window *)window->Node.Next;
+ window = (SFG_Window *)window->Node.Next ;
}
#endif
- fgState.ExecState = GLUT_EXEC_STATE_RUNNING;
+ fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
{
glutMainLoopEvent( );
if( fgState.IdleCallback )
fgState.IdleCallback( );
- fgSleepForEvents( );
+ fgSleepForEvents();
}
}
*/
void FGAPIENTRY glutLeaveMainLoop( void )
{
- fgState.ExecState = GLUT_EXEC_STATE_STOP;
+ fgState.ExecState = GLUT_EXEC_STATE_STOP ;
}
wglCreateContext( window->Window.Device );
}
- /* window->Window.Context = wglGetCurrentContext( ); */
+ /* window->Window.Context = wglGetCurrentContext (); */
window->Window.Context = wglCreateContext( window->Window.Device );
}
else
}
window->State.NeedToResize = GL_TRUE;
+ window->State.Width = fgState.Size.X;
+ window->State.Height = fgState.Size.Y;
+
ReleaseDC( window->Window.Handle, window->Window.Device );
break;
/*
* We got resized... But check if the window has been already added...
*/
- fghReshapeWindowByHandle( hWnd, LOWORD(lParam), HIWORD(lParam) );
+ window->State.NeedToResize = GL_TRUE;
+ window->State.Width = LOWORD(lParam);
+ window->State.Height = HIWORD(lParam);
break;
#if 0
case WM_SETFOCUS:
- printf( "WM_SETFOCUS: %p\n", window );
+ printf("WM_SETFOCUS: %p\n", window );
lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
break;
case WM_ACTIVATE:
- if( LOWORD( wParam ) != WA_INACTIVE )
+ if (LOWORD(wParam) != WA_INACTIVE)
{
/* glutSetCursor( fgStructure.Window->State.Cursor ); */
printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
break;
#endif
- case WM_SETCURSOR:
- /*
- * Windows seems to need reminding to erase the cursor for NONE.
- */
-
/*
- * XXX Is this #if 0 section anything that we need to worry
- * XXX about? Can we delete it? If it will ever be used,
- * XXX why not re-use some common code with the glutSetCursor()
+ * XXX Why not re-use some common code with the glutSetCursor()
* XXX function (or perhaps invoke glutSetCursor())?
+ * XXX That is, why are we duplicating code, here, from
+ * XXX glutSetCursor()? The WIN32 code should be able to just
+ * XXX call glutSetCurdsor() instead of defining two macros
+ * XXX and implementing a nested case in-line.
*/
-#if 0
- if( ( LOWORD( lParam ) == HTCLIENT ) &&
- ( fgStructure.Window->State.Cursor == GLUT_CURSOR_NONE ) )
- SetCursor( NULL );
-#else
-
+ case WM_SETCURSOR:
/* Set the cursor AND change it for this window class. */
-#define MAP_CURSOR(a,b) \
- case a: \
- SetCursor( LoadCursor( NULL, b ) ); \
- break;
+#define MAP_CURSOR(a,b) \
+ case a: \
+ SetCursor( LoadCursor( NULL, b ) ); \
+ break;
/* Nuke the cursor AND change it for this window class. */
-#define ZAP_CURSOR(a,b) \
- case a: \
- SetCursor( NULL ); \
- break;
+#define ZAP_CURSOR(a,b) \
+ case a: \
+ SetCursor( NULL ); \
+ break;
if( LOWORD( lParam ) == HTCLIENT )
switch( window->State.Cursor )
default:
MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
}
-#endif
else
lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
break;
*/
if( fgStructure.Window == window )
{
- int used = FALSE;
- SFG_Window *iter;
+ int used = FALSE ;
+ SFG_Window *iter ;
wglMakeCurrent( NULL, NULL );
/*
used = TRUE;
}
- if( used == FALSE )
+ if( ! used )
wglDeleteContext( window->Window.Context );
}
window->State.MouseX = LOWORD( lParam );
window->State.MouseY = HIWORD( lParam );
- /*
- * XXX Either these multi-statement lines should be broken
- * XXX in the form:
- * XXX pressed = GL_TRUE;
- * XXX button = GLUT_LEFT_BUTTON;
- * XXX break;
- * XXX ...or we should use a macro (much as I dislike freeglut's
- * XXX preponderance of using macros to "compress" code).
- */
switch( uMsg )
{
case WM_LBUTTONDOWN:
- pressed = GL_TRUE; button = GLUT_LEFT_BUTTON; break;
+ pressed = GL_TRUE;
+ button = GLUT_LEFT_BUTTON;
+ break;
case WM_MBUTTONDOWN:
- pressed = GL_TRUE; button = GLUT_MIDDLE_BUTTON; break;
+ pressed = GL_TRUE;
+ button = GLUT_MIDDLE_BUTTON;
+ break;
case WM_RBUTTONDOWN:
- pressed = GL_TRUE; button = GLUT_RIGHT_BUTTON; break;
+ pressed = GL_TRUE;
+ button = GLUT_RIGHT_BUTTON;
+ break;
case WM_LBUTTONUP:
- pressed = GL_FALSE; button = GLUT_LEFT_BUTTON; break;
+ pressed = GL_FALSE;
+ button = GLUT_LEFT_BUTTON;
+ break;
case WM_MBUTTONUP:
- pressed = GL_FALSE; button = GLUT_MIDDLE_BUTTON; break;
+ pressed = GL_FALSE;
+ button = GLUT_MIDDLE_BUTTON;
+ break;
case WM_RBUTTONUP:
- pressed = GL_FALSE; button = GLUT_RIGHT_BUTTON; break;
+ pressed = GL_FALSE;
+ button = GLUT_RIGHT_BUTTON;
+ break;
default:
- pressed = GL_FALSE; button = -1; break;
+ pressed = GL_FALSE;
+ button = -1;
+ break;
}
if( GetSystemMetrics( SM_SWAPBUTTON ) )
fgState.Modifiers = 0xffffffff;
}
- break;
+ break ;
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
{
int keypress = -1;
- POINT mouse_pos;
+ POINT mouse_pos ;
if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
break;
if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
break;
- /*
- * XXX INVOKE_WCB() takes care of the callback-pointer check.
- * XXX We could just uncoditionally find/trash the Modifiers
- * XXX and get rid of the "if( ... ) {" and "}". Unconditinal
- * XXX code is simpler code. (^&
- */
- if( FETCH_WCB( *window, Keyboard ) )
- {
- fgState.Modifiers = fgGetWin32Modifiers( );
- INVOKE_WCB( *window, Keyboard,
- ( (char)wParam,
- window->State.MouseX, window->State.MouseY )
- );
- fgState.Modifiers = 0xffffffff;
- }
+ fgState.Modifiers = fgGetWin32Modifiers( );
+ INVOKE_WCB( *window, Keyboard,
+ ( (char)wParam,
+ window->State.MouseX, window->State.MouseY )
+ );
+ fgState.Modifiers = 0xffffffff;
}
break;
/* User has finished resizing the window, force a redraw */
INVOKE_WCB( *window, Display, ( ) );
- /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; */
+ /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
break;
/*
*/
switch ( lParam )
{
- case SC_SIZE:
- break;
+ case SC_SIZE :
+ break ;
- case SC_MOVE:
- break;
+ case SC_MOVE :
+ break ;
- case SC_MINIMIZE:
+ case SC_MINIMIZE :
/* User has clicked on the "-" to minimize the window */
/* Turn off the visibility */
- window->State.Visible = GL_FALSE;
- break;
+ window->State.Visible = GL_FALSE ;
- case SC_MAXIMIZE:
- break;
+ break ;
- case SC_NEXTWINDOW:
- break;
+ case SC_MAXIMIZE :
+ break ;
- case SC_PREVWINDOW:
- break;
+ case SC_NEXTWINDOW :
+ break ;
+
+ case SC_PREVWINDOW :
+ break ;
- case SC_CLOSE:
+ case SC_CLOSE :
/* Followed very closely by a WM_CLOSE message */
- break;
+ break ;
- case SC_VSCROLL:
- break;
+ case SC_VSCROLL :
+ break ;
- case SC_HSCROLL:
- break;
+ case SC_HSCROLL :
+ break ;
- case SC_MOUSEMENU:
- break;
+ case SC_MOUSEMENU :
+ break ;
- case SC_KEYMENU:
- break;
+ case SC_KEYMENU :
+ break ;
- case SC_ARRANGE:
- break;
+ case SC_ARRANGE :
+ break ;
- case SC_RESTORE:
- break;
+ case SC_RESTORE :
+ break ;
- case SC_TASKLIST:
- break;
+ case SC_TASKLIST :
+ break ;
- case SC_SCREENSAVE:
- break;
+ case SC_SCREENSAVE :
+ break ;
- case SC_HOTKEY:
- break;
+ case SC_HOTKEY :
+ break ;
}
}