menu fonts API improved

No more glutSetOption, casting void* to int and back is not safe
glutSetMenuFont now takes menuID as param

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1588 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2013-04-04 14:32:29 +00:00
parent afb16d74ea
commit 0bb2219049
4 changed files with 11 additions and 25 deletions

View File

@ -88,8 +88,6 @@
#define GLUT_GEOMETRY_VISUALIZE_NORMALS 0x0205 #define GLUT_GEOMETRY_VISUALIZE_NORMALS 0x0205
#define GLUT_MENU_FONT 0x0206 /* TOOD: now glutSetOption only */
/* /*
* New tokens for glutInitDisplayMode. * New tokens for glutInitDisplayMode.
* Only one GLUT_AUXn bit may be used at a time. * Only one GLUT_AUXn bit may be used at a time.
@ -140,7 +138,7 @@ FGAPI void FGAPIENTRY glutLeaveFullScreen( void );
/* /*
* Menu functions * Menu functions
*/ */
FGAPI void FGAPIENTRY glutSetMenuFont( void* font ); FGAPI void FGAPIENTRY glutSetMenuFont( int menuID, void* font );
/* /*
* Window-specific callback functions, see freeglut_callbacks.c * Window-specific callback functions, see freeglut_callbacks.c

View File

@ -640,8 +640,6 @@ main(int argc, char *argv[])
* what we demonstrate here. * what we demonstrate here.
*/ */
glutSetKeyRepeat(GLUT_KEY_REPEAT_ON); glutSetKeyRepeat(GLUT_KEY_REPEAT_ON);
/* global setting: default font for any menus created after this call (we call it again below to demo) */
glutSetOption(GLUT_MENU_FONT,(int)GLUT_BITMAP_HELVETICA_12);
/* Set other global callback (global as in not associated with any specific menu or window) */ /* Set other global callback (global as in not associated with any specific menu or window) */
glutIdleFunc ( Idle ); glutIdleFunc ( Idle );
@ -665,9 +663,8 @@ main(int argc, char *argv[])
glutAddMenuEntry( "Sub menu A2 (02)", 12 ); glutAddMenuEntry( "Sub menu A2 (02)", 12 );
glutAddMenuEntry( "Sub menu A3 (03)", 13 ); glutAddMenuEntry( "Sub menu A3 (03)", 13 );
glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */ glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */
/* Change font for this menu */
/* change font for any menus created after this call */ glutSetMenuFont(subMenuA, GLUT_BITMAP_HELVETICA_12);
glutSetOption(GLUT_MENU_FONT,(int)GLUT_BITMAP_8_BY_13);
subMenuB = glutCreateMenu( MenuCallback ); subMenuB = glutCreateMenu( MenuCallback );
glutAddMenuEntry( "Sub menu B1 (04)", 14 ); glutAddMenuEntry( "Sub menu B1 (04)", 14 );
@ -675,6 +672,7 @@ main(int argc, char *argv[])
glutAddMenuEntry( "Sub menu B3 (06)", 16 ); glutAddMenuEntry( "Sub menu B3 (06)", 16 );
glutAddSubMenu( "Going to sub menu A", subMenuA ); glutAddSubMenu( "Going to sub menu A", subMenuA );
glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */ glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */
glutSetMenuFont(subMenuB, GLUT_BITMAP_9_BY_15);
menuID = glutCreateMenu( MenuCallback ); menuID = glutCreateMenu( MenuCallback );
glutAddMenuEntry( "Entry one", 21 ); glutAddMenuEntry( "Entry one", 21 );
@ -687,8 +685,6 @@ main(int argc, char *argv[])
glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */ glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */
glutAttachMenu( GLUT_LEFT_BUTTON ); glutAttachMenu( GLUT_LEFT_BUTTON );
/* You can also change the font of the current menu: */
glutSetMenuFont(GLUT_BITMAP_TIMES_ROMAN_10);
/* Position second window right next to the first */ /* Position second window right next to the first */

View File

@ -881,19 +881,23 @@ void FGAPIENTRY glutAddSubMenu( const char *label, int subMenuID )
/* /*
* Changes the current menu's font * Changes the current menu's font
*/ */
void FGAPIENTRY glutSetMenuFont( void* fontID ) void FGAPIENTRY glutSetMenuFont( int menuID, void* fontID )
{ {
SFG_Font* font; SFG_Font* font;
SFG_Menu* menu;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetMenuFont" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetMenuFont" );
freeglut_return_if_fail( fgStructure.CurrentMenu ); menu = fgMenuByID( menuID );
freeglut_return_if_fail( menu );
if (fgGetActiveMenu()) if (fgGetActiveMenu())
fgError("Menu manipulation not allowed while menus in use."); fgError("Menu manipulation not allowed while menus in use.");
font = fghFontByID( fontID ); font = fghFontByID( fontID );
if (!font) if (!font)
{
fgWarning("glutChangeMenuFont: bitmap font 0x%08x not found. Make sure you're not passing a stroke font. Ignoring...\n",fontID); fgWarning("glutChangeMenuFont: bitmap font 0x%08x not found. Make sure you're not passing a stroke font. Ignoring...\n",fontID);
freeglut_return_if_fail( font ); return;
}
fgStructure.CurrentMenu->Font = fontID; fgStructure.CurrentMenu->Font = fontID;
fghCalculateMenuBoxSize( ); fghCalculateMenuBoxSize( );

View File

@ -118,18 +118,6 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
fgStructure.CurrentWindow->State.VisualizeNormals = value; fgStructure.CurrentWindow->State.VisualizeNormals = value;
break; break;
case GLUT_MENU_FONT:
{
void* fontID = (void*)value;
SFG_Font* font;
font = fghFontByID( fontID );
if (!font)
fgWarning("glutSetOption(GLUT_MENU_FONT,...): bitmap font 0x%08x not found. Make sure you're not passing a stroke font. Ignoring...\n",fontID);
else
fgState.MenuFont = fontID;
}
break;
default: default:
fgWarning( "glutSetOption(): missing enum handle %d", eWhat ); fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
break; break;