4 * Pull-down menu creation and handling.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Thu Dec 16 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define G_LOG_DOMAIN "freeglut-menu"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
40 * It would be cool if the submenu entries were somehow marked, for example with a dings
41 * on the right menu border or something like that. Think about the possibility of doing
42 * the menu on layers *or* using the native window system instead of OpenGL.
45 /* -- DEFINITIONS ---------------------------------------------------------- */
48 * We'll be using freeglut fonts to draw the menu
50 #define FREEGLUT_MENU_FONT GLUT_BITMAP_8_BY_13
51 #define FREEGLUT_MENU_HEIGHT 15
52 #define FREEGLUT_MENU_BORDER 8
55 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
58 * Private static function to find a menu entry by index
60 static SFG_MenuEntry *fghFindMenuEntry( SFG_Menu* menu, int index )
65 for( entry = (SFG_MenuEntry *)menu->Entries.First; entry; entry = (SFG_MenuEntry *)entry->Node.Next)
76 * Private static function to check for the current menu/sub menu activity state
78 static GLboolean fghCheckMenuStatus( SFG_Window* window, SFG_Menu* menu )
80 SFG_MenuEntry* menuEntry;
84 * First of all check any of the active sub menus...
86 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
87 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
90 * Is that an active sub menu by any case?
92 if( menuEntry->SubMenu != NULL && menuEntry->IsActive == TRUE )
95 * OK, have the sub-menu checked, too. If it returns TRUE, it will mean
96 * that it caught the mouse cursor and we do not need to regenerate
97 * the activity list, and so our parents do...
99 GLboolean return_status = fghCheckMenuStatus( window, menuEntry->SubMenu ) ;
102 * Reactivate the submenu as the checkMenuStatus may have turned it off if the mouse
103 * is in its parent menu entry.
105 menuEntry->SubMenu->IsActive = TRUE ;
106 if ( return_status == TRUE )
112 * That much about our sub menus, let's get to checking the current menu:
114 x = window->State.MouseX;
115 y = window->State.MouseY;
118 * Mark all menu entries inactive...
120 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
121 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
123 menuEntry->IsActive = FALSE;
127 menu->IsActive = FALSE;
130 * Check if the mouse cursor is contained within the current menu box
132 if ( ( x >= 0 ) && ( x < menu->Width ) && ( y >= 0 ) && ( y < menu->Height ) && ( window == menu->Window ) )
135 * Calculation of the highlighted menu item is easy enough now:
137 int menuID = y / FREEGLUT_MENU_HEIGHT;
140 * The mouse cursor is somewhere over our box, check it out.
142 menuEntry = fghFindMenuEntry( menu, menuID + 1 );
143 assert( menuEntry != NULL );
146 * Mark the menu as active...
148 menuEntry->IsActive = TRUE;
149 menuEntry->Ordinal = menuID;
152 * If this is not the same as the last active menu entry, deactivate the previous entry.
153 * Specifically, if the previous active entry was a submenu then deactivate it.
155 if ( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
157 if ( menu->ActiveEntry->SubMenu != NULL )
158 fgDeactivateSubMenu ( menu->ActiveEntry ) ;
161 menu->ActiveEntry = menuEntry ;
164 * Don't forget about marking the current menu as active, too:
167 menu->IsActive = TRUE;
170 * OKi, we have marked that entry as active, but it would be also
171 * nice to have its contents updated, in case it's a sub menu.
172 * Also, ignore the return value of the check function:
174 if( menuEntry->SubMenu != NULL )
176 if ( ! menuEntry->SubMenu->IsActive )
178 SFG_Window *current_window = fgStructure.Window ;
181 * Set up the initial menu position now...
185 * Mark the menu as active, so that it gets displayed:
187 menuEntry->SubMenu->IsActive = TRUE ;
190 * Set up the initial submenu position now:
192 menuEntry->SubMenu->X = menu->X + menu->Width ;
193 menuEntry->SubMenu->Y = menu->Y + menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT ;
195 fgSetWindow ( menuEntry->SubMenu->Window ) ;
196 glutPositionWindow ( menuEntry->SubMenu->X, menuEntry->SubMenu->Y ) ;
197 glutReshapeWindow ( menuEntry->SubMenu->Width, menuEntry->SubMenu->Height ) ;
200 menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu ;
201 fgSetWindow ( current_window ) ;
205 * ...then check the submenu's state:
207 fghCheckMenuStatus( window, menuEntry->SubMenu );
210 * Even if the submenu turned up inactive, activate it because its parent entry is active
212 menuEntry->SubMenu->IsActive = TRUE ;
216 * Report back that we have caught the menu cursor
222 * Looks like the menu cursor is somewhere else...
228 * Displays a menu box and all of its submenus (if they are active)
230 static void fghDisplayMenuBox( SFG_Menu* menu )
232 SFG_MenuEntry *menuEntry;
236 * Have the menu box drawn first. The +- values are
237 * here just to make it more nice-looking...
239 glColor4f( 0.1289f, 0.2257f, 0.28516f, 1.0f ); /* a non-black dark version of the below. */
242 glVertex2i( menu->Width, 0 );
243 glVertex2i( menu->Width, menu->Height );
244 glVertex2i( 0 , menu->Height );
247 glColor4f( 0.3f, 0.4f, 0.5f, 1.0f );
250 glVertex2i( menu->Width-1, 1 );
251 glVertex2i( menu->Width-1, menu->Height-1);
252 glVertex2i( 1, menu->Height-1);
256 * Check if any of the submenus is currently active...
258 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
259 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
262 * Has the menu been marked as active, maybe?
264 if( menuEntry->IsActive == TRUE )
267 * That's truly right, and we need to have it highlighted.
268 * There is an assumption that mouse cursor didn't move
269 * since the last check of menu activity state:
271 int menuID = menuEntry->Ordinal;
274 * So have the highlight drawn...
276 glColor4f( 0.2f, 0.3f, 0.4f, 1.0f );
278 glVertex2i( 2 , (menuID + 0)*FREEGLUT_MENU_HEIGHT + 1 );
279 glVertex2i( menu->Width-2, (menuID + 0)*FREEGLUT_MENU_HEIGHT + 1 );
280 glVertex2i( menu->Width-2, (menuID + 1)*FREEGLUT_MENU_HEIGHT + 2 );
281 glVertex2i( 2 , (menuID + 1)*FREEGLUT_MENU_HEIGHT + 2 );
287 * Print the menu entries now...
289 glColor4f( 1, 1, 1, 1 );
291 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First, i=0; menuEntry;
292 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next, ++i )
295 * Move the raster into position...
298 FREEGLUT_MENU_BORDER,
299 (i + 1)*FREEGLUT_MENU_HEIGHT-(int)(FREEGLUT_MENU_HEIGHT*0.3) /* Try to center the text - JCJ 31 July 2003*/
303 * Have the label drawn, character after character:
305 glutBitmapString( FREEGLUT_MENU_FONT, menuEntry->Text);
308 * If it's a submenu, draw a right arrow
310 if ( menuEntry->SubMenu != NULL )
312 GLubyte arrow_char [] = { 0, 0, 32, 48, 56, 60, 62, 63, 62, 60, 56, 48, 32, 0, 0 } ;
313 int width = glutBitmapWidth ( FREEGLUT_MENU_FONT, ' ' ) ;
315 glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
318 * Set up the pixel unpacking ways
320 glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
321 glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE );
322 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
323 glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
324 glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
325 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
327 glRasterPos2i ( menu->Width - 2 - width,
328 (i + 1)*FREEGLUT_MENU_HEIGHT ) ;
329 glBitmap ( width, FREEGLUT_MENU_HEIGHT, 0, 0, 0.0, 0.0, arrow_char ) ;
335 * Now we are ready to check if any of our children needs to be redrawn:
337 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
338 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
341 * Is that an active sub menu by any case?
343 if( menuEntry->SubMenu != NULL && menuEntry->IsActive == TRUE )
346 * Yeah, indeed. Have it redrawn now:
348 fgSetWindow ( menuEntry->SubMenu->Window ) ;
349 fghDisplayMenuBox( menuEntry->SubMenu );
350 fgSetWindow ( menu->Window ) ;
356 * Private static function to set the parent window of a submenu and all of its submenus
358 static void fghSetSubmenuParentWindow ( SFG_Window *window, SFG_Menu *menu )
360 SFG_MenuEntry *menuEntry ;
362 menu->ParentWindow = window ;
364 for ( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry; menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
366 if ( menuEntry->SubMenu != NULL )
367 fghSetSubmenuParentWindow ( window, menuEntry->SubMenu ) ;
373 * Displays the currently active menu for the current window
375 void fgDisplayMenu( void )
377 SFG_Window* window = fgStructure.Window;
378 SFG_Menu* menu = NULL;
381 * Make sure there is a current window available
383 freeglut_assert_window;
386 * Check if there is an active menu attached to this window...
388 menu = window->ActiveMenu;
391 * Did we find an active menu?
393 freeglut_return_if_fail( menu != NULL );
395 fgSetWindow ( menu->Window ) ;
398 * Prepare the OpenGL state to do the rendering first:
400 glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT );
402 glDisable( GL_DEPTH_TEST );
403 glDisable( GL_TEXTURE_2D );
404 glDisable( GL_LIGHTING );
405 glDisable( GL_CULL_FACE );
408 * We'll use an orthogonal projection matrix to draw the menu:
410 glMatrixMode( GL_PROJECTION );
414 0, glutGet( GLUT_WINDOW_WIDTH ),
415 glutGet( GLUT_WINDOW_HEIGHT ), 0,
420 * Model-view matix gets reset to identity:
422 glMatrixMode( GL_MODELVIEW );
427 * First of all, have the exact menu status check:
429 fghCheckMenuStatus( window, menu );
432 * The status has been updated and we're ready to have the menu drawn now:
434 fghDisplayMenuBox( menu );
437 * Restore the old OpenGL settings now
441 glMatrixMode( GL_PROJECTION );
443 glMatrixMode( GL_MODELVIEW );
449 * Restore the current window
451 fgSetWindow ( window ) ;
455 * Activates a menu pointed by the function argument
457 void fgActivateMenu( SFG_Window* window, int button )
460 * We'll be referencing this menu a lot, so remember its address:
462 SFG_Menu* menu = window->Menu[ button ];
465 * Mark the menu as active, so that it gets displayed:
467 window->ActiveMenu = menu;
468 menu->IsActive = TRUE ;
469 fgState.ActiveMenus ++ ;
472 * Set up the initial menu position now:
475 menu->X = window->State.MouseX + glutGet ( GLUT_WINDOW_X ) ;
476 menu->Y = window->State.MouseY + glutGet ( GLUT_WINDOW_Y ) ;
478 fgSetWindow ( menu->Window ) ;
479 glutPositionWindow ( menu->X, menu->Y ) ;
480 glutReshapeWindow ( menu->Width, menu->Height ) ;
483 menu->Window->ActiveMenu = menu ;
485 /* if( x > ( glutGet( GLUT_WINDOW_WIDTH ) - menu->Width ) )
486 menu->X = glutGet( GLUT_WINDOW_WIDTH ) - menu->Width;
487 if( y > ( glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height) )
488 menu->Y = glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height; */
492 * Check whether an active menu absorbs a mouse click
494 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
497 * Near as I can tell, this is the active menu behaviour:
498 * - Down-click any button outside the menu, menu active: deactivate the menu
499 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
500 * - Up-click the menu button outside the menu, menu active: nothing happens
501 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
502 * Since menus can have submenus, we need to check this recursively.
504 return fghCheckMenuStatus ( window, menu ) ;
508 * Function to check for menu entry selection on menu deactivation
510 void fgExecuteMenuCallback( SFG_Menu* menu )
512 SFG_MenuEntry *menuEntry;
515 * First of all check any of the active sub menus...
517 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry; menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
520 * Is this menu entry active?
522 if( menuEntry->IsActive == TRUE )
525 * If there is not a sub menu, execute the menu callback and return...
527 if( menuEntry->SubMenu == NULL )
530 * ...certainly given that there is one...
532 if( menu->Callback != NULL )
533 menu->Callback( menuEntry->ID );
539 * Otherwise recurse into the submenu.
541 fgExecuteMenuCallback( menuEntry->SubMenu );
544 * There is little sense in dwelling the search on
552 * Deactivates a menu pointed by the function argument.
554 void fgDeactivateMenu( SFG_Window *window )
556 SFG_Window *current_window = fgStructure.Window ;
559 * Check if there is an active menu attached to this window...
561 SFG_Menu* menu = window->ActiveMenu;
562 SFG_MenuEntry *menuEntry ;
565 * Did we find an active window?
567 freeglut_return_if_fail( menu != NULL );
570 * Hide the present menu's window
572 fgSetWindow ( menu->Window ) ;
576 * Forget about having that menu active anymore, now:
578 menu->Window->ActiveMenu = NULL ;
579 menu->ParentWindow->ActiveMenu = NULL ;
580 menu->IsActive = FALSE ;
582 fgState.ActiveMenus -- ;
585 * Hide all submenu windows, and the root menu's window.
587 for ( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
588 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
591 * Is that an active submenu by any case?
593 if ( ( menuEntry->SubMenu != NULL ) && menuEntry->SubMenu->IsActive )
594 fgDeactivateSubMenu ( menuEntry ) ;
597 fgSetWindow ( current_window ) ;
601 * Deactivates a menu pointed by the function argument.
603 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
605 SFG_Window *current_window = fgStructure.Window ;
606 SFG_MenuEntry *subMenuIter ;
608 * Hide the present menu's window
610 fgSetWindow ( menuEntry->SubMenu->Window ) ;
614 * Forget about having that menu active anymore, now:
616 menuEntry->SubMenu->Window->ActiveMenu = NULL ;
617 menuEntry->SubMenu->IsActive = FALSE ;
620 * Hide all submenu windows, and the root menu's window.
622 for ( subMenuIter = (SFG_MenuEntry *)menuEntry->SubMenu->Entries.First; subMenuIter;
623 subMenuIter = (SFG_MenuEntry *)subMenuIter->Node.Next )
626 * Is that an active submenu by any case?
628 if ( ( subMenuIter->SubMenu != NULL ) && subMenuIter->SubMenu->IsActive )
629 fgDeactivateSubMenu ( subMenuIter ) ;
632 fgSetWindow ( current_window ) ;
636 * Recalculates current menu's box size
638 void fghCalculateMenuBoxSize( void )
640 SFG_MenuEntry* menuEntry;
641 int width = 0, height = 0;
644 * Make sure there is a current menu set
646 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
649 * The menu's box size depends on the menu entries:
651 for( menuEntry = (SFG_MenuEntry *)fgStructure.Menu->Entries.First; menuEntry;
652 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
655 * Update the menu entry's width value
657 menuEntry->Width = glutBitmapLength( FREEGLUT_MENU_FONT, menuEntry->Text );
660 * If the entry is a submenu, then it needs to be wider to accomodate the arrow. JCJ 31 July 2003
663 if (menuEntry->SubMenu != NULL)
664 menuEntry->Width += glutBitmapLength( FREEGLUT_MENU_FONT, " " );
667 * Check if it's the biggest we've found
669 if( menuEntry->Width > width )
670 width = menuEntry->Width;
672 height += FREEGLUT_MENU_HEIGHT;
676 * Store the menu's box size now:
678 fgStructure.Menu->Height = height;
679 fgStructure.Menu->Width = width + 2 * FREEGLUT_MENU_BORDER ;
683 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
686 * Creates a new menu object, adding it to the freeglut structure
688 int FGAPIENTRY glutCreateMenu( void (* callback)( int ) )
691 * The menu object creation code resides in freeglut_structure.c
693 return( fgCreateMenu( callback )->ID );
697 * Destroys a menu object, removing all references to it
699 void FGAPIENTRY glutDestroyMenu( int menuID )
701 SFG_Menu* menu = fgMenuByID( menuID );
703 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
706 * The menu object destruction code resides in freeglut_structure.c
708 fgDestroyMenu( menu );
712 * Returns the ID number of the currently active menu
714 int FGAPIENTRY glutGetMenu( void )
716 freeglut_assert_ready;
719 * Is there a current menu set?
721 if( fgStructure.Menu != NULL )
724 * Yes, there is indeed...
726 return( fgStructure.Menu->ID );
730 * No, there is no current menu at all
736 * Sets the current menu given its menu ID
738 void FGAPIENTRY glutSetMenu( int menuID )
740 SFG_Menu* menu = fgMenuByID( menuID );
742 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
745 * The current menu pointer is stored in fgStructure.Menu
747 fgStructure.Menu = menu;
751 * Adds a menu entry to the bottom of the current menu
753 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
755 SFG_MenuEntry* menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
758 * Make sure there is a current menu set
760 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
763 * Fill in the appropriate values...
765 menuEntry->Text = strdup( label );
766 menuEntry->ID = value;
769 * Have the new menu entry attached to the current menu
771 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
774 * Update the menu's dimensions now
776 fghCalculateMenuBoxSize();
780 * Add a sub menu to the bottom of the current menu
782 void FGAPIENTRY glutAddSubMenu( const char* label, int subMenuID )
784 SFG_MenuEntry* menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
785 SFG_Menu* subMenu = fgMenuByID( subMenuID );
788 * Make sure there is a current menu and the sub menu
789 * we want to attach actually exists...
791 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
792 freeglut_return_if_fail( subMenu != NULL );
795 * Fill in the appropriate values
797 menuEntry->Text = strdup( label );
798 menuEntry->SubMenu = subMenu;
802 * Make the submenu's parent window be the menu's parent window
804 fghSetSubmenuParentWindow ( fgStructure.Menu->ParentWindow, subMenu ) ;
807 * Have the new menu entry attached to the current menu
809 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
812 * Update the menu's dimensions now
814 fghCalculateMenuBoxSize();
818 * Changes the specified menu item in the current menu into a menu entry
820 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
822 SFG_MenuEntry* menuEntry = NULL;
825 * Make sure there is a current menu set...
827 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
830 * Get n-th menu entry in the current menu, starting from one:
832 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
835 * Make sure the menu entry exists
837 freeglut_return_if_fail( menuEntry != NULL );
840 * We want it to become a normal menu entry, so:
842 if( menuEntry->Text != NULL )
843 free( menuEntry->Text );
845 menuEntry->Text = strdup( label );
846 menuEntry->ID = value;
847 menuEntry->SubMenu = NULL;
850 * Update the menu's dimensions now
852 fghCalculateMenuBoxSize();
856 * Changes the specified menu item in the current menu into a sub-menu trigger.
858 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int subMenuID )
860 SFG_Menu* subMenu = fgMenuByID( subMenuID );
861 SFG_MenuEntry* menuEntry = NULL;
864 * Make sure there is a current menu set and the sub menu exists...
866 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
867 freeglut_return_if_fail( subMenu != NULL );
870 * Get n-th menu entry in the current menu, starting from one:
872 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
875 * Make sure the menu entry exists
877 freeglut_return_if_fail( menuEntry != NULL );
880 * We want it to become a sub menu entry, so:
882 if( menuEntry->Text != NULL )
883 free( menuEntry->Text );
885 menuEntry->Text = strdup( label );
886 menuEntry->SubMenu = subMenu;
890 * Update the menu's dimensions now
892 fghCalculateMenuBoxSize();
896 * Removes the specified menu item from the current menu
898 void FGAPIENTRY glutRemoveMenuItem( int item )
900 SFG_MenuEntry* menuEntry;
903 * Make sure there is a current menu set
905 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
908 * Get n-th menu entry in the current menu, starting from one:
910 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
913 * Make sure the menu entry exists
915 freeglut_return_if_fail( menuEntry != NULL );
918 * Removing a menu entry is quite simple...
920 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
923 * Free the entry label string, too
925 free( menuEntry->Text );
930 * Update the menu's dimensions now
932 fghCalculateMenuBoxSize();
936 * Attaches a menu to the current window
938 void FGAPIENTRY glutAttachMenu( int button )
940 freeglut_assert_ready;
943 * There must be a current window and a current menu set:
945 freeglut_return_if_fail( fgStructure.Window != NULL || fgStructure.Menu != NULL );
948 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
950 freeglut_return_if_fail( button == GLUT_LEFT_BUTTON || button == GLUT_MIDDLE_BUTTON || button == GLUT_RIGHT_BUTTON );
953 * It is safe now to attach the menu
955 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
958 * Make the parent window of the menu (and all submenus) the current window
960 fghSetSubmenuParentWindow ( fgStructure.Window, fgStructure.Menu ) ;
964 * Detaches a menu from the current window
966 void FGAPIENTRY glutDetachMenu( int button )
968 freeglut_assert_ready;
971 * There must be a current window set:
973 freeglut_return_if_fail( fgStructure.Window != NULL );
976 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
978 freeglut_return_if_fail( button != 0 && button != 1 && button != 2 );
981 * It is safe now to detach the menu
983 fgStructure.Window->Menu[ button ] = NULL;
987 * A.Donev: Set and retrieve the menu's user data
989 void* FGAPIENTRY glutGetMenuData( void )
991 return(fgStructure.Menu->UserData);
994 void FGAPIENTRY glutSetMenuData(void* data)
996 fgStructure.Menu->UserData=data;
999 /*** END OF FILE ***/