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() -- Check when default position and size is {-1,-1}
45 * glutCreateSubWindow() -- Check 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
67 XVisualInfo* fgChooseVisual( void )
69 #define BUFFER_SIZES 6
70 int bufferSize[BUFFER_SIZES] = { 16, 12, 8, 4, 2, 1 };
71 GLboolean wantIndexedMode = FALSE;
76 * First we have to process the display mode settings...
79 * Why is there a semi-colon in this #define? The code
80 * that uses the macro seems to always add more semicolons...
82 #define ATTRIB(a) attributes[where++]=a;
83 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
85 if( fgState.DisplayMode & GLUT_INDEX )
87 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
88 wantIndexedMode = TRUE;
93 ATTRIB_VAL( GLX_RED_SIZE, 1 );
94 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
95 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
96 if( fgState.DisplayMode & GLUT_ALPHA )
97 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
100 if( fgState.DisplayMode & GLUT_DOUBLE )
101 ATTRIB( GLX_DOUBLEBUFFER );
103 if( fgState.DisplayMode & GLUT_STEREO )
104 ATTRIB( GLX_STEREO );
106 if( fgState.DisplayMode & GLUT_DEPTH )
107 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
109 if( fgState.DisplayMode & GLUT_STENCIL )
110 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
112 if( fgState.DisplayMode & GLUT_ACCUM )
114 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
115 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
116 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
117 if( fgState.DisplayMode & GLUT_ALPHA )
118 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
122 * Push a null at the end of the list
126 if( wantIndexedMode == FALSE )
127 return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
131 XVisualInfo* visualInfo;
135 * In indexed mode, we need to check how many bits of depth can we
136 * achieve. We do this by trying each possibility from the list
137 * given in the {bufferSize} array. If we match, we return to caller.
139 for( i=0; i<BUFFER_SIZES; i++ )
141 attributes[ 1 ] = bufferSize[ i ];
142 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
144 if( visualInfo != NULL )
153 * Setup the pixel format for a Win32 window
155 #if TARGET_HOST_WIN32
156 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
157 unsigned char layer_type )
159 PIXELFORMATDESCRIPTOR* ppfd, pfd;
160 int flags, pixelformat;
162 freeglut_return_val_if_fail( window != NULL, 0 );
163 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
164 if( fgState.DisplayMode & GLUT_DOUBLE )
165 flags |= PFD_DOUBLEBUFFER;
167 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
170 * Specify which pixel format do we opt for...
172 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
175 pfd.iPixelType = PFD_TYPE_RGBA;
186 pfd.cAccumRedBits = 0;
187 pfd.cAccumGreenBits = 0;
188 pfd.cAccumBlueBits = 0;
189 pfd.cAccumAlphaBits = 0;
192 pfd.cStencilBits = 0;
195 pfd.cStencilBits = 8;
198 pfd.iLayerType = layer_type;
201 pfd.dwVisibleMask = 0;
202 pfd.dwDamageMask = 0;
204 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
207 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
208 if( pixelformat == 0 )
213 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
218 * Sets the OpenGL context and the fgStructure "Current Window" pointer to the window
219 * structure passed in.
221 void fgSetWindow ( SFG_Window *window )
223 #if TARGET_HOST_UNIX_X11
227 * Make the selected window's GLX context the current one
231 window->Window.Handle,
232 window->Window.Context
235 #elif TARGET_HOST_WIN32
237 * Release the previous' context's device context
239 if( fgStructure.Window != NULL )
240 ReleaseDC( fgStructure.Window->Window.Handle, fgStructure.Window->Window.Device );
245 * We will care about releasing the device context later
247 window->Window.Device = GetDC( window->Window.Handle );
250 * Set the new current context:
253 window->Window.Device,
254 window->Window.Context
260 * Remember that we have changed the current window state
262 fgStructure.Window = window;
267 * Opens a window. Requires a SFG_Window object created and attached
268 * to the freeglut structure. OpenGL context is created here.
270 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow )
272 #if TARGET_HOST_UNIX_X11
273 XSetWindowAttributes winAttr;
274 XTextProperty textProperty;
275 XSizeHints sizeHints;
279 freeglut_assert_ready;
282 * Here we are upon the stage. Have the visual selected.
284 if ( fgState.BuildingAMenu )
287 * If there isn't already an OpenGL rendering context for menu windows, make one
289 if ( !fgStructure.MenuContext )
291 unsigned int current_DisplayMode = fgState.DisplayMode ;
292 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
293 window->Window.VisualInfo = fgChooseVisual();
294 fgState.DisplayMode = current_DisplayMode ;
297 window->Window.VisualInfo = fgChooseVisual();
300 window->Window.VisualInfo = fgChooseVisual();
302 if ( ! window->Window.VisualInfo )
305 * The "fgChooseVisual" returned a null meaning that the visual context is not available.
306 * Try a couple of variations to see if they will work.
308 if ( ! ( fgState.DisplayMode & GLUT_DOUBLE ) )
311 * Single buffering--try it doubled
313 fgState.DisplayMode |= GLUT_DOUBLE ;
314 window->Window.VisualInfo = fgChooseVisual();
315 /* OK, we got a double-buffered window, but we only wanted
316 * single-buffered. Clear the double-buffer flag now.
318 fgState.DisplayMode &= ~GLUT_DOUBLE ;
322 * GLUT also checks for multi-sampling, but I don't see that anywhere else in FREEGLUT
323 * so I won't bother with it for the moment.
327 assert( window->Window.VisualInfo != NULL );
330 * Have the windows attributes set
332 * HINT: the masks should be updated when adding/removing callbacks.
333 * This might speed up message processing. Is that true?
335 winAttr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
336 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease |
337 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
338 PointerMotionMask | ButtonMotionMask;
339 winAttr.background_pixmap = None;
340 winAttr.background_pixel = 0;
341 winAttr.border_pixel = 0;
344 * The color map is required, too
346 winAttr.colormap = XCreateColormap(
347 fgDisplay.Display, fgDisplay.RootWindow,
348 window->Window.VisualInfo->visual, AllocNone
352 * This tells the XCreateWindow() what attributes are we supplying it with
354 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
357 * If this is a menu window we want the window manager to ignore it.
359 if ( fgState.BuildingAMenu )
361 winAttr.override_redirect = True;
362 mask |= CWOverrideRedirect;
366 * Have the window created now
368 window->Window.Handle = XCreateWindow(
370 window->Parent == NULL ? fgDisplay.RootWindow : window->Parent->Window.Handle,
372 window->Window.VisualInfo->depth, InputOutput,
373 window->Window.VisualInfo->visual, mask,
378 * The GLX context creation, possibly trying the direct context rendering
379 * or else use the current context if the user has so specified
381 if ( fgState.BuildingAMenu )
384 * If there isn't already an OpenGL rendering context for menu windows, make one
386 if ( !fgStructure.MenuContext )
388 fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
389 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo ;
390 fgStructure.MenuContext->Context = glXCreateContext(
391 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
392 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
396 /* window->Window.Context = fgStructure.MenuContext->Context ; */
397 window->Window.Context = glXCreateContext(
398 fgDisplay.Display, window->Window.VisualInfo,
399 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
402 else if ( fgState.UseCurrentContext == TRUE )
404 window->Window.Context = glXGetCurrentContext();
406 if ( ! window->Window.Context )
407 window->Window.Context = glXCreateContext(
408 fgDisplay.Display, window->Window.VisualInfo,
409 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
413 window->Window.Context = glXCreateContext(
414 fgDisplay.Display, window->Window.VisualInfo,
415 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
419 * Make sure the context is direct when the user wants it forced
421 if( fgState.ForceDirectContext && !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
422 fgError( "unable to force direct context rendering for window '%s'", title );
425 * Set the new context as the current one. That's all about the window creation.
429 window->Window.Handle,
430 window->Window.Context
434 * Assume the new window is visible by default
436 window->State.Visible = TRUE;
439 * For the position and size hints -- make sure we are passing valid values
443 if (fgState.Position.Use == TRUE) sizeHints.flags |= USPosition;
444 if (fgState.Size.Use == TRUE) sizeHints.flags |= USSize;
447 * Fill in the size hints values now (the x, y, width and height
448 * settings are obsolote, are there any more WMs that support them?)
450 sizeHints.x = x; sizeHints.y = y;
451 sizeHints.width = w; sizeHints.height = h;
454 * We can have forced all new windows start in iconified state:
456 wmHints.flags = StateHint;
457 wmHints.initial_state = (fgState.ForceIconic == FALSE) ? NormalState : IconicState;
460 * Prepare the window and iconified window names...
462 XStringListToTextProperty( (char **) &title, 1, &textProperty );
465 * Set the window's properties now
469 window->Window.Handle,
480 * Make sure we are informed about the window deletion commands
482 XSetWMProtocols( fgDisplay.Display, window->Window.Handle, &fgDisplay.DeleteWindow, 1 );
485 * Finally, have the window mapped to our display
487 XMapWindow( fgDisplay.Display, window->Window.Handle );
489 #elif TARGET_HOST_WIN32
495 freeglut_assert_ready;
498 * Grab the window class we have registered on glutInit():
500 atom = GetClassInfo( fgDisplay.Instance, "FREEGLUT", &wc );
503 if( gameMode == FALSE )
505 if ( ( !isSubWindow ) && ( ! window->IsMenu ) )
508 * Update the window dimensions, taking account of window decorations.
509 * "freeglut" is to create the window with the outside of its border at (x,y)
510 * and with dimensions (w,h).
512 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
513 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 + GetSystemMetrics( SM_CYCAPTION );
517 * Check if the user wants us to use the default position/size
519 if( fgState.Position.Use == FALSE ) { x = CW_USEDEFAULT; y = CW_USEDEFAULT; }
520 if( fgState.Size .Use == FALSE ) { w = CW_USEDEFAULT; h = CW_USEDEFAULT; }
523 * There's a small difference between creating the top, child and game mode windows
525 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
528 * If we're a menu, set our flags to include WS_POPUP to remove decorations
530 if ( window->IsMenu )
532 else if( window->Parent == NULL )
533 flags |= WS_OVERLAPPEDWINDOW;
540 * In game mode, the story is a little bit different...
542 assert( window->Parent == NULL );
545 * Set the window creation flags appropriately to make the window entirely visible:
547 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
551 * Create the window now, passing the freeglut window structure as the parameter
553 window->Window.Handle = CreateWindow(
558 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
565 * Make sure window was created
567 assert( window->Window.Handle != NULL );
570 * Show and update the main window. Hide the mouse cursor.
572 ShowWindow( window->Window.Handle, fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
573 UpdateWindow( window->Window.Handle );
579 * Save the window's single- or double-buffering state
581 window->Window.DoubleBuffered = ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0 ;
584 * If it's not double-buffered, make sure the rendering is done to the front buffer.
586 if ( ! window->Window.DoubleBuffered )
588 glDrawBuffer ( GL_FRONT ) ;
589 glReadBuffer ( GL_FRONT ) ;
593 * Set the newly created window as the current one
595 fgSetWindow( window );
599 * Closes a window, destroying the frame and OpenGL context
601 void fgCloseWindow( SFG_Window* window )
603 freeglut_assert_ready;
605 #if TARGET_HOST_UNIX_X11
607 * As easy as kill bunnies with axes. Destroy the context first:
609 glXDestroyContext( fgDisplay.Display, window->Window.Context );
612 * Then have the window killed:
614 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
617 * Finally, flush the rests down the stream
619 XFlush( fgDisplay.Display );
621 #elif TARGET_HOST_WIN32
623 * Send the WM_CLOSE message to the window now
626 window->Window.Handle,
636 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
639 * Creates a new top-level freeglut window
641 int FGAPIENTRY glutCreateWindow( const char* title )
644 * Create a new window and return its unique ID number
646 return( fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
647 fgState.Size.X, fgState.Size.Y, FALSE )->ID );
651 * This function creates a sub window.
653 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
655 SFG_Window* window = NULL;
656 SFG_Window* parent = NULL;
658 freeglut_assert_ready;
661 * Find a parent to the newly created window...
663 parent = fgWindowByID( parentID );
666 * Fail if the parent has not been found
668 freeglut_return_val_if_fail( parent != NULL, 0 );
671 * Create the new window
673 window = fgCreateWindow( parent, "", x, y, w, h, FALSE );
676 * Return the new window's ID
678 return( window->ID );
682 * Destroys a window and all of its subwindows
684 void FGAPIENTRY glutDestroyWindow( int windowID )
686 fgExecutionState ExecState = fgState.ExecState ;
689 * Grab the freeglut window pointer from the structure
691 SFG_Window* window = fgWindowByID( windowID );
692 freeglut_return_if_fail( window != NULL );
695 * There is a function that performs all needed steps
696 * defined in freeglut_structure.c. Let's use it:
698 fgAddToWindowDestroyList( window, TRUE );
701 * Since the "fgAddToWindowDestroyList" function could easily have set the "ExecState"
702 * to stop, let's set it back to what it was.
704 fgState.ExecState = ExecState ;
708 * This function selects the current window
710 void FGAPIENTRY glutSetWindow( int ID )
712 SFG_Window* window = NULL;
715 * Make sure we don't get called too early
717 freeglut_assert_ready;
720 * Be wise. Be wise. Be wise. Be quick.
722 if( fgStructure.Window != NULL )
723 if( fgStructure.Window->ID == ID )
727 * Now we are sure there is sense in looking for the window
729 window = fgWindowByID( ID );
732 * In the case of an utter failure...
737 * ...issue a warning message and keep rolling on
739 fgWarning( "glutSetWindow(): window ID %i not found!", ID );
743 fgSetWindow ( window ) ;
747 * This function returns the ID number of the current window, 0 if none exists
749 int FGAPIENTRY glutGetWindow( void )
751 freeglut_assert_ready;
754 * Do we have a current window selected?
756 if( fgStructure.Window == NULL )
759 * Nope. Return zero to mark the state.
765 * Otherwise, return the ID of the current window
767 return( fgStructure.Window->ID );
771 * This function makes the current window visible
773 void FGAPIENTRY glutShowWindow( void )
775 freeglut_assert_ready; freeglut_assert_window;
777 #if TARGET_HOST_UNIX_X11
779 * Showing the window is done via mapping under X
781 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
782 XFlush( fgDisplay.Display );
784 #elif TARGET_HOST_WIN32
786 * Restore the window's originial position and size
788 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
793 * Since the window is visible, we need to redisplay it ...
795 fgStructure.Window->State.Redisplay = TRUE;
800 * This function hides the current window
802 void FGAPIENTRY glutHideWindow( void )
804 freeglut_assert_ready; freeglut_assert_window;
806 #if TARGET_HOST_UNIX_X11
808 * The way we hide a window depends on if we're dealing
809 * with a top-level or children one...
811 if( fgStructure.Window->Parent == NULL )
814 * This is a top-level window
816 XWithdrawWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
821 * Nope, it's a child window
823 XUnmapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
827 * Flush the X state now
829 XFlush( fgDisplay.Display );
831 #elif TARGET_HOST_WIN32
835 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
840 * Since the window is hidden, we don't need to redisplay it ...
842 fgStructure.Window->State.Redisplay = FALSE;
846 * Iconify the current window (top-level windows only)
848 void FGAPIENTRY glutIconifyWindow( void )
850 freeglut_assert_ready; freeglut_assert_window;
852 #if TARGET_HOST_UNIX_X11
854 * Iconify the window and flush the X state
856 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
857 XFlush( fgDisplay.Display );
859 #elif TARGET_HOST_WIN32
861 * Minimize the current window (this should be the same as X window iconifying)
863 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
868 * Since the window is just an icon, we don't need to redisplay it ...
870 fgStructure.Window->State.Redisplay = FALSE;
875 * Set the current window's title
877 void FGAPIENTRY glutSetWindowTitle( const char* title )
879 freeglut_assert_ready; freeglut_assert_window;
882 * Works only for top-level windows
884 if( fgStructure.Window->Parent != NULL )
887 #if TARGET_HOST_UNIX_X11
892 * Prepare the text properties
894 text.value = (unsigned char *) title;
895 text.encoding = XA_STRING;
897 text.nitems = strlen( title );
904 fgStructure.Window->Window.Handle,
909 * Have the X display state flushed
911 XFlush( fgDisplay.Display );
914 #elif TARGET_HOST_WIN32
916 * This seems to be a bit easier under Win32
918 SetWindowText( fgStructure.Window->Window.Handle, title );
924 * Set the current window's iconified title
926 void FGAPIENTRY glutSetIconTitle( const char* title )
928 freeglut_assert_ready; freeglut_assert_window;
931 * Works only for top-level windows
933 if( fgStructure.Window->Parent != NULL )
936 #if TARGET_HOST_UNIX_X11
941 * Prepare the text properties
943 text.value = (unsigned char *) title;
944 text.encoding = XA_STRING;
946 text.nitems = strlen( title );
953 fgStructure.Window->Window.Handle,
958 * Have the X display state flushed
960 XFlush( fgDisplay.Display );
963 #elif TARGET_HOST_WIN32
965 * This seems to be a bit easier under Win32
967 SetWindowText( fgStructure.Window->Window.Handle, title );
973 * Change the current window's size
975 void FGAPIENTRY glutReshapeWindow( int width, int height )
977 freeglut_assert_ready; freeglut_assert_window;
979 #if TARGET_HOST_UNIX_X11
981 * Resize the window and flush the X state
983 XResizeWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, width, height );
984 XFlush( fgDisplay.Display );
986 #elif TARGET_HOST_WIN32
992 * First off, grab the current window's position
994 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
998 if ( fgStructure.Window->Parent == NULL ) /* If this is not a subwindow ... */
1001 * Adjust the size of the window to allow for the size of the frame, if we are not a menu
1003 if ( ! fgStructure.Window->IsMenu )
1005 width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
1006 height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION );
1009 else /* This is a subwindow, get the parent window's position and subtract it off */
1011 GetWindowRect ( fgStructure.Window->Parent->Window.Handle, &winRect ) ;
1012 x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) ;
1013 y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION ) ;
1017 * Resize the window, forcing a redraw to happen
1020 fgStructure.Window->Window.Handle,
1032 * Change the current window's position
1034 void FGAPIENTRY glutPositionWindow( int x, int y )
1036 freeglut_assert_ready; freeglut_assert_window;
1038 #if TARGET_HOST_UNIX_X11
1040 * Reposition the window and flush the X state
1042 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, x, y );
1043 XFlush( fgDisplay.Display );
1045 #elif TARGET_HOST_WIN32
1050 * First off, grab the current window's position
1052 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
1055 * Reposition the window, forcing a redraw to happen
1058 fgStructure.Window->Window.Handle,
1061 winRect.right - winRect.left,
1062 winRect.bottom - winRect.top,
1071 * Lowers the current window (by Z order change)
1073 void FGAPIENTRY glutPushWindow( void )
1075 freeglut_assert_ready; freeglut_assert_window;
1077 #if TARGET_HOST_UNIX_X11
1079 * Lower the current window
1081 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1083 #elif TARGET_HOST_WIN32
1085 * Set the new window's Z position, not affecting the rest of the settings:
1088 fgStructure.Window->Window.Handle,
1091 SWP_NOSIZE | SWP_NOMOVE
1098 * Raises the current window (by Z order change)
1100 void FGAPIENTRY glutPopWindow( void )
1102 freeglut_assert_ready; freeglut_assert_window;
1104 #if TARGET_HOST_UNIX_X11
1106 * Raise the current window
1108 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1110 #elif TARGET_HOST_WIN32
1112 * Set the new window's Z position, not affecting the rest of the settings:
1115 fgStructure.Window->Window.Handle,
1118 SWP_NOSIZE | SWP_NOMOVE
1125 * Resize the current window so that it fits the whole screen
1127 void FGAPIENTRY glutFullScreen( void )
1129 freeglut_assert_ready; freeglut_assert_window;
1131 #if TARGET_HOST_UNIX_X11
1138 fgStructure.Window->Window.Handle,
1140 fgDisplay.ScreenWidth,
1141 fgDisplay.ScreenHeight
1143 XFlush( fgDisplay.Display );
1145 XTranslateCoordinates(
1147 fgStructure.Window->Window.Handle,
1148 fgDisplay.RootWindow,
1156 fgStructure.Window->Window.Handle,
1159 XFlush( fgDisplay.Display );
1162 #elif TARGET_HOST_WIN32
1164 fgStructure.Window->Window.Handle,
1166 fgDisplay.ScreenWidth,
1167 fgDisplay.ScreenHeight,
1174 * A.Donev: Set and retrieve the window's user data
1176 void* FGAPIENTRY glutGetWindowData( void )
1178 return(fgStructure.Window->UserData);
1181 void FGAPIENTRY glutSetWindowData(void* data)
1183 fgStructure.Window->UserData=data;
1186 /*** END OF FILE ***/