X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FCallbackMaker%2FCallbackMaker.c;h=a8cd18b96e976a08b7d8ed72f84b9a0d9dcbdbe2;hb=bcf3fe1b4600eb9926d8d17a5a6cca363f0d3ee4;hp=1b41b0ed2f93bb50066556cff485b94eb029ddf0;hpb=0d72f166aecf3392abf1c1a31667937f24905264;p=freeglut diff --git a/progs/demos/CallbackMaker/CallbackMaker.c b/progs/demos/CallbackMaker/CallbackMaker.c index 1b41b0e..a8cd18b 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 ; @@ -15,16 +16,17 @@ static int sequence_number = 0 ; int windows[CALLBACKMAKER_N_WINDOWS] = {0}; /* define status vars showing whether given callback has been called for given window */ -#define CALLBACK_CALLED_VAR(name) int name##_called[CALLBACKMAKER_N_WINDOWS] = {0}; -#define CALLBACK_0V(name) int name##_seq[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_CALLED_VAR(name); -#define CALLBACK_1V(name,field) int name##_##field[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_0V(name); -#define CALLBACK_2V(name,field1,field2) int name##_##field2[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_1V(name,field1); -#define CALLBACK_3V(name,field1,field2,field3) int name##_##field3[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_2V(name,field1,field2); -#define CALLBACK_4V(name,field1,field2,field3,field4) int name##_##field4[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_3V(name,field1,field2,field3); -#define CALLBACK_5V(name,field1,field2,field3,field4,field5) int name##_##field5[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_4V(name,field1,field2,field3,field4); +#define CALLBACK_CALLED_VAR(name) int name##_called[CALLBACKMAKER_N_WINDOWS] = {0} +#define CALLBACK_0V(name) int name##_seq[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_CALLED_VAR(name) +#define CALLBACK_1V(name,field) int name##_##field[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_0V(name) +#define CALLBACK_2V(name,field1,field2) int name##_##field2[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_1V(name,field1) +#define CALLBACK_3V(name,field1,field2,field3) int name##_##field3[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_2V(name,field1,field2) +#define CALLBACK_4V(name,field1,field2,field3,field4) int name##_##field4[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_3V(name,field1,field2,field3) +#define CALLBACK_5V(name,field1,field2,field3,field4,field5) int name##_##field5[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_4V(name,field1,field2,field3,field4) 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); @@ -37,7 +39,7 @@ CALLBACK_3V(passivemotion,x,y,mod); CALLBACK_1V(entry,state); CALLBACK_0V(close); /* menudestroy is registered on each menu, not a window */ -int menudestroy_called = 0 ; +int menudestroy_called = 0; /* menustatus and menustate are global callbacks, set for all menus at the same time */ int menustatus_called = 0; int menustate_called = 0; @@ -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 () ; } @@ -576,7 +592,6 @@ static void SetWindowCallbacks( int first ) glutPositionFunc( Position ); glutKeyboardFunc( Key ); glutSpecialFunc( Special ); - glutVisibilityFunc( Visibility ); glutKeyboardUpFunc( KeyUp ); glutSpecialUpFunc( SpecialUp ); if (first) @@ -588,7 +603,6 @@ static void SetWindowCallbacks( int first ) glutEntryFunc ( Entry ) ; glutCloseFunc ( Close ) ; glutOverlayDisplayFunc ( OverlayDisplay ) ; - glutWindowStatusFunc ( WindowStatus ) ; glutSpaceballMotionFunc ( SpaceMotion ) ; glutSpaceballRotateFunc ( SpaceRotation ) ; glutSpaceballButtonFunc ( SpaceButton ) ; @@ -596,6 +610,11 @@ static void SetWindowCallbacks( int first ) glutDialsFunc ( Dials ) ; glutTabletMotionFunc ( TabletMotion ) ; glutTabletButtonFunc ( TabletButton ) ; + /* glutVisibilityFunc is deprecated in favor of glutWindowStatusFunc, which provides more detail. + * Setting one of these overwrites the other (see docs). + */ + glutVisibilityFunc ( Visibility ); /* This will thus never be called, as glutWindowStatusFunc is set afterwards */ + glutWindowStatusFunc ( WindowStatus ) ; } int @@ -637,12 +656,15 @@ 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 ); glutAddMenuEntry( "Sub menu A2 (02)", 12 ); glutAddMenuEntry( "Sub menu A3 (03)", 13 ); glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */ + /* Change font for this menu */ + glutSetMenuFont(subMenuA, GLUT_BITMAP_HELVETICA_12); subMenuB = glutCreateMenu( MenuCallback ); glutAddMenuEntry( "Sub menu B1 (04)", 14 ); @@ -650,6 +672,7 @@ main(int argc, char *argv[]) glutAddMenuEntry( "Sub menu B3 (06)", 16 ); glutAddSubMenu( "Going to sub menu A", subMenuA ); glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */ + glutSetMenuFont(subMenuB, GLUT_BITMAP_9_BY_15); menuID = glutCreateMenu( MenuCallback ); glutAddMenuEntry( "Entry one", 21 );