#define GLUT_GEOMETRY_VISUALIZE_NORMALS 0x0205
+#define GLUT_MENU_FONT 0x0206 /* TOOD: now glutSetOption only */
+
/*
* New tokens for glutInitDisplayMode.
* Only one GLUT_AUXn bit may be used at a time.
FGAPI void FGAPIENTRY glutLeaveFullScreen( void );
/*
+ * Menu functions
+ */
+FGAPI void FGAPIENTRY glutSetMenuFont( void* font );
+
+/*
* Window-specific callback functions, see freeglut_callbacks.c
*/
FGAPI void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) );
* what we demonstrate here.
*/
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) */
glutIdleFunc ( Idle );
glutAddMenuEntry( "Sub menu A3 (03)", 13 );
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 );
glutAddMenuEntry( "Sub menu B1 (04)", 14 );
glutAddMenuEntry( "Sub menu B2 (05)", 15 );
glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */
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 */
CHECK_NAME(glutMenuDestroyFunc);
CHECK_NAME(glutFullScreenToggle);
CHECK_NAME(glutLeaveFullScreen);
+ CHECK_NAME(glutSetMenuFont);
CHECK_NAME(glutSetOption);
CHECK_NAME(glutGetModeValues);
CHECK_NAME(glutSetWindowData);
* Matches a font ID with a SFG_Font structure pointer.
* 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 )
return &fgFontFixed8x13;
if( font == GLUT_BITMAP_TIMES_ROMAN_24 )
return &fgFontTimesRoman24;
- fgWarning( "font 0x%08x not found", font );
return 0;
}
if( font == GLUT_STROKE_MONO_ROMAN )
return &fgStrokeMonoRoman;
- fgWarning( "stroke font 0x%08x not found", font );
return 0;
}
SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapCharacter" );
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( font );
/*
* Find the character we want to draw (???)
SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapString" );
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 )
return;
{
SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapWidth" );
- font = fghFontByID( fontID );
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 ] );
}
SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapLength" );
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 )
return 0;
SFG_Font* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapHeight" );
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;
}
SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeCharacter" );
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 < font->Quantity );
- freeglut_return_if_fail( font );
schar = font->Characters[ character ];
freeglut_return_if_fail( schar );
SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeString" );
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 )
return;
SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeWidth" );
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 ) &&
( character < font->Quantity ),
0
);
- freeglut_return_val_if_fail( font, 0 );
schar = font->Characters[ character ];
freeglut_return_val_if_fail( schar, 0 );
SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeLength" );
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 )
return 0;
SFG_StrokeFont* font;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeHeight" );
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;
}
0, /* ActiveMenus */
NULL, /* MenuStateCallback */
NULL, /* MenuStatusCallback */
+ FREEGLUT_MENU_FONT,
{ -1, -1, GL_TRUE }, /* GameModeSize */
-1, /* GameModeDepth */
-1, /* GameModeRefresh */
int ActiveMenus; /* Num. of currently active menus */
FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
FGCBMenuStatus MenuStatusCallback;
+ void* MenuFont; /* Font to be used for newly created menus */
SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
int GameModeDepth; /* The pixel depth for game mode */
FGCBMenu Callback; /* The menu callback */
FGCBDestroy Destroy; /* Destruction callback */
GLboolean IsActive; /* Is the menu selected? */
+ void* Font; /* Font to be used for displaying this menu */
int Width; /* Menu box width in pixels */
int Height; /* Menu box height in pixels */
int X, Y; /* Menu box raster position */
* GLUT apparently uses host-system menus rather than building its own.
* freeglut is building its own menus from scratch.)
*
- * FREEGLUT_MENU_HEIGHT gives the height of ONE menu box. This should be
- * the distances between two adjacent menu entries. It should scale
+ * FREEGLUT_MENUENTRY_HEIGHT gives the height of ONE menu box. This should
+ * be the distances between two adjacent menu entries. It should scale
* automatically with the font choice, so you needn't alter it---unless you
* use a stroked font.
*
*/
/* See platform-specific header files for menu font and color definitions */
-#define FREEGLUT_MENU_HEIGHT (glutBitmapHeight(FREEGLUT_MENU_FONT) + \
- FREEGLUT_MENU_BORDER)
+#define FREEGLUT_MENUENTRY_HEIGHT(font) (glutBitmapHeight(font) + \
+ FREEGLUT_MENU_BORDER)
#define FREEGLUT_MENU_BORDER 2
extern GLvoid fgPlatformGetGameModeVMaxExtent( SFG_Window* window, int* x, int* y );
extern void fghPlatformGetCursorPos(const SFG_Window *window, GLboolean client, SFG_XYUse *mouse_pos);
+extern SFG_Font* fghFontByID( void* font );
/* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
( y >= 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. */
menuEntry = fghFindMenuEntry( menu, menuID + 1 );
fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y);
menuEntry->SubMenu->X = menu->X + menu->Width;
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 )
menuEntry->SubMenu->X = menu->X - menuEntry->SubMenu->Width;
if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height > max_y )
{
menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
- FREEGLUT_MENU_HEIGHT -
+ FREEGLUT_MENUENTRY_HEIGHT(menu->Font) -
2 * FREEGLUT_MENU_BORDER );
if( menuEntry->SubMenu->Y < 0 )
menuEntry->SubMenu->Y = 0;
glColor4fv( menu_pen_hback );
glBegin( GL_QUADS );
glVertex2i( border,
- (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
+ (menuID + 0)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glVertex2i( menu->Width - border,
- (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
+ (menuID + 0)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glVertex2i( menu->Width - border,
- (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
+ (menuID + 1)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glVertex2i( border,
- (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
+ (menuID + 1)*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border );
glEnd( );
}
}
/* Try to center the text - JCJ 31 July 2003*/
glRasterPos2i(
2 * border,
- ( i + 1 )*FREEGLUT_MENU_HEIGHT -
- ( int )( FREEGLUT_MENU_HEIGHT*0.3 - border )
+ ( i + 1 )*FREEGLUT_MENUENTRY_HEIGHT(menu->Font) -
+ ( int )( FREEGLUT_MENUENTRY_HEIGHT(menu->Font)*0.3 - border )
);
/* Have the label drawn, character after character: */
- glutBitmapString( FREEGLUT_MENU_FONT,
+ glutBitmapString( menu->Font,
(unsigned char *)menuEntry->Text);
/* If it's a submenu, draw a right arrow */
if( menuEntry->SubMenu )
{
- int width = glutBitmapWidth( FREEGLUT_MENU_FONT, '_' );
+ int width = glutBitmapWidth( menu->Font, '_' );
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 );
glVertex2i( x_base, y_base + 2*border);
glVertex2i( menu->Width - 2, y_base +
- ( FREEGLUT_MENU_HEIGHT + border) / 2 );
- glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - border );
+ ( FREEGLUT_MENUENTRY_HEIGHT(menu->Font) + border) / 2 );
+ glVertex2i( x_base, y_base + FREEGLUT_MENUENTRY_HEIGHT(menu->Font) - border );
glEnd( );
}
{
/* Update the menu entry's width value */
menuEntry->Width = glutBitmapLength(
- FREEGLUT_MENU_FONT,
+ fgStructure.CurrentMenu->Font,
(unsigned char *)menuEntry->Text
);
*/
if (menuEntry->SubMenu )
menuEntry->Width += glutBitmapLength(
- FREEGLUT_MENU_FONT,
+ fgStructure.CurrentMenu->Font,
(unsigned char *)"_"
);
if( menuEntry->Width > width )
width = menuEntry->Width;
- height += FREEGLUT_MENU_HEIGHT;
+ height += FREEGLUT_MENUENTRY_HEIGHT(fgStructure.CurrentMenu->Font);
}
/* Store the menu's box size now: */
}
/*
+ * 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
*/
void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value )
extern int fgPlatformGlutGet ( GLenum eWhat );
extern int fgPlatformGlutDeviceGet ( GLenum eWhat );
extern int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size);
+extern SFG_Font* fghFontByID( void* font );
/* -- LOCAL DEFINITIONS ---------------------------------------------------- */
fgStructure.CurrentWindow->State.VisualizeNormals = value;
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:
fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
break;
menu->ID = ++fgStructure.MenuID;
menu->Callback = menuCallback;
menu->ActiveEntry = NULL;
+ menu->Font = fgState.MenuFont;
fgListInit( &menu->Entries );
fgListAppend( &fgStructure.Menus, &menu->Node );
glutExit
glutFullScreenToggle
glutLeaveFullScreen
+ glutSetMenuFont
glutGetModeValues
glutInitContextFlags
glutInitContextVersion