Propogated a pointer-check from menu-attach to menu-detach. (Apparently,

in some cases, the Menu member variable can be NULL.)

Corrected the menu-attach code to make sure that both Window and Menu
pointers are non-NULL (rather than "at least one").

Rewrote button-checks to more simply and more clearly assert that the
"menu button" is a valid button for menu actions: Instead of laboriously
comparing against the three valid buttons (0, 1, 2 or GLUT_BUTTON_*),
we do a simpler range-check and the upper bound is {FREEGLUT_MAX_MENUS},
allowing us to change the number of menuable buttons fairly easily in
the future.

Also deleted a few say-nothing-new comments.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@250 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-10-27 06:39:57 +00:00
parent 763b02a955
commit 09d6d7342e

View File

@ -992,20 +992,10 @@ void FGAPIENTRY glutRemoveMenuItem( int item )
void FGAPIENTRY glutAttachMenu( int button )
{
freeglut_assert_ready;
/*
* There must be a current window and a current menu set:
*/
freeglut_return_if_fail( fgStructure.Window != NULL || fgStructure.Menu != NULL );
/*
* Make sure the button value is valid (0, 1 or 2, see freeglut.h)
*/
freeglut_return_if_fail( button == GLUT_LEFT_BUTTON || button == GLUT_MIDDLE_BUTTON || button == GLUT_RIGHT_BUTTON );
/*
* It is safe now to attach the menu
*/
freeglut_return_if_fail( fgStructure.Window );
freeglut_return_if_fail( fgStructure.Menu );
freeglut_return_if_fail( button >= 0 );
freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
fgStructure.Window->Menu[ button ] = fgStructure.Menu;
/*
@ -1020,20 +1010,10 @@ void FGAPIENTRY glutAttachMenu( int button )
void FGAPIENTRY glutDetachMenu( int button )
{
freeglut_assert_ready;
/*
* There must be a current window set:
*/
freeglut_return_if_fail( fgStructure.Window != NULL );
/*
* Make sure the button value is valid (0, 1 or 2, see freeglut.h)
*/
freeglut_return_if_fail( button != 0 && button != 1 && button != 2 );
/*
* It is safe now to detach the menu
*/
freeglut_return_if_fail( fgStructure.Menu );
freeglut_return_if_fail( button >= 0 );
freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
fgStructure.Window->Menu[ button ] = NULL;
}