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.
28 #include <GL/freeglut.h>
29 #include "freeglut_internal.h"
33 #pragma comment( lib, "Aygshell.lib" )
35 static wchar_t* fghWstrFromStr(const char* str)
37 int i,len=strlen(str);
38 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
46 #endif /* TARGET_HOST_WINCE */
49 * TODO BEFORE THE STABLE RELEASE:
51 * fgChooseVisual() -- OK, but what about glutInitDisplayString()?
52 * fgSetupPixelFormat -- ignores the display mode settings
53 * fgOpenWindow() -- check the Win32 version, -iconic handling!
54 * fgCloseWindow() -- check the Win32 version
55 * glutCreateWindow() -- Check when default position and size is {-1,-1}
56 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
57 * glutDestroyWindow() -- check the Win32 version
58 * glutSetWindow() -- check the Win32 version
59 * glutGetWindow() -- OK
60 * glutSetWindowTitle() -- check the Win32 version
61 * glutSetIconTitle() -- check the Win32 version
62 * glutShowWindow() -- check the Win32 version
63 * glutHideWindow() -- check the Win32 version
64 * glutIconifyWindow() -- check the Win32 version
65 * glutReshapeWindow() -- check the Win32 version
66 * glutPositionWindow() -- check the Win32 version
67 * glutPushWindow() -- check the Win32 version
68 * glutPopWindow() -- check the Win32 version
71 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
74 * Chooses a visual basing on the current display mode settings
76 #if TARGET_HOST_UNIX_X11
78 XVisualInfo* fgChooseVisual( void )
80 #define BUFFER_SIZES 6
81 int bufferSize[BUFFER_SIZES] = { 16, 12, 8, 4, 2, 1 };
82 GLboolean wantIndexedMode = GL_FALSE;
86 /* First we have to process the display mode settings... */
88 * XXX Why is there a semi-colon in this #define? The code
89 * XXX that uses the macro seems to always add more semicolons...
91 #define ATTRIB(a) attributes[where++]=a;
92 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
94 if( fgState.DisplayMode & GLUT_INDEX )
96 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
97 wantIndexedMode = GL_TRUE;
102 ATTRIB_VAL( GLX_RED_SIZE, 1 );
103 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
104 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
105 if( fgState.DisplayMode & GLUT_ALPHA )
106 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
109 if( fgState.DisplayMode & GLUT_DOUBLE )
110 ATTRIB( GLX_DOUBLEBUFFER );
112 if( fgState.DisplayMode & GLUT_STEREO )
113 ATTRIB( GLX_STEREO );
115 if( fgState.DisplayMode & GLUT_DEPTH )
116 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
118 if( fgState.DisplayMode & GLUT_STENCIL )
119 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
121 if( fgState.DisplayMode & GLUT_ACCUM )
123 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
124 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
125 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
126 if( fgState.DisplayMode & GLUT_ALPHA )
127 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
130 if( fgState.DisplayMode & GLUT_AUX1 )
131 ATTRIB_VAL( GLX_AUX_BUFFERS, 1 );
132 if( fgState.DisplayMode & GLUT_AUX2 )
133 ATTRIB_VAL( GLX_AUX_BUFFERS, 2 );
134 if( fgState.DisplayMode & GLUT_AUX3 )
135 ATTRIB_VAL( GLX_AUX_BUFFERS, 3 );
136 if( fgState.DisplayMode & GLUT_AUX4 )
137 ATTRIB_VAL( GLX_AUX_BUFFERS, 4 );
140 /* Push a null at the end of the list */
143 if( ! wantIndexedMode )
144 return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
148 XVisualInfo* visualInfo;
152 * In indexed mode, we need to check how many bits of depth can we
153 * achieve. We do this by trying each possibility from the list
154 * given in the {bufferSize} array. If we match, we return to caller.
156 for( i=0; i<BUFFER_SIZES; i++ )
158 attributes[ 1 ] = bufferSize[ i ];
159 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
161 if( visualInfo != NULL )
170 * Setup the pixel format for a Win32 window
172 #if TARGET_HOST_WIN32
173 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
174 unsigned char layer_type )
176 #if TARGET_HOST_WINCE
179 PIXELFORMATDESCRIPTOR* ppfd, pfd;
180 int flags, pixelformat;
182 freeglut_return_val_if_fail( window != NULL, 0 );
183 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
184 if( fgState.DisplayMode & GLUT_DOUBLE )
185 flags |= PFD_DOUBLEBUFFER;
187 if( fgState.DisplayMode & GLUT_STEREO )
190 #if defined(_MSC_VER)
191 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
194 /* Specify which pixel format do we opt for... */
195 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
198 pfd.iPixelType = PFD_TYPE_RGBA;
209 pfd.cAccumRedBits = 0;
210 pfd.cAccumGreenBits = 0;
211 pfd.cAccumBlueBits = 0;
212 pfd.cAccumAlphaBits = 0;
215 pfd.cStencilBits = 0;
218 pfd.cStencilBits = 8;
220 if( fgState.DisplayMode & GLUT_AUX4 )
222 else if( fgState.DisplayMode & GLUT_AUX3 )
224 else if( fgState.DisplayMode & GLUT_AUX2 )
226 else if( fgState.DisplayMode & GLUT_AUX1 )
231 pfd.iLayerType = layer_type;
234 pfd.dwVisibleMask = 0;
235 pfd.dwDamageMask = 0;
237 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
240 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
241 if( pixelformat == 0 )
246 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
247 #endif /* TARGET_HOST_WINCE */
252 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
253 * the window structure passed in.
255 void fgSetWindow ( SFG_Window *window )
257 #if TARGET_HOST_UNIX_X11
261 window->Window.Handle,
262 window->Window.Context
264 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
265 if( fgStructure.CurrentWindow )
266 ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
267 fgStructure.CurrentWindow->Window.Device );
271 window->Window.Device = GetDC( window->Window.Handle );
273 window->Window.Device,
274 window->Window.Context
278 fgStructure.CurrentWindow = window;
283 * Opens a window. Requires a SFG_Window object created and attached
284 * to the freeglut structure. OpenGL context is created here.
286 void fgOpenWindow( SFG_Window* window, const char* title,
287 int x, int y, int w, int h,
288 GLboolean gameMode, GLboolean isSubWindow )
290 #if TARGET_HOST_UNIX_X11
291 XSetWindowAttributes winAttr;
292 XTextProperty textProperty;
293 XSizeHints sizeHints;
296 unsigned int current_DisplayMode = fgState.DisplayMode ;
298 /* Save the display mode if we are creating a menu window */
299 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
300 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
302 window->Window.VisualInfo = fgChooseVisual( );
304 if( window->IsMenu && ( ! fgStructure.MenuContext ) )
305 fgState.DisplayMode = current_DisplayMode ;
307 if( ! window->Window.VisualInfo )
310 * The "fgChooseVisual" returned a null meaning that the visual
311 * context is not available.
312 * Try a couple of variations to see if they will work.
314 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
316 fgState.DisplayMode |= GLUT_DOUBLE ;
317 window->Window.VisualInfo = fgChooseVisual( );
318 fgState.DisplayMode &= ~GLUT_DOUBLE;
322 * GLUT also checks for multi-sampling, but I don't see that
323 * anywhere else in FREEGLUT so I won't bother with it for the moment.
327 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.VisualInfo != NULL,
328 "Visual with necessary capabilities not found", "fgOpenWindow" );
331 * XXX HINT: the masks should be updated when adding/removing callbacks.
332 * XXX This might speed up message processing. Is that true?
334 * XXX A: Not appreciably, but it WILL make it easier to debug.
335 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
336 * XXX turns off events that it doesn't need and is a whole lot
337 * XXX more pleasant to trace. (Think mouse-motion! Tons of
338 * XXX ``bonus'' GUI events stream in.)
341 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
342 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
343 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
344 PointerMotionMask | ButtonMotionMask;
345 winAttr.background_pixmap = None;
346 winAttr.background_pixel = 0;
347 winAttr.border_pixel = 0;
349 winAttr.colormap = XCreateColormap(
350 fgDisplay.Display, fgDisplay.RootWindow,
351 window->Window.VisualInfo->visual, AllocNone
354 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
356 if( window->IsMenu || ( gameMode == GL_TRUE ) )
358 winAttr.override_redirect = True;
359 mask |= CWOverrideRedirect;
362 window->Window.Handle = XCreateWindow(
364 window->Parent == NULL ? fgDisplay.RootWindow :
365 window->Parent->Window.Handle,
367 window->Window.VisualInfo->depth, InputOutput,
368 window->Window.VisualInfo->visual, mask,
373 * The GLX context creation, possibly trying the direct context rendering
374 * or else use the current context if the user has so specified
379 * If there isn't already an OpenGL rendering context for menu
382 if( !fgStructure.MenuContext )
384 fgStructure.MenuContext =
385 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
386 fgStructure.MenuContext->MVisualInfo = window->Window.VisualInfo;
387 fgStructure.MenuContext->MContext = glXCreateContext(
388 fgDisplay.Display, fgStructure.MenuContext->MVisualInfo,
389 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
393 /* window->Window.Context = fgStructure.MenuContext->MContext; */
394 window->Window.Context = glXCreateContext(
395 fgDisplay.Display, window->Window.VisualInfo,
396 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
399 else if( fgState.UseCurrentContext )
401 window->Window.Context = glXGetCurrentContext( );
403 if( ! window->Window.Context )
404 window->Window.Context = glXCreateContext(
405 fgDisplay.Display, window->Window.VisualInfo,
406 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
410 window->Window.Context = glXCreateContext(
411 fgDisplay.Display, window->Window.VisualInfo,
412 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
415 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
416 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
418 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
419 fgError( "Unable to force direct context rendering for window '%s'",
421 else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
422 fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
428 * XXX Assume the new window is visible by default
429 * XXX Is this a safe assumption?
431 window->State.Visible = GL_TRUE;
434 if ( fgState.Position.Use )
435 sizeHints.flags |= USPosition;
436 if ( fgState.Size.Use )
437 sizeHints.flags |= USSize;
440 * Fill in the size hints values now (the x, y, width and height
441 * settings are obsolete, are there any more WMs that support them?)
442 * Unless the X servers actually stop supporting these, we should
443 * continue to fill them in. It is *not* our place to tell the user
444 * that they should replace a window manager that they like, and which
445 * works, just because *we* think that it's not "modern" enough.
450 sizeHints.height = h;
452 wmHints.flags = StateHint;
453 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
454 /* Prepare the window and iconified window names... */
455 XStringListToTextProperty( (char **) &title, 1, &textProperty );
459 window->Window.Handle,
468 XFree( textProperty.value );
470 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
471 &fgDisplay.DeleteWindow, 1 );
475 window->Window.Handle,
476 window->Window.Context
479 XMapWindow( fgDisplay.Display, window->Window.Handle );
481 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
488 /* Grab the window class we have registered on glutInit(): */
489 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
490 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
495 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
496 "Game mode being invoked on a subwindow",
500 * Set the window creation flags appropriately to make the window
503 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
507 #if !TARGET_HOST_WINCE
508 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
511 * Update the window dimensions, taking account of window
512 * decorations. "freeglut" is to create the window with the
513 * outside of its border at (x,y) and with dimensions (w,h).
515 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
516 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
517 GetSystemMetrics( SM_CYCAPTION );
519 #endif /* TARGET_HOST_WINCE */
521 if( ! fgState.Position.Use )
526 if( ! fgState.Size.Use )
533 * There's a small difference between creating the top, child and
536 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
538 if ( window->IsMenu )
541 exFlags |= WS_EX_TOOLWINDOW;
543 #if !TARGET_HOST_WINCE
544 else if( window->Parent == NULL )
545 flags |= WS_OVERLAPPEDWINDOW;
551 #if TARGET_HOST_WINCE
553 wchar_t* wstr = fghWstrFromStr(title);
555 window->Window.Handle = CreateWindow(
558 WS_VISIBLE | WS_POPUP,
568 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
569 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
570 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
571 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
572 ShowWindow(window->Window.Handle, SW_SHOW);
573 UpdateWindow(window->Window.Handle);
576 window->Window.Handle = CreateWindowEx(
582 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
587 #endif /* TARGET_HOST_WINCE */
589 if( !( window->Window.Handle ) )
590 fgError( "Failed to create a window (%s)!", title );
592 #if TARGET_HOST_WINCE
593 ShowWindow( window->Window.Handle, SW_SHOW );
595 ShowWindow( window->Window.Handle,
596 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
597 #endif /* TARGET_HOST_WINCE */
599 UpdateWindow( window->Window.Handle );
600 ShowCursor( TRUE ); /* XXX Old comments say "hide cursor"! */
604 fgSetWindow( window );
606 window->Window.DoubleBuffered =
607 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
609 if ( ! window->Window.DoubleBuffered )
611 glDrawBuffer ( GL_FRONT );
612 glReadBuffer ( GL_FRONT );
617 * Closes a window, destroying the frame and OpenGL context
619 void fgCloseWindow( SFG_Window* window )
621 #if TARGET_HOST_UNIX_X11
623 glXDestroyContext( fgDisplay.Display, window->Window.Context );
624 XFree( window->Window.VisualInfo );
625 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
626 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
628 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
630 /* Make sure we don't close a window with current context active */
631 if( fgStructure.CurrentWindow == window )
632 wglMakeCurrent( NULL, NULL );
635 * Step through the list of windows. If the rendering context
636 * is not being used by another window, then we delete it.
642 for( iter = (SFG_Window *)fgStructure.Windows.First;
644 iter = (SFG_Window *)iter->Node.Next )
646 if( ( iter->Window.Context == window->Window.Context ) &&
652 wglDeleteContext( window->Window.Context );
655 DestroyWindow( window->Window.Handle );
660 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
663 * Creates a new top-level freeglut window
665 int FGAPIENTRY glutCreateWindow( const char* title )
667 /* XXX GLUT does not exit; it simply calls "glutInit" quietly if the
668 * XXX application has not already done so. The "freeglut" community
669 * XXX decided not to go this route (freeglut-developer e-mail from
670 * XXX Steve Baker, 12/16/04, 4:22 PM CST, "Re: [Freeglut-developer]
671 * XXX Desired 'freeglut' behaviour when there is no current window"
673 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
675 return fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
676 fgState.Size.X, fgState.Size.Y, GL_FALSE,
681 * This function creates a sub window.
683 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
686 SFG_Window* window = NULL;
687 SFG_Window* parent = NULL;
689 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
690 parent = fgWindowByID( parentID );
691 freeglut_return_val_if_fail( parent != NULL, 0 );
694 x = parent->State.Width + x ;
695 if ( w >= 0 ) x -= w ;
698 if ( w < 0 ) w = parent->State.Width - x + w ;
707 y = parent->State.Height + y ;
708 if ( h >= 0 ) y -= h ;
711 if ( h < 0 ) h = parent->State.Height - y + h ;
718 window = fgCreateWindow( parent, "", x, y, w, h, GL_FALSE, GL_FALSE );
725 * Destroys a window and all of its subwindows
727 void FGAPIENTRY glutDestroyWindow( int windowID )
730 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
731 window = fgWindowByID( windowID );
732 freeglut_return_if_fail( window != NULL );
734 fgExecutionState ExecState = fgState.ExecState;
735 fgAddToWindowDestroyList( window );
736 fgState.ExecState = ExecState;
741 * This function selects the current window
743 void FGAPIENTRY glutSetWindow( int ID )
745 SFG_Window* window = NULL;
747 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
748 if( fgStructure.CurrentWindow != NULL )
749 if( fgStructure.CurrentWindow->ID == ID )
752 window = fgWindowByID( ID );
755 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
759 fgSetWindow( window );
763 * This function returns the ID number of the current window, 0 if none exists
765 int FGAPIENTRY glutGetWindow( void )
767 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindow" );
768 if( fgStructure.CurrentWindow == NULL )
770 return fgStructure.CurrentWindow->ID;
774 * This function makes the current window visible
776 void FGAPIENTRY glutShowWindow( void )
778 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
779 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
781 #if TARGET_HOST_UNIX_X11
783 XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
784 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
786 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
788 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW );
792 fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
796 * This function hides the current window
798 void FGAPIENTRY glutHideWindow( void )
800 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
801 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
803 #if TARGET_HOST_UNIX_X11
805 if( fgStructure.CurrentWindow->Parent == NULL )
806 XWithdrawWindow( fgDisplay.Display,
807 fgStructure.CurrentWindow->Window.Handle,
810 XUnmapWindow( fgDisplay.Display,
811 fgStructure.CurrentWindow->Window.Handle );
812 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
814 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
816 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE );
820 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
824 * Iconify the current window (top-level windows only)
826 void FGAPIENTRY glutIconifyWindow( void )
828 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
829 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
831 fgStructure.CurrentWindow->State.Visible = GL_FALSE;
832 #if TARGET_HOST_UNIX_X11
834 XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
836 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
838 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
840 ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE );
844 fgStructure.CurrentWindow->State.Redisplay = GL_FALSE;
848 * Set the current window's title
850 void FGAPIENTRY glutSetWindowTitle( const char* title )
852 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
853 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
854 if( ! fgStructure.CurrentWindow->Parent )
856 #if TARGET_HOST_UNIX_X11
860 text.value = (unsigned char *) title;
861 text.encoding = XA_STRING;
863 text.nitems = strlen( title );
867 fgStructure.CurrentWindow->Window.Handle,
871 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
873 #elif TARGET_HOST_WIN32
875 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
877 #elif TARGET_HOST_WINCE
879 wchar_t* wstr = fghWstrFromStr(title);
881 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
890 * Set the current window's iconified title
892 void FGAPIENTRY glutSetIconTitle( const char* title )
894 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
895 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
897 if( ! fgStructure.CurrentWindow->Parent )
899 #if TARGET_HOST_UNIX_X11
903 text.value = (unsigned char *) title;
904 text.encoding = XA_STRING;
906 text.nitems = strlen( title );
910 fgStructure.CurrentWindow->Window.Handle,
914 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
916 #elif TARGET_HOST_WIN32
918 SetWindowText( fgStructure.CurrentWindow->Window.Handle, title );
920 #elif TARGET_HOST_WINCE
922 wchar_t* wstr = fghWstrFromStr(title);
924 SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );
933 * Change the current window's size
935 void FGAPIENTRY glutReshapeWindow( int width, int height )
937 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
938 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
940 fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
941 fgStructure.CurrentWindow->State.Width = width ;
942 fgStructure.CurrentWindow->State.Height = height;
946 * Change the current window's position
948 void FGAPIENTRY glutPositionWindow( int x, int y )
950 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
951 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
953 #if TARGET_HOST_UNIX_X11
955 XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
957 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
959 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
964 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
965 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
967 fgStructure.CurrentWindow->Window.Handle,
970 winRect.right - winRect.left,
971 winRect.bottom - winRect.top,
980 * Lowers the current window (by Z order change)
982 void FGAPIENTRY glutPushWindow( void )
984 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
985 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
987 #if TARGET_HOST_UNIX_X11
989 XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
991 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
994 fgStructure.CurrentWindow->Window.Handle,
997 SWP_NOSIZE | SWP_NOMOVE
1004 * Raises the current window (by Z order change)
1006 void FGAPIENTRY glutPopWindow( void )
1008 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
1009 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
1011 #if TARGET_HOST_UNIX_X11
1013 XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
1015 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1018 fgStructure.CurrentWindow->Window.Handle,
1021 SWP_NOSIZE | SWP_NOMOVE
1028 * Resize the current window so that it fits the whole screen
1030 void FGAPIENTRY glutFullScreen( void )
1032 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
1033 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
1036 #if TARGET_HOST_UNIX_X11
1042 fgStructure.CurrentWindow->Window.Handle,
1044 fgDisplay.ScreenWidth,
1045 fgDisplay.ScreenHeight
1048 XFlush( fgDisplay.Display ); /* This is needed */
1050 XTranslateCoordinates(
1052 fgStructure.CurrentWindow->Window.Handle,
1053 fgDisplay.RootWindow,
1061 fgStructure.CurrentWindow->Window.Handle,
1064 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1066 #elif TARGET_HOST_WIN32
1069 /* For fullscreen mode, force the top-left corner to 0,0
1070 * and adjust the window rectangle so that the client area
1071 * covers the whole screen.
1076 rect.right = fgDisplay.ScreenWidth;
1077 rect.bottom = fgDisplay.ScreenHeight;
1079 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1080 WS_CLIPCHILDREN, FALSE );
1083 * SWP_NOACTIVATE Do not activate the window
1084 * SWP_NOOWNERZORDER Do not change position in z-order
1085 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1086 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1089 SetWindowPos( fgStructure.CurrentWindow->Window.Handle,
1093 rect.right - rect.left,
1094 rect.bottom - rect.top,
1095 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1103 * A.Donev: Set and retrieve the window's user data
1105 void* FGAPIENTRY glutGetWindowData( void )
1107 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1108 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1109 return fgStructure.CurrentWindow->UserData;
1112 void FGAPIENTRY glutSetWindowData(void* data)
1114 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1115 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1116 fgStructure.CurrentWindow->UserData = data;
1119 /*** END OF FILE ***/