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, unsigned char layer_type )
158 PIXELFORMATDESCRIPTOR* ppfd, pfd;
159 int flags, pixelformat;
162 * Check if the window seems valid
164 freeglut_return_val_if_fail( window != NULL, 0 );
167 * The pixel format should allow us to draw to the window using OpenGL
169 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
172 * It might be the case for us to use double buffering
174 if( fgState.DisplayMode & GLUT_DOUBLE )
175 flags |= PFD_DOUBLEBUFFER;
178 * Specify which pixel format do we opt for...
180 # pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
182 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
185 pfd.iPixelType = PFD_TYPE_RGBA;
196 pfd.cAccumRedBits = 0;
197 pfd.cAccumGreenBits = 0;
198 pfd.cAccumBlueBits = 0;
199 pfd.cAccumAlphaBits = 0;
202 pfd.cStencilBits = 0;
205 pfd.cStencilBits = 8;
208 pfd.iLayerType = layer_type;
211 pfd.dwVisibleMask = 0;
212 pfd.dwDamageMask = 0;
215 * Fill in the color bits...
217 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
221 * Choose the pixel format that matches our demand
223 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
224 if( pixelformat == 0 )
228 * We might have been called to check if the pixel format exists only
234 * Finally, set the window's pixel format
236 return ( SetPixelFormat( window->Window.Device, pixelformat, ppfd ) ) ;
241 * Sets the OpenGL context and the fgStructure "Current Window" pointer to the window
242 * structure passed in.
244 void fgSetWindow ( SFG_Window *window )
246 #if TARGET_HOST_UNIX_X11
250 * Make the selected window's GLX context the current one
254 window->Window.Handle,
255 window->Window.Context
258 #elif TARGET_HOST_WIN32
260 * Release the previous' context's device context
262 if( fgStructure.Window != NULL )
263 ReleaseDC( fgStructure.Window->Window.Handle, fgStructure.Window->Window.Device );
268 * We will care about releasing the device context later
270 window->Window.Device = GetDC( window->Window.Handle );
273 * Set the new current context:
276 window->Window.Device,
277 window->Window.Context
283 * Remember that we have changed the current window state
285 fgStructure.Window = window;
290 * Opens a window. Requires a SFG_Window object created and attached
291 * to the freeglut structure. OpenGL context is created here.
293 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow )
295 #if TARGET_HOST_UNIX_X11
296 XSetWindowAttributes winAttr;
297 XTextProperty textProperty;
298 XSizeHints sizeHints;
302 freeglut_assert_ready;
305 * Here we are upon the stage. Have the visual selected.
307 if ( fgState.BuildingAMenu )
310 * If there isn't already an OpenGL rendering context for menu windows, make one
312 if ( !fgStructure.MenuContext )
314 unsigned int current_DisplayMode = fgState.DisplayMode ;
315 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
316 window->Window.VisualInfo = fgChooseVisual();
317 fgState.DisplayMode = current_DisplayMode ;
320 window->Window.VisualInfo = fgChooseVisual();
323 window->Window.VisualInfo = fgChooseVisual();
325 if ( ! window->Window.VisualInfo )
328 * The "fgChooseVisual" returned a null meaning that the visual context is not available.
329 * Try a couple of variations to see if they will work.
331 if ( ! ( fgState.DisplayMode & GLUT_DOUBLE ) )
334 * Single buffering--try it doubled
336 fgState.DisplayMode |= GLUT_DOUBLE ;
337 window->Window.VisualInfo = fgChooseVisual();
338 /* OK, we got a double-buffered window, but we only wanted
339 * single-buffered. Clear the double-buffer flag now.
341 fgState.DisplayMode &= ~GLUT_DOUBLE ;
345 * GLUT also checks for multi-sampling, but I don't see that anywhere else in FREEGLUT
346 * so I won't bother with it for the moment.
350 assert( window->Window.VisualInfo != NULL );
353 * Have the windows attributes set
355 * HINT: the masks should be updated when adding/removing callbacks.
356 * This might speed up message processing. Is that true?
358 winAttr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
359 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease |
360 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
361 PointerMotionMask | ButtonMotionMask;
362 winAttr.background_pixmap = None;
363 winAttr.background_pixel = 0;
364 winAttr.border_pixel = 0;
367 * The color map is required, too
369 winAttr.colormap = XCreateColormap(
370 fgDisplay.Display, fgDisplay.RootWindow,
371 window->Window.VisualInfo->visual, AllocNone
375 * This tells the XCreateWindow() what attributes are we supplying it with
377 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
380 * If this is a menu window we want the window manager to ignore it.
382 if ( fgState.BuildingAMenu )
384 winAttr.override_redirect = True;
385 mask |= CWOverrideRedirect;
389 * Have the window created now
391 window->Window.Handle = XCreateWindow(
393 window->Parent == NULL ? fgDisplay.RootWindow : window->Parent->Window.Handle,
395 window->Window.VisualInfo->depth, InputOutput,
396 window->Window.VisualInfo->visual, mask,
401 * The GLX context creation, possibly trying the direct context rendering
402 * or else use the current context if the user has so specified
404 if ( fgState.BuildingAMenu )
407 * If there isn't already an OpenGL rendering context for menu windows, make one
409 if ( !fgStructure.MenuContext )
411 fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
412 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo ;
413 fgStructure.MenuContext->Context = glXCreateContext(
414 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
415 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
419 /* window->Window.Context = fgStructure.MenuContext->Context ; */
420 window->Window.Context = glXCreateContext(
421 fgDisplay.Display, window->Window.VisualInfo,
422 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
425 else if ( fgState.UseCurrentContext == TRUE )
427 window->Window.Context = glXGetCurrentContext();
429 if ( ! window->Window.Context )
430 window->Window.Context = glXCreateContext(
431 fgDisplay.Display, window->Window.VisualInfo,
432 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
436 window->Window.Context = glXCreateContext(
437 fgDisplay.Display, window->Window.VisualInfo,
438 NULL, fgState.ForceDirectContext | fgState.TryDirectContext
442 * Make sure the context is direct when the user wants it forced
444 if( fgState.ForceDirectContext && !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
445 fgError( "unable to force direct context rendering for window '%s'", title );
448 * Set the new context as the current one. That's all about the window creation.
452 window->Window.Handle,
453 window->Window.Context
457 * Assume the new window is visible by default
459 window->State.Visible = TRUE;
462 * For the position and size hints -- make sure we are passing valid values
466 if (fgState.Position.Use == TRUE) sizeHints.flags |= USPosition;
467 if (fgState.Size.Use == TRUE) sizeHints.flags |= USSize;
470 * Fill in the size hints values now (the x, y, width and height
471 * settings are obsolote, are there any more WMs that support them?)
473 sizeHints.x = x; sizeHints.y = y;
474 sizeHints.width = w; sizeHints.height = h;
477 * We can have forced all new windows start in iconified state:
479 wmHints.flags = StateHint;
480 wmHints.initial_state = (fgState.ForceIconic == FALSE) ? NormalState : IconicState;
483 * Prepare the window and iconified window names...
485 XStringListToTextProperty( (char **) &title, 1, &textProperty );
488 * Set the window's properties now
492 window->Window.Handle,
503 * Make sure we are informed about the window deletion commands
505 XSetWMProtocols( fgDisplay.Display, window->Window.Handle, &fgDisplay.DeleteWindow, 1 );
508 * Finally, have the window mapped to our display
510 XMapWindow( fgDisplay.Display, window->Window.Handle );
512 #elif TARGET_HOST_WIN32
518 freeglut_assert_ready;
521 * Grab the window class we have registered on glutInit():
523 atom = GetClassInfo( fgDisplay.Instance, "FREEGLUT", &wc );
526 if( gameMode == FALSE )
528 if ( ( !isSubWindow ) && ( ! window->IsMenu ) )
531 * Update the window dimensions, taking account of window decorations.
532 * "freeglut" is to create the window with the outside of its border at (x,y)
533 * and with dimensions (w,h).
535 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
536 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 + GetSystemMetrics( SM_CYCAPTION );
540 * Check if the user wants us to use the default position/size
542 if( fgState.Position.Use == FALSE ) { x = CW_USEDEFAULT; y = CW_USEDEFAULT; }
543 if( fgState.Size .Use == FALSE ) { w = CW_USEDEFAULT; h = CW_USEDEFAULT; }
546 * There's a small difference between creating the top, child and game mode windows
548 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
551 * If we're a menu, set our flags to include WS_POPUP to remove decorations
553 if ( window->IsMenu )
555 else if( window->Parent == NULL )
556 flags |= WS_OVERLAPPEDWINDOW;
563 * In game mode, the story is a little bit different...
565 assert( window->Parent == NULL );
568 * Set the window creation flags appropriately to make the window entirely visible:
570 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
574 * Create the window now, passing the freeglut window structure as the parameter
576 window->Window.Handle = CreateWindow(
581 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
588 * Make sure window was created
590 assert( window->Window.Handle != NULL );
593 * Show and update the main window. Hide the mouse cursor.
595 ShowWindow( window->Window.Handle, fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
596 UpdateWindow( window->Window.Handle );
602 * Save the window's single- or double-buffering state
604 window->Window.DoubleBuffered = ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0 ;
607 * If it's not double-buffered, make sure the rendering is done to the front buffer.
609 if ( ! window->Window.DoubleBuffered )
611 glDrawBuffer ( GL_FRONT ) ;
612 glReadBuffer ( GL_FRONT ) ;
616 * Set the newly created window as the current one
618 fgSetWindow( window );
622 * Closes a window, destroying the frame and OpenGL context
624 void fgCloseWindow( SFG_Window* window )
626 freeglut_assert_ready;
628 #if TARGET_HOST_UNIX_X11
630 * As easy as kill bunnies with axes. Destroy the context first:
632 glXDestroyContext( fgDisplay.Display, window->Window.Context );
635 * Then have the window killed:
637 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
640 * Finally, flush the rests down the stream
642 XFlush( fgDisplay.Display );
644 #elif TARGET_HOST_WIN32
646 * Send the WM_CLOSE message to the window now
649 window->Window.Handle,
659 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
662 * Creates a new top-level freeglut window
664 int FGAPIENTRY glutCreateWindow( const char* title )
667 * Create a new window and return its unique ID number
669 return( fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
670 fgState.Size.X, fgState.Size.Y, FALSE )->ID );
674 * This function creates a sub window.
676 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
678 SFG_Window* window = NULL;
679 SFG_Window* parent = NULL;
681 freeglut_assert_ready;
684 * Find a parent to the newly created window...
686 parent = fgWindowByID( parentID );
689 * Fail if the parent has not been found
691 freeglut_return_val_if_fail( parent != NULL, 0 );
694 * Create the new window
696 window = fgCreateWindow( parent, "", x, y, w, h, FALSE );
699 * Return the new window's ID
701 return( window->ID );
705 * Destroys a window and all of its subwindows
707 void FGAPIENTRY glutDestroyWindow( int windowID )
709 fgExecutionState ExecState = fgState.ExecState ;
712 * Grab the freeglut window pointer from the structure
714 SFG_Window* window = fgWindowByID( windowID );
715 freeglut_return_if_fail( window != NULL );
718 * There is a function that performs all needed steps
719 * defined in freeglut_structure.c. Let's use it:
721 fgAddToWindowDestroyList( window, TRUE );
724 * Since the "fgAddToWindowDestroyList" function could easily have set the "ExecState"
725 * to stop, let's set it back to what it was.
727 fgState.ExecState = ExecState ;
731 * This function selects the current window
733 void FGAPIENTRY glutSetWindow( int ID )
735 SFG_Window* window = NULL;
738 * Make sure we don't get called too early
740 freeglut_assert_ready;
743 * Be wise. Be wise. Be wise. Be quick.
745 if( fgStructure.Window != NULL )
746 if( fgStructure.Window->ID == ID )
750 * Now we are sure there is sense in looking for the window
752 window = fgWindowByID( ID );
755 * In the case of an utter failure...
760 * ...issue a warning message and keep rolling on
762 fgWarning( "glutSetWindow(): window ID %i not found!", ID );
766 fgSetWindow ( window ) ;
770 * This function returns the ID number of the current window, 0 if none exists
772 int FGAPIENTRY glutGetWindow( void )
774 freeglut_assert_ready;
777 * Do we have a current window selected?
779 if( fgStructure.Window == NULL )
782 * Nope. Return zero to mark the state.
788 * Otherwise, return the ID of the current window
790 return( fgStructure.Window->ID );
794 * This function makes the current window visible
796 void FGAPIENTRY glutShowWindow( void )
798 freeglut_assert_ready; freeglut_assert_window;
800 #if TARGET_HOST_UNIX_X11
802 * Showing the window is done via mapping under X
804 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
805 XFlush( fgDisplay.Display );
807 #elif TARGET_HOST_WIN32
809 * Restore the window's originial position and size
811 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
816 * Since the window is visible, we need to redisplay it ...
818 fgStructure.Window->State.Redisplay = TRUE;
823 * This function hides the current window
825 void FGAPIENTRY glutHideWindow( void )
827 freeglut_assert_ready; freeglut_assert_window;
829 #if TARGET_HOST_UNIX_X11
831 * The way we hide a window depends on if we're dealing
832 * with a top-level or children one...
834 if( fgStructure.Window->Parent == NULL )
837 * This is a top-level window
839 XWithdrawWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
844 * Nope, it's a child window
846 XUnmapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
850 * Flush the X state now
852 XFlush( fgDisplay.Display );
854 #elif TARGET_HOST_WIN32
858 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
863 * Since the window is hidden, we don't need to redisplay it ...
865 fgStructure.Window->State.Redisplay = FALSE;
869 * Iconify the current window (top-level windows only)
871 void FGAPIENTRY glutIconifyWindow( void )
873 freeglut_assert_ready; freeglut_assert_window;
875 #if TARGET_HOST_UNIX_X11
877 * Iconify the window and flush the X state
879 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.Screen );
880 XFlush( fgDisplay.Display );
882 #elif TARGET_HOST_WIN32
884 * Minimize the current window (this should be the same as X window iconifying)
886 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
891 * Since the window is just an icon, we don't need to redisplay it ...
893 fgStructure.Window->State.Redisplay = FALSE;
898 * Set the current window's title
900 void FGAPIENTRY glutSetWindowTitle( const char* title )
902 freeglut_assert_ready; freeglut_assert_window;
905 * Works only for top-level windows
907 if( fgStructure.Window->Parent != NULL )
910 #if TARGET_HOST_UNIX_X11
915 * Prepare the text properties
917 text.value = (unsigned char *) title;
918 text.encoding = XA_STRING;
920 text.nitems = strlen( title );
927 fgStructure.Window->Window.Handle,
932 * Have the X display state flushed
934 XFlush( fgDisplay.Display );
937 #elif TARGET_HOST_WIN32
939 * This seems to be a bit easier under Win32
941 SetWindowText( fgStructure.Window->Window.Handle, title );
947 * Set the current window's iconified title
949 void FGAPIENTRY glutSetIconTitle( const char* title )
951 freeglut_assert_ready; freeglut_assert_window;
954 * Works only for top-level windows
956 if( fgStructure.Window->Parent != NULL )
959 #if TARGET_HOST_UNIX_X11
964 * Prepare the text properties
966 text.value = (unsigned char *) title;
967 text.encoding = XA_STRING;
969 text.nitems = strlen( title );
976 fgStructure.Window->Window.Handle,
981 * Have the X display state flushed
983 XFlush( fgDisplay.Display );
986 #elif TARGET_HOST_WIN32
988 * This seems to be a bit easier under Win32
990 SetWindowText( fgStructure.Window->Window.Handle, title );
996 * Change the current window's size
998 void FGAPIENTRY glutReshapeWindow( int width, int height )
1000 freeglut_assert_ready; freeglut_assert_window;
1002 #if TARGET_HOST_UNIX_X11
1004 * Resize the window and flush the X state
1006 XResizeWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, width, height );
1007 XFlush( fgDisplay.Display );
1009 #elif TARGET_HOST_WIN32
1015 * First off, grab the current window's position
1017 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
1021 if ( fgStructure.Window->Parent == NULL ) /* If this is not a subwindow ... */
1024 * Adjust the size of the window to allow for the size of the frame, if we are not a menu
1026 if ( ! fgStructure.Window->IsMenu )
1028 width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
1029 height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION );
1032 else /* This is a subwindow, get the parent window's position and subtract it off */
1034 GetWindowRect ( fgStructure.Window->Parent->Window.Handle, &winRect ) ;
1035 x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) ;
1036 y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION ) ;
1040 * Resize the window, forcing a redraw to happen
1043 fgStructure.Window->Window.Handle,
1055 * Change the current window's position
1057 void FGAPIENTRY glutPositionWindow( int x, int y )
1059 freeglut_assert_ready; freeglut_assert_window;
1061 #if TARGET_HOST_UNIX_X11
1063 * Reposition the window and flush the X state
1065 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, x, y );
1066 XFlush( fgDisplay.Display );
1068 #elif TARGET_HOST_WIN32
1073 * First off, grab the current window's position
1075 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
1078 * Reposition the window, forcing a redraw to happen
1081 fgStructure.Window->Window.Handle,
1084 winRect.right - winRect.left,
1085 winRect.bottom - winRect.top,
1094 * Lowers the current window (by Z order change)
1096 void FGAPIENTRY glutPushWindow( void )
1098 freeglut_assert_ready; freeglut_assert_window;
1100 #if TARGET_HOST_UNIX_X11
1102 * Lower the current window
1104 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1106 #elif TARGET_HOST_WIN32
1108 * Set the new window's Z position, not affecting the rest of the settings:
1111 fgStructure.Window->Window.Handle,
1114 SWP_NOSIZE | SWP_NOMOVE
1121 * Raises the current window (by Z order change)
1123 void FGAPIENTRY glutPopWindow( void )
1125 freeglut_assert_ready; freeglut_assert_window;
1127 #if TARGET_HOST_UNIX_X11
1129 * Raise the current window
1131 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
1133 #elif TARGET_HOST_WIN32
1135 * Set the new window's Z position, not affecting the rest of the settings:
1138 fgStructure.Window->Window.Handle,
1141 SWP_NOSIZE | SWP_NOMOVE
1148 * Resize the current window so that it fits the whole screen
1150 void FGAPIENTRY glutFullScreen( void )
1152 freeglut_assert_ready; freeglut_assert_window;
1154 #if TARGET_HOST_UNIX_X11
1161 fgStructure.Window->Window.Handle,
1163 fgDisplay.ScreenWidth,
1164 fgDisplay.ScreenHeight
1166 XFlush( fgDisplay.Display );
1168 XTranslateCoordinates(
1170 fgStructure.Window->Window.Handle,
1171 fgDisplay.RootWindow,
1179 fgStructure.Window->Window.Handle,
1182 XFlush( fgDisplay.Display );
1185 #elif TARGET_HOST_WIN32
1187 fgStructure.Window->Window.Handle,
1189 fgDisplay.ScreenWidth,
1190 fgDisplay.ScreenHeight,
1197 * A.Donev: Set and retrieve the window's user data
1199 void* FGAPIENTRY glutGetWindowData( void )
1201 return(fgStructure.Window->UserData);
1204 void FGAPIENTRY glutSetWindowData(void* data)
1206 fgStructure.Window->UserData=data;
1209 /*** END OF FILE ***/