* Indentation issues.

* Pulled some common code into a nicely packaged function.
 * Found some pointer/int issues.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@290 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-11-03 21:25:11 +00:00
parent fa26d7b700
commit 5342fe966f
2 changed files with 51 additions and 68 deletions

View File

@ -1042,10 +1042,25 @@ void FGAPIENTRY glutLeaveMainLoop( void )
fgState.ExecState = GLUT_EXEC_STATE_STOP ; fgState.ExecState = GLUT_EXEC_STATE_STOP ;
} }
#if TARGET_HOST_WIN32
/*
* Determine a GLUT modifer mask based on MS-WINDOWS system info.
*/
int fgGetWin32Modifiers (void)
{
return
( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
}
/* /*
* The window procedure for handling Win32 events * The window procedure for handling Win32 events
*/ */
#if TARGET_HOST_WIN32
LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam ) LPARAM lParam )
{ {
@ -1145,32 +1160,38 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
(fgStructure.Window->State.Cursor == GLUT_CURSOR_NONE)) (fgStructure.Window->State.Cursor == GLUT_CURSOR_NONE))
SetCursor( NULL ); SetCursor( NULL );
#else #else
/* Set the cursor AND change it for this window class. */ /* Set the cursor AND change it for this window class. */
# define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \ #define MAP_CURSOR(a,b) \
break; case a: \
SetCursor( LoadCursor( NULL, b ) ); \
break;
/* Nuke the cursor AND change it for this window class. */ /* Nuke the cursor AND change it for this window class. */
# define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \ #define ZAP_CURSOR(a,b) \
break; case a: \
SetCursor( NULL ); \
break;
if( LOWORD( lParam ) == HTCLIENT ) if( LOWORD( lParam ) == HTCLIENT )
switch( window->State.Cursor ) switch( window->State.Cursor )
{ {
MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW ); MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW ); MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP ); MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS ); MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP ); MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL ); MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS ); MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT ); MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW ); MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS ); MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
/* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */ /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
ZAP_CURSOR( GLUT_CURSOR_NONE, NULL ); ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
default: default:
MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW ); MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
} }
#endif #endif
else else
lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
@ -1245,13 +1266,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
break; break;
} }
window->State.Modifiers = window->State.Modifiers = fgGetWin32Modifiers( );
( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
if( ( wParam & MK_LBUTTON ) || if( ( wParam & MK_LBUTTON ) ||
( wParam & MK_MBUTTON ) || ( wParam & MK_MBUTTON ) ||
@ -1388,14 +1403,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
break; break;
fgSetWindow( window ); fgSetWindow( window );
fgStructure.Window->State.Modifiers = fgGetWin32Modifiers( );
fgStructure.Window->State.Modifiers =
( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
window->Callbacks.Mouse( window->Callbacks.Mouse(
button, button,
@ -1436,13 +1444,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
break; break;
fgSetWindow( window ); fgSetWindow( window );
fgStructure.Window->State.Modifiers = fgStructure.Window->State.Modifiers = fgGetWin32Modifiers( );
( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
while( ticks-- ) while( ticks-- )
if( window->Callbacks.MouseWheel ) if( window->Callbacks.MouseWheel )
@ -1485,13 +1487,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
* Remember the current modifiers state. This is done here in order * Remember the current modifiers state. This is done here in order
* to make sure the VK_DELETE keyboard callback is executed properly. * to make sure the VK_DELETE keyboard callback is executed properly.
*/ */
window->State.Modifiers = window->State.Modifiers = fgGetWin32Modifiers( );
( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
GetCursorPos( &mouse_pos ); GetCursorPos( &mouse_pos );
ScreenToClient( window->Window.Handle, &mouse_pos ); ScreenToClient( window->Window.Handle, &mouse_pos );
@ -1561,13 +1557,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
* Remember the current modifiers state. This is done here in order * Remember the current modifiers state. This is done here in order
* to make sure the VK_DELETE keyboard callback is executed properly. * to make sure the VK_DELETE keyboard callback is executed properly.
*/ */
window->State.Modifiers = window->State.Modifiers = fgGetWin32Modifiers( );
( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
GetCursorPos( &mouse_pos ); GetCursorPos( &mouse_pos );
ScreenToClient( window->Window.Handle, &mouse_pos ); ScreenToClient( window->Window.Handle, &mouse_pos );
@ -1657,14 +1647,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
if( window->Callbacks.Keyboard ) if( window->Callbacks.Keyboard )
{ {
fgSetWindow( window ); fgSetWindow( window );
window->State.Modifiers = window->State.Modifiers = fgGetWin32Modifiers( );
( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
window->Callbacks.Keyboard( (char)wParam, window->State.MouseX, window->Callbacks.Keyboard( (char)wParam, window->State.MouseX,
window->State.MouseY ); window->State.MouseY );
window->State.Modifiers = 0xffffffff; window->State.Modifiers = 0xffffffff;

View File

@ -561,7 +561,7 @@ static void fghcbWindowByID( SFG_Window *window, SFG_Enumerator *enumerator )
/* /*
* Check the window's handle. Hope this works. Looks ugly. That's for sure. * Check the window's handle. Hope this works. Looks ugly. That's for sure.
*/ */
if( window->ID == (int) (enumerator->data) ) if( window->ID == (int) (enumerator->data) ) /* XXX int/ptr conversion! */
{ {
enumerator->found = TRUE; enumerator->found = TRUE;
enumerator->data = window; enumerator->data = window;
@ -588,7 +588,7 @@ SFG_Window* fgWindowByID( int windowID )
* Uses a method very similiar for fgWindowByHandle... * Uses a method very similiar for fgWindowByHandle...
*/ */
enumerator.found = FALSE; enumerator.found = FALSE;
enumerator.data = (void *) windowID; enumerator.data = (void *) windowID; /* XXX int/pointer conversion! */
fgEnumWindows( fghcbWindowByID, &enumerator ); fgEnumWindows( fghcbWindowByID, &enumerator );
if( enumerator.found == TRUE ) if( enumerator.found == TRUE )
return( SFG_Window *) enumerator.data; return( SFG_Window *) enumerator.data;