can now set the font used for a menu

set default font using glutSetOption(GLUT_MENU_FONT,...) and set font of current menu using glutSetMenuFont()

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1582 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2013-04-04 10:13:04 +00:00
parent 58a343f2e3
commit 75dcd74677
10 changed files with 128 additions and 35 deletions

View File

@ -88,6 +88,8 @@
#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.
@ -135,6 +137,11 @@ FGAPI void FGAPIENTRY glutExit ( void );
FGAPI void FGAPIENTRY glutFullScreenToggle( void ); FGAPI void FGAPIENTRY glutFullScreenToggle( void );
FGAPI void FGAPIENTRY glutLeaveFullScreen( void ); FGAPI void FGAPIENTRY glutLeaveFullScreen( void );
/*
* Menu functions
*/
FGAPI void FGAPIENTRY glutSetMenuFont( void* font );
/* /*
* Window-specific callback functions, see freeglut_callbacks.c * Window-specific callback functions, see freeglut_callbacks.c
*/ */

View File

@ -640,6 +640,8 @@ 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 );
@ -664,6 +666,9 @@ main(int argc, char *argv[])
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 any menus created after this call */
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 );
glutAddMenuEntry( "Sub menu B2 (05)", 15 ); glutAddMenuEntry( "Sub menu B2 (05)", 15 );
@ -682,6 +687,8 @@ 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

@ -172,6 +172,7 @@ static GLUTproc fghGetGLUTProcAddress( const char* procName )
CHECK_NAME(glutMenuDestroyFunc); CHECK_NAME(glutMenuDestroyFunc);
CHECK_NAME(glutFullScreenToggle); CHECK_NAME(glutFullScreenToggle);
CHECK_NAME(glutLeaveFullScreen); CHECK_NAME(glutLeaveFullScreen);
CHECK_NAME(glutSetMenuFont);
CHECK_NAME(glutSetOption); CHECK_NAME(glutSetOption);
CHECK_NAME(glutGetModeValues); CHECK_NAME(glutGetModeValues);
CHECK_NAME(glutSetWindowData); CHECK_NAME(glutSetWindowData);

View File

@ -56,7 +56,7 @@ extern SFG_StrokeFont fgStrokeMonoRoman;
* Matches a font ID with a SFG_Font structure pointer. * Matches a font ID with a SFG_Font structure pointer.
* This was changed to match the GLUT header style. * This was changed to match the GLUT header style.
*/ */
static SFG_Font* fghFontByID( void* font ) SFG_Font* fghFontByID( void* font )
{ {
if( font == GLUT_BITMAP_8_BY_13 ) if( font == GLUT_BITMAP_8_BY_13 )
return &fgFontFixed8x13; return &fgFontFixed8x13;
@ -73,7 +73,6 @@ static SFG_Font* fghFontByID( void* font )
if( font == GLUT_BITMAP_TIMES_ROMAN_24 ) if( font == GLUT_BITMAP_TIMES_ROMAN_24 )
return &fgFontTimesRoman24; return &fgFontTimesRoman24;
fgWarning( "font 0x%08x not found", font );
return 0; return 0;
} }
@ -88,7 +87,6 @@ static SFG_StrokeFont* fghStrokeByID( void* font )
if( font == GLUT_STROKE_MONO_ROMAN ) if( font == GLUT_STROKE_MONO_ROMAN )
return &fgStrokeMonoRoman; return &fgStrokeMonoRoman;
fgWarning( "stroke font 0x%08x not found", font );
return 0; return 0;
} }
@ -104,8 +102,12 @@ void FGAPIENTRY glutBitmapCharacter( void* fontID, int character )
SFG_Font* font; SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapCharacter" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapCharacter" );
font = fghFontByID( fontID ); font = fghFontByID( fontID );
if (!font)
{
fgWarning("glutBitmapCharacter: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
return;
}
freeglut_return_if_fail( ( character >= 1 )&&( character < 256 ) ); freeglut_return_if_fail( ( character >= 1 )&&( character < 256 ) );
freeglut_return_if_fail( font );
/* /*
* Find the character we want to draw (???) * Find the character we want to draw (???)
@ -135,7 +137,11 @@ void FGAPIENTRY glutBitmapString( void* fontID, const unsigned char *string )
SFG_Font* font; SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapString" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapString" );
font = fghFontByID( fontID ); font = fghFontByID( fontID );
freeglut_return_if_fail( font ); if (!font)
{
fgWarning("glutBitmapString: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
return;
}
if ( !string || ! *string ) if ( !string || ! *string )
return; return;
@ -182,9 +188,13 @@ int FGAPIENTRY glutBitmapWidth( void* fontID, int character )
{ {
SFG_Font* font; SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapWidth" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapWidth" );
font = fghFontByID( fontID );
freeglut_return_val_if_fail( character > 0 && character < 256, 0 ); freeglut_return_val_if_fail( character > 0 && character < 256, 0 );
freeglut_return_val_if_fail( font, 0 ); font = fghFontByID( fontID );
if (!font)
{
fgWarning("glutBitmapWidth: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
return 0;
}
return *( font->Characters[ character ] ); return *( font->Characters[ character ] );
} }
@ -198,7 +208,11 @@ int FGAPIENTRY glutBitmapLength( void* fontID, const unsigned char* string )
SFG_Font* font; SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapLength" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapLength" );
font = fghFontByID( fontID ); font = fghFontByID( fontID );
freeglut_return_val_if_fail( font, 0 ); if (!font)
{
fgWarning("glutBitmapLength: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
return 0;
}
if ( !string || ! *string ) if ( !string || ! *string )
return 0; return 0;
@ -227,7 +241,11 @@ int FGAPIENTRY glutBitmapHeight( void* fontID )
SFG_Font* font; SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapHeight" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapHeight" );
font = fghFontByID( fontID ); font = fghFontByID( fontID );
freeglut_return_val_if_fail( font, 0 ); if (!font)
{
fgWarning("glutBitmapHeight: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
return 0;
}
return font->Height; return font->Height;
} }
@ -242,9 +260,13 @@ void FGAPIENTRY glutStrokeCharacter( void* fontID, int character )
SFG_StrokeFont* font; SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeCharacter" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeCharacter" );
font = fghStrokeByID( fontID ); font = fghStrokeByID( fontID );
if (!font)
{
fgWarning("glutStrokeCharacter: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
return;
}
freeglut_return_if_fail( character >= 0 ); freeglut_return_if_fail( character >= 0 );
freeglut_return_if_fail( character < font->Quantity ); freeglut_return_if_fail( character < font->Quantity );
freeglut_return_if_fail( font );
schar = font->Characters[ character ]; schar = font->Characters[ character ];
freeglut_return_if_fail( schar ); freeglut_return_if_fail( schar );
@ -272,7 +294,11 @@ void FGAPIENTRY glutStrokeString( void* fontID, const unsigned char *string )
SFG_StrokeFont* font; SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeString" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeString" );
font = fghStrokeByID( fontID ); font = fghStrokeByID( fontID );
freeglut_return_if_fail( font ); if (!font)
{
fgWarning("glutStrokeString: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
return;
}
if ( !string || ! *string ) if ( !string || ! *string )
return; return;
@ -322,11 +348,15 @@ int FGAPIENTRY glutStrokeWidth( void* fontID, int character )
SFG_StrokeFont* font; SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeWidth" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeWidth" );
font = fghStrokeByID( fontID ); font = fghStrokeByID( fontID );
if (!font)
{
fgWarning("glutStrokeWidth: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
return 0;
}
freeglut_return_val_if_fail( ( character >= 0 ) && freeglut_return_val_if_fail( ( character >= 0 ) &&
( character < font->Quantity ), ( character < font->Quantity ),
0 0
); );
freeglut_return_val_if_fail( font, 0 );
schar = font->Characters[ character ]; schar = font->Characters[ character ];
freeglut_return_val_if_fail( schar, 0 ); freeglut_return_val_if_fail( schar, 0 );
@ -344,7 +374,11 @@ int FGAPIENTRY glutStrokeLength( void* fontID, const unsigned char* string )
SFG_StrokeFont* font; SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeLength" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeLength" );
font = fghStrokeByID( fontID ); font = fghStrokeByID( fontID );
freeglut_return_val_if_fail( font, 0 ); if (!font)
{
fgWarning("glutStrokeLength: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
return 0;
}
if ( !string || ! *string ) if ( !string || ! *string )
return 0; return 0;
@ -377,7 +411,11 @@ GLfloat FGAPIENTRY glutStrokeHeight( void* fontID )
SFG_StrokeFont* font; SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeHeight" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeHeight" );
font = fghStrokeByID( fontID ); font = fghStrokeByID( fontID );
freeglut_return_val_if_fail( font, 0.0 ); if (!font)
{
fgWarning("glutStrokeHeight: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
return 0.f;
}
return font->Height; return font->Height;
} }

View File

@ -73,6 +73,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
0, /* ActiveMenus */ 0, /* ActiveMenus */
NULL, /* MenuStateCallback */ NULL, /* MenuStateCallback */
NULL, /* MenuStatusCallback */ NULL, /* MenuStatusCallback */
FREEGLUT_MENU_FONT,
{ -1, -1, GL_TRUE }, /* GameModeSize */ { -1, -1, GL_TRUE }, /* GameModeSize */
-1, /* GameModeDepth */ -1, /* GameModeDepth */
-1, /* GameModeRefresh */ -1, /* GameModeRefresh */

View File

@ -306,6 +306,7 @@ struct tagSFG_State
int ActiveMenus; /* Num. of currently active menus */ int ActiveMenus; /* Num. of currently active menus */
FGCBMenuState MenuStateCallback; /* Menu callbacks are global */ FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
FGCBMenuStatus MenuStatusCallback; FGCBMenuStatus MenuStatusCallback;
void* MenuFont; /* Font to be used for newly created menus */
SFG_XYUse GameModeSize; /* Game mode screen's dimensions */ SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
int GameModeDepth; /* The pixel depth for game mode */ int GameModeDepth; /* The pixel depth for game mode */
@ -640,6 +641,7 @@ struct tagSFG_Menu
FGCBMenu Callback; /* The menu callback */ FGCBMenu Callback; /* The menu callback */
FGCBDestroy Destroy; /* Destruction callback */ FGCBDestroy Destroy; /* Destruction callback */
GLboolean IsActive; /* Is the menu selected? */ GLboolean IsActive; /* Is the menu selected? */
void* Font; /* Font to be used for displaying this menu */
int Width; /* Menu box width in pixels */ int Width; /* Menu box width in pixels */
int Height; /* Menu box height in pixels */ int Height; /* Menu box height in pixels */
int X, Y; /* Menu box raster position */ int X, Y; /* Menu box raster position */

View File

@ -43,8 +43,8 @@
* GLUT apparently uses host-system menus rather than building its own. * GLUT apparently uses host-system menus rather than building its own.
* freeglut is building its own menus from scratch.) * freeglut is building its own menus from scratch.)
* *
* FREEGLUT_MENU_HEIGHT gives the height of ONE menu box. This should be * FREEGLUT_MENUENTRY_HEIGHT gives the height of ONE menu box. This should
* the distances between two adjacent menu entries. It should scale * be the distances between two adjacent menu entries. It should scale
* automatically with the font choice, so you needn't alter it---unless you * automatically with the font choice, so you needn't alter it---unless you
* use a stroked font. * use a stroked font.
* *
@ -56,8 +56,8 @@
*/ */
/* See platform-specific header files for menu font and color definitions */ /* See platform-specific header files for menu font and color definitions */
#define FREEGLUT_MENU_HEIGHT (glutBitmapHeight(FREEGLUT_MENU_FONT) + \ #define FREEGLUT_MENUENTRY_HEIGHT(font) (glutBitmapHeight(font) + \
FREEGLUT_MENU_BORDER) FREEGLUT_MENU_BORDER)
#define FREEGLUT_MENU_BORDER 2 #define FREEGLUT_MENU_BORDER 2
@ -77,6 +77,7 @@ static float menu_pen_hback [4] = FREEGLUT_MENU_PEN_HBACK_COLORS;
extern GLvoid fgPlatformGetGameModeVMaxExtent( SFG_Window* window, int* x, int* y ); extern GLvoid fgPlatformGetGameModeVMaxExtent( SFG_Window* window, int* x, int* y );
extern void fghPlatformGetCursorPos(const SFG_Window *window, GLboolean client, SFG_XYUse *mouse_pos); extern void fghPlatformGetCursorPos(const SFG_Window *window, GLboolean client, SFG_XYUse *mouse_pos);
extern SFG_Font* fghFontByID( void* font );
/* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
@ -187,7 +188,7 @@ static GLboolean fghCheckMenuStatus( SFG_Menu* menu )
( y >= FREEGLUT_MENU_BORDER ) && ( y >= FREEGLUT_MENU_BORDER ) &&
( y < menu->Height - FREEGLUT_MENU_BORDER ) ) ( y < menu->Height - FREEGLUT_MENU_BORDER ) )
{ {
int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENU_HEIGHT; int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENUENTRY_HEIGHT(menu->Font);
/* The mouse cursor is somewhere over our box, check it out. */ /* The mouse cursor is somewhere over our box, check it out. */
menuEntry = fghFindMenuEntry( menu, menuID + 1 ); menuEntry = fghFindMenuEntry( menu, menuID + 1 );
@ -235,7 +236,7 @@ static GLboolean fghCheckMenuStatus( SFG_Menu* menu )
fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y); fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y);
menuEntry->SubMenu->X = menu->X + menu->Width; menuEntry->SubMenu->X = menu->X + menu->Width;
menuEntry->SubMenu->Y = menu->Y + menuEntry->SubMenu->Y = menu->Y +
menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT; menuEntry->Ordinal * FREEGLUT_MENUENTRY_HEIGHT(menu->Font);
if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width > max_x ) if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width > max_x )
menuEntry->SubMenu->X = menu->X - menuEntry->SubMenu->Width; menuEntry->SubMenu->X = menu->X - menuEntry->SubMenu->Width;
@ -243,7 +244,7 @@ static GLboolean fghCheckMenuStatus( SFG_Menu* menu )
if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height > max_y ) if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height > max_y )
{ {
menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height - menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
FREEGLUT_MENU_HEIGHT - FREEGLUT_MENUENTRY_HEIGHT(menu->Font) -
2 * FREEGLUT_MENU_BORDER ); 2 * FREEGLUT_MENU_BORDER );
if( menuEntry->SubMenu->Y < 0 ) if( menuEntry->SubMenu->Y < 0 )
menuEntry->SubMenu->Y = 0; menuEntry->SubMenu->Y = 0;
@ -348,13 +349,13 @@ static void fghDisplayMenuBox( SFG_Menu* menu )
glColor4fv( menu_pen_hback ); glColor4fv( menu_pen_hback );
glBegin( GL_QUADS ); glBegin( GL_QUADS );
glVertex2i( border, glVertex2i( border,
(menuID + 0)*FREEGLUT_MENU_HEIGHT + border ); (menuID + 0)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glVertex2i( menu->Width - border, glVertex2i( menu->Width - border,
(menuID + 0)*FREEGLUT_MENU_HEIGHT + border ); (menuID + 0)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glVertex2i( menu->Width - border, glVertex2i( menu->Width - border,
(menuID + 1)*FREEGLUT_MENU_HEIGHT + border ); (menuID + 1)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glVertex2i( border, glVertex2i( border,
(menuID + 1)*FREEGLUT_MENU_HEIGHT + border ); (menuID + 1)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glEnd( ); glEnd( );
} }
} }
@ -375,25 +376,25 @@ static void fghDisplayMenuBox( SFG_Menu* menu )
/* Try to center the text - JCJ 31 July 2003*/ /* Try to center the text - JCJ 31 July 2003*/
glRasterPos2i( glRasterPos2i(
2 * border, 2 * border,
( i + 1 )*FREEGLUT_MENU_HEIGHT - ( i + 1 )*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) -
( int )( FREEGLUT_MENU_HEIGHT*0.3 - border ) ( int )( FREEGLUT_MENUENTRY_HEIGHT(menu->Font)*0.3 - border )
); );
/* Have the label drawn, character after character: */ /* Have the label drawn, character after character: */
glutBitmapString( FREEGLUT_MENU_FONT, glutBitmapString( menu->Font,
(unsigned char *)menuEntry->Text); (unsigned char *)menuEntry->Text);
/* If it's a submenu, draw a right arrow */ /* If it's a submenu, draw a right arrow */
if( menuEntry->SubMenu ) if( menuEntry->SubMenu )
{ {
int width = glutBitmapWidth( FREEGLUT_MENU_FONT, '_' ); int width = glutBitmapWidth( menu->Font, '_' );
int x_base = menu->Width - 2 - width; int x_base = menu->Width - 2 - width;
int y_base = i*FREEGLUT_MENU_HEIGHT + border; int y_base = i*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border;
glBegin( GL_TRIANGLES ); glBegin( GL_TRIANGLES );
glVertex2i( x_base, y_base + 2*border); glVertex2i( x_base, y_base + 2*border);
glVertex2i( menu->Width - 2, y_base + glVertex2i( menu->Width - 2, y_base +
( FREEGLUT_MENU_HEIGHT + border) / 2 ); ( FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border) / 2 );
glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - border ); glVertex2i( x_base, y_base + FREEGLUT_MENUENTRY_HEIGHT(menu->Font) - border );
glEnd( ); glEnd( );
} }
@ -771,7 +772,7 @@ void fghCalculateMenuBoxSize( void )
{ {
/* Update the menu entry's width value */ /* Update the menu entry's width value */
menuEntry->Width = glutBitmapLength( menuEntry->Width = glutBitmapLength(
FREEGLUT_MENU_FONT, fgStructure.CurrentMenu->Font,
(unsigned char *)menuEntry->Text (unsigned char *)menuEntry->Text
); );
@ -781,7 +782,7 @@ void fghCalculateMenuBoxSize( void )
*/ */
if (menuEntry->SubMenu ) if (menuEntry->SubMenu )
menuEntry->Width += glutBitmapLength( menuEntry->Width += glutBitmapLength(
FREEGLUT_MENU_FONT, fgStructure.CurrentMenu->Font,
(unsigned char *)"_" (unsigned char *)"_"
); );
@ -789,7 +790,7 @@ void fghCalculateMenuBoxSize( void )
if( menuEntry->Width > width ) if( menuEntry->Width > width )
width = menuEntry->Width; width = menuEntry->Width;
height += FREEGLUT_MENU_HEIGHT; height += FREEGLUT_MENUENTRY_HEIGHT(fgStructure.CurrentMenu->Font);
} }
/* Store the menu's box size now: */ /* Store the menu's box size now: */
@ -907,6 +908,27 @@ void FGAPIENTRY glutAddSubMenu( const char *label, int subMenuID )
fghCalculateMenuBoxSize( ); fghCalculateMenuBoxSize( );
} }
/*
* Changes the current menu's font
*/
void FGAPIENTRY glutSetMenuFont( void* fontID )
{
SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetMenuFont" );
freeglut_return_if_fail( fgStructure.CurrentMenu );
if (fgGetActiveMenu())
fgError("Menu manipulation not allowed while menus in use.");
font = fghFontByID( fontID );
if (!font)
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 );
fgStructure.CurrentMenu->Font = fontID;
fghCalculateMenuBoxSize( );
}
/* /*
* Changes the specified menu item in the current menu into a menu entry * Changes the specified menu item in the current menu into a menu entry
*/ */

View File

@ -44,6 +44,7 @@
extern int fgPlatformGlutGet ( GLenum eWhat ); extern int fgPlatformGlutGet ( GLenum eWhat );
extern int fgPlatformGlutDeviceGet ( GLenum eWhat ); extern int fgPlatformGlutDeviceGet ( GLenum eWhat );
extern int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size); extern int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size);
extern SFG_Font* fghFontByID( void* font );
/* -- LOCAL DEFINITIONS ---------------------------------------------------- */ /* -- LOCAL DEFINITIONS ---------------------------------------------------- */
@ -120,6 +121,18 @@ 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;

View File

@ -132,6 +132,7 @@ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback )
menu->ID = ++fgStructure.MenuID; menu->ID = ++fgStructure.MenuID;
menu->Callback = menuCallback; menu->Callback = menuCallback;
menu->ActiveEntry = NULL; menu->ActiveEntry = NULL;
menu->Font = fgState.MenuFont;
fgListInit( &menu->Entries ); fgListInit( &menu->Entries );
fgListAppend( &fgStructure.Menus, &menu->Node ); fgListAppend( &fgStructure.Menus, &menu->Node );

View File

@ -144,6 +144,7 @@ EXPORTS
glutExit glutExit
glutFullScreenToggle glutFullScreenToggle
glutLeaveFullScreen glutLeaveFullScreen
glutSetMenuFont
glutGetModeValues glutGetModeValues
glutInitContextFlags glutInitContextFlags
glutInitContextVersion glutInitContextVersion