4 * Window management methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define G_LOG_DOMAIN "freeglut-window"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
40 * fgChooseVisual() -- OK, but what about glutInitDisplayString()?
41 * fgSetupPixelFormat -- ignores the display mode settings
42 * fgOpenWindow() -- check the Win32 version, -iconic handling!
43 * fgCloseWindow() -- check the Win32 version
44 * glutCreateWindow() -- see what happens when default position and size is {-1,-1}
45 * glutCreateSubWindow() -- see what happens when default position and size is {-1,-1}
46 * glutDestroyWindow() -- check the Win32 version
47 * glutSetWindow() -- check the Win32 version
48 * glutGetWindow() -- OK
49 * glutSetWindowTitle() -- check the Win32 version
50 * glutSetIconTitle() -- check the Win32 version
51 * glutShowWindow() -- check the Win32 version
52 * glutHideWindow() -- check the Win32 version
53 * glutIconifyWindow() -- check the Win32 version
54 * glutReshapeWindow() -- check the Win32 version
55 * glutPositionWindow() -- check the Win32 version
56 * glutPushWindow() -- check the Win32 version
57 * glutPopWindow() -- check the Win32 version
60 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
63 * Chooses a visual basing on the current display mode settings
65 #if TARGET_HOST_UNIX_X11
66 XVisualInfo* fgChooseVisual( void )
68 int bufferSize[] = { 16, 12, 8, 4, 2, 1 };
69 GLboolean wantIndexedMode = FALSE;
74 * First we have to process the display mode settings...
76 # define ATTRIB(a) attributes[where++]=a;
79 * Decide if we want a true or indexed color visual:
81 if( !(fgState.DisplayMode & GLUT_INDEX) )
84 * We are sure that there will be R, B and B components requested:
87 ATTRIB( GLX_RED_SIZE ); ATTRIB( 1 );
88 ATTRIB( GLX_GREEN_SIZE ); ATTRIB( 1 );
89 ATTRIB( GLX_BLUE_SIZE ); ATTRIB( 1 );
92 * Check if the A component is required, too:
94 if( fgState.DisplayMode & GLUT_ALPHA )
96 ATTRIB( GLX_ALPHA_SIZE ); ATTRIB( 1 );
102 * We've got an indexed color request
104 ATTRIB( GLX_BUFFER_SIZE ); ATTRIB( 8 );
107 * Set the 'I want indexed mode' switch
109 wantIndexedMode = TRUE;
113 * We can have double or single buffered contexts created
115 if( fgState.DisplayMode & GLUT_DOUBLE )
117 ATTRIB( GLX_DOUBLEBUFFER );
121 * Stereoscopy seems a nice thing to have
123 if( fgState.DisplayMode & GLUT_STEREO )
125 ATTRIB( GLX_STEREO );
129 * Depth buffer is almost always required
131 if( fgState.DisplayMode & GLUT_DEPTH )
133 ATTRIB( GLX_DEPTH_SIZE ); ATTRIB( 1 );
139 if( fgState.DisplayMode & GLUT_STENCIL )
141 ATTRIB( GLX_STENCIL_SIZE ); ATTRIB( 1 );
145 * And finally the accumulation buffers
147 if( fgState.DisplayMode & GLUT_ACCUM )
149 ATTRIB( GLX_ACCUM_RED_SIZE ); ATTRIB( 1 );
150 ATTRIB( GLX_ACCUM_GREEN_SIZE ); ATTRIB( 1 );
151 ATTRIB( GLX_ACCUM_BLUE_SIZE ); ATTRIB( 1 );
154 * Check if the A component is required, too:
156 if( fgState.DisplayMode & GLUT_ALPHA )
158 ATTRIB( GLX_ACCUM_ALPHA_SIZE ); ATTRIB( 1 );
163 * Push a null at the end of the list
168 * OKi now, we've got two cases -- RGB(A) and index mode visuals
170 if( wantIndexedMode == FALSE )
173 * The easier one. And more common, too.
175 return( glXChooseVisual( fgDisplay.Display, fgDisplay.Screen, attributes ) );
179 XVisualInfo* visualInfo;
183 * In indexed mode, we need to check how many bits of depth can we achieve
189 * The GLX_BUFFER_SIZE value comes always first, so:
191 attributes[ 1 ] = bufferSize[ i ];
194 * Check if such visual is possible
196 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen, attributes );
199 * The buffer size are sorted in descendant order, so choose the first:
201 if( visualInfo != NULL )
202 return( visualInfo );
206 * If we are still here, it means that the visual info was not found
214 * Setup the pixel format for a Win32 window
216 #if TARGET_HOST_WIN32
217 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned char layer_type )
219 PIXELFORMATDESCRIPTOR* ppfd, pfd;
220 int flags, pixelformat;
223 * Check if the window seems valid
225 freeglut_return_val_if_fail( window != NULL, 0 );
228 * The pixel format should allow us to draw to the window using OpenGL
230 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
233 * It might be the case for us to use double buffering
235 if( fgState.DisplayMode & GLUT_DOUBLE )
236 flags |= PFD_DOUBLEBUFFER;
239 * Specify which pixel format do we opt for...
241 # pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
243 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
246 pfd.iPixelType = PFD_TYPE_RGBA;
257 pfd.cAccumRedBits = 0;
258 pfd.cAccumGreenBits = 0;
259 pfd.cAccumBlueBits = 0;
260 pfd.cAccumAlphaBits = 0;
263 pfd.cStencilBits = 0;
266 pfd.cStencilBits = 8;
269 pfd.iLayerType = layer_type;
272 pfd.dwVisibleMask = 0;
273 pfd.dwDamageMask = 0;
276 * Fill in the color bits...
278 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
282 * Choose the pixel format that matches our demand
284 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
285 if( pixelformat == 0 )
289 * We might have been called to check if the pixel format exists only
295 * Finally, set the window's pixel format
297 return ( SetPixelFormat( window->Window.Device, pixelformat, ppfd ) ) ;
302 * Sets the OpenGL context and the fgStructure "Current Window" pointer to the window
303 * structure passed in.
305 void fgSetWindow ( SFG_Window *window )
307 #if TARGET_HOST_UNIX_X11
309 * Make the selected window's GLX context the current one
313 window->Window.Handle,
314 window->Window.Context
317 #elif TARGET_HOST_WIN32
319 * Release the previous' context's device context
321 if( fgStructure.Window != NULL )
322 ReleaseDC( fgStructure.Window->Window.Handle, fgStructure.Window->Window.Device );
327 * We will care about releasing the device context later
329 window->Window.Device = GetDC( window->Window.Handle );
332 * Set the new current context:
335 window->Window.Device,
336 window->Window.Context
342 * Remember that we have changed the current window state
344 fgStructure.Window = window;
349 * Opens a window. Requires a SFG_Window object created and attached
350 * to the freeglut structure. OpenGL context is created here.
352 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow )
354 #if TARGET_HOST_UNIX_X11
355 XSetWindowAttributes winAttr;
356 XTextProperty textProperty;
357 XSizeHints sizeHints;
361 freeglut_assert_ready;
364 * Here we are upon the stage. Have the visual selected.
366 if ( fgState.BuildingAMenu )
369 * If there isn't already an OpenGL rendering context for menu windows, make one
371 if ( !fgStructure.MenuContext )
373 unsigned int current_DisplayMode = fgState.DisplayMode ;
374 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
375 window->Window.VisualInfo = fgChooseVisual();
376 fgState.DisplayMode = current_DisplayMode ;
379 window->Window.VisualInfo = fgChooseVisual();
382 window->Window.VisualInfo = fgChooseVisual();
384 if ( ! window->Window.VisualInfo )
387 * The "fgChooseVisual" returned a null meaning that the visual context is not available.
388 * Try a couple of variations to see if they will work.
390 if ( ! ( fgState.DisplayMode & GLUT_DOUBLE ) )
393 * Single buffering--try it doubled
395 fgState.DisplayMode |= GLUT_DOUBLE ;
396 window->Window.VisualInfo = fgChooseVisual();
400 * GLUT also checks for multi-sampling, but I don't see that anywhere else in FREEGLUT
401 * so I won't bother with it for the moment.
405 assert( window->Window.VisualInfo != NULL );
408 * Have the windows attributes set
410 * HINT: the masks should be updated when adding/removing callbacks.
411 * This might speed up message processing. Is that true?
413 winAttr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
414 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease |
415 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
416 PointerMotionMask | ButtonMotionMask;
417 winAttr.background_pixmap = None;
418 winAttr.background_pixel = 0;
419 winAttr.border_pixel = 0;
422 * The color map is required, too
424 winAttr.colormap = XCreateColormap(
425 fgDisplay.Display, fgDisplay.RootWindow,
426 window->Window.VisualInfo->visual, AllocNone
430 * This tells the XCreateWindow() what attributes are we supplying it with
432 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
435 * Have the window created now
437 window->Window.Handle = XCreateWindow(
439 window->Parent == NULL ? fgDisplay.RootWindow : window->Parent->Window.Handle,
441 window->Window.VisualInfo->depth, InputOutput,
442 window->Window.VisualInfo->visual, mask,
447 * The GLX context creation, possibly trying the direct context rendering
448 * or else use the current context if the user has so specified
450 if ( fgState.BuildingAMenu )
453 * If there isn't already an OpenGL rendering context for menu windows, make one
455 if ( !fgStructure.MenuContext )
457 fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
458 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo ;
459 fgStructure.MenuContext->Context = glXCreateContext(
460 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
461 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
465 /* window->Window.Context = fgStructure.MenuContext->Context ; */
466 window->Window.Context = glXCreateContext(
467 fgDisplay.Display, window->Window.VisualInfo,
468 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
471 else if ( fgState.UseCurrentContext == TRUE )
473 window->Window.Context = glXGetCurrentContext();
475 if ( ! window->Window.Context )
476 window->Window.Context = glXCreateContext(
477 fgDisplay.Display, window->Window.VisualInfo,
478 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
482 window->Window.Context = glXCreateContext(
483 fgDisplay.Display, window->Window.VisualInfo,
484 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
488 * Make sure the context is direct when the user wants it forced
490 if( fgState.ForceDirectContext && !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
491 fgError( "unable to force direct context rendering for window '%s'", title );
494 * Set the new context as the current one. That's all about the window creation.
498 window->Window.Handle,
499 window->Window.Context
503 * Assume the new window is visible by default
505 window->State.Visible = TRUE;
508 * For the position and size hints -- make sure we are passing valid values
512 if (fgState.Position.Use == TRUE) sizeHints.flags |= USPosition;
513 if (fgState.Size.Use == TRUE) sizeHints.flags |= USSize;
516 * Fill in the size hints values now (the x, y, width and height
517 * settings are obsolote, are there any more WMs that support them?)
519 sizeHints.x = x; sizeHints.y = y;
520 sizeHints.width = w; sizeHints.height = h;
523 * We can have forced all new windows start in iconified state:
525 wmHints.flags = StateHint;
526 wmHints.initial_state = (fgState.ForceIconic == FALSE) ? NormalState : IconicState;
529 * Prepare the window and iconified window names...
531 XStringListToTextProperty( (char **) &title, 1, &textProperty );
534 * Set the window's properties now
538 window->Window.Handle,
549 * Make sure we are informed about the window deletion commands
551 XSetWMProtocols( fgDisplay.Display, window->Window.Handle, &fgDisplay.DeleteWindow, 1 );
554 * Finally, have the window mapped to our display
556 XMapWindow( fgDisplay.Display, window->Window.Handle );
559 * In game mode, move the viewport a bit to hide the decorations.
560 * This code depends on the XFree86 video mode extensions.
562 if( gameMode == TRUE )
565 * This somehow fixes the glutGet() GLUT_WINDOW_X and GLUT_WINDOW_Y problem...
567 XMoveWindow( fgDisplay.Display, window->Window.Handle, x, y );
569 # ifdef X_XF86VidModeSetViewPort
572 * Set the newly created window as the current one...
574 fgSetWindow( window );
577 * Move the viewport a bit down and right from top-left corner to hide the decorations
579 XF86VidModeSetViewPort(
582 glutGet( GLUT_WINDOW_X ),
583 glutGet( GLUT_WINDOW_Y )
589 #elif TARGET_HOST_WIN32
595 freeglut_assert_ready;
598 * Grab the window class we have registered on glutInit():
600 atom = GetClassInfo( fgDisplay.Instance, "FREEGLUT", &wc );
603 if( gameMode == FALSE )
605 if ( ( !isSubWindow ) && ( ! window->IsMenu ) )
608 * Update the window dimensions, taking account of window decorations.
609 * "freeglut" is to create the window with the outside of its border at (x,y)
610 * and with dimensions (w,h).
612 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
613 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 + GetSystemMetrics( SM_CYCAPTION );
617 * Check if the user wants us to use the default position/size
619 if( fgState.Position.Use == FALSE ) { x = CW_USEDEFAULT; y = CW_USEDEFAULT; }
620 if( fgState.Size .Use == FALSE ) { w = CW_USEDEFAULT; h = CW_USEDEFAULT; }
623 * There's a small difference between creating the top, child and game mode windows
625 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
628 * If we're a menu, set our flags to include WS_POPUP to remove decorations
630 if ( window->IsMenu )
632 else if( window->Parent == NULL )
633 flags |= WS_OVERLAPPEDWINDOW;
640 * In game mode, the story is a little bit different...
642 assert( window->Parent == NULL );
645 * Set the window creation flags appropriately to make the window entirely visible:
647 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
651 * Create the window now, passing the freeglut window structure as the parameter
653 window->Window.Handle = CreateWindow(
658 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
665 * Make sure window was created
667 assert( window->Window.Handle != NULL );
670 * Show and update the main window. Hide the mouse cursor.
672 ShowWindow( window->Window.Handle, fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
673 UpdateWindow( window->Window.Handle );
679 * Save the window's single- or double-buffering state
681 window->Window.DoubleBuffered = ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0 ;
684 * If it's not double-buffered, make sure the rendering is done to the front buffer.
686 if ( ! window->Window.DoubleBuffered )
688 glDrawBuffer ( GL_FRONT ) ;
689 glReadBuffer ( GL_FRONT ) ;
693 * Set the newly created window as the current one
695 fgSetWindow( window );
699 * Closes a window, destroying the frame and OpenGL context
701 void fgCloseWindow( SFG_Window* window )
703 freeglut_assert_ready;
705 #if TARGET_HOST_UNIX_X11
707 * As easy as kill bunnies with axes. Destroy the context first:
709 glXDestroyContext( fgDisplay.Display, window->Window.Context );
712 * Then have the window killed:
714 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
717 * Finally, flush the rests down the stream
719 XFlush( fgDisplay.Display );
721 #elif TARGET_HOST_WIN32
723 * Send the WM_CLOSE message to the window now
726 window->Window.Handle,
736 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
739 * Creates a new top-level freeglut window
741 int FGAPIENTRY glutCreateWindow( const char* title )
744 * Create a new window and return its unique ID number
746 return( fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
747 fgState.Size.X, fgState.Size.Y, FALSE )->ID );
751 * This function creates a sub window.
753 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
755 SFG_Window* window = NULL;
756 SFG_Window* parent = NULL;
758 freeglut_assert_ready;
761 * Find a parent to the newly created window...
763 parent = fgWindowByID( parentID );
766 * Fail if the parent has not been found
768 freeglut_return_val_if_fail( parent != NULL, 0 );
771 * Create the new window
773 window = fgCreateWindow( parent, "", x, y, w, h, FALSE );
776 * Return the new window's ID
778 return( window->ID );
782 * Destroys a window and all of its subwindows
784 void FGAPIENTRY glutDestroyWindow( int windowID )
786 fgExecutionState ExecState = fgState.ExecState ;
789 * Grab the freeglut window pointer from the structure
791 SFG_Window* window = fgWindowByID( windowID );
792 freeglut_return_if_fail( window != NULL );
795 * There is a function that performs all needed steps
796 * defined in freeglut_structure.c. Let's use it:
798 fgAddToWindowDestroyList( window, TRUE );
801 * Since the "fgAddToWindowDestroyList" function could easily have set the "ExecState"
802 * to stop, let's set it back to what it was.
804 fgState.ExecState = ExecState ;
808 * This function selects the current window
810 void FGAPIENTRY glutSetWindow( int ID )
812 SFG_Window* window = NULL;
815 * Make sure we don't get called too early
817 freeglut_assert_ready;
820 * Be wise. Be wise. Be wise. Be quick.
822 if( fgStructure.Window != NULL )
823 if( fgStructure.Window->ID == ID )
827 * Now we are sure there is sense in looking for the window
829 window = fgWindowByID( ID );
832 * In the case of an utter failure...
837 * ...issue a warning message and keep rolling on
839 fgWarning( "glutSetWindow(): window ID %i not found!", ID );
843 fgSetWindow ( window ) ;
847 * This function returns the ID number of the current window, 0 if none exists
849 int FGAPIENTRY glutGetWindow( void )
851 freeglut_assert_ready;
854 * Do we have a current window selected?
856 if( fgStructure.Window == NULL )
859 * Nope. Return zero to mark the state.
865 * Otherwise, return the ID of the current window
867 return( fgStructure.Window->ID );
871 * This function makes the current window visible
873 void FGAPIENTRY glutShowWindow( void )
875 freeglut_assert_ready; freeglut_assert_window;
877 #if TARGET_HOST_UNIX_X11
879 * Showing the window is done via mapping under X
881 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
882 XFlush( fgDisplay.Display );
884 #elif TARGET_HOST_WIN32
886 * Restore the window's originial position and size
888 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
893 * Since the window is visible, we need to redisplay it ...
895 fgStructure.Window->State.Redisplay = TRUE;
900 * This function hides the current window
902 void FGAPIENTRY glutHideWindow( void )
904 freeglut_assert_ready; freeglut_assert_window;
906 #if TARGET_HOST_UNIX_X11
908 * The way we hide a window depends on if we're dealing
909 * with a top-level or children one...
911 if( fgStructure.Window->Parent == NULL )
914 * This is a top-level window
916 XWithdrawWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
921 * Nope, it's a child window
923 XUnmapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
927 * Flush the X state now
929 XFlush( fgDisplay.Display );
931 #elif TARGET_HOST_WIN32
935 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
940 * Since the window is hidden, we don't need to redisplay it ...
942 fgStructure.Window->State.Redisplay = FALSE;
946 * Iconify the current window (top-level windows only)
948 void FGAPIENTRY glutIconifyWindow( void )
950 freeglut_assert_ready; freeglut_assert_window;
952 #if TARGET_HOST_UNIX_X11
954 * Iconify the window and flush the X state
956 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
957 XFlush( fgDisplay.Display );
959 #elif TARGET_HOST_WIN32
961 * Minimize the current window (this should be the same as X window iconifying)
963 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
968 * Since the window is just an icon, we don't need to redisplay it ...
970 fgStructure.Window->State.Redisplay = FALSE;
975 * Set the current window's title
977 void FGAPIENTRY glutSetWindowTitle( const char* title )
979 freeglut_assert_ready; freeglut_assert_window;
982 * Works only for top-level windows
984 if( fgStructure.Window->Parent != NULL )
987 #if TARGET_HOST_UNIX_X11
992 * Prepare the text properties
994 text.value = (unsigned char *) title;
995 text.encoding = XA_STRING;
997 text.nitems = strlen( title );
1004 fgStructure.Window->Window.Handle,
1009 * Have the X display state flushed
1011 XFlush( fgDisplay.Display );
1014 #elif TARGET_HOST_WIN32
1016 * This seems to be a bit easier under Win32
1018 SetWindowText( fgStructure.Window->Window.Handle, title );
1024 * Set the current window's iconified title
1026 void FGAPIENTRY glutSetIconTitle( const char* title )
1028 freeglut_assert_ready; freeglut_assert_window;
1031 * Works only for top-level windows
1033 if( fgStructure.Window->Parent != NULL )
1036 #if TARGET_HOST_UNIX_X11
1041 * Prepare the text properties
1043 text.value = (unsigned char *) title;
1044 text.encoding = XA_STRING;
1046 text.nitems = strlen( title );
1053 fgStructure.Window->Window.Handle,
1058 * Have the X display state flushed
1060 XFlush( fgDisplay.Display );
1063 #elif TARGET_HOST_WIN32
1065 * This seems to be a bit easier under Win32
1067 SetWindowText( fgStructure.Window->Window.Handle, title );
1073 * Change the current window's size
1075 void FGAPIENTRY glutReshapeWindow( int width, int height )
1077 freeglut_assert_ready; freeglut_assert_window;
1079 #if TARGET_HOST_UNIX_X11
1081 * Resize the window and flush the X state
1083 XResizeWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, width, height );
1084 XFlush( fgDisplay.Display );
1086 #elif TARGET_HOST_WIN32
1092 * First off, grab the current window's position
1094 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
1098 if ( fgStructure.Window->Parent == NULL ) /* If this is not a subwindow ... */
1101 * Adjust the size of the window to allow for the size of the frame, if we are not a menu
1103 if ( ! fgStructure.Window->IsMenu )
1105 width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
1106 height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION );
1109 else /* This is a subwindow, get the parent window's position and subtract it off */
1111 GetWindowRect ( fgStructure.Window->Parent->Window.Handle, &winRect ) ;
1112 x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) ;
1113 y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION ) ;
1117 * Resize the window, forcing a redraw to happen
1120 fgStructure.Window->Window.Handle,
1132 * Change the current window's position
1134 void FGAPIENTRY glutPositionWindow( int x, int y )
1136 freeglut_assert_ready; freeglut_assert_window;
1138 #if TARGET_HOST_UNIX_X11
1140 * Reposition the window and flush the X state
1142 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, x, y );
1143 XFlush( fgDisplay.Display );
1145 #elif TARGET_HOST_WIN32
1150 * First off, grab the current window's position
1152 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
1155 * Reposition the window, forcing a redraw to happen
1158 fgStructure.Window->Window.Handle,
1161 winRect.right - winRect.left,
1162 winRect.bottom - winRect.top,
1171 * Lowers the current window (by Z order change)
1173 void FGAPIENTRY glutPushWindow( void )
1175 freeglut_assert_ready; freeglut_assert_window;
1177 #if TARGET_HOST_UNIX_X11
1179 * Lower the current window
1181 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1183 #elif TARGET_HOST_WIN32
1185 * Set the new window's Z position, not affecting the rest of the settings:
1188 fgStructure.Window->Window.Handle,
1191 SWP_NOSIZE | SWP_NOMOVE
1198 * Raises the current window (by Z order change)
1200 void FGAPIENTRY glutPopWindow( void )
1202 freeglut_assert_ready; freeglut_assert_window;
1204 #if TARGET_HOST_UNIX_X11
1206 * Raise the current window
1208 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1210 #elif TARGET_HOST_WIN32
1212 * Set the new window's Z position, not affecting the rest of the settings:
1215 fgStructure.Window->Window.Handle,
1218 SWP_NOSIZE | SWP_NOMOVE
1225 * Resize the current window so that it fits the whole screen
1227 void FGAPIENTRY glutFullScreen( void )
1229 freeglut_assert_ready; freeglut_assert_window;
1232 * Just have the window repositioned and resized
1234 glutPositionWindow( 0, 0 );
1237 fgDisplay.ScreenWidth,
1238 fgDisplay.ScreenHeight
1243 * A.Donev: Set and retrieve the window's user data
1245 void* FGAPIENTRY glutGetWindowData( void )
1247 return(fgStructure.Window->UserData);
1250 void FGAPIENTRY glutSetWindowData(void* data)
1252 fgStructure.Window->UserData=data;
1255 /*** END OF FILE ***/