Polished off the say-nothing-new comments and lines-over-80-columns in

freeglut_window.c

There should be no functional changes.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@278 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-10-31 11:11:48 +00:00
parent 350de30921
commit a92096db1a

View File

@ -575,11 +575,8 @@ void fgCloseWindow( SFG_Window* window )
*/ */
int FGAPIENTRY glutCreateWindow( const char* title ) int FGAPIENTRY glutCreateWindow( const char* title )
{ {
/* return fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
* Create a new window and return its unique ID number fgState.Size.X, fgState.Size.Y, FALSE )->ID;
*/
return( fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
fgState.Size.X, fgState.Size.Y, FALSE )->ID );
} }
/* /*
@ -591,26 +588,10 @@ int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
SFG_Window* parent = NULL; SFG_Window* parent = NULL;
freeglut_assert_ready; freeglut_assert_ready;
/*
* Find a parent to the newly created window...
*/
parent = fgWindowByID( parentID ); parent = fgWindowByID( parentID );
/*
* Fail if the parent has not been found
*/
freeglut_return_val_if_fail( parent != NULL, 0 ); freeglut_return_val_if_fail( parent != NULL, 0 );
/*
* Create the new window
*/
window = fgCreateWindow( parent, "", x, y, w, h, FALSE ); window = fgCreateWindow( parent, "", x, y, w, h, FALSE );
return window->ID;
/*
* Return the new window's ID
*/
return( window->ID );
} }
/* /*
@ -618,26 +599,14 @@ int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
*/ */
void FGAPIENTRY glutDestroyWindow( int windowID ) void FGAPIENTRY glutDestroyWindow( int windowID )
{ {
fgExecutionState ExecState = fgState.ExecState ;
/*
* Grab the freeglut window pointer from the structure
*/
SFG_Window* window = fgWindowByID( windowID ); SFG_Window* window = fgWindowByID( windowID );
freeglut_return_if_fail( window != NULL ); freeglut_return_if_fail( window != NULL );
{
/* fgExecutionState ExecState = fgState.ExecState;
* There is a function that performs all needed steps
* defined in freeglut_structure.c. Let's use it:
*/
fgAddToWindowDestroyList( window, TRUE ); fgAddToWindowDestroyList( window, TRUE );
/*
* Since the "fgAddToWindowDestroyList" function could easily have set the "ExecState"
* to stop, let's set it back to what it was.
*/
fgState.ExecState = ExecState; fgState.ExecState = ExecState;
} }
}
/* /*
* This function selects the current window * This function selects the current window
@ -646,31 +615,14 @@ void FGAPIENTRY glutSetWindow( int ID )
{ {
SFG_Window* window = NULL; SFG_Window* window = NULL;
/*
* Make sure we don't get called too early
*/
freeglut_assert_ready; freeglut_assert_ready;
/*
* Be wise. Be wise. Be wise. Be quick.
*/
if( fgStructure.Window != NULL ) if( fgStructure.Window != NULL )
if( fgStructure.Window->ID == ID ) if( fgStructure.Window->ID == ID )
return; return;
/*
* Now we are sure there is sense in looking for the window
*/
window = fgWindowByID( ID ); window = fgWindowByID( ID );
/*
* In the case of an utter failure...
*/
if( window == NULL ) if( window == NULL )
{ {
/*
* ...issue a warning message and keep rolling on
*/
fgWarning( "glutSetWindow(): window ID %i not found!", ID ); fgWarning( "glutSetWindow(): window ID %i not found!", ID );
return; return;
} }
@ -684,22 +636,9 @@ void FGAPIENTRY glutSetWindow( int ID )
int FGAPIENTRY glutGetWindow( void ) int FGAPIENTRY glutGetWindow( void )
{ {
freeglut_assert_ready; freeglut_assert_ready;
/*
* Do we have a current window selected?
*/
if( fgStructure.Window == NULL ) if( fgStructure.Window == NULL )
{ return 0;
/* return fgStructure.Window->ID;
* Nope. Return zero to mark the state.
*/
return( 0 );
}
/*
* Otherwise, return the ID of the current window
*/
return( fgStructure.Window->ID );
} }
/* /*
@ -707,28 +646,21 @@ int FGAPIENTRY glutGetWindow( void )
*/ */
void FGAPIENTRY glutShowWindow( void ) void FGAPIENTRY glutShowWindow( void )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Showing the window is done via mapping under X
*/
XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle ); XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
XFlush( fgDisplay.Display ); XFlush( fgDisplay.Display );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* Restore the window's originial position and size
*/
ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW ); ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
#endif #endif
/*
* Since the window is visible, we need to redisplay it ...
*/
fgStructure.Window->State.Redisplay = TRUE; fgStructure.Window->State.Redisplay = TRUE;
} }
/* /*
@ -736,44 +668,24 @@ void FGAPIENTRY glutShowWindow( void )
*/ */
void FGAPIENTRY glutHideWindow( void ) void FGAPIENTRY glutHideWindow( void )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* The way we hide a window depends on if we're dealing
* with a top-level or children one...
*/
if( fgStructure.Window->Parent == NULL )
{
/*
* This is a top-level window
*/
XWithdrawWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
}
else
{
/*
* Nope, it's a child window
*/
XUnmapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
}
/* if( fgStructure.Window->Parent == NULL )
* Flush the X state now XWithdrawWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
*/ fgDisplay.Screen );
else
XUnmapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
XFlush( fgDisplay.Display ); XFlush( fgDisplay.Display );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* Hide the window
*/
ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE ); ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
#endif #endif
/*
* Since the window is hidden, we don't need to redisplay it ...
*/
fgStructure.Window->State.Redisplay = FALSE; fgStructure.Window->State.Redisplay = FALSE;
} }
@ -782,28 +694,22 @@ void FGAPIENTRY glutHideWindow( void )
*/ */
void FGAPIENTRY glutIconifyWindow( void ) void FGAPIENTRY glutIconifyWindow( void )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Iconify the window and flush the X state XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
*/ fgDisplay.Screen );
XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
XFlush( fgDisplay.Display ); XFlush( fgDisplay.Display );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* Minimize the current window (this should be the same as X window iconifying)
*/
ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE ); ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
#endif #endif
/*
* Since the window is just an icon, we don't need to redisplay it ...
*/
fgStructure.Window->State.Redisplay = FALSE; fgStructure.Window->State.Redisplay = FALSE;
} }
/* /*
@ -811,48 +717,36 @@ void FGAPIENTRY glutIconifyWindow( void )
*/ */
void FGAPIENTRY glutSetWindowTitle( const char* title ) void FGAPIENTRY glutSetWindowTitle( const char* title )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
/*
* Works only for top-level windows
*/
if( fgStructure.Window->Parent != NULL ) if( fgStructure.Window->Parent != NULL )
return; return;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
{ {
XTextProperty text; XTextProperty text;
/*
* Prepare the text properties
*/
text.value = (unsigned char *) title; text.value = (unsigned char *) title;
text.encoding = XA_STRING; text.encoding = XA_STRING;
text.format = 8; text.format = 8;
text.nitems = strlen( title ); text.nitems = strlen( title );
/*
* Set the title now
*/
XSetWMName( XSetWMName(
fgDisplay.Display, fgDisplay.Display,
fgStructure.Window->Window.Handle, fgStructure.Window->Window.Handle,
&text &text
); );
/*
* Have the X display state flushed
*/
XFlush( fgDisplay.Display ); XFlush( fgDisplay.Display );
} }
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* This seems to be a bit easier under Win32
*/
SetWindowText( fgStructure.Window->Window.Handle, title ); SetWindowText( fgStructure.Window->Window.Handle, title );
#endif #endif
} }
/* /*
@ -860,48 +754,37 @@ void FGAPIENTRY glutSetWindowTitle( const char* title )
*/ */
void FGAPIENTRY glutSetIconTitle( const char* title ) void FGAPIENTRY glutSetIconTitle( const char* title )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
/*
* Works only for top-level windows
*/
if( fgStructure.Window->Parent != NULL ) if( fgStructure.Window->Parent != NULL )
return; return;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
{ {
XTextProperty text; XTextProperty text;
/*
* Prepare the text properties
*/
text.value = (unsigned char *) title; text.value = (unsigned char *) title;
text.encoding = XA_STRING; text.encoding = XA_STRING;
text.format = 8; text.format = 8;
text.nitems = strlen( title ); text.nitems = strlen( title );
/*
* Set the title now
*/
XSetWMIconName( XSetWMIconName(
fgDisplay.Display, fgDisplay.Display,
fgStructure.Window->Window.Handle, fgStructure.Window->Window.Handle,
&text &text
); );
/*
* Have the X display state flushed
*/
XFlush( fgDisplay.Display ); XFlush( fgDisplay.Display );
} }
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* This seems to be a bit easier under Win32
*/
SetWindowText( fgStructure.Window->Window.Handle, title ); SetWindowText( fgStructure.Window->Window.Handle, title );
#endif #endif
} }
/* /*
@ -909,48 +792,47 @@ void FGAPIENTRY glutSetIconTitle( const char* title )
*/ */
void FGAPIENTRY glutReshapeWindow( int width, int height ) void FGAPIENTRY glutReshapeWindow( int width, int height )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Resize the window and flush the X state XResizeWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
*/ width, height );
XResizeWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, width, height );
XFlush( fgDisplay.Display ); XFlush( fgDisplay.Display );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
{ {
RECT winRect; RECT winRect;
int x, y; int x, y;
/*
* First off, grab the current window's position
*/
GetWindowRect( fgStructure.Window->Window.Handle, &winRect ); GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
x = winRect.left; x = winRect.left;
y = winRect.top; y = winRect.top;
if ( fgStructure.Window->Parent == NULL ) /* If this is not a subwindow ... */ if ( fgStructure.Window->Parent == NULL )
{ {
/* /*
* Adjust the size of the window to allow for the size of the frame, if we are not a menu * Adjust the size of the window to allow for the size of the
* frame, if we are not a menu
*/ */
if ( ! fgStructure.Window->IsMenu ) if ( ! fgStructure.Window->IsMenu )
{ {
width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2; width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION ); height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
GetSystemMetrics( SM_CYCAPTION );
} }
} }
else /* This is a subwindow, get the parent window's position and subtract it off */ else
{ {
GetWindowRect ( fgStructure.Window->Parent->Window.Handle, &winRect ) ; GetWindowRect( fgStructure.Window->Parent->Window.Handle,
&winRect );
x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME ); x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME );
y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION ) ; y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) +
GetSystemMetrics( SM_CYCAPTION );
} }
/*
* Resize the window, forcing a redraw to happen
*/
MoveWindow( MoveWindow(
fgStructure.Window->Window.Handle, fgStructure.Window->Window.Handle,
x, x,
@ -960,7 +842,9 @@ void FGAPIENTRY glutReshapeWindow( int width, int height )
TRUE TRUE
); );
} }
#endif #endif
} }
/* /*
@ -968,27 +852,20 @@ void FGAPIENTRY glutReshapeWindow( int width, int height )
*/ */
void FGAPIENTRY glutPositionWindow( int x, int y ) void FGAPIENTRY glutPositionWindow( int x, int y )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Reposition the window and flush the X state
*/
XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, x, y ); XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, x, y );
XFlush( fgDisplay.Display ); XFlush( fgDisplay.Display );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
{ {
RECT winRect; RECT winRect;
/*
* First off, grab the current window's position
*/
GetWindowRect( fgStructure.Window->Window.Handle, &winRect ); GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
/*
* Reposition the window, forcing a redraw to happen
*/
MoveWindow( MoveWindow(
fgStructure.Window->Window.Handle, fgStructure.Window->Window.Handle,
x, x,
@ -1000,6 +877,7 @@ void FGAPIENTRY glutPositionWindow( int x, int y )
} }
#endif #endif
} }
/* /*
@ -1007,18 +885,15 @@ void FGAPIENTRY glutPositionWindow( int x, int y )
*/ */
void FGAPIENTRY glutPushWindow( void ) void FGAPIENTRY glutPushWindow( void )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Lower the current window
*/
XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle ); XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* Set the new window's Z position, not affecting the rest of the settings:
*/
SetWindowPos( SetWindowPos(
fgStructure.Window->Window.Handle, fgStructure.Window->Window.Handle,
HWND_BOTTOM, HWND_BOTTOM,
@ -1027,6 +902,7 @@ void FGAPIENTRY glutPushWindow( void )
); );
#endif #endif
} }
/* /*
@ -1034,18 +910,15 @@ void FGAPIENTRY glutPushWindow( void )
*/ */
void FGAPIENTRY glutPopWindow( void ) void FGAPIENTRY glutPopWindow( void )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Raise the current window
*/
XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle ); XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/*
* Set the new window's Z position, not affecting the rest of the settings:
*/
SetWindowPos( SetWindowPos(
fgStructure.Window->Window.Handle, fgStructure.Window->Window.Handle,
HWND_TOP, HWND_TOP,
@ -1054,6 +927,7 @@ void FGAPIENTRY glutPopWindow( void )
); );
#endif #endif
} }
/* /*
@ -1061,7 +935,8 @@ void FGAPIENTRY glutPopWindow( void )
*/ */
void FGAPIENTRY glutFullScreen( void ) void FGAPIENTRY glutFullScreen( void )
{ {
freeglut_assert_ready; freeglut_assert_window; freeglut_assert_ready;
freeglut_assert_window;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
{ {
@ -1110,7 +985,7 @@ void FGAPIENTRY glutFullScreen( void )
*/ */
void* FGAPIENTRY glutGetWindowData( void ) void* FGAPIENTRY glutGetWindowData( void )
{ {
return(fgStructure.Window->UserData); return fgStructure.Window->UserData;
} }
void FGAPIENTRY glutSetWindowData(void* data) void FGAPIENTRY glutSetWindowData(void* data)