Moving some Windows-specific code from "freeglut_gamemode.c" into its own file

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@986 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
fayjf 2012-01-20 03:51:15 +00:00
parent c28372cd99
commit 2b3c51b0bd
2 changed files with 160 additions and 106 deletions

View File

@ -39,6 +39,10 @@
/* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
extern void fghRememberState( void );
extern void fghRestoreState( void );
extern GLboolean fghChangeDisplayMode( GLboolean haveToTest );
#if TARGET_HOST_POSIX_X11 #if TARGET_HOST_POSIX_X11
static int xrandr_resize(int xsz, int ysz, int rate, int just_checking) static int xrandr_resize(int xsz, int ysz, int rate, int just_checking)
@ -154,13 +158,13 @@ static int xrandr_resize(int xsz, int ysz, int rate, int just_checking)
} }
#endif /* TARGET_HOST_POSIX_X11 */ #endif /* TARGET_HOST_POSIX_X11 */
#if TARGET_HOST_POSIX_X11
/* /*
* Remembers the current visual settings, so that * Remembers the current visual settings, so that
* we can change them and restore later... * we can change them and restore later...
*/ */
static void fghRememberState( void ) static void fghRememberState( void )
{ {
#if TARGET_HOST_POSIX_X11
int event_base, error_base; int event_base, error_base;
/* /*
@ -237,31 +241,15 @@ static void fghRememberState( void )
fgWarning( "XF86VidModeGetModeLine failed" ); fgWarning( "XF86VidModeGetModeLine failed" );
# endif # endif
#elif TARGET_HOST_MS_WINDOWS
/* DEVMODE devMode; */
/* Grab the current desktop settings... */
/* hack to get around my stupid cross-gcc headers */
#define FREEGLUT_ENUM_CURRENT_SETTINGS -1
EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS,
&fgDisplay.DisplayMode );
/* Make sure we will be restoring all settings needed */
fgDisplay.DisplayMode.dmFields |=
DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
#endif
} }
#endif
#if TARGET_HOST_POSIX_X11
/* /*
* Restores the previously remembered visual settings * Restores the previously remembered visual settings
*/ */
static void fghRestoreState( void ) static void fghRestoreState( void )
{ {
#if TARGET_HOST_POSIX_X11
/* Restore the remembered pointer position: */ /* Restore the remembered pointer position: */
XWarpPointer( XWarpPointer(
fgDisplay.Display, None, fgDisplay.RootWindow, 0, 0, 0, 0, fgDisplay.Display, None, fgDisplay.RootWindow, 0, 0, 0, 0,
@ -352,13 +340,8 @@ static void fghRestoreState( void )
# endif # endif
#elif TARGET_HOST_MS_WINDOWS
/* Restore the previously remembered desktop display settings */
ChangeDisplaySettingsEx( fgDisplay.DisplayName,&fgDisplay.DisplayMode, 0,0,0 );
#endif
} }
#endif
#if TARGET_HOST_POSIX_X11 #if TARGET_HOST_POSIX_X11
#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
@ -410,14 +393,14 @@ static int fghCheckDisplayModes( GLboolean exactMatch, int displayModesCount, XF
#endif #endif
#endif #endif
#if TARGET_HOST_POSIX_X11
/* /*
* Changes the current display mode to match user's settings * Changes the current display mode to match user's settings
*/ */
static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) static GLboolean fghChangeDisplayMode( GLboolean haveToTest )
{ {
GLboolean success = GL_FALSE; GLboolean success = GL_FALSE;
#if TARGET_HOST_POSIX_X11
/* first try to use XRandR, then fallback to XF86VidMode */ /* first try to use XRandR, then fallback to XF86VidMode */
# ifdef HAVE_X11_EXTENSIONS_XRANDR_H # ifdef HAVE_X11_EXTENSIONS_XRANDR_H
if(xrandr_resize(fgState.GameModeSize.X, fgState.GameModeSize.Y, if(xrandr_resize(fgState.GameModeSize.X, fgState.GameModeSize.Y,
@ -512,88 +495,10 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest )
# endif # endif
#elif TARGET_HOST_MS_WINDOWS
DEVMODE devMode;
char *fggmstr = NULL;
char displayMode[300];
success = GL_FALSE;
EnumDisplaySettings( fgDisplay.DisplayName, -1, &devMode );
devMode.dmFields = 0;
if (fgState.GameModeSize.X!=-1)
{
devMode.dmPelsWidth = fgState.GameModeSize.X;
devMode.dmFields |= DM_PELSWIDTH;
}
if (fgState.GameModeSize.Y!=-1)
{
devMode.dmPelsHeight = fgState.GameModeSize.Y;
devMode.dmFields |= DM_PELSHEIGHT;
}
if (fgState.GameModeDepth!=-1)
{
devMode.dmBitsPerPel = fgState.GameModeDepth;
devMode.dmFields |= DM_BITSPERPEL;
}
if (fgState.GameModeRefresh!=-1)
{
devMode.dmDisplayFrequency = fgState.GameModeRefresh;
devMode.dmFields |= DM_DISPLAYFREQUENCY;
}
switch ( ChangeDisplaySettingsEx(fgDisplay.DisplayName, &devMode, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) )
{
case DISP_CHANGE_SUCCESSFUL:
success = GL_TRUE;
if (!haveToTest)
{
/* update vars in case if windows switched to proper mode */
EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode );
fgState.GameModeSize.X = devMode.dmPelsWidth;
fgState.GameModeSize.Y = devMode.dmPelsHeight;
fgState.GameModeDepth = devMode.dmBitsPerPel;
fgState.GameModeRefresh = devMode.dmDisplayFrequency;
}
break;
case DISP_CHANGE_RESTART:
fggmstr = "The computer must be restarted for the graphics mode to work.";
break;
case DISP_CHANGE_BADFLAGS:
fggmstr = "An invalid set of flags was passed in.";
break;
case DISP_CHANGE_BADPARAM:
fggmstr = "An invalid parameter was passed in. This can include an invalid flag or combination of flags.";
break;
case DISP_CHANGE_FAILED:
fggmstr = "The display driver failed the specified graphics mode.";
break;
case DISP_CHANGE_BADMODE:
fggmstr = "The graphics mode is not supported.";
break;
default:
fggmstr = "Unknown error in graphics mode???"; /* dunno if it is possible,MSDN does not mention any other error */
break;
}
if ( !success )
{
/* I'd rather get info whats going on in my program than wonder about */
/* magic happenings behind my back, its lib for devels at last ;) */
/* append display mode to error to make things more informative */
sprintf(displayMode,"%s Problem with requested mode: %ix%i:%i@%i", fggmstr, devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmDisplayFrequency);
fgWarning(displayMode);
}
#endif
return success; return success;
} }
#endif
/* -- INTERFACE FUNCTIONS -------------------------------------------------- */ /* -- INTERFACE FUNCTIONS -------------------------------------------------- */

View File

@ -0,0 +1,149 @@
/*
* freeglut_cursor_mswin.c
*
* The Windows-specific mouse cursor related stuff.
*
* Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
* Written by John F. Fay, <fayjf@sourceforge.net>
* Creation date: Thu Jan 19, 2012
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <GL/freeglut.h>
#include "freeglut_internal_mswin.h"
/*
* Remembers the current visual settings, so that
* we can change them and restore later...
*/
void fghRememberState( void )
{
/* DEVMODE devMode; */
/* Grab the current desktop settings... */
/* hack to get around my stupid cross-gcc headers */
#define FREEGLUT_ENUM_CURRENT_SETTINGS -1
EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS,
&fgDisplay.DisplayMode );
/* Make sure we will be restoring all settings needed */
fgDisplay.DisplayMode.dmFields |=
DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
}
/*
* Restores the previously remembered visual settings
*/
void fghRestoreState( void )
{
/* Restore the previously remembered desktop display settings */
ChangeDisplaySettingsEx( fgDisplay.DisplayName,&fgDisplay.DisplayMode, 0,0,0 );
}
/*
* Changes the current display mode to match user's settings
*/
GLboolean fghChangeDisplayMode( GLboolean haveToTest )
{
GLboolean success = GL_FALSE;
DEVMODE devMode;
char *fggmstr = NULL;
char displayMode[300];
success = GL_FALSE;
EnumDisplaySettings( fgDisplay.DisplayName, -1, &devMode );
devMode.dmFields = 0;
if (fgState.GameModeSize.X!=-1)
{
devMode.dmPelsWidth = fgState.GameModeSize.X;
devMode.dmFields |= DM_PELSWIDTH;
}
if (fgState.GameModeSize.Y!=-1)
{
devMode.dmPelsHeight = fgState.GameModeSize.Y;
devMode.dmFields |= DM_PELSHEIGHT;
}
if (fgState.GameModeDepth!=-1)
{
devMode.dmBitsPerPel = fgState.GameModeDepth;
devMode.dmFields |= DM_BITSPERPEL;
}
if (fgState.GameModeRefresh!=-1)
{
devMode.dmDisplayFrequency = fgState.GameModeRefresh;
devMode.dmFields |= DM_DISPLAYFREQUENCY;
}
switch ( ChangeDisplaySettingsEx(fgDisplay.DisplayName, &devMode, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) )
{
case DISP_CHANGE_SUCCESSFUL:
success = GL_TRUE;
if (!haveToTest)
{
/* update vars in case if windows switched to proper mode */
EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode );
fgState.GameModeSize.X = devMode.dmPelsWidth;
fgState.GameModeSize.Y = devMode.dmPelsHeight;
fgState.GameModeDepth = devMode.dmBitsPerPel;
fgState.GameModeRefresh = devMode.dmDisplayFrequency;
}
break;
case DISP_CHANGE_RESTART:
fggmstr = "The computer must be restarted for the graphics mode to work.";
break;
case DISP_CHANGE_BADFLAGS:
fggmstr = "An invalid set of flags was passed in.";
break;
case DISP_CHANGE_BADPARAM:
fggmstr = "An invalid parameter was passed in. This can include an invalid flag or combination of flags.";
break;
case DISP_CHANGE_FAILED:
fggmstr = "The display driver failed the specified graphics mode.";
break;
case DISP_CHANGE_BADMODE:
fggmstr = "The graphics mode is not supported.";
break;
default:
fggmstr = "Unknown error in graphics mode???"; /* dunno if it is possible,MSDN does not mention any other error */
break;
}
if ( !success )
{
/* I'd rather get info whats going on in my program than wonder about */
/* magic happenings behind my back, its lib for devels at last ;) */
/* append display mode to error to make things more informative */
sprintf(displayMode,"%s Problem with requested mode: %ix%i:%i@%i", fggmstr, devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmDisplayFrequency);
fgWarning(displayMode);
}
return success;
}