* Grab the next event to be processed...
*/
XNextEvent( fgDisplay.Display, &event );
- window = fgWindowByHandle ( event.xany.window ) ;
/*
* Check the event's type
/*
* Call the window closure callback, remove from the structure, etc.
*/
- fgStructure.Window = window ;
/* fgAddToWindowDestroyList ( window, FALSE ); */
break;
*/
if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
{
- fgStructure.Window = window ;
+ GETWINDOW( xclient );
/*
* Call the XWindows functions to close the window
* We are too dumb to process partial exposes...
*/
if( event.xexpose.count == 0 )
- fghRedrawWindowByHandle( window->Window.Handle );
+ fghRedrawWindowByHandle( event.xexpose.window );
break;
case ConfigureNotify:
/*
* The window's visiblity might have changed
*/
+ GETWINDOW( xvisibility );
+
/*
* Break now if no window status callback has been hooked to that window
*/
/*
* Mouse is over one of our windows
*/
- GETMOUSE( xcrossing );
+ GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
/*
* Is there an entry callback hooked to the window?
/*
* Mouse is no longer over one of our windows
*/
- GETMOUSE( xcrossing );
+ GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
/*
* Is there an entry callback hooked to the window?
/*
* The mouse cursor was moved...
*/
- GETMOUSE( xmotion );
+ GETWINDOW( xmotion ); GETMOUSE( xmotion );
/*
- * Set the current window
+ * Fallback if there's an active menu hooked to this window
*/
- fgStructure.Window = window ;
+ if( window->ActiveMenu != NULL )
+ {
+ /*
+ * Let's make the window redraw as a result of the mouse motion.
+ */
+ window->State.Redisplay = TRUE ;
+
+ break;
+ }
/*
* What kind of a movement was it?
if( window->Callbacks.Motion != NULL )
{
/*
+ * Set the current window
+ */
+ fgStructure.Window = window ;
+
+ /*
* Yup. Have it executed immediately
*/
window->Callbacks.Motion( event.xmotion.x, event.xmotion.y );
if( window->Callbacks.Passive != NULL )
{
/*
+ * Set the current window
+ */
+ fgStructure.Window = window ;
+
+ /*
* That's right, and there is a passive callback, too.
*/
window->Callbacks.Passive( event.xmotion.x, event.xmotion.y );
* A mouse button has been pressed or released. Traditionally,
* break if the window was found within the freeglut structures.
*/
- GETMOUSE( xbutton );
+ GETWINDOW( xbutton ); GETMOUSE( xbutton );
/*
* GLUT API assumes that you can't have more than three mouse buttons, so:
/* Execute the menu callback */
fgExecuteMenuCallback ( window->ActiveMenu ) ;
- fgDeactivateMenu ( window ) ;
+ fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
/* Restore the current window and menu */
fgSetWindow ( save_window ) ;
}
else /* Outside the menu, deactivate the menu if it's a downclick */
{
- if ( pressed == TRUE ) fgDeactivateMenu ( window ) ;
+ if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
}
/*
window->State.Redisplay = TRUE ;
/*
+ * Set the current window
+ */
+ fgSetWindow( window );
+
+ /*
* Activate the appropriate menu structure...
*/
fgActivateMenu( window, button );
/*
* Check if there is a mouse callback hooked to the window
*/
- if( window->Callbacks.Mouse == NULL )
+ if( fgStructure.Window->Callbacks.Mouse == NULL )
break;
-
/*
* Set the current window
*/
- fgSetWindow( window );
+ fgSetWindow ( window );
+
/*
* Remember the current modifiers state
modifiers |= GLUT_ACTIVE_CTRL;
if (event.xbutton.state & Mod1Mask)
modifiers |= GLUT_ACTIVE_ALT;
- window->State.Modifiers = modifiers;
+ fgStructure.Window->State.Modifiers = modifiers;
/*
* Finally execute the mouse callback
*/
- window->Callbacks.Mouse(
+ fgStructure.Window->Callbacks.Mouse(
button,
event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
event.xbutton.x,
/*
* Trash the modifiers state
*/
- window->State.Modifiers = 0xffffffff;
+ fgStructure.Window->State.Modifiers = 0xffffffff;
}
break;
/*
* A key has been pressed, find the window that had the focus:
*/
- GETMOUSE( xkey );
+ GETWINDOW( xkey ); GETMOUSE( xkey );
if( event.type == KeyPress )
{
fghDisplayAll();
}
#endif
+
+ /*
+ * If an event caused a window to be closed, do the actual closing here
+ */
+ fgCloseWindows () ;
}
/*
glutMainLoopEvent () ;
/*
- * If an event caused a window to be closed, do the actual closing here
- */
- fgCloseWindows () ;
-
- /*
* If there are no more windows open, stop execution
*/
if ( fgStructure.Windows.First == NULL )
window->Window.Device = GetDC( hWnd );
/*
- * Setup the pixel format of our window
+ * Create or get the OpenGL rendering context now
*/
- fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
+ if ( fgState.BuildingAMenu )
+ {
+ /*
+ * Setup the pixel format of our window
+ */
+ unsigned int current_DisplayMode = fgState.DisplayMode ;
+ fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
+ fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
+ fgState.DisplayMode = current_DisplayMode ;
- /*
- * Create the OpenGL rendering context now
- */
- window->Window.Context = wglCreateContext( window->Window.Device );
+ /*
+ * If there isn't already an OpenGL rendering context for menu windows, make one
+ */
+ if ( !fgStructure.MenuContext )
+ {
+ fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
+ fgStructure.MenuContext->Context = wglCreateContext( window->Window.Device );
+ }
+ else
+ wglMakeCurrent ( window->Window.Device, fgStructure.MenuContext->Context ) ;
+
+/* window->Window.Context = wglGetCurrentContext () ; */
+ window->Window.Context = wglCreateContext( window->Window.Device );
+ }
+ else
+ {
+ /*
+ * Setup the pixel format of our window
+ */
+ fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
+
+ if ( fgState.UseCurrentContext == TRUE )
+ {
+ window->Window.Context = wglGetCurrentContext();
+ if ( ! window->Window.Context )
+ window->Window.Context = wglCreateContext( window->Window.Device );
+ }
+ else
+ window->Window.Context = wglCreateContext( window->Window.Device );
+ }
/*
* Still, we'll be needing to explicitly resize the window
*/
if( fgStructure.Window == window )
{
+ int used = FALSE ;
+ SFG_Window *iter ;
+
wglMakeCurrent( NULL, NULL );
- wglDeleteContext( window->Window.Context );
+ /* Step through the list of windows. If the rendering context is notbeing used
+ * by another window, then we delete it.
+ */
+ for ( iter = fgStructure.Windows.First; iter; iter = iter->Node.Next )
+ {
+ if ( ( iter->Window.Context == window->Window.Context ) && ( iter != window ) )
+ used = TRUE ;
+ }
+
+ if ( used == FALSE ) wglDeleteContext( window->Window.Context );
}
/*
/* Execute the menu callback */
fgExecuteMenuCallback ( window->ActiveMenu ) ;
- fgDeactivateMenu ( window ) ;
+ fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
/* Restore the current window and menu */
fgSetWindow ( save_window ) ;
}
else /* Outside the menu, deactivate the menu if it's a downclick */
{
- if ( pressed == TRUE ) fgDeactivateMenu ( window ) ;
+ if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
}
/*
* Let's make the window redraw as a result of the mouse click and menu activity.
*/
- window->State.Redisplay = TRUE ;
+ if ( ! window->IsMenu ) window->State.Redisplay = TRUE ;
break ;
}
window->State.Redisplay = TRUE ;
/*
+ * Set the current window
+ */
+ fgSetWindow( window );
+
+ /*
* Activate the appropriate menu structure...
*/
fgActivateMenu( window, button );
/*
* Check if there is a mouse callback hooked to the window
*/
- if( window->Callbacks.Mouse == NULL )
+ if( fgStructure.Window->Callbacks.Mouse == NULL )
break;
/*
- * Set the current window
- */
- fgSetWindow( window );
-
- /*
* Remember the current modifiers state.
*/
- window->State.Modifiers =
+ fgStructure.Window->State.Modifiers =
( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
/*
+ * Set the current window
+ */
+ fgSetWindow ( window );
+
+ /*
* Finally execute the mouse callback
*/
- window->Callbacks.Mouse(
+ fgStructure.Window->Callbacks.Mouse(
button,
pressed == TRUE ? GLUT_DOWN : GLUT_UP,
window->State.MouseX,
/*
* Trash the modifiers state
*/
- window->State.Modifiers = 0xffffffff;
+ fgStructure.Window->State.Modifiers = 0xffffffff;
}
break;