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 );
167 FREEGLUT_INTERNAL_ERROR_EXIT( menuEntry, "Cannot find menu entry",
168 "fghCheckMenuStatus" );
170 menuEntry->IsActive = GL_TRUE;
171 menuEntry->Ordinal = menuID;
174 * If this is not the same as the last active menu entry, deactivate
175 * the previous entry. Specifically, if the previous active entry
176 * was a submenu then deactivate it.
178 if( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
179 if( menu->ActiveEntry->SubMenu )
180 fgDeactivateSubMenu( menu->ActiveEntry );
182 menu->ActiveEntry = menuEntry;
183 menu->IsActive = GL_TRUE;
186 * OKi, we have marked that entry as active, but it would be also
187 * nice to have its contents updated, in case it's a sub menu.
188 * Also, ignore the return value of the check function:
190 if( menuEntry->SubMenu )
192 if ( ! menuEntry->SubMenu->IsActive )
194 SFG_Window *current_window = fgStructure.Window;
196 /* Set up the initial menu position now... */
197 menuEntry->SubMenu->IsActive = GL_TRUE;
199 /* Set up the initial submenu position now: */
200 menuEntry->SubMenu->X = menu->X + menu->Width;
201 menuEntry->SubMenu->Y = menu->Y +
202 menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT;
204 if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width >
205 glutGet( GLUT_SCREEN_WIDTH ) )
206 menuEntry->SubMenu->X = menu->X -
207 menuEntry->SubMenu->Width;
209 if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height >
210 glutGet( GLUT_SCREEN_HEIGHT ) )
211 menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
212 FREEGLUT_MENU_HEIGHT -
213 2 * FREEGLUT_MENU_BORDER );
215 fgSetWindow( menuEntry->SubMenu->Window );
216 glutPositionWindow( menuEntry->SubMenu->X,
217 menuEntry->SubMenu->Y );
218 glutReshapeWindow( menuEntry->SubMenu->Width,
219 menuEntry->SubMenu->Height );
222 menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu;
223 fgSetWindow( current_window );
226 fghCheckMenuStatus( window, menuEntry->SubMenu );
228 /* Activate it because its parent entry is active */
229 menuEntry->SubMenu->IsActive = GL_TRUE;
232 /* Report back that we have caught the menu cursor */
236 /* Looks like the menu cursor is somewhere else... */
241 * Displays a menu box and all of its submenus (if they are active)
243 static void fghDisplayMenuBox( SFG_Menu* menu )
245 SFG_MenuEntry *menuEntry;
247 int border = FREEGLUT_MENU_BORDER;
250 * Have the menu box drawn first. The +- values are
251 * here just to make it more nice-looking...
253 /* a non-black dark version of the below. */
254 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
255 glBegin( GL_QUAD_STRIP );
256 glVertex2i( menu->Width , 0 );
257 glVertex2i( menu->Width - border, border);
259 glVertex2i( border, border);
260 glVertex2i( 0 , menu->Height );
261 glVertex2i( border, menu->Height - border);
264 /* a non-black dark version of the below. */
265 glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
266 glBegin( GL_QUAD_STRIP );
267 glVertex2i( 0 , menu->Height );
268 glVertex2i( border, menu->Height - border);
269 glVertex2i( menu->Width , menu->Height );
270 glVertex2i( menu->Width - border, menu->Height - border);
271 glVertex2i( menu->Width , 0 );
272 glVertex2i( menu->Width - border, border);
275 glColor4fv( menu_pen_back );
277 glVertex2i( border, border);
278 glVertex2i( menu->Width - border, border);
279 glVertex2i( menu->Width - border, menu->Height - border);
280 glVertex2i( border, menu->Height - border);
283 /* Check if any of the submenus is currently active... */
284 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
286 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
288 /* Has the menu been marked as active, maybe? */
289 if( menuEntry->IsActive )
292 * That's truly right, and we need to have it highlighted.
293 * There is an assumption that mouse cursor didn't move
294 * since the last check of menu activity state:
296 int menuID = menuEntry->Ordinal;
298 /* So have the highlight drawn... */
299 glColor4fv( menu_pen_hback );
302 (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
303 glVertex2i( menu->Width - border,
304 (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
305 glVertex2i( menu->Width - border,
306 (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
308 (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
313 /* Print the menu entries now... */
315 glColor4fv( menu_pen_fore );
317 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First, i = 0;
319 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next, ++i )
321 /* If the menu entry is active, set the color to white */
322 if( menuEntry->IsActive )
323 glColor4fv( menu_pen_hfore );
325 /* Move the raster into position... */
326 /* Try to center the text - JCJ 31 July 2003*/
329 ( i + 1 )*FREEGLUT_MENU_HEIGHT -
330 ( int )( FREEGLUT_MENU_HEIGHT*0.3 - border )
333 /* Have the label drawn, character after character: */
334 glutBitmapString( FREEGLUT_MENU_FONT,
335 (unsigned char *)menuEntry->Text);
337 /* If it's a submenu, draw a right arrow */
338 if( menuEntry->SubMenu )
340 int width = glutBitmapWidth( FREEGLUT_MENU_FONT, '_' );
341 int x_base = menu->Width - 2 - width;
342 int y_base = i*FREEGLUT_MENU_HEIGHT + border;
343 glBegin( GL_TRIANGLES );
344 glVertex2i( x_base, y_base + 2*border);
345 glVertex2i( menu->Width - 2, y_base +
346 ( FREEGLUT_MENU_HEIGHT + border) / 2 );
347 glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - border );
351 /* If the menu entry is active, reset the color */
352 if( menuEntry->IsActive )
353 glColor4fv( menu_pen_fore );
356 /* Now we are ready to check if any of our children needs to be redrawn: */
357 for( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
359 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
361 /* Is that an active sub menu by any case? */
362 if( menuEntry->SubMenu && menuEntry->IsActive )
364 /* Yeah, indeed. Have it redrawn now: */
365 fgSetWindow( menuEntry->SubMenu->Window );
366 fghDisplayMenuBox( menuEntry->SubMenu );
367 fgSetWindow( menu->Window );
373 * Private static function to set the parent window of a submenu and all
376 static void fghSetSubmenuParentWindow( SFG_Window *window, SFG_Menu *menu )
378 SFG_MenuEntry *menuEntry;
380 menu->ParentWindow = window;
382 for( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
384 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
385 if( menuEntry->SubMenu )
386 fghSetSubmenuParentWindow( window, menuEntry->SubMenu );
391 * Displays the currently active menu for the current window
393 void fgDisplayMenu( void )
395 SFG_Window* window = fgStructure.Window;
396 SFG_Menu* menu = NULL;
398 FREEGLUT_INTERNAL_ERROR_EXIT ( fgStructure.Window, "Displaying menu in nonexistent window",
401 /* Check if there is an active menu attached to this window... */
402 menu = window->ActiveMenu;
403 freeglut_return_if_fail( menu );
405 fgSetWindow( menu->Window );
407 glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT |
410 glDisable( GL_DEPTH_TEST );
411 glDisable( GL_TEXTURE_2D );
412 glDisable( GL_LIGHTING );
413 glDisable( GL_CULL_FACE );
415 glMatrixMode( GL_PROJECTION );
419 0, glutGet( GLUT_WINDOW_WIDTH ),
420 glutGet( GLUT_WINDOW_HEIGHT ), 0,
424 glMatrixMode( GL_MODELVIEW );
428 fghCheckMenuStatus( window, menu );
429 fghDisplayMenuBox( menu );
433 glMatrixMode( GL_PROJECTION );
435 glMatrixMode( GL_MODELVIEW );
440 fgSetWindow ( window );
444 * Activates a menu pointed by the function argument
446 void fgActivateMenu( SFG_Window* window, int button )
448 /* We'll be referencing this menu a lot, so remember its address: */
449 SFG_Menu* menu = window->Menu[ button ];
451 /* Mark the menu as active, so that it gets displayed: */
452 window->ActiveMenu = menu;
453 menu->IsActive = GL_TRUE;
454 fgState.ActiveMenus++;
456 /* Set up the initial menu position now: */
457 menu->X = window->State.MouseX + glutGet( GLUT_WINDOW_X );
458 menu->Y = window->State.MouseY + glutGet( GLUT_WINDOW_Y );
460 if( menu->X + menu->Width > glutGet ( GLUT_SCREEN_WIDTH ) )
461 menu->X -=menu->Width;
463 if( menu->Y + menu->Height > glutGet ( GLUT_SCREEN_HEIGHT ) )
464 menu->Y -=menu->Height;
466 fgSetWindow( menu->Window );
467 glutPositionWindow( menu->X, menu->Y );
468 glutReshapeWindow( menu->Width, menu->Height );
471 menu->Window->ActiveMenu = menu;
475 * Check whether an active menu absorbs a mouse click
477 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu )
480 * Near as I can tell, this is the active menu behaviour:
481 * - Down-click any button outside the menu, menu active:
482 * deactivate the menu
483 * - Down-click any button inside the menu, menu active:
484 * select the menu entry and deactivate the menu
485 * - Up-click the menu button outside the menu, menu active:
487 * - Up-click the menu button inside the menu, menu active:
488 * select the menu entry and deactivate the menu
489 * Since menus can have submenus, we need to check this recursively.
491 return fghCheckMenuStatus( window, menu );
495 * Function to check for menu entry selection on menu deactivation
497 void fgExecuteMenuCallback( SFG_Menu* menu )
499 SFG_MenuEntry *menuEntry;
501 /* First of all check any of the active sub menus... */
502 for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
504 menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next)
506 if( menuEntry->IsActive )
508 if( menuEntry->SubMenu )
509 fgExecuteMenuCallback( menuEntry->SubMenu );
512 menu->Callback( menuEntry->ID );
519 * Deactivates a menu pointed by the function argument.
521 void fgDeactivateMenu( SFG_Window *window )
523 SFG_Window *current_window = fgStructure.Window;
525 /* Check if there is an active menu attached to this window... */
526 SFG_Menu* menu = window->ActiveMenu;
527 SFG_MenuEntry *menuEntry;
529 /* Did we find an active window? */
530 freeglut_return_if_fail( menu );
532 /* Hide the present menu's window */
533 fgSetWindow( menu->Window );
536 /* Forget about having that menu active anymore, now: */
537 menu->Window->ActiveMenu = NULL;
538 menu->ParentWindow->ActiveMenu = NULL;
539 menu->IsActive = GL_FALSE;
541 fgState.ActiveMenus--;
543 /* Hide all submenu windows, and the root menu's window. */
544 for ( menuEntry = ( SFG_MenuEntry * )menu->Entries.First;
546 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
548 /* Is that an active submenu by any case? */
549 if( menuEntry->SubMenu )
550 fgDeactivateSubMenu( menuEntry );
553 fgSetWindow( current_window );
557 * Deactivates a menu pointed by the function argument.
559 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
561 SFG_Window *current_window = fgStructure.Window;
562 SFG_MenuEntry *subMenuIter;
563 /* Hide the present menu's window */
564 fgSetWindow( menuEntry->SubMenu->Window );
567 /* Forget about having that menu active anymore, now: */
568 menuEntry->SubMenu->Window->ActiveMenu = NULL;
569 menuEntry->SubMenu->IsActive = GL_FALSE;
571 /* Hide all submenu windows, and the root menu's window. */
572 for ( subMenuIter = (SFG_MenuEntry *)menuEntry->SubMenu->Entries.First;
574 subMenuIter = (SFG_MenuEntry *)subMenuIter->Node.Next )
576 /* Is that an active submenu by any case? */
577 if( subMenuIter->SubMenu )
578 fgDeactivateSubMenu( subMenuIter );
581 fgSetWindow( current_window );
585 * Recalculates current menu's box size
587 void fghCalculateMenuBoxSize( void )
589 SFG_MenuEntry* menuEntry;
590 int width = 0, height = 0;
592 /* Make sure there is a current menu set */
593 freeglut_return_if_fail( fgStructure.Menu );
595 /* The menu's box size depends on the menu entries: */
596 for( menuEntry = ( SFG_MenuEntry * )fgStructure.Menu->Entries.First;
598 menuEntry = ( SFG_MenuEntry * )menuEntry->Node.Next )
600 /* Update the menu entry's width value */
601 menuEntry->Width = glutBitmapLength(
603 (unsigned char *)menuEntry->Text
607 * If the entry is a submenu, then it needs to be wider to
608 * accomodate the arrow. JCJ 31 July 2003
610 if (menuEntry->SubMenu )
611 menuEntry->Width += glutBitmapLength(
616 /* Check if it's the biggest we've found */
617 if( menuEntry->Width > width )
618 width = menuEntry->Width;
620 height += FREEGLUT_MENU_HEIGHT;
623 /* Store the menu's box size now: */
624 fgStructure.Menu->Height = height + 2 * FREEGLUT_MENU_BORDER;
625 fgStructure.Menu->Width = width + 4 * FREEGLUT_MENU_BORDER;
629 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
632 * Creates a new menu object, adding it to the freeglut structure
634 int FGAPIENTRY glutCreateMenu( void(* callback)( int ) )
636 /* The menu object creation code resides in freeglut_structure.c */
637 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateMenu" );
638 return fgCreateMenu( callback )->ID;
642 * Destroys a menu object, removing all references to it
644 void FGAPIENTRY glutDestroyMenu( int menuID )
648 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyMenu" );
649 menu = fgMenuByID( menuID );
651 freeglut_return_if_fail( menu );
653 /* The menu object destruction code resides in freeglut_structure.c */
654 fgDestroyMenu( menu );
658 * Returns the ID number of the currently active menu
660 int FGAPIENTRY glutGetMenu( void )
662 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetMenu" );
664 if( fgStructure.Menu )
665 return fgStructure.Menu->ID;
671 * Sets the current menu given its menu ID
673 void FGAPIENTRY glutSetMenu( int menuID )
677 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetMenu" );
678 menu = fgMenuByID( menuID );
680 freeglut_return_if_fail( menu );
682 fgStructure.Menu = menu;
686 * Adds a menu entry to the bottom of the current menu
688 void FGAPIENTRY glutAddMenuEntry( const char* label, int value )
690 SFG_MenuEntry* menuEntry;
691 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutAddMenuEntry" );
692 menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 );
693 freeglut_return_if_fail( fgStructure.Menu );
695 menuEntry->Text = strdup( label );
696 menuEntry->ID = value;
698 /* Have the new menu entry attached to the current menu */
699 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
701 fghCalculateMenuBoxSize( );
705 * Add a sub menu to the bottom of the current menu
707 void FGAPIENTRY glutAddSubMenu( const char *label, int subMenuID )
709 SFG_MenuEntry *menuEntry;
712 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutAddSubMenu" );
713 menuEntry = ( SFG_MenuEntry * )calloc( sizeof( SFG_MenuEntry ), 1 );
714 subMenu = fgMenuByID( subMenuID );
716 freeglut_return_if_fail( fgStructure.Menu );
717 freeglut_return_if_fail( subMenu );
719 menuEntry->Text = strdup( label );
720 menuEntry->SubMenu = subMenu;
723 /* Make the submenu's parent window be the menu's parent window */
724 fghSetSubmenuParentWindow( fgStructure.Menu->ParentWindow, subMenu );
726 fgListAppend( &fgStructure.Menu->Entries, &menuEntry->Node );
727 fghCalculateMenuBoxSize( );
731 * Changes the specified menu item in the current menu into a menu entry
733 void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
735 SFG_MenuEntry* menuEntry = NULL;
737 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutChangeToMenuEntry" );
738 freeglut_return_if_fail( fgStructure.Menu );
740 /* Get n-th menu entry in the current menu, starting from one: */
741 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
743 freeglut_return_if_fail( menuEntry );
745 /* We want it to become a normal menu entry, so: */
746 if( menuEntry->Text )
747 free( menuEntry->Text );
749 menuEntry->Text = strdup( label );
750 menuEntry->ID = value;
751 menuEntry->SubMenu = NULL;
752 fghCalculateMenuBoxSize( );
756 * Changes the specified menu item in the current menu into a sub-menu trigger.
758 void FGAPIENTRY glutChangeToSubMenu( int item, const char* label,
762 SFG_MenuEntry* menuEntry;
764 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutChangeToSubMenu" );
765 subMenu = fgMenuByID( subMenuID );
768 freeglut_return_if_fail( fgStructure.Menu );
769 freeglut_return_if_fail( subMenu );
771 /* Get n-th menu entry in the current menu, starting from one: */
772 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
774 freeglut_return_if_fail( menuEntry );
776 /* We want it to become a sub menu entry, so: */
777 if( menuEntry->Text )
778 free( menuEntry->Text );
780 menuEntry->Text = strdup( label );
781 menuEntry->SubMenu = subMenu;
783 fghCalculateMenuBoxSize( );
787 * Removes the specified menu item from the current menu
789 void FGAPIENTRY glutRemoveMenuItem( int item )
791 SFG_MenuEntry* menuEntry;
793 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutRemoveMenuItem" );
794 freeglut_return_if_fail( fgStructure.Menu );
796 /* Get n-th menu entry in the current menu, starting from one: */
797 menuEntry = fghFindMenuEntry( fgStructure.Menu, item );
799 freeglut_return_if_fail( menuEntry );
801 fgListRemove( &fgStructure.Menu->Entries, &menuEntry->Node );
802 if ( menuEntry->Text )
803 free( menuEntry->Text );
806 fghCalculateMenuBoxSize( );
810 * Attaches a menu to the current window
812 void FGAPIENTRY glutAttachMenu( int button )
814 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutAttachMenu" );
816 freeglut_return_if_fail( fgStructure.Window );
817 freeglut_return_if_fail( fgStructure.Menu );
819 freeglut_return_if_fail( button >= 0 );
820 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
822 fgStructure.Window->Menu[ button ] = fgStructure.Menu;
824 /* Make the parent window of the menu (and all submenus) the current window */
825 fghSetSubmenuParentWindow( fgStructure.Window, fgStructure.Menu );
829 * Detaches a menu from the current window
831 void FGAPIENTRY glutDetachMenu( int button )
833 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDetachMenu" );
835 freeglut_return_if_fail( fgStructure.Window );
836 freeglut_return_if_fail( fgStructure.Menu );
838 freeglut_return_if_fail( button >= 0 );
839 freeglut_return_if_fail( button < FREEGLUT_MAX_MENUS );
841 fgStructure.Window->Menu[ button ] = NULL;
845 * A.Donev: Set and retrieve the menu's user data
847 void* FGAPIENTRY glutGetMenuData( void )
849 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetMenuData" );
850 return fgStructure.Menu->UserData;
853 void FGAPIENTRY glutSetMenuData(void* data)
855 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetMenuData" );
856 fgStructure.Menu->UserData=data;
859 /*** END OF FILE ***/