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 ) ;
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 = menu->Entries.First; menuEntry;
259 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 = menu->Entries.First, i=0; menuEntry;
292 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 = menu->Entries.First; menuEntry;
338 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 = menu->Entries.First; menuEntry; 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 ;
471 * Set up the initial menu position now:
474 menu->X = window->State.MouseX + glutGet ( GLUT_WINDOW_X ) ;
475 menu->Y = window->State.MouseY + glutGet ( GLUT_WINDOW_Y ) ;
477 fgSetWindow ( menu->Window ) ;
478 glutPositionWindow ( menu->X, menu->Y ) ;
479 glutReshapeWindow ( menu->Width, menu->Height ) ;
482 menu->Window->ActiveMenu = menu ;
484 /* if( x > ( glutGet( GLUT_WINDOW_WIDTH ) - menu->Width ) )
485 menu->X = glutGet( GLUT_WINDOW_WIDTH ) - menu->Width;
486 if( y > ( glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height) )
487 menu->Y = glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height; */
491 * Check whether an active menu absorbs a mouse click
493 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
496 * Near as I can tell, this is the active menu behaviour:
497 * - Down-click any button outside the menu, menu active: deactivate the menu
498 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
499 * - Up-click the menu button outside the menu, menu active: nothing happens
500 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
501 * Since menus can have submenus, we need to check this recursively.
503 return fghCheckMenuStatus ( window, menu ) ;
507 * Function to check for menu entry selection on menu deactivation
509 void fgExecuteMenuCallback( SFG_Menu* menu )
511 SFG_MenuEntry *menuEntry;
514 * First of all check any of the active sub menus...
516 for( menuEntry = menu->Entries.First; menuEntry; menuEntry = menuEntry->Node.Next)
519 * Is this menu entry active?
521 if( menuEntry->IsActive == TRUE )
524 * If there is not a sub menu, execute the menu callback and return...
526 if( menuEntry->SubMenu == NULL )
529 * ...certainly given that there is one...
531 if( menu->Callback != NULL )
532 menu->Callback( menuEntry->ID );
538 * Otherwise recurse into the submenu.
540 fgExecuteMenuCallback( menuEntry->SubMenu );
543 * There is little sense in dwelling the search on
551 * Deactivates a menu pointed by the function argument.
553 void fgDeactivateMenu( SFG_Window *window )
555 SFG_Window *current_window = fgStructure.Window ;
558 * Check if there is an active menu attached to this window...
560 SFG_Menu* menu = window->ActiveMenu;
561 SFG_MenuEntry *menuEntry ;
564 * Did we find an active window?
566 freeglut_return_if_fail( menu != NULL );
569 * Hide the present menu's window
571 fgSetWindow ( menu->Window ) ;
575 * Forget about having that menu active anymore, now:
577 menu->Window->ActiveMenu = NULL ;
578 menu->ParentWindow->ActiveMenu = NULL ;
579 menu->IsActive = FALSE ;
582 * Hide all submenu windows, and the root menu's window.
584 for ( menuEntry = menu->Entries.First; menuEntry;
585 menuEntry = menuEntry->Node.Next )
588 * Is that an active submenu by any case?
590 if ( ( menuEntry->SubMenu != NULL ) && menuEntry->SubMenu->IsActive )
591 fgDeactivateSubMenu ( menuEntry ) ;
594 fgStructure.Window = current_window ;
598 * Deactivates a menu pointed by the function argument.
600 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
602 SFG_Window *current_window = fgStructure.Window ;
603 SFG_MenuEntry *subMenuIter ;
605 * Hide the present menu's window
607 fgSetWindow ( menuEntry->SubMenu->Window ) ;
611 * Forget about having that menu active anymore, now:
613 menuEntry->SubMenu->Window->ActiveMenu = NULL ;
614 menuEntry->SubMenu->IsActive = FALSE ;
617 * Hide all submenu windows, and the root menu's window.
619 for ( subMenuIter = menuEntry->SubMenu->Entries.First; subMenuIter;
620 subMenuIter = subMenuIter->Node.Next )
623 * Is that an active submenu by any case?
625 if ( ( subMenuIter->SubMenu != NULL ) && subMenuIter->SubMenu->IsActive )
626 fgDeactivateSubMenu ( subMenuIter ) ;
629 fgStructure.Window = current_window ;
633 * Recalculates current menu's box size
635 void fghCalculateMenuBoxSize( void )
637 SFG_MenuEntry* menuEntry;
638 int width = 0, height = 0;
641 * Make sure there is a current menu set
643 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
646 * The menu's box size depends on the menu entries:
648 for( menuEntry = fgStructure.Menu->Entries.First; menuEntry;
649 menuEntry = menuEntry->Node.Next)
652 * Update the menu entry's width value
654 menuEntry->Width = glutBitmapLength( FREEGLUT_MENU_FONT, menuEntry->Text );
657 * If the entry is a submenu, then it needs to be wider to accomodate the arrow. JCJ 31 July 2003
660 if (menuEntry->SubMenu != NULL)
661 menuEntry->Width += glutBitmapLength( FREEGLUT_MENU_FONT, " " );
664 * Check if it's the biggest we've found
666 if( menuEntry->Width > width )
667 width = menuEntry->Width;
669 height += FREEGLUT_MENU_HEIGHT;
673 * Store the menu's box size now:
675 fgStructure.Menu->Height = height;
676 fgStructure.Menu->Width = width + 2 * FREEGLUT_MENU_BORDER ;
680 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
683 * Creates a new menu object, adding it to the freeglut structure
685 int FGAPIENTRY glutCreateMenu( void (* callback)( int ) )
688 * The menu object creation code resides in freeglut_structure.c
690 return( fgCreateMenu( callback )->ID );
694 * Destroys a menu object, removing all references to it
696 void FGAPIENTRY glutDestroyMenu( int menuID )
698 SFG_Menu* menu = fgMenuByID( menuID );
700 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
703 * The menu object destruction code resides in freeglut_structure.c
705 fgDestroyMenu( menu );
709 * Returns the ID number of the currently active menu
711 int FGAPIENTRY glutGetMenu( void )
713 freeglut_assert_ready;
716 * Is there a current menu set?
718 if( fgStructure.Menu != NULL )
721 * Yes, there is indeed...
723 return( fgStructure.Menu->ID );
727 * No, there is no current menu at all
733 * Sets the current menu given its menu ID
735 void FGAPIENTRY glutSetMenu( int menuID )
737 SFG_Menu* menu = fgMenuByID( menuID );
739 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
742 * The current menu pointer is stored in fgStructure.Menu
744 fgStructure.Menu = menu;
748 * Adds a menu entry to the bottom of the current menu
750 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
752 SFG_MenuEntry* menuEntry = calloc( sizeof(SFG_MenuEntry), 1 );
755 * Make sure there is a current menu set
757 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
760 * Fill in the appropriate values...
762 menuEntry->Text = strdup( label );
763 menuEntry->ID = value;
766 * Have the new menu entry attached to the current menu
768 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
771 * Update the menu's dimensions now
773 fghCalculateMenuBoxSize();
777 * Add a sub menu to the bottom of the current menu
779 void FGAPIENTRY glutAddSubMenu( const char* label, int subMenuID )
781 SFG_MenuEntry* menuEntry = calloc( sizeof(SFG_MenuEntry), 1 );
782 SFG_Menu* subMenu = fgMenuByID( subMenuID );
785 * Make sure there is a current menu and the sub menu
786 * we want to attach actually exists...
788 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
789 freeglut_return_if_fail( subMenu != NULL );
792 * Fill in the appropriate values
794 menuEntry->Text = strdup( label );
795 menuEntry->SubMenu = subMenu;
799 * Make the submenu's parent window be the menu's parent window
801 fghSetSubmenuParentWindow ( fgStructure.Menu->ParentWindow, subMenu ) ;
804 * Have the new menu entry attached to the current menu
806 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
809 * Update the menu's dimensions now
811 fghCalculateMenuBoxSize();
815 * Changes the specified menu item in the current menu into a menu entry
817 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
819 SFG_MenuEntry* menuEntry = NULL;
822 * Make sure there is a current menu set...
824 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
827 * Get n-th menu entry in the current menu, starting from one:
829 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
832 * Make sure the menu entry exists
834 freeglut_return_if_fail( menuEntry != NULL );
837 * We want it to become a normal menu entry, so:
839 if( menuEntry->Text != NULL )
840 free( menuEntry->Text );
842 menuEntry->Text = strdup( label );
843 menuEntry->ID = value;
844 menuEntry->SubMenu = NULL;
847 * Update the menu's dimensions now
849 fghCalculateMenuBoxSize();
853 * Changes the specified menu item in the current menu into a sub-menu trigger.
855 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int subMenuID )
857 SFG_Menu* subMenu = fgMenuByID( subMenuID );
858 SFG_MenuEntry* menuEntry = NULL;
861 * Make sure there is a current menu set and the sub menu exists...
863 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
864 freeglut_return_if_fail( subMenu != NULL );
867 * Get n-th menu entry in the current menu, starting from one:
869 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
872 * Make sure the menu entry exists
874 freeglut_return_if_fail( menuEntry != NULL );
877 * We want it to become a sub menu entry, so:
879 if( menuEntry->Text != NULL )
880 free( menuEntry->Text );
882 menuEntry->Text = strdup( label );
883 menuEntry->SubMenu = subMenu;
887 * Update the menu's dimensions now
889 fghCalculateMenuBoxSize();
893 * Removes the specified menu item from the current menu
895 void FGAPIENTRY glutRemoveMenuItem( int item )
897 SFG_MenuEntry* menuEntry;
900 * Make sure there is a current menu set
902 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
905 * Get n-th menu entry in the current menu, starting from one:
907 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
910 * Make sure the menu entry exists
912 freeglut_return_if_fail( menuEntry != NULL );
915 * Removing a menu entry is quite simple...
917 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
920 * Free the entry label string, too
922 free( menuEntry->Text );
927 * Update the menu's dimensions now
929 fghCalculateMenuBoxSize();
933 * Attaches a menu to the current window
935 void FGAPIENTRY glutAttachMenu( int button )
937 freeglut_assert_ready;
940 * There must be a current window and a current menu set:
942 freeglut_return_if_fail( fgStructure.Window != NULL || fgStructure.Menu != NULL );
945 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
947 freeglut_return_if_fail( button == GLUT_LEFT_BUTTON || button == GLUT_MIDDLE_BUTTON || button == GLUT_RIGHT_BUTTON );
950 * It is safe now to attach the menu
952 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
955 * Make the parent window of the menu (and all submenus) the current window
957 fghSetSubmenuParentWindow ( fgStructure.Window, fgStructure.Menu ) ;
961 * Detaches a menu from the current window
963 void FGAPIENTRY glutDetachMenu( int button )
965 freeglut_assert_ready;
968 * There must be a current window set:
970 freeglut_return_if_fail( fgStructure.Window != NULL );
973 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
975 freeglut_return_if_fail( button != 0 && button != 1 && button != 2 );
978 * It is safe now to detach the menu
980 fgStructure.Window->Menu[ button ] = NULL;
984 * A.Donev: Set and retrieve the menu's user data
986 void* FGAPIENTRY glutGetMenuData( void )
988 return(fgStructure.Menu->UserData);
991 void FGAPIENTRY glutSetMenuData(void* data)
993 fgStructure.Menu->UserData=data;
996 /*** END OF FILE ***/