From 0b9beccf1aac816de6c749c4f7ffdac559fa03b1 Mon Sep 17 00:00:00 2001 From: cjp Date: Sun, 5 Aug 2001 22:47:35 +0000 Subject: [PATCH] Added keyup events code. Added missing specal keys. Made menu callbacks global. git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@21 7f0cb862-5218-0410-a997-914c9d46530a --- .../freeglut-1.3/freeglut_callbacks.c | 8 +++-- .../freeglut/freeglut-1.3/freeglut_main.c | 36 ++++++++++++++++--- .../freeglut/freeglut-1.3/freeglut_window.c | 6 ++-- .../freeglut/include/GL/freeglut_internal.h | 15 ++++---- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/freeglut/freeglut/freeglut-1.3/freeglut_callbacks.c b/freeglut/freeglut/freeglut-1.3/freeglut_callbacks.c index 196b054..743077a 100644 --- a/freeglut/freeglut/freeglut-1.3/freeglut_callbacks.c +++ b/freeglut/freeglut/freeglut-1.3/freeglut_callbacks.c @@ -223,7 +223,9 @@ void FGAPIENTRY glutEntryFunc( void (* callback)( int ) ) */ void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) ) { - SET_CALLBACK( MenuState ); + freeglut_assert_ready; + + fgState.MenuStateCallback = callback; } /* @@ -231,7 +233,9 @@ void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) ) */ void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) ) { - SET_CALLBACK( MenuStatus ); + freeglut_assert_ready; + + fgState.MenuStatusCallback = callback; } /* diff --git a/freeglut/freeglut/freeglut-1.3/freeglut_main.c b/freeglut/freeglut/freeglut-1.3/freeglut_main.c index 682e316..b01be6e 100644 --- a/freeglut/freeglut/freeglut-1.3/freeglut_main.c +++ b/freeglut/freeglut/freeglut-1.3/freeglut_main.c @@ -698,17 +698,32 @@ void FGAPIENTRY glutMainLoop( void ) } break; + case KeyRelease: case KeyPress: { + FGCBkeyboard keyboard_cb; + FGCBspecial special_cb; + /* * A key has been pressed, find the window that had the focus: */ GETWINDOW( xkey ); GETMOUSE( xkey ); + if( event.type == KeyPress ) + { + keyboard_cb = window->Callbacks.Keyboard; + special_cb = window->Callbacks.Special; + } + else + { + keyboard_cb = window->Callbacks.KeyboardUp; + special_cb = window->Callbacks.SpecialUp; + } + /* * Is there a keyboard/special callback hooked for this window? */ - if( (window->Callbacks.Keyboard != NULL) || (window->Callbacks.Special != NULL) ) + if( (keyboard_cb != NULL) || (special_cb != NULL) ) { XComposeStatus composeStatus; char asciiCode[ 32 ]; @@ -733,7 +748,7 @@ void FGAPIENTRY glutMainLoop( void ) /* * ...one for the ASCII translateable keypresses... */ - if( window->Callbacks.Keyboard != NULL ) + if( keyboard_cb != NULL ) { /* * Remember the current modifiers state @@ -750,7 +765,7 @@ void FGAPIENTRY glutMainLoop( void ) /* * Execute the callback */ - window->Callbacks.Keyboard( asciiCode[ 0 ], event.xkey.x, event.xkey.y ); + keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y ); /* * Trash the modifiers state @@ -790,13 +805,24 @@ void FGAPIENTRY glutMainLoop( void ) case XK_Right: special = GLUT_KEY_RIGHT; break; case XK_Up: special = GLUT_KEY_UP; break; case XK_Down: special = GLUT_KEY_DOWN; break; + + case XK_KP_Prior: + case XK_Prior: special = GLUT_KEY_PAGE_UP; break; + case XK_KP_Next: + case XK_Next: special = GLUT_KEY_PAGE_DOWN; break; + case XK_KP_Home: + case XK_Home: special = GLUT_KEY_HOME; break; + case XK_KP_End: + case XK_End: special = GLUT_KEY_END; break; + case XK_KP_Insert: + case XK_Insert: special = GLUT_KEY_INSERT; break; } /* * Execute the callback (if one has been specified), * given that the special code seems to be valid... */ - if( (window->Callbacks.Special != NULL) && (special != -1) ) + if( (special_cb != NULL) && (special != -1) ) { /* * Remember the current modifiers state @@ -810,7 +836,7 @@ void FGAPIENTRY glutMainLoop( void ) modifiers |= GLUT_ACTIVE_ALT; window->State.Modifiers = modifiers; - window->Callbacks.Special( special, event.xkey.x, event.xkey.y ); + special_cb( special, event.xkey.x, event.xkey.y ); /* * Trash the modifiers state diff --git a/freeglut/freeglut/freeglut-1.3/freeglut_window.c b/freeglut/freeglut/freeglut-1.3/freeglut_window.c index 01b494d..943b027 100644 --- a/freeglut/freeglut/freeglut-1.3/freeglut_window.c +++ b/freeglut/freeglut/freeglut-1.3/freeglut_window.c @@ -324,7 +324,7 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i * This might speed up message processing. Is that true? */ winAttr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask | - ButtonPressMask | ButtonReleaseMask | KeyPressMask | + ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease | VisibilityChangeMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask; winAttr.background_pixmap = None; @@ -442,8 +442,8 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i if( gameMode == TRUE ) { /* - * This somehow fixes the glutGet() GLUT_WINDOW_X and GLUT_WINDOW_Y problem... - */ + * This somehow fixes the glutGet() GLUT_WINDOW_X and GLUT_WINDOW_Y problem... + */ XMoveWindow( fgDisplay.Display, window->Window.Handle, x, y ); # ifdef X_XF86VidModeSetViewPort diff --git a/freeglut/freeglut/include/GL/freeglut_internal.h b/freeglut/freeglut/include/GL/freeglut_internal.h index 12a8d37..f5bb1af 100644 --- a/freeglut/freeglut/include/GL/freeglut_internal.h +++ b/freeglut/freeglut/include/GL/freeglut_internal.h @@ -212,6 +212,9 @@ struct tagSFG_State FGCBidle IdleCallback; /* The global idle callback */ + FGCBmenuState MenuStateCallback; /* Menu callbacks are global */ + FGCBmenuStatus MenuStatusCallback; + SFG_XYUse GameModeSize; /* The game mode screen's dimensions */ int GameModeDepth; /* The pixel depth for game mode */ int GameModeRefresh; /* The refresh rate for game mode */ @@ -320,27 +323,21 @@ struct tagSFG_WindowCallbacks FGCBdisplay Display; FGCBreshape Reshape; FGCBkeyboard Keyboard; + FGCBkeyboardUp KeyboardUp; FGCBspecial Special; + FGCBspecialUp SpecialUp; FGCBmouse Mouse; FGCBmotion Motion; FGCBpassive Passive; FGCBentry Entry; FGCBvisibility Visibility; FGCBwindowStatus WindowStatus; - - /* - * Those callbacks are required for the initial version - */ - FGCBmenuState MenuState; - FGCBmenuStatus MenuStatus; - FGCBselect Select; FGCBjoystick Joystick; - FGCBkeyboardUp KeyboardUp; - FGCBspecialUp SpecialUp; /* * Those callbacks are being ignored for the moment */ + FGCBselect Select; FGCBoverlayDisplay OverlayDisplay; FGCBspaceMotion SpaceMotion; FGCBspaceRotate SpaceRotation;