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"
36 * TODO BEFORE THE STABLE RELEASE:
38 * Wouldn't 1.0 have been "the" stable release? Now we are past 2.0,
39 * so this comment is probably just out of date. (20031026; rkr)
41 * Think about the possibility of doing the menu on layers *or* using the
42 * native window system instead of OpenGL.
45 /* -- DEFINITIONS ---------------------------------------------------------- */
48 * FREEGLUT_MENU_FONT can be any freeglut bitmapped font.
49 * (Stroked fonts would not be out of the question, but we'd need to alter
50 * code, since GLUT (hence freeglut) does not quite unify stroked and
51 * bitmapped font handling.)
52 * Old UNIX/X11 GLUT (BSD, UNIX, IRIX, LINUX, HPUX, ...) used a system
53 * font best approximated by an 18-pixel HELVETICA, I think. MS-WINDOWS
54 * GLUT used something closest to the 8x13 fixed-width font. (Old
55 * GLUT apparently uses host-system menus rather than building its own.
56 * freeglut is building its own menus from scratch.)
58 * FREEGLUT_MENU_HEIGHT gives the height of ONE menu box. This should be
59 * the distances between two adjacent menu entries. It should scale
60 * automatically with the font choice, so you needn't alter it---unless you
63 * FREEGLUT_MENU_BORDER says how many pixels to allow around the edge of a
64 * menu. (It also seems to be the same as the number of pixels used as
65 * a border around *items* to separate them from neighbors. John says
66 * that that wasn't the original intent...if not, perhaps we need another
67 * symbolic constant, FREEGLUT_MENU_ITEM_BORDER, or such.)
70 #define FREEGLUT_MENU_FONT GLUT_BITMAP_8_BY_13
72 #define FREEGLUT_MENU_FONT GLUT_BITMAP_HELVETICA_18
75 #define FREEGLUT_MENU_HEIGHT (glutBitmapHeight(FREEGLUT_MENU_FONT) + FREEGLUT_MENU_BORDER)
76 #define FREEGLUT_MENU_BORDER 2
80 * These variables are for rendering the freeglut menu items.
82 * The choices are fore- and background, with and without h for Highlighting.
83 * Old GLUT appeared to be system-dependant for its colors (sigh) so we are
84 * too. These variables should be stuffed into global state and initialized
85 * via the glutInit*() system.
88 static float menu_pen_fore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
89 static float menu_pen_back [4] = {0.85f, 0.85f, 0.85f, 1.0f};
90 static float menu_pen_hfore [4] = {1.0f, 1.0f, 1.0f, 1.0f};
91 static float menu_pen_hback [4] = {0.15f, 0.15f, 0.45f, 1.0f};
93 static float menu_pen_fore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
94 static float menu_pen_back [4] = {0.70f, 0.70f, 0.70f, 1.0f};
95 static float menu_pen_hfore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
96 static float menu_pen_hback [4] = {1.0f, 1.0f, 1.0f, 1.0f};
100 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
103 * Private function to find a menu entry by index
105 static SFG_MenuEntry *fghFindMenuEntry( SFG_Menu* menu, int index )
107 SFG_MenuEntry *entry;
110 for( entry = (SFG_MenuEntry *)menu->Entries.First; entry; entry = (SFG_MenuEntry *)entry->Node.Next)
121 * Private function to check for the current menu/sub menu activity state
123 static GLboolean fghCheckMenuStatus( SFG_Window* window, SFG_Menu* menu )
125 SFG_MenuEntry* menuEntry;
129 * First of all check any of the active sub menus...
131 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
132 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
134 if( menuEntry->SubMenu != NULL && menuEntry->IsActive == TRUE )
137 * OK, have the sub-menu checked, too. If it returns TRUE, it will mean
138 * that it caught the mouse cursor and we do not need to regenerate
139 * the activity list, and so our parents do...
141 GLboolean return_status = fghCheckMenuStatus( window, menuEntry->SubMenu ) ;
144 * Reactivate the submenu as the checkMenuStatus may have turned it off
145 * if the mouse is in its parent menu entry.
147 menuEntry->SubMenu->IsActive = TRUE ;
148 if ( return_status == TRUE )
154 * That much about our sub menus, let's get to checking the current menu:
156 x = window->State.MouseX;
157 y = window->State.MouseY;
159 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
160 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
162 menuEntry->IsActive = FALSE;
166 menu->IsActive = FALSE;
169 * Check if the mouse cursor is contained within the current menu box
171 if( ( x >= FREEGLUT_MENU_BORDER ) &&
172 ( x < menu->Width - FREEGLUT_MENU_BORDER ) &&
173 ( y >= FREEGLUT_MENU_BORDER ) &&
174 ( y < menu->Height - FREEGLUT_MENU_BORDER ) &&
175 ( window == menu->Window ) )
177 int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENU_HEIGHT ;
180 * The mouse cursor is somewhere over our box, check it out.
182 menuEntry = fghFindMenuEntry( menu, menuID + 1 );
183 assert( menuEntry != NULL );
185 menuEntry->IsActive = TRUE;
186 menuEntry->Ordinal = menuID;
189 * If this is not the same as the last active menu entry, deactivate the
190 * previous entry. Specifically, if the previous active entry was a
191 * submenu then deactivate it.
193 if ( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
195 if ( menu->ActiveEntry->SubMenu != NULL )
196 fgDeactivateSubMenu ( menu->ActiveEntry ) ;
199 menu->ActiveEntry = menuEntry ;
200 menu->IsActive = TRUE;
203 * OKi, we have marked that entry as active, but it would be also
204 * nice to have its contents updated, in case it's a sub menu.
205 * Also, ignore the return value of the check function:
207 if( menuEntry->SubMenu != NULL )
209 if ( ! menuEntry->SubMenu->IsActive )
211 SFG_Window *current_window = fgStructure.Window ;
214 * Set up the initial menu position now...
217 menuEntry->SubMenu->IsActive = TRUE ;
220 * Set up the initial submenu position now:
222 menuEntry->SubMenu->X = menu->X + menu->Width ;
223 menuEntry->SubMenu->Y = menu->Y + menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT ;
225 if ( menuEntry->SubMenu->X + menuEntry->SubMenu->Width > glutGet (GLUT_SCREEN_WIDTH ) )
226 menuEntry->SubMenu->X = menu->X - menuEntry->SubMenu->Width;
228 if ( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height > glutGet (GLUT_SCREEN_HEIGHT ) )
229 menuEntry->SubMenu->Y -= (menuEntry->SubMenu->Height -
230 FREEGLUT_MENU_HEIGHT - 2*FREEGLUT_MENU_BORDER);
232 fgSetWindow ( menuEntry->SubMenu->Window ) ;
233 glutPositionWindow ( menuEntry->SubMenu->X, menuEntry->SubMenu->Y ) ;
234 glutReshapeWindow ( menuEntry->SubMenu->Width, menuEntry->SubMenu->Height ) ;
237 menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu ;
238 fgSetWindow ( current_window ) ;
241 fghCheckMenuStatus( window, menuEntry->SubMenu );
244 * Activate it because its parent entry is active
246 menuEntry->SubMenu->IsActive = TRUE ;
250 * Report back that we have caught the menu cursor
256 * Looks like the menu cursor is somewhere else...
262 * Displays a menu box and all of its submenus (if they are active)
264 static void fghDisplayMenuBox( SFG_Menu* menu )
266 SFG_MenuEntry *menuEntry;
268 int border = FREEGLUT_MENU_BORDER ;
271 * Have the menu box drawn first. The +- values are
272 * here just to make it more nice-looking...
274 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); /* a non-black dark version of the below. */
275 glBegin( GL_QUAD_STRIP );
276 glVertex2i( menu->Width , 0 );
277 glVertex2i( menu->Width-border, border);
279 glVertex2i( border, border);
280 glVertex2i( 0 , menu->Height );
281 glVertex2i( border, menu->Height-border);
284 glColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); /* a non-black dark version of the below. */
285 glBegin( GL_QUAD_STRIP );
286 glVertex2i( 0 , menu->Height );
287 glVertex2i( border, menu->Height-border);
288 glVertex2i( menu->Width , menu->Height );
289 glVertex2i( menu->Width-border, menu->Height-border);
290 glVertex2i( menu->Width , 0 );
291 glVertex2i( menu->Width-border, border);
294 glColor4fv ( menu_pen_back ) ;
296 glVertex2i( border, border);
297 glVertex2i( menu->Width-border, border);
298 glVertex2i( menu->Width-border, menu->Height-border);
299 glVertex2i( border, menu->Height-border);
303 * Check if any of the submenus is currently active...
305 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
306 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
309 * Has the menu been marked as active, maybe?
311 if( menuEntry->IsActive == TRUE )
314 * That's truly right, and we need to have it highlighted.
315 * There is an assumption that mouse cursor didn't move
316 * since the last check of menu activity state:
318 int menuID = menuEntry->Ordinal;
321 * So have the highlight drawn...
323 glColor4fv ( menu_pen_hback ) ;
325 glVertex2i( FREEGLUT_MENU_BORDER, (menuID + 0)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
326 glVertex2i( menu->Width-FREEGLUT_MENU_BORDER, (menuID + 0)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
327 glVertex2i( menu->Width-FREEGLUT_MENU_BORDER, (menuID + 1)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
328 glVertex2i( FREEGLUT_MENU_BORDER, (menuID + 1)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
334 * Print the menu entries now...
337 glColor4fv ( menu_pen_fore );
339 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First, i=0; menuEntry;
340 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next, ++i )
343 * If the menu entry is active, set the color to white
345 if ( menuEntry->IsActive )
346 glColor4fv ( menu_pen_hfore ) ;
349 * Move the raster into position...
352 2 * FREEGLUT_MENU_BORDER,
353 (i + 1)*FREEGLUT_MENU_HEIGHT-(int)(FREEGLUT_MENU_HEIGHT*0.3 - FREEGLUT_MENU_BORDER ) /* Try to center the text - JCJ 31 July 2003*/
357 * Have the label drawn, character after character:
359 glutBitmapString( FREEGLUT_MENU_FONT, menuEntry->Text);
362 * If it's a submenu, draw a right arrow
364 if ( menuEntry->SubMenu != NULL )
366 int width = glutBitmapWidth ( FREEGLUT_MENU_FONT, '_' ) ;
367 int x_base = menu->Width - 2 - width;
368 int y_base = i*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER;
369 glBegin( GL_TRIANGLES );
370 glVertex2i( x_base, y_base + 2*FREEGLUT_MENU_BORDER);
371 glVertex2i( menu->Width - 2, y_base + (FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER) / 2 );
372 glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - FREEGLUT_MENU_BORDER);
377 * If the menu entry is active, reset the color
379 if ( menuEntry->IsActive )
380 glColor4fv ( menu_pen_fore ) ;
384 * Now we are ready to check if any of our children needs to be redrawn:
386 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
387 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
390 * Is that an active sub menu by any case?
392 if( menuEntry->SubMenu != NULL && menuEntry->IsActive == TRUE )
395 * Yeah, indeed. Have it redrawn now:
397 fgSetWindow ( menuEntry->SubMenu->Window ) ;
398 fghDisplayMenuBox( menuEntry->SubMenu );
399 fgSetWindow ( menu->Window ) ;
405 * Private static function to set the parent window of a submenu and all of its submenus
407 static void fghSetSubmenuParentWindow ( SFG_Window *window, SFG_Menu *menu )
409 SFG_MenuEntry *menuEntry ;
411 menu->ParentWindow = window ;
413 for ( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry; menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
415 if ( menuEntry->SubMenu != NULL )
416 fghSetSubmenuParentWindow ( window, menuEntry->SubMenu ) ;
422 * Displays the currently active menu for the current window
424 void fgDisplayMenu( void )
426 SFG_Window* window = fgStructure.Window;
427 SFG_Menu* menu = NULL;
430 * Make sure there is a current window available
432 freeglut_assert_window;
435 * Check if there is an active menu attached to this window...
437 menu = window->ActiveMenu;
440 * Did we find an active menu?
442 freeglut_return_if_fail( menu != NULL );
444 fgSetWindow ( menu->Window ) ;
447 * Prepare the OpenGL state to do the rendering first:
449 glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT );
451 glDisable( GL_DEPTH_TEST );
452 glDisable( GL_TEXTURE_2D );
453 glDisable( GL_LIGHTING );
454 glDisable( GL_CULL_FACE );
457 * We'll use an orthogonal projection matrix to draw the menu:
459 glMatrixMode( GL_PROJECTION );
463 0, glutGet( GLUT_WINDOW_WIDTH ),
464 glutGet( GLUT_WINDOW_HEIGHT ), 0,
469 * Model-view matix gets reset to identity:
471 glMatrixMode( GL_MODELVIEW );
476 * First of all, have the exact menu status check:
478 fghCheckMenuStatus( window, menu );
481 * The status has been updated and we're ready to have the menu drawn now:
483 fghDisplayMenuBox( menu );
486 * Restore the old OpenGL settings now
490 glMatrixMode( GL_PROJECTION );
492 glMatrixMode( GL_MODELVIEW );
498 * Restore the current window
500 fgSetWindow ( window ) ;
504 * Activates a menu pointed by the function argument
506 void fgActivateMenu( SFG_Window* window, int button )
509 * We'll be referencing this menu a lot, so remember its address:
511 SFG_Menu* menu = window->Menu[ button ];
514 * Mark the menu as active, so that it gets displayed:
516 window->ActiveMenu = menu;
517 menu->IsActive = TRUE ;
518 fgState.ActiveMenus ++ ;
521 * Set up the initial menu position now:
524 menu->X = window->State.MouseX + glutGet ( GLUT_WINDOW_X ) ;
525 menu->Y = window->State.MouseY + glutGet ( GLUT_WINDOW_Y ) ;
527 if ( menu->X + menu->Width > glutGet ( GLUT_SCREEN_WIDTH ) )
528 menu->X -=menu->Width ;
530 if ( menu->Y + menu->Height > glutGet ( GLUT_SCREEN_HEIGHT ) )
531 menu->Y -=menu->Height ;
533 fgSetWindow ( menu->Window ) ;
534 glutPositionWindow ( menu->X, menu->Y ) ;
535 glutReshapeWindow ( menu->Width, menu->Height ) ;
538 menu->Window->ActiveMenu = menu ;
543 * Check whether an active menu absorbs a mouse click
545 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
548 * Near as I can tell, this is the active menu behaviour:
549 * - Down-click any button outside the menu, menu active: deactivate the menu
550 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
551 * - Up-click the menu button outside the menu, menu active: nothing happens
552 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
553 * Since menus can have submenus, we need to check this recursively.
555 return fghCheckMenuStatus ( window, menu ) ;
559 * Function to check for menu entry selection on menu deactivation
561 void fgExecuteMenuCallback( SFG_Menu* menu )
563 SFG_MenuEntry *menuEntry;
566 * First of all check any of the active sub menus...
568 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry; menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
571 * Is this menu entry active?
573 if( menuEntry->IsActive == TRUE )
576 * If there is not a sub menu, execute the menu callback and return...
578 if( menuEntry->SubMenu == NULL )
581 * ...certainly given that there is one...
583 if( menu->Callback != NULL )
584 menu->Callback( menuEntry->ID );
590 * Otherwise recurse into the submenu.
592 fgExecuteMenuCallback( menuEntry->SubMenu );
595 * There is little sense in dwelling the search on
603 * Deactivates a menu pointed by the function argument.
605 void fgDeactivateMenu( SFG_Window *window )
607 SFG_Window *current_window = fgStructure.Window ;
610 * Check if there is an active menu attached to this window...
612 SFG_Menu* menu = window->ActiveMenu;
613 SFG_MenuEntry *menuEntry ;
616 * Did we find an active window?
618 freeglut_return_if_fail( menu != NULL );
621 * Hide the present menu's window
623 fgSetWindow ( menu->Window ) ;
627 * Forget about having that menu active anymore, now:
629 menu->Window->ActiveMenu = NULL ;
630 menu->ParentWindow->ActiveMenu = NULL ;
631 menu->IsActive = FALSE ;
633 fgState.ActiveMenus -- ;
636 * Hide all submenu windows, and the root menu's window.
638 for ( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
639 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
642 * Is that an active submenu by any case?
644 if ( menuEntry->SubMenu != NULL )
645 fgDeactivateSubMenu ( menuEntry ) ;
648 fgSetWindow ( current_window ) ;
652 * Deactivates a menu pointed by the function argument.
654 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
656 SFG_Window *current_window = fgStructure.Window ;
657 SFG_MenuEntry *subMenuIter ;
659 * Hide the present menu's window
661 fgSetWindow ( menuEntry->SubMenu->Window ) ;
665 * Forget about having that menu active anymore, now:
667 menuEntry->SubMenu->Window->ActiveMenu = NULL ;
668 menuEntry->SubMenu->IsActive = FALSE ;
671 * Hide all submenu windows, and the root menu's window.
673 for ( subMenuIter = (SFG_MenuEntry *)menuEntry->SubMenu->Entries.First; subMenuIter;
674 subMenuIter = (SFG_MenuEntry *)subMenuIter->Node.Next )
677 * Is that an active submenu by any case?
679 if ( subMenuIter->SubMenu != NULL )
680 fgDeactivateSubMenu ( subMenuIter ) ;
683 fgSetWindow ( current_window ) ;
687 * Recalculates current menu's box size
689 void fghCalculateMenuBoxSize( void )
691 SFG_MenuEntry* menuEntry;
692 int width = 0, height = 0;
695 * Make sure there is a current menu set
697 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
700 * The menu's box size depends on the menu entries:
702 for( menuEntry = (SFG_MenuEntry *)fgStructure.Menu->Entries.First; menuEntry;
703 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
706 * Update the menu entry's width value
708 menuEntry->Width = glutBitmapLength( FREEGLUT_MENU_FONT, menuEntry->Text );
711 * If the entry is a submenu, then it needs to be wider to accomodate the arrow. JCJ 31 July 2003
714 if (menuEntry->SubMenu != NULL)
715 menuEntry->Width += glutBitmapLength( FREEGLUT_MENU_FONT, "_" );
718 * Check if it's the biggest we've found
720 if( menuEntry->Width > width )
721 width = menuEntry->Width;
723 height += FREEGLUT_MENU_HEIGHT;
727 * Store the menu's box size now:
729 fgStructure.Menu->Height = height + 2 * FREEGLUT_MENU_BORDER ;
730 fgStructure.Menu->Width = width + 4 * FREEGLUT_MENU_BORDER ;
734 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
737 * Creates a new menu object, adding it to the freeglut structure
739 int FGAPIENTRY glutCreateMenu( void (* callback)( int ) )
742 * The menu object creation code resides in freeglut_structure.c
744 return( fgCreateMenu( callback )->ID );
748 * Destroys a menu object, removing all references to it
750 void FGAPIENTRY glutDestroyMenu( int menuID )
752 SFG_Menu* menu = fgMenuByID( menuID );
754 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
757 * The menu object destruction code resides in freeglut_structure.c
759 fgDestroyMenu( menu );
763 * Returns the ID number of the currently active menu
765 int FGAPIENTRY glutGetMenu( void )
767 freeglut_assert_ready;
768 if( fgStructure.Menu != NULL )
769 return( fgStructure.Menu->ID );
774 * Sets the current menu given its menu ID
776 void FGAPIENTRY glutSetMenu( int menuID )
778 SFG_Menu* menu = fgMenuByID( menuID );
780 freeglut_assert_ready;
781 freeglut_return_if_fail( menu != NULL );
782 fgStructure.Menu = menu;
786 * Adds a menu entry to the bottom of the current menu
788 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
790 SFG_MenuEntry* menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
792 freeglut_assert_ready;
793 freeglut_return_if_fail( fgStructure.Menu != NULL );
794 menuEntry->Text = strdup( label );
795 menuEntry->ID = value;
798 * Have the new menu entry attached to the current menu
800 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
801 fghCalculateMenuBoxSize();
805 * Add a sub menu to the bottom of the current menu
807 void FGAPIENTRY glutAddSubMenu( const char* label, int subMenuID )
809 SFG_MenuEntry* menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
810 SFG_Menu* subMenu = fgMenuByID( subMenuID );
812 freeglut_assert_ready;
813 freeglut_return_if_fail( fgStructure.Menu != NULL );
814 freeglut_return_if_fail( subMenu != NULL );
816 menuEntry->Text = strdup( label );
817 menuEntry->SubMenu = subMenu;
821 * Make the submenu's parent window be the menu's parent window
823 fghSetSubmenuParentWindow ( fgStructure.Menu->ParentWindow, subMenu ) ;
824 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
825 fghCalculateMenuBoxSize();
829 * Changes the specified menu item in the current menu into a menu entry
831 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
833 SFG_MenuEntry* menuEntry = NULL;
835 freeglut_assert_ready;
836 freeglut_return_if_fail( fgStructure.Menu != NULL );
837 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
838 freeglut_return_if_fail( menuEntry != NULL );
841 * We want it to become a normal menu entry, so:
843 if( menuEntry->Text != NULL )
844 free( menuEntry->Text );
846 menuEntry->Text = strdup( label );
847 menuEntry->ID = value;
848 menuEntry->SubMenu = NULL;
850 fghCalculateMenuBoxSize();
854 * Changes the specified menu item in the current menu into a sub-menu trigger.
856 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int subMenuID )
858 SFG_Menu* subMenu = fgMenuByID( subMenuID );
859 SFG_MenuEntry* menuEntry = NULL;
861 freeglut_assert_ready;
862 freeglut_return_if_fail( fgStructure.Menu );
863 freeglut_return_if_fail( subMenu );
864 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
865 freeglut_return_if_fail( menuEntry );
868 * We want it to become a sub menu entry, so:
870 if( menuEntry->Text )
871 free( menuEntry->Text );
873 menuEntry->Text = strdup( label );
874 menuEntry->SubMenu = subMenu;
877 fghCalculateMenuBoxSize();
881 * Removes the specified menu item from the current menu
883 void FGAPIENTRY glutRemoveMenuItem( int item )
885 SFG_MenuEntry* menuEntry;
887 freeglut_assert_ready;
888 freeglut_return_if_fail( fgStructure.Menu );
889 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
890 freeglut_return_if_fail( menuEntry );
891 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
892 free( menuEntry->Text );
894 fghCalculateMenuBoxSize();
898 * Attaches a menu to the current window
900 void FGAPIENTRY glutAttachMenu( int button )
902 freeglut_assert_ready;
903 freeglut_return_if_fail( fgStructure.Window );
904 freeglut_return_if_fail( fgStructure.Menu );
905 freeglut_return_if_fail( button >= 0 );
906 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
907 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
910 * Make the parent window of the menu (and all submenus) the current window
912 fghSetSubmenuParentWindow ( fgStructure.Window, fgStructure.Menu ) ;
916 * Detaches a menu from the current window
918 void FGAPIENTRY glutDetachMenu( int button )
920 freeglut_assert_ready;
921 freeglut_return_if_fail( fgStructure.Window );
922 freeglut_return_if_fail( fgStructure.Menu );
923 freeglut_return_if_fail( button >= 0 );
924 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
925 fgStructure.Window->Menu[ button ] = NULL;
929 * A.Donev: Set and retrieve the menu's user data
931 void* FGAPIENTRY glutGetMenuData( void )
933 return(fgStructure.Menu->UserData);
936 void FGAPIENTRY glutSetMenuData(void* data)
938 fgStructure.Menu->UserData=data;
941 /*** END OF FILE ***/