Added stroke fonts.
[freeglut] / freeglut-1.3 / freeglut_main.c
index 1d98edd..86ee47c 100644 (file)
@@ -72,7 +72,7 @@ static void fghRedrawWindowByHandle
     /*
      * Return if the window is not visible
      */
-    freeglut_return_if_fail( window->State.Visible != TRUE );
+    freeglut_return_if_fail( window->State.Visible == TRUE );
 
     /*
      * Set the window as the current one. Calling glutSetWindow()
@@ -139,9 +139,8 @@ static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
     /*
      * Check if there is an idle callback hooked
      */
-// #   warning there is a redisplay hack here (see the code commented out)
     if( (window->Callbacks.Display != NULL) &&
-        /*(window->State.Redisplay == TRUE) &&*/
+        (window->State.Redisplay == TRUE) &&
         (window->State.Visible == TRUE) )
     {
         /*
@@ -313,6 +312,7 @@ static void fghCheckTimers( void )
  */
 long fgElapsedTime( void )
 {
+#ifndef WIN32
        struct timeval now;
        long elapsed;
 
@@ -322,6 +322,9 @@ long fgElapsedTime( void )
        elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
 
        return( elapsed );
+#else
+        return (timeGetTime() - fgState.Time.Value);
+#endif
 }
 
 /*
@@ -365,6 +368,7 @@ void FGAPIENTRY glutMainLoop( void )
 #if TARGET_HOST_UNIX_X11
     SFG_Window* window;
     XEvent event;
+    int modifiers;
 
     /*
      * This code was repeated constantly, so here it goes into a definition:
@@ -668,7 +672,14 @@ void FGAPIENTRY glutMainLoop( void )
                     /*
                      * Remember the current modifiers state
                      */
-                    window->State.Modifiers = event.xbutton.state;
+                    modifiers = 0;
+                    if (event.xbutton.state & (ShiftMask|LockMask))
+                        modifiers |= GLUT_ACTIVE_SHIFT;
+                    if (event.xbutton.state & ControlMask)
+                        modifiers |= GLUT_ACTIVE_CTRL;
+                    if (event.xbutton.state & Mod1Mask)
+                        modifiers |= GLUT_ACTIVE_ALT;
+                    window->State.Modifiers = modifiers;
 
                     /*
                      * Finally execute the mouse callback
@@ -687,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 ];
@@ -722,17 +748,24 @@ void FGAPIENTRY glutMainLoop( void )
                             /*
                              * ...one for the ASCII translateable keypresses...
                              */
-                            if( window->Callbacks.Keyboard != NULL )
+                            if( keyboard_cb != NULL )
                             {
                                 /*
                                  * Remember the current modifiers state
                                  */
-                                window->State.Modifiers = event.xkey.state;
+                                modifiers = 0;
+                                if (event.xkey.state & (ShiftMask|LockMask))
+                                    modifiers |= GLUT_ACTIVE_SHIFT;
+                                if (event.xkey.state & ControlMask)
+                                    modifiers |= GLUT_ACTIVE_CTRL;
+                                if (event.xkey.state & Mod1Mask)
+                                    modifiers |= GLUT_ACTIVE_ALT;
+                                window->State.Modifiers = modifiers;
 
                                 /*
                                  * 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
@@ -772,25 +805,43 @@ 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
-                                  */
-                                 window->State.Modifiers = event.xkey.state;
+                                /*
+                                 * Remember the current modifiers state
+                                 */
+                                modifiers = 0;
+                                if (event.xkey.state & (ShiftMask|LockMask))
+                                    modifiers |= GLUT_ACTIVE_SHIFT;
+                                if (event.xkey.state & ControlMask)
+                                    modifiers |= GLUT_ACTIVE_CTRL;
+                                if (event.xkey.state & Mod1Mask)
+                                    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
-                                  */
-                                 window->State.Modifiers = 0xffffffff;
+                                /*
+                                 * Trash the modifiers state
+                                 */
+                                window->State.Modifiers = 0xffffffff;
                             }
                         }
                     }
@@ -826,7 +877,7 @@ void FGAPIENTRY glutMainLoop( void )
 
 #elif TARGET_HOST_WIN32
 
-    gboolean bLoop = TRUE;
+    GLboolean bLoop = TRUE;
     MSG stMsg;
 
     /*
@@ -875,7 +926,7 @@ void FGAPIENTRY glutMainLoop( void )
             /*
              * We need to terminate the main loop if no windows are left
              */
-            bLoop = (g_list_length( fgStructure.Windows ) != 0);
+            bLoop = (fgStructure.Windows.First != NULL);
         }
     }
 
@@ -910,7 +961,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
          * The window structure is passed as the creation structure paramter...
          */
         window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
-        g_assert( window != NULL );
+        assert( window != NULL );
 
         /*
          * We can safely store the window's handle now:
@@ -1068,8 +1119,8 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
     case WM_MBUTTONUP:
     case WM_RBUTTONUP:
     {
-        gboolean pressed = TRUE;
-        gint button;
+        GLboolean pressed = TRUE;
+        int button;
 
         /*
          * A mouse button has been pressed *or* released. Again, break off
@@ -1181,7 +1232,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
     case WM_SYSKEYDOWN:
     case WM_KEYDOWN:
     {
-        gint keypress = -1;
+        int keypress = -1;
 
         /*
          * First of all, make sure that there is a window to be notified of this