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 = menu->Entries.First; entry; entry = 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 = menu->Entries.First; menuEntry;
87 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 = menu->Entries.First; menuEntry;
121 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 ) ;
197 glutPositionWindow ( menuEntry->SubMenu->X, menuEntry->SubMenu->Y ) ;
198 glutReshapeWindow ( menuEntry->SubMenu->Width, menuEntry->SubMenu->Height ) ;
199 menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu ;
200 fgSetWindow ( current_window ) ;
204 * ...then check the submenu's state:
206 fghCheckMenuStatus( window, menuEntry->SubMenu );
209 * Even if the submenu turned up inactive, activate it because its parent entry is active
211 menuEntry->SubMenu->IsActive = TRUE ;
215 * Report back that we have caught the menu cursor
221 * Looks like the menu cursor is somewhere else...
227 * Displays a menu box and all of its submenus (if they are active)
229 static void fghDisplayMenuBox( SFG_Menu* menu )
231 SFG_MenuEntry *menuEntry;
235 * Have the menu box drawn first. The +- values are
236 * here just to make it more nice-looking...
238 glColor4f( 0.1289f, 0.2257f, 0.28516f, 1.0f ); /* a non-black dark version of the below. */
241 glVertex2i( menu->Width, 0 );
242 glVertex2i( menu->Width, menu->Height );
243 glVertex2i( 0 , menu->Height );
246 glColor4f( 0.3f, 0.4f, 0.5f, 1.0f );
249 glVertex2i( menu->Width-1, 1 );
250 glVertex2i( menu->Width-1, menu->Height-1);
251 glVertex2i( 1, menu->Height-1);
255 * Check if any of the submenus is currently active...
257 for( menuEntry = menu->Entries.First; menuEntry;
258 menuEntry = menuEntry->Node.Next )
261 * Has the menu been marked as active, maybe?
263 if( menuEntry->IsActive == TRUE )
266 * That's truly right, and we need to have it highlighted.
267 * There is an assumption that mouse cursor didn't move
268 * since the last check of menu activity state:
270 int menuID = menuEntry->Ordinal;
273 * So have the highlight drawn...
275 glColor4f( 0.2f, 0.3f, 0.4f, 1.0f );
277 glVertex2i( 2 , (menuID + 0)*FREEGLUT_MENU_HEIGHT + 1 );
278 glVertex2i( menu->Width-2, (menuID + 0)*FREEGLUT_MENU_HEIGHT + 1 );
279 glVertex2i( menu->Width-2, (menuID + 1)*FREEGLUT_MENU_HEIGHT + 2 );
280 glVertex2i( 2 , (menuID + 1)*FREEGLUT_MENU_HEIGHT + 2 );
286 * Print the menu entries now...
288 glColor4f( 1, 1, 1, 1 );
290 for( menuEntry = menu->Entries.First, i=0; menuEntry;
291 menuEntry = menuEntry->Node.Next, ++i )
294 * Move the raster into position...
297 FREEGLUT_MENU_BORDER,
298 (i + 1)*FREEGLUT_MENU_HEIGHT-(int)(FREEGLUT_MENU_HEIGHT*0.3) /* Try to center the text - JCJ 31 July 2003*/
302 * Have the label drawn, character after character:
304 glutBitmapString( FREEGLUT_MENU_FONT, menuEntry->Text);
307 * If it's a submenu, draw a right arrow
309 if ( menuEntry->SubMenu != NULL )
311 GLubyte arrow_char [] = { 0, 0, 32, 48, 56, 60, 62, 63, 62, 60, 56, 48, 32, 0, 0 } ;
312 int width = glutBitmapWidth ( FREEGLUT_MENU_FONT, ' ' ) ;
314 glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
317 * Set up the pixel unpacking ways
319 glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
320 glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE );
321 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
322 glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
323 glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
324 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
326 glRasterPos2i ( menu->Width - 2 - width,
327 (i + 1)*FREEGLUT_MENU_HEIGHT ) ;
328 glBitmap ( width, FREEGLUT_MENU_HEIGHT, 0, 0, 0.0, 0.0, arrow_char ) ;
334 * Now we are ready to check if any of our children needs to be redrawn:
336 for( menuEntry = menu->Entries.First; menuEntry;
337 menuEntry = menuEntry->Node.Next )
340 * Is that an active sub menu by any case?
342 if( menuEntry->SubMenu != NULL && menuEntry->IsActive == TRUE )
345 * Yeah, indeed. Have it redrawn now:
347 fgSetWindow ( menuEntry->SubMenu->Window ) ;
348 fghDisplayMenuBox( menuEntry->SubMenu );
349 fgSetWindow ( menu->Window ) ;
355 * Private static function to set the parent window of a submenu and all of its submenus
357 static void fghSetSubmenuParentWindow ( SFG_Window *window, SFG_Menu *menu )
359 SFG_MenuEntry *menuEntry ;
361 menu->ParentWindow = window ;
363 for ( menuEntry = menu->Entries.First; menuEntry; menuEntry = menuEntry->Node.Next )
365 if ( menuEntry->SubMenu != NULL )
366 fghSetSubmenuParentWindow ( window, menuEntry->SubMenu ) ;
372 * Displays the currently active menu for the current window
374 void fgDisplayMenu( void )
376 SFG_Window* window = fgStructure.Window;
377 SFG_Menu* menu = NULL;
380 * Make sure there is a current window available
382 freeglut_assert_window;
385 * Check if there is an active menu attached to this window...
387 menu = window->ActiveMenu;
390 * Did we find an active menu?
392 freeglut_return_if_fail( menu != NULL );
394 fgSetWindow ( menu->Window ) ;
397 * Prepare the OpenGL state to do the rendering first:
399 glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT );
401 glDisable( GL_DEPTH_TEST );
402 glDisable( GL_TEXTURE_2D );
403 glDisable( GL_LIGHTING );
404 glDisable( GL_CULL_FACE );
407 * We'll use an orthogonal projection matrix to draw the menu:
409 glMatrixMode( GL_PROJECTION );
413 0, glutGet( GLUT_WINDOW_WIDTH ),
414 glutGet( GLUT_WINDOW_HEIGHT ), 0,
419 * Model-view matix gets reset to identity:
421 glMatrixMode( GL_MODELVIEW );
426 * First of all, have the exact menu status check:
428 fghCheckMenuStatus( window, menu );
431 * The status has been updated and we're ready to have the menu drawn now:
433 fghDisplayMenuBox( menu );
436 * Restore the old OpenGL settings now
440 glMatrixMode( GL_PROJECTION );
442 glMatrixMode( GL_MODELVIEW );
448 * Restore the current window
450 fgSetWindow ( window ) ;
454 * Activates a menu pointed by the function argument
456 void fgActivateMenu( SFG_Window* window, int button )
459 * We'll be referencing this menu a lot, so remember its address:
461 SFG_Menu* menu = window->Menu[ button ];
464 * Mark the menu as active, so that it gets displayed:
466 window->ActiveMenu = menu;
467 menu->IsActive = TRUE ;
470 * Set up the initial menu position now:
473 menu->X = window->State.MouseX + glutGet ( GLUT_WINDOW_X ) ;
474 menu->Y = window->State.MouseY + glutGet ( GLUT_WINDOW_Y ) ;
476 fgSetWindow ( menu->Window ) ;
478 glutPositionWindow ( menu->X, menu->Y ) ;
479 glutReshapeWindow ( menu->Width, menu->Height ) ;
480 menu->Window->ActiveMenu = menu ;
482 /* if( x > ( glutGet( GLUT_WINDOW_WIDTH ) - menu->Width ) )
483 menu->X = glutGet( GLUT_WINDOW_WIDTH ) - menu->Width;
484 if( y > ( glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height) )
485 menu->Y = glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height; */
489 * Check whether an active menu absorbs a mouse click
491 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
494 * Near as I can tell, this is the active menu behaviour:
495 * - Down-click any button outside the menu, menu active: deactivate the menu
496 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
497 * - Up-click the menu button outside the menu, menu active: nothing happens
498 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
499 * Since menus can have submenus, we need to check this recursively.
501 return fghCheckMenuStatus ( window, menu ) ;
505 * Function to check for menu entry selection on menu deactivation
507 void fgExecuteMenuCallback( SFG_Menu* menu )
509 SFG_MenuEntry *menuEntry;
512 * First of all check any of the active sub menus...
514 for( menuEntry = menu->Entries.First; menuEntry; menuEntry = menuEntry->Node.Next)
517 * Is this menu entry active?
519 if( menuEntry->IsActive == TRUE )
522 * If there is not a sub menu, execute the menu callback and return...
524 if( menuEntry->SubMenu == NULL )
527 * ...certainly given that there is one...
529 if( menu->Callback != NULL )
530 menu->Callback( menuEntry->ID );
536 * Otherwise recurse into the submenu.
538 fgExecuteMenuCallback( menuEntry->SubMenu );
541 * There is little sense in dwelling the search on
549 * Deactivates a menu pointed by the function argument.
551 void fgDeactivateMenu( SFG_Window *window )
553 SFG_Window *current_window = fgStructure.Window ;
556 * Check if there is an active menu attached to this window...
558 SFG_Menu* menu = window->ActiveMenu;
559 SFG_MenuEntry *menuEntry ;
562 * Did we find an active window?
564 freeglut_return_if_fail( menu != NULL );
567 * Hide the present menu's window
569 fgSetWindow ( menu->Window ) ;
573 * Forget about having that menu active anymore, now:
575 menu->Window->ActiveMenu = NULL ;
576 menu->ParentWindow->ActiveMenu = NULL ;
577 menu->IsActive = FALSE ;
580 * Hide all submenu windows, and the root menu's window.
582 for ( menuEntry = menu->Entries.First; menuEntry;
583 menuEntry = menuEntry->Node.Next )
586 * Is that an active submenu by any case?
588 if ( ( menuEntry->SubMenu != NULL ) && menuEntry->SubMenu->IsActive )
589 fgDeactivateSubMenu ( menuEntry ) ;
592 fgStructure.Window = current_window ;
596 * Deactivates a menu pointed by the function argument.
598 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
600 SFG_Window *current_window = fgStructure.Window ;
601 SFG_MenuEntry *subMenuIter ;
603 * Hide the present menu's window
605 fgSetWindow ( menuEntry->SubMenu->Window ) ;
609 * Forget about having that menu active anymore, now:
611 menuEntry->SubMenu->Window->ActiveMenu = NULL ;
612 menuEntry->SubMenu->IsActive = FALSE ;
615 * Hide all submenu windows, and the root menu's window.
617 for ( subMenuIter = menuEntry->SubMenu->Entries.First; subMenuIter;
618 subMenuIter = subMenuIter->Node.Next )
621 * Is that an active submenu by any case?
623 if ( ( subMenuIter->SubMenu != NULL ) && subMenuIter->SubMenu->IsActive )
624 fgDeactivateSubMenu ( subMenuIter ) ;
627 fgStructure.Window = current_window ;
631 * Recalculates current menu's box size
633 void fghCalculateMenuBoxSize( void )
635 SFG_MenuEntry* menuEntry;
636 int width = 0, height = 0;
639 * Make sure there is a current menu set
641 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
644 * The menu's box size depends on the menu entries:
646 for( menuEntry = fgStructure.Menu->Entries.First; menuEntry;
647 menuEntry = menuEntry->Node.Next)
650 * Update the menu entry's width value
652 menuEntry->Width = glutBitmapLength( FREEGLUT_MENU_FONT, menuEntry->Text );
655 * If the entry is a submenu, then it needs to be wider to accomodate the arrow. JCJ 31 July 2003
658 if (menuEntry->SubMenu != NULL)
659 menuEntry->Width += glutBitmapLength( FREEGLUT_MENU_FONT, " " );
662 * Check if it's the biggest we've found
664 if( menuEntry->Width > width )
665 width = menuEntry->Width;
667 height += FREEGLUT_MENU_HEIGHT;
671 * Store the menu's box size now:
673 fgStructure.Menu->Height = height;
674 fgStructure.Menu->Width = width + 2 * FREEGLUT_MENU_BORDER ;
678 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
681 * Creates a new menu object, adding it to the freeglut structure
683 int FGAPIENTRY glutCreateMenu( void (* callback)( int ) )
686 * The menu object creation code resides in freeglut_structure.c
688 return( fgCreateMenu( callback )->ID );
692 * Destroys a menu object, removing all references to it
694 void FGAPIENTRY glutDestroyMenu( int menuID )
696 SFG_Menu* menu = fgMenuByID( menuID );
698 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
701 * The menu object destruction code resides in freeglut_structure.c
703 fgDestroyMenu( menu );
707 * Returns the ID number of the currently active menu
709 int FGAPIENTRY glutGetMenu( void )
711 freeglut_assert_ready;
714 * Is there a current menu set?
716 if( fgStructure.Menu != NULL )
719 * Yes, there is indeed...
721 return( fgStructure.Menu->ID );
725 * No, there is no current menu at all
731 * Sets the current menu given its menu ID
733 void FGAPIENTRY glutSetMenu( int menuID )
735 SFG_Menu* menu = fgMenuByID( menuID );
737 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
740 * The current menu pointer is stored in fgStructure.Menu
742 fgStructure.Menu = menu;
746 * Adds a menu entry to the bottom of the current menu
748 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
750 SFG_MenuEntry* menuEntry = calloc( sizeof(SFG_MenuEntry), 1 );
753 * Make sure there is a current menu set
755 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
758 * Fill in the appropriate values...
760 menuEntry->Text = strdup( label );
761 menuEntry->ID = value;
764 * Have the new menu entry attached to the current menu
766 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
769 * Update the menu's dimensions now
771 fghCalculateMenuBoxSize();
775 * Add a sub menu to the bottom of the current menu
777 void FGAPIENTRY glutAddSubMenu( const char* label, int subMenuID )
779 SFG_MenuEntry* menuEntry = calloc( sizeof(SFG_MenuEntry), 1 );
780 SFG_Menu* subMenu = fgMenuByID( subMenuID );
783 * Make sure there is a current menu and the sub menu
784 * we want to attach actually exists...
786 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
787 freeglut_return_if_fail( subMenu != NULL );
790 * Fill in the appropriate values
792 menuEntry->Text = strdup( label );
793 menuEntry->SubMenu = subMenu;
797 * Make the submenu's parent window be the menu's parent window
799 fghSetSubmenuParentWindow ( fgStructure.Menu->ParentWindow, subMenu ) ;
802 * Have the new menu entry attached to the current menu
804 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
807 * Update the menu's dimensions now
809 fghCalculateMenuBoxSize();
813 * Changes the specified menu item in the current menu into a menu entry
815 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
817 SFG_MenuEntry* menuEntry = NULL;
820 * Make sure there is a current menu set...
822 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
825 * Get n-th menu entry in the current menu, starting from one:
827 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
830 * Make sure the menu entry exists
832 freeglut_return_if_fail( menuEntry != NULL );
835 * We want it to become a normal menu entry, so:
837 if( menuEntry->Text != NULL )
838 free( menuEntry->Text );
840 menuEntry->Text = strdup( label );
841 menuEntry->ID = value;
842 menuEntry->SubMenu = NULL;
845 * Update the menu's dimensions now
847 fghCalculateMenuBoxSize();
851 * Changes the specified menu item in the current menu into a sub-menu trigger.
853 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int subMenuID )
855 SFG_Menu* subMenu = fgMenuByID( subMenuID );
856 SFG_MenuEntry* menuEntry = NULL;
859 * Make sure there is a current menu set and the sub menu exists...
861 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
862 freeglut_return_if_fail( subMenu != NULL );
865 * Get n-th menu entry in the current menu, starting from one:
867 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
870 * Make sure the menu entry exists
872 freeglut_return_if_fail( menuEntry != NULL );
875 * We want it to become a sub menu entry, so:
877 if( menuEntry->Text != NULL )
878 free( menuEntry->Text );
880 menuEntry->Text = strdup( label );
881 menuEntry->SubMenu = subMenu;
885 * Update the menu's dimensions now
887 fghCalculateMenuBoxSize();
891 * Removes the specified menu item from the current menu
893 void FGAPIENTRY glutRemoveMenuItem( int item )
895 SFG_MenuEntry* menuEntry;
898 * Make sure there is a current menu set
900 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
903 * Get n-th menu entry in the current menu, starting from one:
905 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
908 * Make sure the menu entry exists
910 freeglut_return_if_fail( menuEntry != NULL );
913 * Removing a menu entry is quite simple...
915 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
918 * Free the entry label string, too
920 free( menuEntry->Text );
925 * Update the menu's dimensions now
927 fghCalculateMenuBoxSize();
931 * Attaches a menu to the current window
933 void FGAPIENTRY glutAttachMenu( int button )
935 freeglut_assert_ready;
938 * There must be a current window and a current menu set:
940 freeglut_return_if_fail( fgStructure.Window != NULL || fgStructure.Menu != NULL );
943 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
945 freeglut_return_if_fail( button == GLUT_LEFT_BUTTON || button == GLUT_MIDDLE_BUTTON || button == GLUT_RIGHT_BUTTON );
948 * It is safe now to attach the menu
950 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
953 * Make the parent window of the menu (and all submenus) the current window
955 fghSetSubmenuParentWindow ( fgStructure.Window, fgStructure.Menu ) ;
959 * Detaches a menu from the current window
961 void FGAPIENTRY glutDetachMenu( int button )
963 freeglut_assert_ready;
966 * There must be a current window set:
968 freeglut_return_if_fail( fgStructure.Window != NULL );
971 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
973 freeglut_return_if_fail( button != 0 && button != 1 && button != 2 );
976 * It is safe now to detach the menu
978 fgStructure.Window->Menu[ button ] = NULL;
982 * A.Donev: Set and retrieve the menu's user data
984 void* FGAPIENTRY glutGetMenuData( void )
986 return(fgStructure.Menu->UserData);
989 void FGAPIENTRY glutSetMenuData(void* data)
991 fgStructure.Menu->UserData=data;
994 /*** END OF FILE ***/