X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FCallbackMaker%2FCallbackMaker.c;h=0cee8271dc45fc3be8ab1b6c2d789c4e3e75787d;hb=a2e0d9e66235abc1e9d555ffb7ba0903d85c0581;hp=771a6cdee361eab0f4f04f72f05deccd7db6fadc;hpb=2822fb448bf8ebc2a07fac999d07d1ea522e9964;p=freeglut diff --git a/progs/demos/CallbackMaker/CallbackMaker.c b/progs/demos/CallbackMaker/CallbackMaker.c index 771a6cd..0cee827 100644 --- a/progs/demos/CallbackMaker/CallbackMaker.c +++ b/progs/demos/CallbackMaker/CallbackMaker.c @@ -8,6 +8,7 @@ #include #include #include +#include static int sequence_number = 0 ; @@ -25,6 +26,7 @@ int windows[CALLBACKMAKER_N_WINDOWS] = {0}; CALLBACK_2V(reshape,width,height); CALLBACK_2V(position,top,left); CALLBACK_1V(visibility,vis); +CALLBACK_1V(windowStatus,state); CALLBACK_4V(key,key,x,y,mod); CALLBACK_4V(keyup,key,x,y,mod); CALLBACK_4V(special,key,x,y,mod); @@ -79,15 +81,19 @@ Mod2Text(int mods, char *text) if (mods&GLUT_ACTIVE_CTRL) strcat(text,"CTRL"); if (mods&GLUT_ACTIVE_SHIFT) + { if (text[0]) strcat(text,"+SHIFT"); else strcat(text,"SHIFT"); + } if (mods&GLUT_ACTIVE_ALT) + { if (text[0]) strcat(text,"+ALT"); else strcat(text,"ALT"); + } if (!text[0]) strcat(text,"none"); @@ -122,6 +128,11 @@ Display(void) bitmapPrintf ( "Visibility %d: %d\n", visibility_seq[winIdx], visibility_vis[winIdx] ); } + if ( windowStatus_called[winIdx] ) + { + bitmapPrintf ( "WindowStatus %d: %d\n", windowStatus_seq[winIdx], windowStatus_state[winIdx] ); + } + if ( reshape_called[winIdx] ) { bitmapPrintf ( "Reshape %d: %d %d\n", reshape_seq[winIdx], reshape_width[winIdx], reshape_height[winIdx] ); @@ -207,7 +218,7 @@ Display(void) static void Warning(const char *fmt, va_list ap) { - printf("%6d Warning callback:\n"); + printf("%6d Warning callback:\n",++sequence_number); /* print warning message */ vprintf(fmt, ap); @@ -217,10 +228,11 @@ static void Error(const char *fmt, va_list ap) { char dummy_string[STRING_LENGTH]; - printf("%6d Error callback:\n"); + printf("%6d Error callback:\n",++sequence_number); /* print warning message */ vprintf(fmt, ap); + printf("\n"); /* terminate program, after pause for input so user can see */ printf ( "Please enter something to exit: " ); @@ -233,19 +245,6 @@ Error(const char *fmt, va_list ap) } static void -Visibility(int vis) -{ - int winIdx; - int window = getWindowAndIdx(&winIdx); - printf ( "%6d Window %d Visibility Callback: %d\n", - ++sequence_number, window, vis ) ; - visibility_called[winIdx] = 1 ; - visibility_vis[winIdx] = vis ; - visibility_seq[winIdx] = sequence_number ; - glutPostRedisplay () ; -} - -static void Reshape(int width, int height) { int winIdx; @@ -449,11 +448,28 @@ OverlayDisplay(void) } static void +Visibility(int vis) +{ + int winIdx; + int window = getWindowAndIdx(&winIdx); + printf ( "%6d Window %d Visibility Callback: %d\n", + ++sequence_number, window, vis ) ; + visibility_called[winIdx] = 1 ; + visibility_vis[winIdx] = vis ; + visibility_seq[winIdx] = sequence_number ; + glutPostRedisplay () ; +} + +static void WindowStatus(int state) { - int window = getWindowAndIdx(NULL); + int winIdx; + int window = getWindowAndIdx(&winIdx); printf ( "%6d Window %d WindowStatus Callback: %d\n", ++sequence_number, window, state ) ; + windowStatus_called[winIdx] = 1 ; + windowStatus_state[winIdx] = state ; + windowStatus_seq[winIdx] = sequence_number ; glutPostRedisplay () ; } @@ -624,6 +640,8 @@ main(int argc, char *argv[]) * 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 ); @@ -640,6 +658,7 @@ main(int argc, char *argv[]) /* callbacks, settings and menus for this window */ SetWindowCallbacks( 1 ); glutIgnoreKeyRepeat(GL_TRUE); + glutSetIconTitle("Icon Test - Callback Demo"); subMenuA = glutCreateMenu( MenuCallback ); glutAddMenuEntry( "Sub menu A1 (01)", 11 ); @@ -647,6 +666,9 @@ main(int argc, char *argv[]) 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 ); @@ -665,6 +687,8 @@ main(int argc, char *argv[]) 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 */