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 <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.)
59 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
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.
78 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
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;
120 /* First of all check any of the active sub menus... */
121 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
123 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
125 if( menuEntry->SubMenu && menuEntry->IsActive )
128 * OK, have the sub-menu checked, too. If it returns GL_TRUE, it
129 * will mean that it caught the mouse cursor and we do not need
130 * to regenerate the activity list, and so our parents do...
132 GLboolean return_status = fghCheckMenuStatus( window,
133 menuEntry->SubMenu );
136 * Reactivate the submenu as the checkMenuStatus may have turned
137 * it off if the mouse is in its parent menu entry.
139 menuEntry->SubMenu->IsActive = GL_TRUE;
145 /* That much about our sub menus, let's get to checking the current menu: */
146 x = window->State.MouseX;
147 y = window->State.MouseY;
149 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
151 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
152 menuEntry->IsActive = GL_FALSE;
154 menu->IsActive = GL_FALSE;
156 /* Check if the mouse cursor is contained within the current menu box */
157 if( ( x >= FREEGLUT_MENU_BORDER ) &&
158 ( x < menu->Width - FREEGLUT_MENU_BORDER ) &&
159 ( y >= FREEGLUT_MENU_BORDER ) &&
160 ( y < menu->Height - FREEGLUT_MENU_BORDER ) &&
161 ( window == menu->Window ) )
163 int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENU_HEIGHT;
165 /* The mouse cursor is somewhere over our box, check it out. */
166 menuEntry = fghFindMenuEntry( menu, menuID + 1 );
169 menuEntry->IsActive = GL_TRUE;
170 menuEntry->Ordinal = menuID;
173 * If this is not the same as the last active menu entry, deactivate
174 * the previous entry. Specifically, if the previous active entry
175 * was a submenu then deactivate it.
177 if( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
178 if( menu->ActiveEntry->SubMenu )
179 fgDeactivateSubMenu( menu->ActiveEntry );
181 menu->ActiveEntry = menuEntry;
182 menu->IsActive = GL_TRUE;
185 * OKi, we have marked that entry as active, but it would be also
186 * nice to have its contents updated, in case it's a sub menu.
187 * Also, ignore the return value of the check function:
189 if( menuEntry->SubMenu )
191 if ( ! menuEntry->SubMenu->IsActive )
193 SFG_Window *current_window = fgStructure.Window;
195 /* Set up the initial menu position now... */
196 menuEntry->SubMenu->IsActive = GL_TRUE;
198 /* Set up the initial submenu position now: */
199 menuEntry->SubMenu->X = menu->X + menu->Width;
200 menuEntry->SubMenu->Y = menu->Y +
201 menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT;
203 if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width >
204 glutGet( GLUT_SCREEN_WIDTH ) )
205 menuEntry->SubMenu->X = menu->X -
206 menuEntry->SubMenu->Width;
208 if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height >
209 glutGet( GLUT_SCREEN_HEIGHT ) )
210 menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
211 FREEGLUT_MENU_HEIGHT -
212 2 * FREEGLUT_MENU_BORDER );
214 fgSetWindow( menuEntry->SubMenu->Window );
215 glutPositionWindow( menuEntry->SubMenu->X,
216 menuEntry->SubMenu->Y );
217 glutReshapeWindow( menuEntry->SubMenu->Width,
218 menuEntry->SubMenu->Height );
221 menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu;
222 fgSetWindow( current_window );
225 fghCheckMenuStatus( window, menuEntry->SubMenu );
227 /* Activate it because its parent entry is active */
228 menuEntry->SubMenu->IsActive = GL_TRUE;
231 /* Report back that we have caught the menu cursor */
235 /* Looks like the menu cursor is somewhere else... */
240 * Displays a menu box and all of its submenus (if they are active)
242 static void fghDisplayMenuBox( SFG_Menu* menu )
244 SFG_MenuEntry *menuEntry;
246 int border = FREEGLUT_MENU_BORDER;
249 * Have the menu box drawn first. The +- values are
250 * here just to make it more nice-looking...
252 /* a non-black dark version of the below. */
253 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
254 glBegin( GL_QUAD_STRIP );
255 glVertex2i( menu->Width , 0 );
256 glVertex2i( menu->Width - border, border);
258 glVertex2i( border, border);
259 glVertex2i( 0 , menu->Height );
260 glVertex2i( border, menu->Height - border);
263 /* a non-black dark version of the below. */
264 glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
265 glBegin( GL_QUAD_STRIP );
266 glVertex2i( 0 , menu->Height );
267 glVertex2i( border, menu->Height - border);
268 glVertex2i( menu->Width , menu->Height );
269 glVertex2i( menu->Width - border, menu->Height - border);
270 glVertex2i( menu->Width , 0 );
271 glVertex2i( menu->Width - border, border);
274 glColor4fv( menu_pen_back );
276 glVertex2i( border, border);
277 glVertex2i( menu->Width - border, border);
278 glVertex2i( menu->Width - border, menu->Height - border);
279 glVertex2i( border, menu->Height - border);
282 /* Check if any of the submenus is currently active... */
283 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
285 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
287 /* Has the menu been marked as active, maybe? */
288 if( menuEntry->IsActive )
291 * That's truly right, and we need to have it highlighted.
292 * There is an assumption that mouse cursor didn't move
293 * since the last check of menu activity state:
295 int menuID = menuEntry->Ordinal;
297 /* So have the highlight drawn... */
298 glColor4fv( menu_pen_hback );
301 (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
302 glVertex2i( menu->Width - border,
303 (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
304 glVertex2i( menu->Width - border,
305 (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
307 (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
312 /* Print the menu entries now... */
314 glColor4fv( menu_pen_fore );
316 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First, i = 0;
318 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next, ++i )
320 /* If the menu entry is active, set the color to white */
321 if( menuEntry->IsActive )
322 glColor4fv( menu_pen_hfore );
324 /* Move the raster into position... */
325 /* Try to center the text - JCJ 31 July 2003*/
328 ( i + 1 )*FREEGLUT_MENU_HEIGHT -
329 ( int )( FREEGLUT_MENU_HEIGHT*0.3 - border )
332 /* Have the label drawn, character after character: */
333 glutBitmapString( FREEGLUT_MENU_FONT,
334 (unsigned char *)menuEntry->Text);
336 /* If it's a submenu, draw a right arrow */
337 if( menuEntry->SubMenu )
339 int width = glutBitmapWidth( FREEGLUT_MENU_FONT, '_' );
340 int x_base = menu->Width - 2 - width;
341 int y_base = i*FREEGLUT_MENU_HEIGHT + border;
342 glBegin( GL_TRIANGLES );
343 glVertex2i( x_base, y_base + 2*border);
344 glVertex2i( menu->Width - 2, y_base +
345 ( FREEGLUT_MENU_HEIGHT + border) / 2 );
346 glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - border );
350 /* If the menu entry is active, reset the color */
351 if( menuEntry->IsActive )
352 glColor4fv( menu_pen_fore );
355 /* Now we are ready to check if any of our children needs to be redrawn: */
356 for( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
358 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
360 /* Is that an active sub menu by any case? */
361 if( menuEntry->SubMenu && menuEntry->IsActive )
363 /* Yeah, indeed. Have it redrawn now: */
364 fgSetWindow( menuEntry->SubMenu->Window );
365 fghDisplayMenuBox( menuEntry->SubMenu );
366 fgSetWindow( menu->Window );
372 * Private static function to set the parent window of a submenu and all
375 static void fghSetSubmenuParentWindow( SFG_Window *window, SFG_Menu *menu )
377 SFG_MenuEntry *menuEntry;
379 menu->ParentWindow = window;
381 for( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
383 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
384 if( menuEntry->SubMenu )
385 fghSetSubmenuParentWindow( window, menuEntry->SubMenu );
390 * Displays the currently active menu for the current window
392 void fgDisplayMenu( void )
394 SFG_Window* window = fgStructure.Window;
395 SFG_Menu* menu = NULL;
397 freeglut_assert_window;
399 /* Check if there is an active menu attached to this window... */
400 menu = window->ActiveMenu;
401 freeglut_return_if_fail( menu );
403 fgSetWindow( menu->Window );
405 glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT |
408 glDisable( GL_DEPTH_TEST );
409 glDisable( GL_TEXTURE_2D );
410 glDisable( GL_LIGHTING );
411 glDisable( GL_CULL_FACE );
413 glMatrixMode( GL_PROJECTION );
417 0, glutGet( GLUT_WINDOW_WIDTH ),
418 glutGet( GLUT_WINDOW_HEIGHT ), 0,
422 glMatrixMode( GL_MODELVIEW );
426 fghCheckMenuStatus( window, menu );
427 fghDisplayMenuBox( menu );
431 glMatrixMode( GL_PROJECTION );
433 glMatrixMode( GL_MODELVIEW );
438 fgSetWindow ( window );
442 * Activates a menu pointed by the function argument
444 void fgActivateMenu( SFG_Window* window, int button )
446 /* We'll be referencing this menu a lot, so remember its address: */
447 SFG_Menu* menu = window->Menu[ button ];
449 /* Mark the menu as active, so that it gets displayed: */
450 window->ActiveMenu = menu;
451 menu->IsActive = GL_TRUE;
452 fgState.ActiveMenus++;
454 /* Set up the initial menu position now: */
455 menu->X = window->State.MouseX + glutGet( GLUT_WINDOW_X );
456 menu->Y = window->State.MouseY + glutGet( GLUT_WINDOW_Y );
458 if( menu->X + menu->Width > glutGet ( GLUT_SCREEN_WIDTH ) )
459 menu->X -=menu->Width;
461 if( menu->Y + menu->Height > glutGet ( GLUT_SCREEN_HEIGHT ) )
462 menu->Y -=menu->Height;
464 fgSetWindow( menu->Window );
465 glutPositionWindow( menu->X, menu->Y );
466 glutReshapeWindow( menu->Width, menu->Height );
469 menu->Window->ActiveMenu = menu;
473 * Check whether an active menu absorbs a mouse click
475 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
478 * Near as I can tell, this is the active menu behaviour:
479 * - Down-click any button outside the menu, menu active:
480 * deactivate the menu
481 * - Down-click any button inside the menu, menu active:
482 * select the menu entry and deactivate the menu
483 * - Up-click the menu button outside the menu, menu active:
485 * - Up-click the menu button inside the menu, menu active:
486 * select the menu entry and deactivate the menu
487 * Since menus can have submenus, we need to check this recursively.
489 return fghCheckMenuStatus( window, menu );
493 * Function to check for menu entry selection on menu deactivation
495 void fgExecuteMenuCallback( SFG_Menu* menu )
497 SFG_MenuEntry *menuEntry;
499 /* First of all check any of the active sub menus... */
500 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
502 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
504 if( menuEntry->IsActive )
506 if( menuEntry->SubMenu )
507 fgExecuteMenuCallback( menuEntry->SubMenu );
510 menu->Callback( menuEntry->ID );
517 * Deactivates a menu pointed by the function argument.
519 void fgDeactivateMenu( SFG_Window *window )
521 SFG_Window *current_window = fgStructure.Window;
523 /* Check if there is an active menu attached to this window... */
524 SFG_Menu* menu = window->ActiveMenu;
525 SFG_MenuEntry *menuEntry;
527 /* Did we find an active window? */
528 freeglut_return_if_fail( menu );
530 /* Hide the present menu's window */
531 fgSetWindow( menu->Window );
534 /* Forget about having that menu active anymore, now: */
535 menu->Window->ActiveMenu = NULL;
536 menu->ParentWindow->ActiveMenu = NULL;
537 menu->IsActive = GL_FALSE;
539 fgState.ActiveMenus--;
541 /* Hide all submenu windows, and the root menu's window. */
542 for ( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
544 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
546 /* Is that an active submenu by any case? */
547 if( menuEntry->SubMenu )
548 fgDeactivateSubMenu( menuEntry );
551 fgSetWindow( current_window );
555 * Deactivates a menu pointed by the function argument.
557 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
559 SFG_Window *current_window = fgStructure.Window;
560 SFG_MenuEntry *subMenuIter;
561 /* Hide the present menu's window */
562 fgSetWindow( menuEntry->SubMenu->Window );
565 /* Forget about having that menu active anymore, now: */
566 menuEntry->SubMenu->Window->ActiveMenu = NULL;
567 menuEntry->SubMenu->IsActive = GL_FALSE;
569 /* Hide all submenu windows, and the root menu's window. */
570 for ( subMenuIter = (SFG_MenuEntry *)menuEntry->SubMenu->Entries.First;
572 subMenuIter = (SFG_MenuEntry *)subMenuIter->Node.Next )
574 /* Is that an active submenu by any case? */
575 if( subMenuIter->SubMenu )
576 fgDeactivateSubMenu( subMenuIter );
579 fgSetWindow( current_window );
583 * Recalculates current menu's box size
585 void fghCalculateMenuBoxSize( void )
587 SFG_MenuEntry* menuEntry;
588 int width = 0, height = 0;
590 /* Make sure there is a current menu set */
591 freeglut_assert_ready;
592 freeglut_return_if_fail( fgStructure.Menu );
594 /* The menu's box size depends on the menu entries: */
595 for( menuEntry = ( SFG_MenuEntry * )fgStructure.Menu->Entries.First;
597 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
599 /* Update the menu entry's width value */
600 menuEntry->Width = glutBitmapLength(
602 (unsigned char *)menuEntry->Text
606 * If the entry is a submenu, then it needs to be wider to
607 * accomodate the arrow. JCJ 31 July 2003
609 if (menuEntry->SubMenu )
610 menuEntry->Width += glutBitmapLength(
615 /* Check if it's the biggest we've found */
616 if( menuEntry->Width > width )
617 width = menuEntry->Width;
619 height += FREEGLUT_MENU_HEIGHT;
622 /* Store the menu's box size now: */
623 fgStructure.Menu->Height = height + 2 * FREEGLUT_MENU_BORDER;
624 fgStructure.Menu->Width = width + 4 * FREEGLUT_MENU_BORDER;
628 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
631 * Creates a new menu object, adding it to the freeglut structure
633 int FGAPIENTRY glutCreateMenu( void(* callback)( int ) )
635 /* The menu object creation code resides in freeglut_structure.c */
636 return fgCreateMenu( callback )->ID;
640 * Destroys a menu object, removing all references to it
642 void FGAPIENTRY glutDestroyMenu( int menuID )
644 SFG_Menu* menu = fgMenuByID( menuID );
646 freeglut_assert_ready;
647 freeglut_return_if_fail( menu );
649 /* The menu object destruction code resides in freeglut_structure.c */
650 fgDestroyMenu( menu );
654 * Returns the ID number of the currently active menu
656 int FGAPIENTRY glutGetMenu( void )
658 freeglut_assert_ready;
660 if( fgStructure.Menu )
661 return fgStructure.Menu->ID;
667 * Sets the current menu given its menu ID
669 void FGAPIENTRY glutSetMenu( int menuID )
671 SFG_Menu* menu = fgMenuByID( menuID );
673 freeglut_assert_ready;
674 freeglut_return_if_fail( menu );
676 fgStructure.Menu = menu;
680 * Adds a menu entry to the bottom of the current menu
682 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
684 SFG_MenuEntry* menuEntry =
685 (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
687 freeglut_assert_ready;
688 freeglut_return_if_fail( fgStructure.Menu );
690 menuEntry->Text = strdup( label );
691 menuEntry->ID = value;
693 /* Have the new menu entry attached to the current menu */
694 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
696 fghCalculateMenuBoxSize( );
700 * Add a sub menu to the bottom of the current menu
702 void FGAPIENTRY glutAddSubMenu( const char *label, int subMenuID )
704 SFG_MenuEntry *menuEntry =
705 ( SFG_MenuEntry * )calloc( sizeof( SFG_MenuEntry ), 1 );
706 SFG_Menu *subMenu = fgMenuByID( subMenuID );
708 freeglut_assert_ready;
709 freeglut_return_if_fail( fgStructure.Menu );
710 freeglut_return_if_fail( subMenu );
712 menuEntry->Text = strdup( label );
713 menuEntry->SubMenu = subMenu;
716 /* Make the submenu's parent window be the menu's parent window */
717 fghSetSubmenuParentWindow( fgStructure.Menu->ParentWindow, subMenu );
719 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
720 fghCalculateMenuBoxSize( );
724 * Changes the specified menu item in the current menu into a menu entry
726 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
728 SFG_MenuEntry* menuEntry = NULL;
730 freeglut_assert_ready;
731 freeglut_return_if_fail( fgStructure.Menu );
733 /* Get n-th menu entry in the current menu, starting from one: */
734 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
736 freeglut_return_if_fail( menuEntry );
738 /* We want it to become a normal menu entry, so: */
739 if( menuEntry->Text )
740 free( menuEntry->Text );
742 menuEntry->Text = strdup( label );
743 menuEntry->ID = value;
744 menuEntry->SubMenu = NULL;
745 fghCalculateMenuBoxSize( );
749 * Changes the specified menu item in the current menu into a sub-menu trigger.
751 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label,
754 SFG_Menu* subMenu = fgMenuByID( subMenuID );
755 SFG_MenuEntry* menuEntry = NULL;
757 freeglut_assert_ready;
758 freeglut_return_if_fail( fgStructure.Menu );
759 freeglut_return_if_fail( subMenu );
761 /* Get n-th menu entry in the current menu, starting from one: */
762 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
764 freeglut_return_if_fail( menuEntry );
766 /* We want it to become a sub menu entry, so: */
767 if( menuEntry->Text )
768 free( menuEntry->Text );
770 menuEntry->Text = strdup( label );
771 menuEntry->SubMenu = subMenu;
773 fghCalculateMenuBoxSize( );
777 * Removes the specified menu item from the current menu
779 void FGAPIENTRY glutRemoveMenuItem( int item )
781 SFG_MenuEntry* menuEntry;
783 freeglut_assert_ready;
784 freeglut_return_if_fail( fgStructure.Menu );
786 /* Get n-th menu entry in the current menu, starting from one: */
787 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
789 freeglut_return_if_fail( menuEntry );
791 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
792 if ( menuEntry->Text )
793 free( menuEntry->Text );
796 fghCalculateMenuBoxSize( );
800 * Attaches a menu to the current window
802 void FGAPIENTRY glutAttachMenu( int button )
804 freeglut_assert_ready;
806 freeglut_return_if_fail( fgStructure.Window );
807 freeglut_return_if_fail( fgStructure.Menu );
809 freeglut_return_if_fail( button >= 0 );
810 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
812 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
814 /* Make the parent window of the menu (and all submenus) the current window */
815 fghSetSubmenuParentWindow( fgStructure.Window, fgStructure.Menu );
819 * Detaches a menu from the current window
821 void FGAPIENTRY glutDetachMenu( int button )
823 freeglut_assert_ready;
825 freeglut_return_if_fail( fgStructure.Window );
826 freeglut_return_if_fail( fgStructure.Menu );
828 freeglut_return_if_fail( button >= 0 );
829 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
831 fgStructure.Window->Menu[ button ] = NULL;
835 * A.Donev: Set and retrieve the menu's user data
837 void* FGAPIENTRY glutGetMenuData( void )
839 return fgStructure.Menu->UserData;
842 void FGAPIENTRY glutSetMenuData(void* data)
844 fgStructure.Menu->UserData=data;
847 /*** END OF FILE ***/