X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FCallbackMaker%2FCallbackMaker.c;h=25e83dc754a14d3b307217bbc129fc06bb06e3f9;hb=21c71cd089968b28ebdbbb9bf1ff4c089a03f5ca;hp=9d5613d0ec3638a715460869210840c955bcb936;hpb=b99a1718b07cc00de078e5fc6d932c5971c2673c;p=freeglut diff --git a/progs/demos/CallbackMaker/CallbackMaker.c b/progs/demos/CallbackMaker/CallbackMaker.c index 9d5613d..25e83dc 100644 --- a/progs/demos/CallbackMaker/CallbackMaker.c +++ b/progs/demos/CallbackMaker/CallbackMaker.c @@ -7,13 +7,17 @@ #include #include #include +#include static int sequence_number = 0 ; int reshape_called = 0, key_called = 0, special_called = 0, visibility_called = 0, keyup_called = 0, specialup_called = 0, joystick_called = 0, mouse_called = 0, mousewheel_called = 0, motion_called = 0, passivemotion_called = 0, entry_called = 0, - close_called = 0 ; + close_called = 0, overlaydisplay_called = 0, windowstatus_called = 0, + spacemotion_called = 0, spacerotation_called = 0, spacebutton_called = 0, + buttonbox_called = 0, dials_called = 0, tabletmotion_called = 0, tabletbutton_called = 0, + menudestroy_called = 0, menustatus_called = 0 ; int reshape_width = -1, reshape_height = -1, reshape_seq = -1 ; int key_key = -1, key_x = -1, key_y = -1, key_seq = -1 ; int special_key = -1, special_x = -1, special_y = -1, special_seq = -1 ; @@ -25,10 +29,27 @@ int mouse_button = -1, mouse_updown = -1, mouse_x = -1, mouse_y = -1, mouse_seq int mousewheel_number = -1, mousewheel_direction = -1, mousewheel_x = -1, mousewheel_y = -1, mousewheel_seq = -1 ; int motion_x = -1, motion_y = -1, motion_seq = -1 ; int passivemotion_x = -1, passivemotion_y = -1, passivemotion_seq = -1 ; + +static void +bitmapPrintf (const char *fmt, ...) +{ + static char buf[256]; + va_list args; + + va_start(args, fmt); +#if defined(WIN32) && !defined(__CYGWIN__) + (void) _vsnprintf (buf, sizeof(buf), fmt, args); +#else + (void) vsnprintf (buf, sizeof(buf), fmt, args); +#endif + va_end(args); + glutBitmapString ( GLUT_BITMAP_HELVETICA_12, (unsigned char*)buf ) ; +} + + static void Display(void) { - char line[180] ; int window = glutGetWindow () ; glClear ( GL_COLOR_BUFFER_BIT ); @@ -46,68 +67,57 @@ Display(void) if ( reshape_called ) { - sprintf ( line, "Reshape %d: %d %d\n", reshape_seq, reshape_width, reshape_height ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Reshape %d: %d %d\n", reshape_seq, reshape_width, reshape_height ); } if ( key_called ) { - sprintf ( line, "Key %d: %d(%c) %d %d\n", key_seq, key_key, key_key, key_x, key_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Key %d: %d(%c) %d %d\n", key_seq, key_key, key_key, key_x, key_y ); } if ( special_called ) { - sprintf ( line, "Special %d: %d(%c) %d %d\n", special_seq, special_key, special_key, special_x, special_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Special %d: %d(%c) %d %d\n", special_seq, special_key, special_key, special_x, special_y ); } if ( visibility_called ) { - sprintf ( line, "Visibility %d: %d\n", visibility_seq, visibility_vis ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Visibility %d: %d\n", visibility_seq, visibility_vis ); } if ( keyup_called ) { - sprintf ( line, "Key Up %d: %d(%c) %d %d\n", keyup_seq, keyup_key, keyup_key, keyup_x, keyup_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Key Up %d: %d(%c) %d %d\n", keyup_seq, keyup_key, keyup_key, keyup_x, keyup_y ); } if ( specialup_called ) { - sprintf ( line, "Special Up %d: %d(%c) %d %d\n", specialup_seq, specialup_key, specialup_key, specialup_x, specialup_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Special Up %d: %d(%c) %d %d\n", specialup_seq, specialup_key, specialup_key, specialup_x, specialup_y ); } if ( joystick_called ) { - sprintf ( line, "Joystick %d: %d %d %d %d\n", joystick_seq, joystick_a, joystick_b, joystick_c, joystick_d ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Joystick %d: %d %d %d %d\n", joystick_seq, joystick_a, joystick_b, joystick_c, joystick_d ); } if ( mouse_called ) { - sprintf ( line, "Mouse %d: %d %d %d %d\n", mouse_seq, mouse_button, mouse_updown, mouse_x, mouse_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Mouse %d: %d %d %d %d\n", mouse_seq, mouse_button, mouse_updown, mouse_x, mouse_y ); } if ( mousewheel_called ) { - sprintf ( line, "Mouse Wheel %d: %d %d %d %d\n", mousewheel_seq, mousewheel_number, mousewheel_direction, mousewheel_x, mousewheel_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Mouse Wheel %d: %d %d %d %d\n", mousewheel_seq, mousewheel_number, mousewheel_direction, mousewheel_x, mousewheel_y ); } if ( motion_called ) { - sprintf ( line, "Motion %d: %d %d\n", motion_seq, motion_x, motion_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Motion %d: %d %d\n", motion_seq, motion_x, motion_y ); } if ( passivemotion_called ) { - sprintf ( line, "Passive Motion %d: %d %d\n", passivemotion_seq, passivemotion_x, passivemotion_y ); - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, line ); + bitmapPrintf ( "Passive Motion %d: %d %d\n", passivemotion_seq, passivemotion_x, passivemotion_y ); } glMatrixMode ( GL_PROJECTION ); @@ -292,12 +302,137 @@ Close(void) ++sequence_number, window ) ; } +static void +OverlayDisplay(void) +{ + int window = glutGetWindow () ; + overlaydisplay_called = 1 ; + printf ( "%6d Window %d OverlayDisplay Callback\n", + ++sequence_number, window ) ; + glutPostRedisplay () ; +} + +static void +WindowStatus(int state) +{ + int window = glutGetWindow () ; + windowstatus_called = 1 ; + printf ( "%6d Window %d WindowStatus Callback: %d\n", + ++sequence_number, window, state ) ; + glutPostRedisplay () ; +} + +static void +SpaceMotion(int x, int y, int z) +{ + int window = glutGetWindow () ; + spacemotion_called = 1 ; + printf ( "%6d Window %d SpaceMotion Callback: %d %d %d\n", + ++sequence_number, window, x, y, z ) ; + glutPostRedisplay () ; +} + +static void +SpaceRotation(int x, int y, int z) +{ + int window = glutGetWindow () ; + spacerotation_called = 1 ; + printf ( "%6d Window %d SpaceRotation Callback: %d %d %d\n", + ++sequence_number, window, x, y, z ) ; + glutPostRedisplay () ; +} +static void +SpaceButton(int button, int updown) +{ + int window = glutGetWindow () ; + spacebutton_called = 1 ; + printf ( "%6d Window %d SpaceButton Callback: %d %d\n", + ++sequence_number, window, button, updown ) ; + glutPostRedisplay () ; +} + +static void +Dials(int x, int y) +{ + int window = glutGetWindow () ; + dials_called = 1 ; + printf ( "%6d Window %d Dials Callback: %d %d\n", + ++sequence_number, window, x, y ) ; + glutPostRedisplay () ; +} + +static void +ButtonBox(int button, int updown) +{ + int window = glutGetWindow () ; + buttonbox_called = 1 ; + printf ( "%6d Window %d ButtonBox Callback: %d %d\n", + ++sequence_number, window, button, updown ) ; + glutPostRedisplay () ; +} + +static void +TabletMotion(int x, int y) +{ + int window = glutGetWindow () ; + tabletmotion_called = 1 ; + printf ( "%6d Window %d TabletMotion Callback: %d %d\n", + ++sequence_number, window, x, y ) ; + glutPostRedisplay () ; +} + +static void +TabletButton(int button, int updown, int x, int y) +{ + int window = glutGetWindow () ; + tabletbutton_called = 1 ; + printf ( "%6d Window %d TabletButton Callback: %d %d %d %d\n", + ++sequence_number, window, button, updown, x, y ) ; + glutPostRedisplay () ; +} + +static void +MenuCallback ( int menuID ) +{ + int window = glutGetWindow () ; + printf( "%6d Window %d MenuCallback - menuID is %d\n", + ++sequence_number, window, menuID ); +} + +static void +MenuDestroy( void ) +{ + int window = glutGetWindow () ; + menudestroy_called = 1 ; + printf ( "%6d Window %d MenuDestroy Callback\n", + ++sequence_number, window ) ; + glutPostRedisplay () ; +} + +static void +MenuStatus( int status, int x, int y ) +{ + int window = glutGetWindow () ; + menudestroy_called = 1 ; + printf ( "%6d Window %d MenuStatus Callback: %d %d %d\n", + ++sequence_number, window, status, x, y ) ; + glutPostRedisplay () ; +} + +static void Idle ( void ) +{ + ++sequence_number ; +} int main(int argc, char *argv[]) { +#define STRING_LENGTH 10 int freeglut_window, aux_window ; + char dummy_string[STRING_LENGTH]; + + int menuID, subMenuA, subMenuB; glutInitWindowSize(500, 250); glutInitWindowPosition ( 140, 140 ); @@ -323,6 +458,40 @@ main(int argc, char *argv[]) glutPassiveMotionFunc ( PassiveMotion ) ; glutEntryFunc ( Entry ) ; glutCloseFunc ( Close ) ; + glutOverlayDisplayFunc ( OverlayDisplay ) ; + glutWindowStatusFunc ( WindowStatus ) ; + glutSpaceballMotionFunc ( SpaceMotion ) ; + glutSpaceballRotateFunc ( SpaceRotation ) ; + glutSpaceballButtonFunc ( SpaceButton ) ; + glutButtonBoxFunc ( ButtonBox ) ; + glutDialsFunc ( Dials ) ; + glutTabletMotionFunc ( TabletMotion ) ; + glutTabletButtonFunc ( TabletButton ) ; + glutMenuDestroyFunc ( MenuDestroy ); + glutMenuStatusFunc ( MenuStatus ); + glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF) ; + + subMenuA = glutCreateMenu( MenuCallback ); + glutAddMenuEntry( "Sub menu A1 (01)", 1 ); + glutAddMenuEntry( "Sub menu A2 (02)", 2 ); + glutAddMenuEntry( "Sub menu A3 (03)", 3 ); + + subMenuB = glutCreateMenu( MenuCallback ); + glutAddMenuEntry( "Sub menu B1 (04)", 4 ); + glutAddMenuEntry( "Sub menu B2 (05)", 5 ); + glutAddMenuEntry( "Sub menu B3 (06)", 6 ); + glutAddSubMenu( "Going to sub menu A", subMenuA ); + + menuID = glutCreateMenu( MenuCallback ); + glutAddMenuEntry( "Entry one", 1 ); + glutAddMenuEntry( "Entry two", 2 ); + glutAddMenuEntry( "Entry three", 3 ); + glutAddMenuEntry( "Entry four", 4 ); + glutAddMenuEntry( "Entry five", 5 ); + glutAddSubMenu( "Enter sub menu A", subMenuA ); + glutAddSubMenu( "Enter sub menu B", subMenuB ); + + glutAttachMenu( GLUT_LEFT_BUTTON ); aux_window = glutCreateWindow( "Second Window" ); printf ( "Creating window %d as 'Second Window'\n", aux_window ) ; @@ -336,13 +505,28 @@ main(int argc, char *argv[]) glutVisibilityFunc( Visibility ); glutKeyboardUpFunc( KeyUp ); glutSpecialUpFunc( SpecialUp ); -// glutJoystickFunc( Joystick, 100 ); + /* glutJoystickFunc( Joystick, 100 ); */ glutMouseFunc ( Mouse ) ; glutMouseWheelFunc ( MouseWheel ) ; glutMotionFunc ( Motion ) ; glutPassiveMotionFunc ( PassiveMotion ) ; glutEntryFunc ( Entry ) ; glutCloseFunc ( Close ) ; + glutOverlayDisplayFunc ( OverlayDisplay ) ; + glutWindowStatusFunc ( WindowStatus ) ; + glutSpaceballMotionFunc ( SpaceMotion ) ; + glutSpaceballRotateFunc ( SpaceRotation ) ; + glutSpaceballButtonFunc ( SpaceButton ) ; + glutButtonBoxFunc ( ButtonBox ) ; + glutDialsFunc ( Dials ) ; + glutTabletMotionFunc ( TabletMotion ) ; + glutTabletButtonFunc ( TabletButton ) ; + glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF) ; + + glutIdleFunc ( Idle ); + + printf ( "Please enter something to continue: " ); + fgets ( dummy_string, STRING_LENGTH, stdin ); glutMainLoop();