Made Modifers variable global as per glut classic.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@357 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
cjp 2003-11-16 14:10:35 +00:00
parent b47a8b1fcc
commit a437c328e9
5 changed files with 32 additions and 32 deletions

View File

@ -66,6 +66,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
GL_FALSE, /* GLDebugSwitch */ GL_FALSE, /* GLDebugSwitch */
GL_FALSE, /* XSyncSwitch */ GL_FALSE, /* XSyncSwitch */
GL_TRUE, /* IgnoreKeyRepeat */ GL_TRUE, /* IgnoreKeyRepeat */
0xffffffff, /* Modifiers */
0, /* FPSInterval */ 0, /* FPSInterval */
0, /* SwapCount */ 0, /* SwapCount */
0, /* SwapTime */ 0, /* SwapTime */
@ -84,6 +85,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
72, /* GameModeRefresh */ 72, /* GameModeRefresh */
GLUT_ACTION_EXIT, /* ActionOnWindowClose */ GLUT_ACTION_EXIT, /* ActionOnWindowClose */
GLUT_EXEC_STATE_INIT /* ExecState */ GLUT_EXEC_STATE_INIT /* ExecState */
NULL, /* ProgramName */
}; };
@ -258,6 +260,7 @@ void fgDeinitialize( void )
fgState.ExecState = GLUT_EXEC_STATE_INIT; fgState.ExecState = GLUT_EXEC_STATE_INIT;
fgState.IgnoreKeyRepeat = GL_TRUE; fgState.IgnoreKeyRepeat = GL_TRUE;
fgState.Modifiers = 0xffffffff;
fgState.GameModeSize.X = 640; fgState.GameModeSize.X = 640;
fgState.GameModeSize.Y = 480; fgState.GameModeSize.Y = 480;
@ -453,16 +456,17 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
char* geometry = NULL; char* geometry = NULL;
int i, j, argc = *pargc; int i, j, argc = *pargc;
if (pargc && *pargc && argv && *argv && **argv)
fgState.ProgramName = strdup (*argv);
else
fgState.ProgramName = strdup ("");
if( !fgState.ProgramName )
fgError ("Could not allocate space for the program's name.");
if( fgState.Initalized ) if( fgState.Initalized )
fgError( "illegal glutInit() reinitialization attemp" ); fgError( "illegal glutInit() reinitialization attemp" );
if (pargc && *pargc && argv && *argv && **argv)
{
fgState.ProgramName = strdup (*argv);
if( !fgState.ProgramName )
fgError ("Could not allocate space for the program's name.");
}
fgCreateStructure( ); fgCreateStructure( );
fgElapsedTime( ); fgElapsedTime( );

View File

@ -230,6 +230,7 @@ struct tagSFG_State
GLboolean XSyncSwitch; /* X11 sync protocol switch */ GLboolean XSyncSwitch; /* X11 sync protocol switch */
GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */ GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
int Modifiers; /* Current ALT/SHIFT/CTRL state */
GLuint FPSInterval; /* Interval between FPS printfs */ GLuint FPSInterval; /* Interval between FPS printfs */
GLuint SwapCount; /* Count of glutSwapBuffer calls */ GLuint SwapCount; /* Count of glutSwapBuffer calls */
@ -342,7 +343,6 @@ struct tagSFG_WindowState
GLboolean Visible; /* Is the window visible now */ GLboolean Visible; /* Is the window visible now */
int Cursor; /* The currently selected cursor */ int Cursor; /* The currently selected cursor */
int Modifiers; /* The current ALT/SHIFT/CTRL state */
long JoystickPollRate; /* The joystick polling rate */ long JoystickPollRate; /* The joystick polling rate */
long JoystickLastPoll; /* When the last poll has happened */ long JoystickLastPoll; /* When the last poll has happened */

View File

@ -796,7 +796,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
/* /*
* XXX Why don't we use {window}? Other code here does... * XXX Why don't we use {window}? Other code here does...
*/ */
fgStructure.Window->State.Modifiers = fgGetXModifiers( &event ); fgState.Modifiers = fgGetXModifiers( &event );
/* /*
* Finally execute the mouse or mouse wheel callback * Finally execute the mouse or mouse wheel callback
@ -839,7 +839,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
/* /*
* Trash the modifiers state * Trash the modifiers state
*/ */
fgStructure.Window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
break; break;
@ -891,11 +891,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
if( keyboard_cb ) if( keyboard_cb )
{ {
fgSetWindow( window ); fgSetWindow( window );
window->State.Modifiers = fgGetXModifiers( &event ); fgState.Modifiers = fgGetXModifiers( &event );
keyboard_cb( asciiCode[ 0 ], keyboard_cb( asciiCode[ 0 ],
event.xkey.x, event.xkey.y event.xkey.x, event.xkey.y
); );
window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
} }
else else
@ -945,9 +945,9 @@ void FGAPIENTRY glutMainLoopEvent( void )
if( special_cb && ( special != -1 ) ) if( special_cb && ( special != -1 ) )
{ {
fgSetWindow( window ); fgSetWindow( window );
window->State.Modifiers = fgGetXModifiers( &event ); fgState.Modifiers = fgGetXModifiers( &event );
special_cb( special, event.xkey.x, event.xkey.y ); special_cb( special, event.xkey.x, event.xkey.y );
window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
} }
} }
@ -1286,7 +1286,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
break; break;
} }
window->State.Modifiers = fgGetWin32Modifiers( ); fgState.Modifiers = fgGetWin32Modifiers( );
if( ( wParam & MK_LBUTTON ) || if( ( wParam & MK_LBUTTON ) ||
( wParam & MK_MBUTTON ) || ( wParam & MK_MBUTTON ) ||
@ -1297,7 +1297,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
INVOKE_WCB( *window, Passive, ( window->State.MouseX, INVOKE_WCB( *window, Passive, ( window->State.MouseX,
window->State.MouseY ) ); window->State.MouseY ) );
window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
break; break;
@ -1423,7 +1423,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
break; break;
fgSetWindow( window ); fgSetWindow( window );
fgStructure.Window->State.Modifiers = fgGetWin32Modifiers( ); fgState.Modifiers = fgGetWin32Modifiers( );
INVOKE_WCB( INVOKE_WCB(
*window, Mouse, *window, Mouse,
@ -1434,7 +1434,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
) )
); );
fgStructure.Window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
break; break;
@ -1468,7 +1468,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
break; break;
fgSetWindow( window ); fgSetWindow( window );
fgStructure.Window->State.Modifiers = fgGetWin32Modifiers( ); fgState.Modifiers = fgGetWin32Modifiers( );
while( ticks-- ) while( ticks-- )
if( FETCH_WCB( *window, MouseWheel ) ) if( FETCH_WCB( *window, MouseWheel ) )
@ -1498,7 +1498,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
); );
} }
fgStructure.Window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
break; break;
@ -1515,7 +1515,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 = fgGetWin32Modifiers( ); fgState.Modifiers = fgGetWin32Modifiers( );
GetCursorPos( &mouse_pos ); GetCursorPos( &mouse_pos );
ScreenToClient( window->Window.Handle, &mouse_pos ); ScreenToClient( window->Window.Handle, &mouse_pos );
@ -1567,7 +1567,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
window->State.MouseX, window->State.MouseY ) window->State.MouseX, window->State.MouseY )
); );
window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
break; break;
@ -1581,7 +1581,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 = fgGetWin32Modifiers( ); fgState.Modifiers = fgGetWin32Modifiers( );
GetCursorPos( &mouse_pos ); GetCursorPos( &mouse_pos );
ScreenToClient( window->Window.Handle, &mouse_pos ); ScreenToClient( window->Window.Handle, &mouse_pos );
@ -1650,7 +1650,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
window->State.MouseX, window->State.MouseY ) window->State.MouseX, window->State.MouseY )
); );
window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
break; break;
@ -1668,12 +1668,12 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
*/ */
if( FETCH_WCB( *window, Keyboard ) ) if( FETCH_WCB( *window, Keyboard ) )
{ {
window->State.Modifiers = fgGetWin32Modifiers( ); fgState.Modifiers = fgGetWin32Modifiers( );
INVOKE_WCB( *window, Keyboard, INVOKE_WCB( *window, Keyboard,
( (char)wParam, ( (char)wParam,
window->State.MouseX, window->State.MouseY ) window->State.MouseX, window->State.MouseY )
); );
window->State.Modifiers = 0xffffffff; fgState.Modifiers = 0xffffffff;
} }
} }
break; break;

View File

@ -562,16 +562,13 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
*/ */
int FGAPIENTRY glutGetModifiers( void ) int FGAPIENTRY glutGetModifiers( void )
{ {
if( fgStructure.Window == NULL ) if( fgState.Modifiers == 0xffffffff )
return( 0 );
if( fgStructure.Window->State.Modifiers == 0xffffffff )
{ {
fgWarning( "glutGetModifiers() called outside an input callback" ); fgWarning( "glutGetModifiers() called outside an input callback" );
return( 0 ); return( 0 );
} }
return( fgStructure.Window->State.Modifiers ); return( fgState.Modifiers );
} }
/* /*

View File

@ -105,7 +105,6 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
* Set the default mouse cursor and reset the modifiers value * Set the default mouse cursor and reset the modifiers value
*/ */
window->State.Cursor = GLUT_CURSOR_INHERIT; window->State.Cursor = GLUT_CURSOR_INHERIT;
window->State.Modifiers = 0xffffffff;
window->IsMenu = isMenu; window->IsMenu = isMenu;