X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_window.c;h=eda79f200a9a88cf8e4371560602a1d368d36875;hb=12965126f5f67bdf811a482b6e4c046f559a0645;hp=8d4f80554c13053f122901049866e43b834e4f5d;hpb=e0fcd0b8dfb6c9b8d2279c9ecc8c0b7909fbcc34;p=freeglut diff --git a/src/freeglut_window.c b/src/freeglut_window.c index 8d4f805..eda79f2 100644 --- a/src/freeglut_window.c +++ b/src/freeglut_window.c @@ -63,6 +63,7 @@ * Chooses a visual basing on the current display mode settings */ #if TARGET_HOST_UNIX_X11 + XVisualInfo* fgChooseVisual( void ) { int bufferSize[] = { 16, 12, 8, 4, 2, 1 }; @@ -233,7 +234,7 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned * It might be the case for us to use double buffering */ if( fgState.DisplayMode & GLUT_DOUBLE ) - flags |= PFD_DOUBLEBUFFER; + flags |= PFD_DOUBLEBUFFER; /* * Specify which pixel format do we opt for... @@ -305,6 +306,8 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned void fgSetWindow ( SFG_Window *window ) { #if TARGET_HOST_UNIX_X11 + if ( window ) + { /* * Make the selected window's GLX context the current one */ @@ -313,7 +316,7 @@ void fgSetWindow ( SFG_Window *window ) window->Window.Handle, window->Window.Context ); - + } #elif TARGET_HOST_WIN32 /* * Release the previous' context's device context @@ -363,7 +366,24 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i /* * Here we are upon the stage. Have the visual selected. */ - window->Window.VisualInfo = fgChooseVisual(); + if ( fgState.BuildingAMenu ) + { + /* + * If there isn't already an OpenGL rendering context for menu windows, make one + */ + if ( !fgStructure.MenuContext ) + { + unsigned int current_DisplayMode = fgState.DisplayMode ; + fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ; + window->Window.VisualInfo = fgChooseVisual(); + fgState.DisplayMode = current_DisplayMode ; + } + else + window->Window.VisualInfo = fgChooseVisual(); + } + else + window->Window.VisualInfo = fgChooseVisual(); + if ( ! window->Window.VisualInfo ) { /* @@ -415,6 +435,15 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask; /* + * If this is a menu window we want the window manager to ignore it. + */ + if ( fgState.BuildingAMenu ) + { + winAttr.override_redirect = True; + mask |= CWOverrideRedirect; + } + + /* * Have the window created now */ window->Window.Handle = XCreateWindow( @@ -430,7 +459,28 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i * The GLX context creation, possibly trying the direct context rendering * or else use the current context if the user has so specified */ - if ( fgState.UseCurrentContext == TRUE ) + if ( fgState.BuildingAMenu ) + { + /* + * 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->VisualInfo = window->Window.VisualInfo ; + fgStructure.MenuContext->Context = glXCreateContext( + fgDisplay.Display, fgStructure.MenuContext->VisualInfo, + NULL, fgState.ForceDirectContext | fgState.TryDirectContext + ); + } + +/* window->Window.Context = fgStructure.MenuContext->Context ; */ + window->Window.Context = glXCreateContext( + fgDisplay.Display, window->Window.VisualInfo, + NULL, fgState.ForceDirectContext | fgState.TryDirectContext + ); + } + else if ( fgState.UseCurrentContext == TRUE ) { window->Window.Context = glXGetCurrentContext(); @@ -517,39 +567,7 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i */ XMapWindow( fgDisplay.Display, window->Window.Handle ); - /* - * In game mode, move the viewport a bit to hide the decorations. - * This code depends on the XFree86 video mode extensions. - */ - if( gameMode == TRUE ) - { - /* - * This somehow fixes the glutGet() GLUT_WINDOW_X and GLUT_WINDOW_Y problem... - */ - XMoveWindow( fgDisplay.Display, window->Window.Handle, x, y ); - -# ifdef X_XF86VidModeSetViewPort - - /* - * Set the newly created window as the current one... - */ - fgSetWindow( window ); - - /* - * Move the viewport a bit down and right from top-left corner to hide the decorations - */ - XF86VidModeSetViewPort( - fgDisplay.Display, - fgDisplay.Screen, - glutGet( GLUT_WINDOW_X ), - glutGet( GLUT_WINDOW_Y ) - ); - -# endif - } - -#elif TAR -GET_HOST_WIN32 +#elif TARGET_HOST_WIN32 WNDCLASS wc; int flags; @@ -565,7 +583,7 @@ GET_HOST_WIN32 if( gameMode == FALSE ) { - if ( !isSubWindow ) + if ( ( !isSubWindow ) && ( ! window->IsMenu ) ) { /* * Update the window dimensions, taking account of window decorations. @@ -576,26 +594,27 @@ GET_HOST_WIN32 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 + GetSystemMetrics( SM_CYCAPTION ); } - /* * Check if the user wants us to use the default position/size */ if( fgState.Position.Use == FALSE ) { x = CW_USEDEFAULT; y = CW_USEDEFAULT; } - - if( fgState.Size .Use == FALSE ) { w = CW_USEDEFAULT; h = CW_USEDEFAULT; } + if( fgState.Size .Use == FALSE ) { w = CW_USEDEFAULT; h = CW_USEDEFAULT; } - - /* + /* * There's a small difference between creating the top, child and game mode windows */ flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; - if( window->Parent == NULL ) + /* + * If we're a menu, set our flags to include WS_POPUP to remove decorations + */ + if ( window->IsMenu ) + flags |= WS_POPUP ; + else if( window->Parent == NULL ) flags |= WS_OVERLAPPEDWINDOW; else flags |= WS_CHILD; } - else { /* @@ -609,7 +628,6 @@ GET_HOST_WIN32 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; } - /* * Create the window now, passing the freeglut window structure as the parameter */ @@ -652,14 +670,12 @@ GET_HOST_WIN32 glReadBuffer ( GL_FRONT ) ; } - /* * Set the newly created window as the current one */ fgSetWindow( window ); } - /* * Closes a window, destroying the frame and OpenGL context */ @@ -698,7 +714,6 @@ void fgCloseWindow( SFG_Window* window ) } - /* -- INTERFACE FUNCTIONS -------------------------------------------------- */ /* @@ -713,7 +728,6 @@ int FGAPIENTRY glutCreateWindow( const char* title ) fgState.Size.X, fgState.Size.Y, FALSE )->ID ); } - /* * This function creates a sub window. */ @@ -745,7 +759,6 @@ int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h ) return( window->ID ); } - /* * Destroys a window and all of its subwindows */ @@ -772,7 +785,6 @@ void FGAPIENTRY glutDestroyWindow( int windowID ) fgState.ExecState = ExecState ; } - /* * This function selects the current window */ @@ -809,11 +821,9 @@ void FGAPIENTRY glutSetWindow( int ID ) return; } - fgSetWindow ( window ) ; } - /* * This function returns the ID number of the current window, 0 if none exists */ @@ -832,14 +842,12 @@ int FGAPIENTRY glutGetWindow( void ) return( 0 ); } - /* * Otherwise, return the ID of the current window */ return( fgStructure.Window->ID ); } - /* * This function makes the current window visible */ @@ -861,8 +869,13 @@ void FGAPIENTRY glutShowWindow( void ) ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW ); #endif -} + /* + * Since the window is visible, we need to redisplay it ... + */ + fgStructure.Window->State.Redisplay = TRUE; + +} /* * This function hides the current window @@ -883,7 +896,6 @@ void FGAPIENTRY glutHideWindow( void ) */ XWithdrawWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen ); } - else { /* @@ -892,7 +904,6 @@ void FGAPIENTRY glutHideWindow( void ) XUnmapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle ); } - /* * Flush the X state now */ @@ -905,8 +916,12 @@ void FGAPIENTRY glutHideWindow( void ) ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE ); #endif -} + /* + * Since the window is hidden, we don't need to redisplay it ... + */ + fgStructure.Window->State.Redisplay = FALSE; +} /* * Iconify the current window (top-level windows only) @@ -929,8 +944,13 @@ void FGAPIENTRY glutIconifyWindow( void ) ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE ); #endif -} + /* + * Since the window is just an icon, we don't need to redisplay it ... + */ + fgStructure.Window->State.Redisplay = FALSE; + +} /* * Set the current window's title @@ -972,7 +992,6 @@ void FGAPIENTRY glutSetWindowTitle( const char* title ) XFlush( fgDisplay.Display ); } - #elif TARGET_HOST_WIN32 /* * This seems to be a bit easier under Win32 @@ -982,7 +1001,6 @@ void FGAPIENTRY glutSetWindowTitle( const char* title ) #endif } - /* * Set the current window's iconified title */ @@ -1023,7 +1041,6 @@ void FGAPIENTRY glutSetIconTitle( const char* title ) XFlush( fgDisplay.Display ); } - #elif TARGET_HOST_WIN32 /* * This seems to be a bit easier under Win32 @@ -1033,7 +1050,6 @@ void FGAPIENTRY glutSetIconTitle( const char* title ) #endif } - /* * Change the current window's size */ @@ -1063,12 +1079,14 @@ void FGAPIENTRY glutReshapeWindow( int width, int height ) if ( fgStructure.Window->Parent == NULL ) /* If this is not a subwindow ... */ { /* - * Adjust the size of the window to allow for the size of the frame + * Adjust the size of the window to allow for the size of the frame, if we are not a menu */ - width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2; - height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION ); + if ( ! fgStructure.Window->IsMenu ) + { + width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2; + height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION ); + } } - else /* This is a subwindow, get the parent window's position and subtract it off */ { GetWindowRect ( fgStructure.Window->Parent->Window.Handle, &winRect ) ; @@ -1076,7 +1094,6 @@ void FGAPIENTRY glutReshapeWindow( int width, int height ) y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION ) ; } - /* * Resize the window, forcing a redraw to happen */ @@ -1089,11 +1106,9 @@ void FGAPIENTRY glutReshapeWindow( int width, int height ) TRUE ); } - #endif } - /* * Change the current window's position */ @@ -1130,11 +1145,9 @@ void FGAPIENTRY glutPositionWindow( int x, int y ) ); } - #endif } - /* * Lowers the current window (by Z order change) */ @@ -1162,7 +1175,6 @@ void FGAPIENTRY glutPushWindow( void ) #endif } - /* * Raises the current window (by Z order change) */ @@ -1190,7 +1202,6 @@ void FGAPIENTRY glutPopWindow( void ) #endif } - /* * Resize the current window so that it fits the whole screen */ @@ -1209,7 +1220,6 @@ void FGAPIENTRY glutFullScreen( void ) ); } - /* * A.Donev: Set and retrieve the window's user data */ @@ -1218,11 +1228,18 @@ void* FGAPIENTRY glutGetWindowData( void ) return(fgStructure.Window->UserData); } - void FGAPIENTRY glutSetWindowData(void* data) { fgStructure.Window->UserData=data; } - /*** END OF FILE ***/ + + + + + + + + +