Added support for more arbitrary number of mouse buttons (though only the
authorRichard Rauch <rkr@olib.org>
Wed, 1 Oct 2003 15:01:58 +0000 (15:01 +0000)
committerRichard Rauch <rkr@olib.org>
Wed, 1 Oct 2003 15:01:58 +0000 (15:01 +0000)
first three can work with menus), in X.  This closes a compatibility gap
with old GLUT, and leaves us the option of supporting scroll-wheels
properly.

git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@210 7f0cb862-5218-0410-a997-914c9d46530a

src/freeglut_main.c

index 21daa87..8fddc90 100644 (file)
@@ -824,26 +824,15 @@ void FGAPIENTRY glutMainLoopEvent( void )
          */
         GETWINDOW( xbutton ); GETMOUSE( xbutton );
 
-        /*
-         * GLUT API assumes that you can't have more than three mouse buttons, so:
-         */
-        switch( event.xbutton.button )
-        {
-        /*
-         * WARNING: this might be wrong, if we only have two mouse buttons,
-         *          Button2 might mean the right button, isn't that right?
-         */
-        case Button1:   button = GLUT_LEFT_BUTTON;   break;
-        case Button2:   button = GLUT_MIDDLE_BUTTON; break;
-        case Button3:   button = GLUT_RIGHT_BUTTON;  break;
-        default:        button = -1;                 break;
-        }
-
-        /*
-         * Skip the unwanted mouse buttons...
-         */
-        if( button == -1 )
-          break;
+       /*
+        * An X button (at least in XFree86) is numbered from 1.
+        * A GLUT button is numbered from 0.
+        * Old GLUT passed through buttons other than just the first
+        * three, though it only gave symbolic names and official
+        * support to the first three.
+        *
+        */
+       button = event.xbutton.button - 1;
 
         /*
          * Do not execute the application's mouse callback if a menu is hooked to this button.
@@ -891,7 +880,8 @@ void FGAPIENTRY glutMainLoopEvent( void )
         /*
          * No active menu, let's check whether we need to activate one.
          */
-        if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
+        if (( 0 <= button ) && ( 2 >= button ) &&
+           ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
         {
           /*
            * Let's make the window redraw as a result of the mouse click.