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_FONT GLUT_BITMAP_HELVETICA_18*/
52 #define FREEGLUT_MENU_HEIGHT (glutBitmapHeight(FREEGLUT_MENU_FONT) + FREEGLUT_MENU_BORDER)
53 #define FREEGLUT_MENU_BORDER 2
57 * These variables should be moved into the freeglut global state, but for now,
58 * we'll put them here. They are for rendering the freeglut menu items.
59 * The choices are fore- and background, with and without h for Highlighting.
60 * Old GLUT appeared to be system-dependant for its colors (sigh) so we are
61 * too. These variables should be stuffed into global state and initialized
62 * via the glutInit*() system.
64 static float menu_pen_fore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
65 static float menu_pen_back [4] = {0.85f, 0.85f, 0.85f, 1.0f};
68 static float menu_pen_hfore [4] = {1.0f, 1.0f, 1.0f, 1.0f};
69 static float menu_pen_hback [4] = {0.15f, 0.15f, 0.45f, 1.0f};
71 static float menu_pen_hfore [4] = {0.0f, 0.0f, 0.0f, 1.0f};
72 static float menu_pen_hback [4] = {1.0f, 1.0f, 1.0f, 1.0f};
76 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
79 * Private static function to find a menu entry by index
81 static SFG_MenuEntry *fghFindMenuEntry( SFG_Menu* menu, int index )
86 for( entry = (SFG_MenuEntry *)menu->Entries.First; entry; entry = (SFG_MenuEntry *)entry->Node.Next)
97 * Private static function to check for the current menu/sub menu activity state
99 static GLboolean fghCheckMenuStatus( SFG_Window* window, SFG_Menu* menu )
101 SFG_MenuEntry* menuEntry;
105 * First of all check any of the active sub menus...
107 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
108 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
111 * Is that an active sub menu by any case?
113 if( menuEntry->SubMenu != NULL && menuEntry->IsActive == TRUE )
116 * OK, have the sub-menu checked, too. If it returns TRUE, it will mean
117 * that it caught the mouse cursor and we do not need to regenerate
118 * the activity list, and so our parents do...
120 GLboolean return_status = fghCheckMenuStatus( window, menuEntry->SubMenu ) ;
123 * Reactivate the submenu as the checkMenuStatus may have turned it off if the mouse
124 * is in its parent menu entry.
126 menuEntry->SubMenu->IsActive = TRUE ;
127 if ( return_status == TRUE )
133 * That much about our sub menus, let's get to checking the current menu:
135 x = window->State.MouseX;
136 y = window->State.MouseY;
139 * Mark all menu entries inactive...
141 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
142 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
144 menuEntry->IsActive = FALSE;
148 menu->IsActive = FALSE;
151 * Check if the mouse cursor is contained within the current menu box
153 if ( ( x >= FREEGLUT_MENU_BORDER ) && ( x < menu->Width - FREEGLUT_MENU_BORDER ) &&
154 ( y >= FREEGLUT_MENU_BORDER ) && ( y < menu->Height - FREEGLUT_MENU_BORDER ) &&
155 ( window == menu->Window ) )
158 * Calculation of the highlighted menu item is easy enough now:
160 int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENU_HEIGHT ;
163 * The mouse cursor is somewhere over our box, check it out.
165 menuEntry = fghFindMenuEntry( menu, menuID + 1 );
166 assert( menuEntry != NULL );
169 * Mark the menu as active...
171 menuEntry->IsActive = TRUE;
172 menuEntry->Ordinal = menuID;
175 * If this is not the same as the last active menu entry, deactivate the previous entry.
176 * Specifically, if the previous active entry was a submenu then deactivate it.
178 if ( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
180 if ( menu->ActiveEntry->SubMenu != NULL )
181 fgDeactivateSubMenu ( menu->ActiveEntry ) ;
184 menu->ActiveEntry = menuEntry ;
187 * Don't forget about marking the current menu as active, too:
190 menu->IsActive = 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 != NULL )
199 if ( ! menuEntry->SubMenu->IsActive )
201 SFG_Window *current_window = fgStructure.Window ;
204 * Set up the initial menu position now...
208 * Mark the menu as active, so that it gets displayed:
210 menuEntry->SubMenu->IsActive = TRUE ;
213 * Set up the initial submenu position now:
215 menuEntry->SubMenu->X = menu->X + menu->Width ;
216 menuEntry->SubMenu->Y = menu->Y + menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT ;
218 fgSetWindow ( menuEntry->SubMenu->Window ) ;
219 glutPositionWindow ( menuEntry->SubMenu->X, menuEntry->SubMenu->Y ) ;
220 glutReshapeWindow ( menuEntry->SubMenu->Width, menuEntry->SubMenu->Height ) ;
223 menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu ;
224 fgSetWindow ( current_window ) ;
228 * ...then check the submenu's state:
230 fghCheckMenuStatus( window, menuEntry->SubMenu );
233 * Even if the submenu turned up inactive, activate it because its parent entry is active
235 menuEntry->SubMenu->IsActive = TRUE ;
239 * Report back that we have caught the menu cursor
245 * Looks like the menu cursor is somewhere else...
251 * Displays a menu box and all of its submenus (if they are active)
253 static void fghDisplayMenuBox( SFG_Menu* menu )
255 SFG_MenuEntry *menuEntry;
257 int border = FREEGLUT_MENU_BORDER ;
260 * Have the menu box drawn first. The +- values are
261 * here just to make it more nice-looking...
263 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); /* a non-black dark version of the below. */
264 glBegin( GL_QUAD_STRIP );
265 glVertex2i( menu->Width , 0 );
266 glVertex2i( menu->Width-border, border);
268 glVertex2i( border, border);
269 glVertex2i( 0 , menu->Height );
270 glVertex2i( border, menu->Height-border);
273 glColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); /* a non-black dark version of the below. */
274 glBegin( GL_QUAD_STRIP );
275 glVertex2i( 0 , menu->Height );
276 glVertex2i( border, menu->Height-border);
277 glVertex2i( menu->Width , menu->Height );
278 glVertex2i( menu->Width-border, menu->Height-border);
279 glVertex2i( menu->Width , 0 );
280 glVertex2i( menu->Width-border, border);
283 glColor4fv ( menu_pen_back ) ;
285 glVertex2i( border, border);
286 glVertex2i( menu->Width-border, border);
287 glVertex2i( menu->Width-border, menu->Height-border);
288 glVertex2i( border, menu->Height-border);
292 * Check if any of the submenus is currently active...
294 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
295 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
298 * Has the menu been marked as active, maybe?
300 if( menuEntry->IsActive == TRUE )
303 * That's truly right, and we need to have it highlighted.
304 * There is an assumption that mouse cursor didn't move
305 * since the last check of menu activity state:
307 int menuID = menuEntry->Ordinal;
310 * So have the highlight drawn...
312 glColor4fv ( menu_pen_hback ) ;
314 glVertex2i( FREEGLUT_MENU_BORDER, (menuID + 0)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
315 glVertex2i( menu->Width-FREEGLUT_MENU_BORDER, (menuID + 0)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
316 glVertex2i( menu->Width-FREEGLUT_MENU_BORDER, (menuID + 1)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
317 glVertex2i( FREEGLUT_MENU_BORDER, (menuID + 1)*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER );
323 * Print the menu entries now...
326 glColor4fv ( menu_pen_fore );
328 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First, i=0; menuEntry;
329 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next, ++i )
332 * If the menu entry is active, set the color to white
334 if ( menuEntry->IsActive )
335 glColor4fv ( menu_pen_hfore ) ;
338 * Move the raster into position...
341 2 * FREEGLUT_MENU_BORDER,
342 (i + 1)*FREEGLUT_MENU_HEIGHT-(int)(FREEGLUT_MENU_HEIGHT*0.3 - FREEGLUT_MENU_BORDER ) /* Try to center the text - JCJ 31 July 2003*/
346 * Have the label drawn, character after character:
348 glutBitmapString( FREEGLUT_MENU_FONT, menuEntry->Text);
351 * If it's a submenu, draw a right arrow
353 if ( menuEntry->SubMenu != NULL )
355 int width = glutBitmapWidth ( FREEGLUT_MENU_FONT, '_' ) ;
356 int x_base = menu->Width - 2 - width;
357 int y_base = i*FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER;
358 glBegin( GL_TRIANGLES );
359 glVertex2i( x_base, y_base + 2*FREEGLUT_MENU_BORDER);
360 glVertex2i( menu->Width - 2, y_base + (FREEGLUT_MENU_HEIGHT + FREEGLUT_MENU_BORDER) / 2 );
361 glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - FREEGLUT_MENU_BORDER);
366 * If the menu entry is active, reset the color
368 if ( menuEntry->IsActive )
369 glColor4fv ( menu_pen_fore ) ;
373 * Now we are ready to check if any of our children needs to be redrawn:
375 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
376 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
379 * Is that an active sub menu by any case?
381 if( menuEntry->SubMenu != NULL && menuEntry->IsActive == TRUE )
384 * Yeah, indeed. Have it redrawn now:
386 fgSetWindow ( menuEntry->SubMenu->Window ) ;
387 fghDisplayMenuBox( menuEntry->SubMenu );
388 fgSetWindow ( menu->Window ) ;
394 * Private static function to set the parent window of a submenu and all of its submenus
396 static void fghSetSubmenuParentWindow ( SFG_Window *window, SFG_Menu *menu )
398 SFG_MenuEntry *menuEntry ;
400 menu->ParentWindow = window ;
402 for ( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry; menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
404 if ( menuEntry->SubMenu != NULL )
405 fghSetSubmenuParentWindow ( window, menuEntry->SubMenu ) ;
411 * Displays the currently active menu for the current window
413 void fgDisplayMenu( void )
415 SFG_Window* window = fgStructure.Window;
416 SFG_Menu* menu = NULL;
419 * Make sure there is a current window available
421 freeglut_assert_window;
424 * Check if there is an active menu attached to this window...
426 menu = window->ActiveMenu;
429 * Did we find an active menu?
431 freeglut_return_if_fail( menu != NULL );
433 fgSetWindow ( menu->Window ) ;
436 * Prepare the OpenGL state to do the rendering first:
438 glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT );
440 glDisable( GL_DEPTH_TEST );
441 glDisable( GL_TEXTURE_2D );
442 glDisable( GL_LIGHTING );
443 glDisable( GL_CULL_FACE );
446 * We'll use an orthogonal projection matrix to draw the menu:
448 glMatrixMode( GL_PROJECTION );
452 0, glutGet( GLUT_WINDOW_WIDTH ),
453 glutGet( GLUT_WINDOW_HEIGHT ), 0,
458 * Model-view matix gets reset to identity:
460 glMatrixMode( GL_MODELVIEW );
465 * First of all, have the exact menu status check:
467 fghCheckMenuStatus( window, menu );
470 * The status has been updated and we're ready to have the menu drawn now:
472 fghDisplayMenuBox( menu );
475 * Restore the old OpenGL settings now
479 glMatrixMode( GL_PROJECTION );
481 glMatrixMode( GL_MODELVIEW );
487 * Restore the current window
489 fgSetWindow ( window ) ;
493 * Activates a menu pointed by the function argument
495 void fgActivateMenu( SFG_Window* window, int button )
498 * We'll be referencing this menu a lot, so remember its address:
500 SFG_Menu* menu = window->Menu[ button ];
503 * Mark the menu as active, so that it gets displayed:
505 window->ActiveMenu = menu;
506 menu->IsActive = TRUE ;
507 fgState.ActiveMenus ++ ;
510 * Set up the initial menu position now:
513 menu->X = window->State.MouseX + glutGet ( GLUT_WINDOW_X ) ;
514 menu->Y = window->State.MouseY + glutGet ( GLUT_WINDOW_Y ) ;
516 fgSetWindow ( menu->Window ) ;
517 glutPositionWindow ( menu->X, menu->Y ) ;
518 glutReshapeWindow ( menu->Width, menu->Height ) ;
521 menu->Window->ActiveMenu = menu ;
523 /* if( x > ( glutGet( GLUT_WINDOW_WIDTH ) - menu->Width ) )
524 menu->X = glutGet( GLUT_WINDOW_WIDTH ) - menu->Width;
525 if( y > ( glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height) )
526 menu->Y = glutGet( GLUT_WINDOW_HEIGHT ) - menu->Height; */
530 * Check whether an active menu absorbs a mouse click
532 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
535 * Near as I can tell, this is the active menu behaviour:
536 * - Down-click any button outside the menu, menu active: deactivate the menu
537 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
538 * - Up-click the menu button outside the menu, menu active: nothing happens
539 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
540 * Since menus can have submenus, we need to check this recursively.
542 return fghCheckMenuStatus ( window, menu ) ;
546 * Function to check for menu entry selection on menu deactivation
548 void fgExecuteMenuCallback( SFG_Menu* menu )
550 SFG_MenuEntry *menuEntry;
553 * First of all check any of the active sub menus...
555 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry; menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
558 * Is this menu entry active?
560 if( menuEntry->IsActive == TRUE )
563 * If there is not a sub menu, execute the menu callback and return...
565 if( menuEntry->SubMenu == NULL )
568 * ...certainly given that there is one...
570 if( menu->Callback != NULL )
571 menu->Callback( menuEntry->ID );
577 * Otherwise recurse into the submenu.
579 fgExecuteMenuCallback( menuEntry->SubMenu );
582 * There is little sense in dwelling the search on
590 * Deactivates a menu pointed by the function argument.
592 void fgDeactivateMenu( SFG_Window *window )
594 SFG_Window *current_window = fgStructure.Window ;
597 * Check if there is an active menu attached to this window...
599 SFG_Menu* menu = window->ActiveMenu;
600 SFG_MenuEntry *menuEntry ;
603 * Did we find an active window?
605 freeglut_return_if_fail( menu != NULL );
608 * Hide the present menu's window
610 fgSetWindow ( menu->Window ) ;
614 * Forget about having that menu active anymore, now:
616 menu->Window->ActiveMenu = NULL ;
617 menu->ParentWindow->ActiveMenu = NULL ;
618 menu->IsActive = FALSE ;
620 fgState.ActiveMenus -- ;
623 * Hide all submenu windows, and the root menu's window.
625 for ( menuEntry = (SFG_MenuEntry *)menu->Entries.First; menuEntry;
626 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
629 * Is that an active submenu by any case?
631 if ( ( menuEntry->SubMenu != NULL ) && menuEntry->SubMenu->IsActive )
632 fgDeactivateSubMenu ( menuEntry ) ;
635 fgSetWindow ( current_window ) ;
639 * Deactivates a menu pointed by the function argument.
641 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
643 SFG_Window *current_window = fgStructure.Window ;
644 SFG_MenuEntry *subMenuIter ;
646 * Hide the present menu's window
648 fgSetWindow ( menuEntry->SubMenu->Window ) ;
652 * Forget about having that menu active anymore, now:
654 menuEntry->SubMenu->Window->ActiveMenu = NULL ;
655 menuEntry->SubMenu->IsActive = FALSE ;
658 * Hide all submenu windows, and the root menu's window.
660 for ( subMenuIter = (SFG_MenuEntry *)menuEntry->SubMenu->Entries.First; subMenuIter;
661 subMenuIter = (SFG_MenuEntry *)subMenuIter->Node.Next )
664 * Is that an active submenu by any case?
666 if ( ( subMenuIter->SubMenu != NULL ) && subMenuIter->SubMenu->IsActive )
667 fgDeactivateSubMenu ( subMenuIter ) ;
670 fgSetWindow ( current_window ) ;
674 * Recalculates current menu's box size
676 void fghCalculateMenuBoxSize( void )
678 SFG_MenuEntry* menuEntry;
679 int width = 0, height = 0;
682 * Make sure there is a current menu set
684 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
687 * The menu's box size depends on the menu entries:
689 for( menuEntry = (SFG_MenuEntry *)fgStructure.Menu->Entries.First; menuEntry;
690 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
693 * Update the menu entry's width value
695 menuEntry->Width = glutBitmapLength( FREEGLUT_MENU_FONT, menuEntry->Text );
698 * If the entry is a submenu, then it needs to be wider to accomodate the arrow. JCJ 31 July 2003
701 if (menuEntry->SubMenu != NULL)
702 menuEntry->Width += glutBitmapLength( FREEGLUT_MENU_FONT, "_" );
705 * Check if it's the biggest we've found
707 if( menuEntry->Width > width )
708 width = menuEntry->Width;
710 height += FREEGLUT_MENU_HEIGHT;
714 * Store the menu's box size now:
716 fgStructure.Menu->Height = height + 2 * FREEGLUT_MENU_BORDER ;
717 fgStructure.Menu->Width = width + 4 * FREEGLUT_MENU_BORDER ;
721 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
724 * Creates a new menu object, adding it to the freeglut structure
726 int FGAPIENTRY glutCreateMenu( void (* callback)( int ) )
729 * The menu object creation code resides in freeglut_structure.c
731 return( fgCreateMenu( callback )->ID );
735 * Destroys a menu object, removing all references to it
737 void FGAPIENTRY glutDestroyMenu( int menuID )
739 SFG_Menu* menu = fgMenuByID( menuID );
741 freeglut_assert_ready; freeglut_return_if_fail( menu != NULL );
744 * The menu object destruction code resides in freeglut_structure.c
746 fgDestroyMenu( menu );
750 * Returns the ID number of the currently active menu
752 int FGAPIENTRY glutGetMenu( void )
754 freeglut_assert_ready;
757 * Is there a current menu set?
759 if( fgStructure.Menu != NULL )
762 * Yes, there is indeed...
764 return( fgStructure.Menu->ID );
768 * No, there is no current menu at all
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; freeglut_return_if_fail( menu != NULL );
783 * The current menu pointer is stored in fgStructure.Menu
785 fgStructure.Menu = menu;
789 * Adds a menu entry to the bottom of the current menu
791 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
793 SFG_MenuEntry* menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
796 * Make sure there is a current menu set
798 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
801 * Fill in the appropriate values...
803 menuEntry->Text = strdup( label );
804 menuEntry->ID = value;
807 * Have the new menu entry attached to the current menu
809 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
812 * Update the menu's dimensions now
814 fghCalculateMenuBoxSize();
818 * Add a sub menu to the bottom of the current menu
820 void FGAPIENTRY glutAddSubMenu( const char* label, int subMenuID )
822 SFG_MenuEntry* menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
823 SFG_Menu* subMenu = fgMenuByID( subMenuID );
826 * Make sure there is a current menu and the sub menu
827 * we want to attach actually exists...
829 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
830 freeglut_return_if_fail( subMenu != NULL );
833 * Fill in the appropriate values
835 menuEntry->Text = strdup( label );
836 menuEntry->SubMenu = subMenu;
840 * Make the submenu's parent window be the menu's parent window
842 fghSetSubmenuParentWindow ( fgStructure.Menu->ParentWindow, subMenu ) ;
845 * Have the new menu entry attached to the current menu
847 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
850 * Update the menu's dimensions now
852 fghCalculateMenuBoxSize();
856 * Changes the specified menu item in the current menu into a menu entry
858 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
860 SFG_MenuEntry* menuEntry = NULL;
863 * Make sure there is a current menu set...
865 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
868 * Get n-th menu entry in the current menu, starting from one:
870 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
873 * Make sure the menu entry exists
875 freeglut_return_if_fail( menuEntry != NULL );
878 * We want it to become a normal menu entry, so:
880 if( menuEntry->Text != NULL )
881 free( menuEntry->Text );
883 menuEntry->Text = strdup( label );
884 menuEntry->ID = value;
885 menuEntry->SubMenu = NULL;
888 * Update the menu's dimensions now
890 fghCalculateMenuBoxSize();
894 * Changes the specified menu item in the current menu into a sub-menu trigger.
896 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int subMenuID )
898 SFG_Menu* subMenu = fgMenuByID( subMenuID );
899 SFG_MenuEntry* menuEntry = NULL;
902 * Make sure there is a current menu set and the sub menu exists...
904 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
905 freeglut_return_if_fail( subMenu != NULL );
908 * Get n-th menu entry in the current menu, starting from one:
910 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
913 * Make sure the menu entry exists
915 freeglut_return_if_fail( menuEntry != NULL );
918 * We want it to become a sub menu entry, so:
920 if( menuEntry->Text != NULL )
921 free( menuEntry->Text );
923 menuEntry->Text = strdup( label );
924 menuEntry->SubMenu = subMenu;
928 * Update the menu's dimensions now
930 fghCalculateMenuBoxSize();
934 * Removes the specified menu item from the current menu
936 void FGAPIENTRY glutRemoveMenuItem( int item )
938 SFG_MenuEntry* menuEntry;
941 * Make sure there is a current menu set
943 freeglut_assert_ready; freeglut_return_if_fail( fgStructure.Menu != NULL );
946 * Get n-th menu entry in the current menu, starting from one:
948 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
951 * Make sure the menu entry exists
953 freeglut_return_if_fail( menuEntry != NULL );
956 * Removing a menu entry is quite simple...
958 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
961 * Free the entry label string, too
963 free( menuEntry->Text );
968 * Update the menu's dimensions now
970 fghCalculateMenuBoxSize();
974 * Attaches a menu to the current window
976 void FGAPIENTRY glutAttachMenu( int button )
978 freeglut_assert_ready;
981 * There must be a current window and a current menu set:
983 freeglut_return_if_fail( fgStructure.Window != NULL || fgStructure.Menu != NULL );
986 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
988 freeglut_return_if_fail( button == GLUT_LEFT_BUTTON || button == GLUT_MIDDLE_BUTTON || button == GLUT_RIGHT_BUTTON );
991 * It is safe now to attach the menu
993 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
996 * Make the parent window of the menu (and all submenus) the current window
998 fghSetSubmenuParentWindow ( fgStructure.Window, fgStructure.Menu ) ;
1002 * Detaches a menu from the current window
1004 void FGAPIENTRY glutDetachMenu( int button )
1006 freeglut_assert_ready;
1009 * There must be a current window set:
1011 freeglut_return_if_fail( fgStructure.Window != NULL );
1014 * Make sure the button value is valid (0, 1 or 2, see freeglut.h)
1016 freeglut_return_if_fail( button != 0 && button != 1 && button != 2 );
1019 * It is safe now to detach the menu
1021 fgStructure.Window->Menu[ button ] = NULL;
1025 * A.Donev: Set and retrieve the menu's user data
1027 void* FGAPIENTRY glutGetMenuData( void )
1029 return(fgStructure.Menu->UserData);
1032 void FGAPIENTRY glutSetMenuData(void* data)
1034 fgStructure.Menu->UserData=data;
1037 /*** END OF FILE ***/