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 #include "../include/GL/freeglut.h"
33 #include "freeglut_internal.h"
35 /* -- DEFINITIONS ---------------------------------------------------------- */
38 * FREEGLUT_MENU_FONT can be any freeglut bitmapped font.
39 * (Stroked fonts would not be out of the question, but we'd need to alter
40 * code, since GLUT (hence freeglut) does not quite unify stroked and
41 * bitmapped font handling.)
42 * Old UNIX/X11 GLUT (BSD, UNIX, IRIX, LINUX, HPUX, ...) used a system
43 * font best approximated by an 18-pixel HELVETICA, I think. MS-WINDOWS
44 * GLUT used something closest to the 8x13 fixed-width font. (Old
45 * GLUT apparently uses host-system menus rather than building its own.
46 * freeglut is building its own menus from scratch.)
48 * FREEGLUT_MENU_HEIGHT gives the height of ONE menu box. This should be
49 * the distances between two adjacent menu entries. It should scale
50 * automatically with the font choice, so you needn't alter it---unless you
53 * FREEGLUT_MENU_BORDER says how many pixels to allow around the edge of a
54 * menu. (It also seems to be the same as the number of pixels used as
55 * a border around *items* to separate them from neighbors. John says
56 * that that wasn't the original intent...if not, perhaps we need another
57 * symbolic constant, FREEGLUT_MENU_ITEM_BORDER, or such.)
60 #define FREEGLUT_MENU_FONT GLUT_BITMAP_8_BY_13
62 #define FREEGLUT_MENU_FONT GLUT_BITMAP_HELVETICA_18
65 #define FREEGLUT_MENU_HEIGHT (glutBitmapHeight(FREEGLUT_MENU_FONT) + \
67 #define FREEGLUT_MENU_BORDER 2
71 * These variables are for rendering the freeglut menu items.
73 * The choices are fore- and background, with and without h for Highlighting.
74 * Old GLUT appeared to be system-dependant for its colors (sigh) so we are
75 * too. These variables should be stuffed into global state and initialized
76 * via the glutInit*() system.
79 static float menu_pen_fore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
80 static float menu_pen_back [4] = {0.85f, 0.85f, 0.85f, 1.0f};
81 static float menu_pen_hfore [4] = {1.0f, 1.0f, 1.0f, 1.0f};
82 static float menu_pen_hback [4] = {0.15f, 0.15f, 0.45f, 1.0f};
84 static float menu_pen_fore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
85 static float menu_pen_back [4] = {0.70f, 0.70f, 0.70f, 1.0f};
86 static float menu_pen_hfore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
87 static float menu_pen_hback [4] = {1.0f, 1.0f, 1.0f, 1.0f};
90 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
93 * Private function to find a menu entry by index
95 static SFG_MenuEntry *fghFindMenuEntry( SFG_Menu* menu, int index )
100 for( entry = (SFG_MenuEntry *)menu->Entries.First;
102 entry = (SFG_MenuEntry *)entry->Node.Next )
113 * Private function to check for the current menu/sub menu activity state
115 static GLboolean fghCheckMenuStatus( SFG_Window* window, SFG_Menu* menu )
117 SFG_MenuEntry* menuEntry;
121 * First of all check any of the active sub menus...
123 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
125 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
127 if( menuEntry->SubMenu && menuEntry->IsActive )
130 * OK, have the sub-menu checked, too. If it returns GL_TRUE, it
131 * will mean that it caught the mouse cursor and we do not need
132 * to regenerate the activity list, and so our parents do...
134 GLboolean return_status = fghCheckMenuStatus( window,
135 menuEntry->SubMenu );
138 * Reactivate the submenu as the checkMenuStatus may have turned
139 * it off if the mouse is in its parent menu entry.
141 menuEntry->SubMenu->IsActive = GL_TRUE;
148 * That much about our sub menus, let's get to checking the current menu:
150 x = window->State.MouseX;
151 y = window->State.MouseY;
153 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
155 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
156 menuEntry->IsActive = GL_FALSE;
158 menu->IsActive = GL_FALSE;
161 * Check if the mouse cursor is contained within the current menu box
163 if( ( x >= FREEGLUT_MENU_BORDER ) &&
164 ( x < menu->Width - FREEGLUT_MENU_BORDER ) &&
165 ( y >= FREEGLUT_MENU_BORDER ) &&
166 ( y < menu->Height - FREEGLUT_MENU_BORDER ) &&
167 ( window == menu->Window ) )
169 int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENU_HEIGHT;
172 * The mouse cursor is somewhere over our box, check it out.
174 menuEntry = fghFindMenuEntry( menu, menuID + 1 );
177 menuEntry->IsActive = GL_TRUE;
178 menuEntry->Ordinal = menuID;
181 * If this is not the same as the last active menu entry, deactivate
182 * the previous entry. Specifically, if the previous active entry
183 * was a submenu then deactivate it.
185 if( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
186 if( menu->ActiveEntry->SubMenu )
187 fgDeactivateSubMenu( menu->ActiveEntry );
189 menu->ActiveEntry = menuEntry;
190 menu->IsActive = GL_TRUE;
193 * OKi, we have marked that entry as active, but it would be also
194 * nice to have its contents updated, in case it's a sub menu.
195 * Also, ignore the return value of the check function:
197 if( menuEntry->SubMenu )
199 if ( ! menuEntry->SubMenu->IsActive )
201 SFG_Window *current_window = fgStructure.Window;
204 * Set up the initial menu position now...
206 menuEntry->SubMenu->IsActive = GL_TRUE;
209 * Set up the initial submenu position now:
211 menuEntry->SubMenu->X = menu->X + menu->Width;
212 menuEntry->SubMenu->Y = menu->Y +
213 menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT;
215 if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width >
216 glutGet( GLUT_SCREEN_WIDTH ) )
217 menuEntry->SubMenu->X = menu->X -
218 menuEntry->SubMenu->Width;
220 if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height >
221 glutGet( GLUT_SCREEN_HEIGHT ) )
222 menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
223 FREEGLUT_MENU_HEIGHT -
224 2 * FREEGLUT_MENU_BORDER );
226 fgSetWindow( menuEntry->SubMenu->Window );
227 glutPositionWindow( menuEntry->SubMenu->X,
228 menuEntry->SubMenu->Y );
229 glutReshapeWindow( menuEntry->SubMenu->Width,
230 menuEntry->SubMenu->Height );
233 menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu;
234 fgSetWindow( current_window );
237 fghCheckMenuStatus( window, menuEntry->SubMenu );
240 * Activate it because its parent entry is active
242 menuEntry->SubMenu->IsActive = GL_TRUE;
246 * Report back that we have caught the menu cursor
252 * Looks like the menu cursor is somewhere else...
258 * Displays a menu box and all of its submenus (if they are active)
260 static void fghDisplayMenuBox( SFG_Menu* menu )
262 SFG_MenuEntry *menuEntry;
264 int border = FREEGLUT_MENU_BORDER;
267 * Have the menu box drawn first. The +- values are
268 * here just to make it more nice-looking...
270 /* a non-black dark version of the below. */
271 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
272 glBegin( GL_QUAD_STRIP );
273 glVertex2i( menu->Width , 0 );
274 glVertex2i( menu->Width - border, border);
276 glVertex2i( border, border);
277 glVertex2i( 0 , menu->Height );
278 glVertex2i( border, menu->Height - border);
281 /* a non-black dark version of the below. */
282 glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
283 glBegin( GL_QUAD_STRIP );
284 glVertex2i( 0 , menu->Height );
285 glVertex2i( border, menu->Height - border);
286 glVertex2i( menu->Width , menu->Height );
287 glVertex2i( menu->Width - border, menu->Height - border);
288 glVertex2i( menu->Width , 0 );
289 glVertex2i( menu->Width - border, border);
292 glColor4fv( menu_pen_back ) ;
294 glVertex2i( border, border);
295 glVertex2i( menu->Width - border, border);
296 glVertex2i( menu->Width - border, menu->Height - border);
297 glVertex2i( border, menu->Height - border);
301 * Check if any of the submenus is currently active...
303 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
305 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
308 * Has the menu been marked as active, maybe?
310 if( menuEntry->IsActive )
313 * That's truly right, and we need to have it highlighted.
314 * There is an assumption that mouse cursor didn't move
315 * since the last check of menu activity state:
317 int menuID = menuEntry->Ordinal;
320 * So have the highlight drawn...
322 glColor4fv( menu_pen_hback );
325 (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
326 glVertex2i( menu->Width - border,
327 (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
328 glVertex2i( menu->Width - border,
329 (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
331 (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
337 * Print the menu entries now...
340 glColor4fv( menu_pen_fore );
342 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First, i = 0;
344 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next, ++i )
347 * If the menu entry is active, set the color to white
349 if( menuEntry->IsActive )
350 glColor4fv( menu_pen_hfore );
353 * Move the raster into position...
355 /* Try to center the text - JCJ 31 July 2003*/
358 ( i + 1 )*FREEGLUT_MENU_HEIGHT -
359 ( int )( FREEGLUT_MENU_HEIGHT*0.3 - border )
363 * Have the label drawn, character after character:
365 glutBitmapString( FREEGLUT_MENU_FONT, menuEntry->Text);
368 * If it's a submenu, draw a right arrow
370 if( menuEntry->SubMenu )
372 int width = glutBitmapWidth( FREEGLUT_MENU_FONT, '_' );
373 int x_base = menu->Width - 2 - width;
374 int y_base = i*FREEGLUT_MENU_HEIGHT + border;
375 glBegin( GL_TRIANGLES );
376 glVertex2i( x_base, y_base + 2*border);
377 glVertex2i( menu->Width - 2, y_base +
378 ( FREEGLUT_MENU_HEIGHT + border) / 2 );
379 glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - border );
384 * If the menu entry is active, reset the color
386 if( menuEntry->IsActive )
387 glColor4fv( menu_pen_fore );
391 * Now we are ready to check if any of our children needs to be redrawn:
393 for( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
395 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
398 * Is that an active sub menu by any case?
400 if( menuEntry->SubMenu && menuEntry->IsActive )
403 * Yeah, indeed. Have it redrawn now:
405 fgSetWindow( menuEntry->SubMenu->Window );
406 fghDisplayMenuBox( menuEntry->SubMenu );
407 fgSetWindow( menu->Window );
413 * Private static function to set the parent window of a submenu and all
416 static void fghSetSubmenuParentWindow( SFG_Window *window, SFG_Menu *menu )
418 SFG_MenuEntry *menuEntry;
420 menu->ParentWindow = window;
422 for( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
424 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
425 if( menuEntry->SubMenu )
426 fghSetSubmenuParentWindow( window, menuEntry->SubMenu );
431 * Displays the currently active menu for the current window
433 void fgDisplayMenu( void )
435 SFG_Window* window = fgStructure.Window;
436 SFG_Menu* menu = NULL;
438 freeglut_assert_window;
441 * Check if there is an active menu attached to this window...
443 menu = window->ActiveMenu;
444 freeglut_return_if_fail( menu );
446 fgSetWindow( menu->Window );
448 glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT |
451 glDisable( GL_DEPTH_TEST );
452 glDisable( GL_TEXTURE_2D );
453 glDisable( GL_LIGHTING );
454 glDisable( GL_CULL_FACE );
456 glMatrixMode( GL_PROJECTION );
460 0, glutGet( GLUT_WINDOW_WIDTH ),
461 glutGet( GLUT_WINDOW_HEIGHT ), 0,
465 glMatrixMode( GL_MODELVIEW );
469 fghCheckMenuStatus( window, menu );
470 fghDisplayMenuBox( menu );
474 glMatrixMode( GL_PROJECTION );
476 glMatrixMode( GL_MODELVIEW );
481 fgSetWindow ( window );
485 * Activates a menu pointed by the function argument
487 void fgActivateMenu( SFG_Window* window, int button )
490 * We'll be referencing this menu a lot, so remember its address:
492 SFG_Menu* menu = window->Menu[ button ];
495 * Mark the menu as active, so that it gets displayed:
497 window->ActiveMenu = menu;
498 menu->IsActive = GL_TRUE;
499 fgState.ActiveMenus++;
502 * Set up the initial menu position now:
504 menu->X = window->State.MouseX + glutGet( GLUT_WINDOW_X );
505 menu->Y = window->State.MouseY + glutGet( GLUT_WINDOW_Y );
507 if( menu->X + menu->Width > glutGet ( GLUT_SCREEN_WIDTH ) )
508 menu->X -=menu->Width;
510 if( menu->Y + menu->Height > glutGet ( GLUT_SCREEN_HEIGHT ) )
511 menu->Y -=menu->Height;
513 fgSetWindow( menu->Window );
514 glutPositionWindow( menu->X, menu->Y );
515 glutReshapeWindow( menu->Width, menu->Height );
518 menu->Window->ActiveMenu = menu;
522 * Check whether an active menu absorbs a mouse click
524 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
527 * Near as I can tell, this is the active menu behaviour:
528 * - Down-click any button outside the menu, menu active:
529 * deactivate the menu
530 * - Down-click any button inside the menu, menu active:
531 * select the menu entry and deactivate the menu
532 * - Up-click the menu button outside the menu, menu active:
534 * - Up-click the menu button inside the menu, menu active:
535 * select the menu entry and deactivate the menu
536 * Since menus can have submenus, we need to check this recursively.
538 return fghCheckMenuStatus( window, menu );
542 * Function to check for menu entry selection on menu deactivation
544 void fgExecuteMenuCallback( SFG_Menu* menu )
546 SFG_MenuEntry *menuEntry;
549 * First of all check any of the active sub menus...
551 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
553 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
555 if( menuEntry->IsActive )
557 if( menuEntry->SubMenu )
558 fgExecuteMenuCallback( menuEntry->SubMenu );
561 menu->Callback( menuEntry->ID );
568 * Deactivates a menu pointed by the function argument.
570 void fgDeactivateMenu( SFG_Window *window )
572 SFG_Window *current_window = fgStructure.Window;
575 * Check if there is an active menu attached to this window...
577 SFG_Menu* menu = window->ActiveMenu;
578 SFG_MenuEntry *menuEntry;
581 * Did we find an active window?
583 freeglut_return_if_fail( menu );
586 * Hide the present menu's window
588 fgSetWindow( menu->Window );
592 * Forget about having that menu active anymore, now:
594 menu->Window->ActiveMenu = NULL;
595 menu->ParentWindow->ActiveMenu = NULL;
596 menu->IsActive = GL_FALSE;
598 fgState.ActiveMenus--;
601 * Hide all submenu windows, and the root menu's window.
603 for ( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
605 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
608 * Is that an active submenu by any case?
610 if( menuEntry->SubMenu )
611 fgDeactivateSubMenu( menuEntry );
614 fgSetWindow( current_window );
618 * Deactivates a menu pointed by the function argument.
620 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
622 SFG_Window *current_window = fgStructure.Window;
623 SFG_MenuEntry *subMenuIter;
625 * Hide the present menu's window
627 fgSetWindow( menuEntry->SubMenu->Window );
631 * Forget about having that menu active anymore, now:
633 menuEntry->SubMenu->Window->ActiveMenu = NULL;
634 menuEntry->SubMenu->IsActive = GL_FALSE;
637 * Hide all submenu windows, and the root menu's window.
639 for ( subMenuIter = (SFG_MenuEntry *)menuEntry->SubMenu->Entries.First;
641 subMenuIter = (SFG_MenuEntry *)subMenuIter->Node.Next )
644 * Is that an active submenu by any case?
646 if( subMenuIter->SubMenu )
647 fgDeactivateSubMenu( subMenuIter );
650 fgSetWindow( current_window );
654 * Recalculates current menu's box size
656 void fghCalculateMenuBoxSize( void )
658 SFG_MenuEntry* menuEntry;
659 int width = 0, height = 0;
662 * Make sure there is a current menu set
664 freeglut_assert_ready;
665 freeglut_return_if_fail( fgStructure.Menu );
668 * The menu's box size depends on the menu entries:
670 for( menuEntry = ( SFG_MenuEntry * )fgStructure.Menu->Entries.First;
672 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
675 * Update the menu entry's width value
677 menuEntry->Width = glutBitmapLength( FREEGLUT_MENU_FONT,
681 * If the entry is a submenu, then it needs to be wider to
682 * accomodate the arrow. JCJ 31 July 2003
684 if (menuEntry->SubMenu )
685 menuEntry->Width += glutBitmapLength( FREEGLUT_MENU_FONT, "_" );
688 * Check if it's the biggest we've found
690 if( menuEntry->Width > width )
691 width = menuEntry->Width;
693 height += FREEGLUT_MENU_HEIGHT;
697 * Store the menu's box size now:
699 fgStructure.Menu->Height = height + 2 * FREEGLUT_MENU_BORDER;
700 fgStructure.Menu->Width = width + 4 * FREEGLUT_MENU_BORDER;
704 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
707 * Creates a new menu object, adding it to the freeglut structure
709 int FGAPIENTRY glutCreateMenu( void(* callback)( int ) )
712 * The menu object creation code resides in freeglut_structure.c
714 return fgCreateMenu( callback )->ID;
718 * Destroys a menu object, removing all references to it
720 void FGAPIENTRY glutDestroyMenu( int menuID )
722 SFG_Menu* menu = fgMenuByID( menuID );
724 freeglut_assert_ready;
725 freeglut_return_if_fail( menu );
728 * The menu object destruction code resides in freeglut_structure.c
730 fgDestroyMenu( menu );
734 * Returns the ID number of the currently active menu
736 int FGAPIENTRY glutGetMenu( void )
738 freeglut_assert_ready;
740 if( fgStructure.Menu )
741 return fgStructure.Menu->ID;
747 * Sets the current menu given its menu ID
749 void FGAPIENTRY glutSetMenu( int menuID )
751 SFG_Menu* menu = fgMenuByID( menuID );
753 freeglut_assert_ready;
754 freeglut_return_if_fail( menu );
756 fgStructure.Menu = menu;
760 * Adds a menu entry to the bottom of the current menu
762 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
764 SFG_MenuEntry* menuEntry =
765 (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
767 freeglut_assert_ready;
768 freeglut_return_if_fail( fgStructure.Menu );
770 menuEntry->Text = strdup( label );
771 menuEntry->ID = value;
774 * Have the new menu entry attached to the current menu
776 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
778 fghCalculateMenuBoxSize( );
782 * Add a sub menu to the bottom of the current menu
784 void FGAPIENTRY glutAddSubMenu( const char *label, int subMenuID )
786 SFG_MenuEntry *menuEntry =
787 ( SFG_MenuEntry * )calloc( sizeof( SFG_MenuEntry ), 1 );
788 SFG_Menu *subMenu = fgMenuByID( subMenuID );
790 freeglut_assert_ready;
791 freeglut_return_if_fail( fgStructure.Menu );
792 freeglut_return_if_fail( subMenu );
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 );
803 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
804 fghCalculateMenuBoxSize( );
808 * Changes the specified menu item in the current menu into a menu entry
810 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
812 SFG_MenuEntry* menuEntry = NULL;
814 freeglut_assert_ready;
815 freeglut_return_if_fail( fgStructure.Menu );
818 * Get n-th menu entry in the current menu, starting from one:
820 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
822 freeglut_return_if_fail( menuEntry );
825 * We want it to become a normal menu entry, so:
827 if( menuEntry->Text )
828 free( menuEntry->Text );
830 menuEntry->Text = strdup( label );
831 menuEntry->ID = value;
832 menuEntry->SubMenu = NULL;
833 fghCalculateMenuBoxSize( );
837 * Changes the specified menu item in the current menu into a sub-menu trigger.
839 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label,
842 SFG_Menu* subMenu = fgMenuByID( subMenuID );
843 SFG_MenuEntry* menuEntry = NULL;
845 freeglut_assert_ready;
846 freeglut_return_if_fail( fgStructure.Menu );
847 freeglut_return_if_fail( subMenu );
850 * Get n-th menu entry in the current menu, starting from one:
852 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
854 freeglut_return_if_fail( menuEntry );
857 * We want it to become a sub menu entry, so:
859 if( menuEntry->Text )
860 free( menuEntry->Text );
862 menuEntry->Text = strdup( label );
863 menuEntry->SubMenu = subMenu;
865 fghCalculateMenuBoxSize( );
869 * Removes the specified menu item from the current menu
871 void FGAPIENTRY glutRemoveMenuItem( int item )
873 SFG_MenuEntry* menuEntry;
875 freeglut_assert_ready;
876 freeglut_return_if_fail( fgStructure.Menu );
879 * Get n-th menu entry in the current menu, starting from one:
881 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
883 freeglut_return_if_fail( menuEntry );
885 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
886 if ( menuEntry->Text )
887 free( menuEntry->Text );
890 fghCalculateMenuBoxSize( );
894 * Attaches a menu to the current window
896 void FGAPIENTRY glutAttachMenu( int button )
898 freeglut_assert_ready;
900 freeglut_return_if_fail( fgStructure.Window );
901 freeglut_return_if_fail( fgStructure.Menu );
903 freeglut_return_if_fail( button >= 0 );
904 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
906 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
909 * Make the parent window of the menu (and all submenus) the current window
911 fghSetSubmenuParentWindow( fgStructure.Window, fgStructure.Menu );
915 * Detaches a menu from the current window
917 void FGAPIENTRY glutDetachMenu( int button )
919 freeglut_assert_ready;
921 freeglut_return_if_fail( fgStructure.Window );
922 freeglut_return_if_fail( fgStructure.Menu );
924 freeglut_return_if_fail( button >= 0 );
925 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
927 fgStructure.Window->Menu[ button ] = NULL;
931 * A.Donev: Set and retrieve the menu's user data
933 void* FGAPIENTRY glutGetMenuData( void )
935 return fgStructure.Menu->UserData;
938 void FGAPIENTRY glutSetMenuData(void* data)
940 fgStructure.Menu->UserData=data;
943 /*** END OF FILE ***/