From 479c9255fc38d6a3dbbc423470c5a923505fbe00 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 10 Sep 2010 22:03:36 +0200 Subject: [PATCH] Formatting pass. --- src/win32/win32_enable.c | 70 ++- src/win32/win32_fullscreen.c | 195 ++++---- src/win32/win32_glext.c | 34 +- src/win32/win32_init.c | 172 +++---- src/win32/win32_joystick.c | 159 +++--- src/win32/win32_time.c | 42 +- src/win32/win32_window.c | 929 ++++++++++++++++------------------- 7 files changed, 725 insertions(+), 876 deletions(-) diff --git a/src/win32/win32_enable.c b/src/win32/win32_enable.c index 9bcfad1b..352b0d5c 100644 --- a/src/win32/win32_enable.c +++ b/src/win32/win32_enable.c @@ -31,16 +31,12 @@ #include "internal.h" -//************************************************************************ -//**** GLFW internal functions **** -//************************************************************************ - //======================================================================== // Low level keyboard hook (system callback) function // Used to disable system keys under Windows NT //======================================================================== -static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam ) +static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam) { BOOL syskeys = FALSE; PKBDLLHOOKSTRUCT p; @@ -49,11 +45,11 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam ) // pointer to a KBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam; - if( nCode == HC_ACTION ) + if (nCode == HC_ACTION) { // We have a keyboard event - switch( wParam ) + switch (wParam) { case WM_KEYDOWN: case WM_SYSKEYDOWN: @@ -61,14 +57,14 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam ) case WM_SYSKEYUP: // Detect: ALT+TAB, ALT+ESC, ALT+F4, CTRL+ESC, // LWIN, RWIN, APPS (mysterious menu key) - syskeys = ( p->vkCode == VK_TAB && - p->flags & LLKHF_ALTDOWN ) || - ( p->vkCode == VK_ESCAPE && - p->flags & LLKHF_ALTDOWN ) || - ( p->vkCode == VK_F4 && - p->flags & LLKHF_ALTDOWN ) || - ( p->vkCode == VK_ESCAPE && - (GetKeyState(VK_CONTROL) & 0x8000)) || + syskeys = (p->vkCode == VK_TAB && + p->flags & LLKHF_ALTDOWN) || + (p->vkCode == VK_ESCAPE && + p->flags & LLKHF_ALTDOWN) || + (p->vkCode == VK_F4 && + p->flags & LLKHF_ALTDOWN) || + (p->vkCode == VK_ESCAPE && + (GetKeyState(VK_CONTROL) & 0x8000)) || p->vkCode == VK_LWIN || p->vkCode == VK_RWIN || p->vkCode == VK_APPS; @@ -80,13 +76,11 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam ) } // Was it a system key combination (e.g. ALT+TAB)? - if( syskeys ) + if (syskeys) { // Pass the key event to our window message loop - if( _glfwWin.opened ) - { - PostMessage( _glfwWin.window, (UINT) wParam, p->vkCode, 0 ); - } + if (_glfwWin.opened) + PostMessage(_glfwWin.window, (UINT) wParam, p->vkCode, 0); // We've taken care of it - don't let the system know about this // key event @@ -95,61 +89,59 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam ) else { // It's a harmless key press, let the system deal with it - return CallNextHookEx( _glfwWin.keyboardHook, nCode, wParam, lParam ); + return CallNextHookEx(_glfwWin.keyboardHook, nCode, wParam, lParam); } } - -//************************************************************************ -//**** Platform implementation functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Enable system keys //======================================================================== -void _glfwPlatformEnableSystemKeys( void ) +void _glfwPlatformEnableSystemKeys(void) { BOOL dummy; // Use different methods depending on operating system version - if( _glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4 ) + if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4) { - if( _glfwWin.keyboardHook != NULL ) + if (_glfwWin.keyboardHook != NULL) { - UnhookWindowsHookEx( _glfwWin.keyboardHook ); + UnhookWindowsHookEx(_glfwWin.keyboardHook); _glfwWin.keyboardHook = NULL; } } else - { - (void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0 ); - } + SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0); } + //======================================================================== // Disable system keys //======================================================================== -void _glfwPlatformDisableSystemKeys( void ) +void _glfwPlatformDisableSystemKeys(void) { BOOL dummy; // Use different methods depending on operating system version - if( _glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4 ) + if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4) { // Under Windows NT, install a low level keyboard hook - _glfwWin.keyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL, - keyboardHook, - _glfwLibrary.instance, - 0 ); + _glfwWin.keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, + keyboardHook, + _glfwLibrary.instance, + 0); } else { // Under Windows 95/98/ME, fool Windows that a screensaver // is running => prevents ALT+TAB, CTRL+ESC and CTRL+ALT+DEL - (void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, TRUE, &dummy, 0 ); + SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &dummy, 0); } } diff --git a/src/win32/win32_fullscreen.c b/src/win32/win32_fullscreen.c index 44e1ad01..850ced75 100644 --- a/src/win32/win32_fullscreen.c +++ b/src/win32/win32_fullscreen.c @@ -31,77 +31,102 @@ #include "internal.h" -//************************************************************************ -//**** GLFW internal functions **** -//************************************************************************ - //======================================================================== // Convert BPP to RGB bits based on "best guess" //======================================================================== -static void bpp2rgb( int bpp, int *r, int *g, int *b ) +static void bpp2rgb(int bpp, int* r, int* g, int* b) { int delta; // We assume that by 32 they really meant 24 - if( bpp == 32 ) - { + if (bpp == 32) bpp = 24; - } // Convert "bits per pixel" to red, green & blue sizes *r = *g = *b = bpp / 3; delta = bpp - (*r * 3); - if( delta >= 1 ) - { + if (delta >= 1) *g = *g + 1; - } - if( delta == 2 ) - { + + if (delta == 2) *r = *r + 1; - } } +//======================================================================== +// Return closest video mode by dimensions, refresh rate and channel sizes +//======================================================================== + +static int getClosestVideoMode(int* w, int* h, + int* r, int* g, int* b, + int* refresh) +{ + int bpp, bestmode; + + // Colorbits = sum of red/green/blue bits + bpp = *r + *g + *b; + + // If colorbits < 15 (e.g. 0) or >= 24, default to 32 bpp + if (bpp < 15 || bpp >= 24) + bpp = 32; + + // Find best match + bestmode = _glfwGetClosestVideoModeBPP(w, h, &bpp, refresh); + + // Convert "bits per pixel" to red, green & blue sizes + bpp2rgb(bpp, r, g, b); + + return bestmode; +} + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + //======================================================================== // Return closest video mode by dimensions, refresh rate and bits per pixel //======================================================================== -int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh ) +int _glfwGetClosestVideoModeBPP(int* w, int* h, int* bpp, int* refresh) { - int mode, bestmode, match, bestmatch, rr, bestrr, success; + int mode, bestmode, match, bestmatch, rr, bestrr, success; DEVMODE dm; // Find best match bestmatch = 0x7fffffff; bestrr = 0x7fffffff; mode = bestmode = 0; + do { - dm.dmSize = sizeof( DEVMODE ); - success = EnumDisplaySettings( NULL, mode, &dm ); - if( success ) + dm.dmSize = sizeof(DEVMODE); + success = EnumDisplaySettings(NULL, mode, &dm); + if (success) { match = dm.dmBitsPerPel - *bpp; - if( match < 0 ) match = -match; - match = ( match << 25 ) | - ( (dm.dmPelsWidth - *w) * - (dm.dmPelsWidth - *w) + - (dm.dmPelsHeight - *h) * - (dm.dmPelsHeight - *h) ); - if( match < bestmatch ) + if (match < 0) + match = -match; + + match = (match << 25) | + ((dm.dmPelsWidth - *w) * + (dm.dmPelsWidth - *w) + + (dm.dmPelsHeight - *h) * + (dm.dmPelsHeight - *h)); + if (match < bestmatch) { bestmatch = match; bestmode = mode; bestrr = (dm.dmDisplayFrequency - *refresh) * (dm.dmDisplayFrequency - *refresh); } - else if( match == bestmatch && *refresh > 0 ) + else if (match == bestmatch && *refresh > 0) { rr = (dm.dmDisplayFrequency - *refresh) * (dm.dmDisplayFrequency - *refresh); - if( rr < bestrr ) + if (rr < bestrr) { bestmatch = match; bestmode = mode; @@ -109,13 +134,13 @@ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh ) } } } - mode ++; + mode++; } - while( success ); + while (success); // Get the parameters for the best matching display mode - dm.dmSize = sizeof( DEVMODE ); - (void) EnumDisplaySettings( NULL, bestmode, &dm ); + dm.dmSize = sizeof(DEVMODE); + EnumDisplaySettings(NULL, bestmode, &dm); // Fill out actual width and height *w = dm.dmPelsWidth; @@ -131,72 +156,41 @@ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh ) } -//======================================================================== -// Return closest video mode by dimensions, refresh rate and channel sizes -//======================================================================== - -static int getClosestVideoMode( int *w, int *h, - int *r, int *g, int *b, - int *refresh ) -{ - int bpp, bestmode; - - // Colorbits = sum of red/green/blue bits - bpp = *r + *g + *b; - - // If colorbits < 15 (e.g. 0) or >= 24, default to 32 bpp - if( bpp < 15 || bpp >= 24 ) - { - bpp = 32; - } - - // Find best match - bestmode = _glfwGetClosestVideoModeBPP( w, h, &bpp, refresh ); - - // Convert "bits per pixel" to red, green & blue sizes - bpp2rgb( bpp, r, g, b ); - - return bestmode; -} - - //======================================================================== // Change the current video mode //======================================================================== -void _glfwSetVideoModeMODE( int mode ) +void _glfwSetVideoModeMODE(int mode) { DEVMODE dm; int success; // Get the parameters for the best matching display mode - dm.dmSize = sizeof( DEVMODE ); - (void) EnumDisplaySettings( NULL, mode, &dm ); + dm.dmSize = sizeof(DEVMODE); + EnumDisplaySettings(NULL, mode, &dm); // Set which fields we want to specify dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; // Do we have a prefered refresh rate? - if( _glfwWin.desiredRefreshRate > 0 ) + if (_glfwWin.desiredRefreshRate > 0) { dm.dmFields = dm.dmFields | DM_DISPLAYFREQUENCY; dm.dmDisplayFrequency = _glfwWin.desiredRefreshRate; } // Change display setting - dm.dmSize = sizeof( DEVMODE ); - success = ChangeDisplaySettings( &dm, CDS_FULLSCREEN ); + dm.dmSize = sizeof(DEVMODE); + success = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); // If the mode change was not possible, query the current display // settings (we'll use the desktop resolution for fullscreen mode) - if( success == DISP_CHANGE_SUCCESSFUL ) - { + if (success == DISP_CHANGE_SUCCESSFUL) _glfwWin.modeID = mode; - } else { _glfwWin.modeID = ENUM_REGISTRY_SETTINGS; - EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm ); + EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm); } // Set the window size to that of the display mode @@ -209,27 +203,27 @@ void _glfwSetVideoModeMODE( int mode ) // Change the current video mode //======================================================================== -void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh ) +void _glfwSetVideoMode(int* w, int* h, int r, int g, int b, int refresh) { - int bestmode; + int bestmode; // Find a best match mode - bestmode = getClosestVideoMode( w, h, &r, &g, &b, &refresh ); + bestmode = getClosestVideoMode(w, h, &r, &g, &b, &refresh); // Change mode - _glfwSetVideoModeMODE( bestmode ); + _glfwSetVideoModeMODE(bestmode); } -//************************************************************************ -//**** GLFW user functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Get a list of available video modes //======================================================================== -int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount ) +int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) { int count, success, mode, i, j; int m1, m2, bpp, r, g, b; @@ -238,37 +232,35 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount ) // Loop through all video modes and extract all the UNIQUE modes count = 0; mode = 0; + do { // Get video mode properties - dm.dmSize = sizeof( DEVMODE ); - success = EnumDisplaySettings( NULL, mode, &dm ); + dm.dmSize = sizeof(DEVMODE); + success = EnumDisplaySettings(NULL, mode, &dm); // Is it a valid mode? (only list depths >= 15 bpp) - if( success && dm.dmBitsPerPel >= 15 ) + if (success && dm.dmBitsPerPel >= 15) { // Convert to RGB, and back to bpp ("mask out" alpha bits etc) - bpp2rgb( dm.dmBitsPerPel, &r, &g, &b ); + bpp2rgb(dm.dmBitsPerPel, &r, &g, &b); bpp = r + g + b; // Mode "code" for this mode m1 = (bpp << 25) | (dm.dmPelsWidth * dm.dmPelsHeight); // Insert mode in list (sorted), and avoid duplicates - for( i = 0; i < count; i ++ ) + for (i = 0; i < count; i++) { // Mode "code" for already listed mode - bpp = list[i].redBits + list[i].greenBits + - list[i].blueBits; + bpp = list[i].redBits + list[i].greenBits + list[i].blueBits; m2 = (bpp << 25) | (list[i].width * list[i].height); - if( m1 <= m2 ) - { + if (m1 <= m2) break; - } } // New entry at the end of the list? - if( i >= count ) + if (i >= count) { list[count].width = dm.dmPelsWidth; list[count].height = dm.dmPelsHeight; @@ -278,23 +270,22 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount ) count ++; } // Insert new entry in the list? - else if( m1 < m2 ) + else if (m1 < m2) { - for( j = count; j > i; j -- ) - { - list[j] = list[j-1]; - } + for (j = count; j > i; j--) + list[j] = list[j - 1]; + list[i].width = dm.dmPelsWidth; list[i].height = dm.dmPelsHeight; list[i].redBits = r; list[i].greenBits = g; list[i].blueBits = b; - count ++; + count++; } } - mode ++; + mode++; } - while( success && (count < maxcount) ); + while (success && (count < maxcount)); return count; } @@ -304,17 +295,17 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount ) // Get the desktop video mode //======================================================================== -void _glfwPlatformGetDesktopMode( GLFWvidmode *mode ) +void _glfwPlatformGetDesktopMode(GLFWvidmode* mode) { DEVMODE dm; // Get desktop display mode - dm.dmSize = sizeof( DEVMODE ); - (void) EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm ); + dm.dmSize = sizeof(DEVMODE); + EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm); // Return desktop mode parameters mode->width = dm.dmPelsWidth; mode->height = dm.dmPelsHeight; - bpp2rgb( dm.dmBitsPerPel, &mode->redBits, &mode->greenBits, &mode->blueBits ); + bpp2rgb(dm.dmBitsPerPel, &mode->redBits, &mode->greenBits, &mode->blueBits); } diff --git a/src/win32/win32_glext.c b/src/win32/win32_glext.c index 6454dfa3..6b0c995e 100644 --- a/src/win32/win32_glext.c +++ b/src/win32/win32_glext.c @@ -31,39 +31,35 @@ #include "internal.h" -//************************************************************************ -//**** Platform implementation functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Check if the current context supports the specified WGL extension //======================================================================== -int _glfwPlatformExtensionSupported( const char *extension ) +int _glfwPlatformExtensionSupported(const char* extension) { - const GLubyte *extensions; + const GLubyte* extensions; - if( _glfwWin.GetExtensionsStringEXT != NULL ) + if (_glfwWin.GetExtensionsStringEXT != NULL) { - extensions = (GLubyte *) _glfwWin.GetExtensionsStringEXT(); - if( extensions != NULL ) + extensions = (GLubyte*) _glfwWin.GetExtensionsStringEXT(); + if (extensions != NULL) { - if( _glfwStringInExtensionString( extension, extensions ) ) - { + if (_glfwStringInExtensionString(extension, extensions)) return GL_TRUE; - } } } - if( _glfwWin.GetExtensionsStringARB != NULL ) + if (_glfwWin.GetExtensionsStringARB != NULL) { - extensions = (GLubyte *) _glfwWin.GetExtensionsStringARB( _glfwWin.DC ); - if( extensions != NULL ) + extensions = (GLubyte*) _glfwWin.GetExtensionsStringARB(_glfwWin.DC); + if (extensions != NULL) { - if( _glfwStringInExtensionString( extension, extensions ) ) - { + if (_glfwStringInExtensionString(extension, extensions)) return GL_TRUE; - } } } @@ -75,8 +71,8 @@ int _glfwPlatformExtensionSupported( const char *extension ) // Get the function pointer to an OpenGL function //======================================================================== -void *_glfwPlatformGetProcAddress( const char *procname ) +void* _glfwPlatformGetProcAddress(const char* procname) { - return (void *) wglGetProcAddress( procname ); + return (void*) wglGetProcAddress(procname); } diff --git a/src/win32/win32_init.c b/src/win32/win32_init.c index 60629458..5034b007 100644 --- a/src/win32/win32_init.c +++ b/src/win32/win32_init.c @@ -36,76 +36,69 @@ #endif // __BORLANDC__ - -//************************************************************************ -//**** GLFW internal functions **** -//************************************************************************ - //======================================================================== // Load necessary libraries (DLLs) //======================================================================== -static int _glfwInitLibraries( void ) +static GLboolean initLibraries(void) { // gdi32.dll (OpenGL pixel format functions & SwapBuffers) #ifndef _GLFW_NO_DLOAD_GDI32 - _glfwLibrary.Libs.gdi32 = LoadLibrary( "gdi32.dll" ); - if( _glfwLibrary.Libs.gdi32 != NULL ) + _glfwLibrary.Libs.gdi32 = LoadLibrary("gdi32.dll"); + if (_glfwLibrary.Libs.gdi32 != NULL) { - _glfwLibrary.Libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T) - GetProcAddress( _glfwLibrary.Libs.gdi32, "ChoosePixelFormat" ); + _glfwLibrary.Libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T) + GetProcAddress(_glfwLibrary.Libs.gdi32, "ChoosePixelFormat"); _glfwLibrary.Libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T) - GetProcAddress( _glfwLibrary.Libs.gdi32, "DescribePixelFormat" ); - _glfwLibrary.Libs.GetPixelFormat = (GETPIXELFORMAT_T) - GetProcAddress( _glfwLibrary.Libs.gdi32, "GetPixelFormat" ); - _glfwLibrary.Libs.SetPixelFormat = (SETPIXELFORMAT_T) - GetProcAddress( _glfwLibrary.Libs.gdi32, "SetPixelFormat" ); - _glfwLibrary.Libs.SwapBuffers = (SWAPBUFFERS_T) - GetProcAddress( _glfwLibrary.Libs.gdi32, "SwapBuffers" ); - if( _glfwLibrary.Libs.ChoosePixelFormat == NULL || - _glfwLibrary.Libs.DescribePixelFormat == NULL || - _glfwLibrary.Libs.GetPixelFormat == NULL || - _glfwLibrary.Libs.SetPixelFormat == NULL || - _glfwLibrary.Libs.SwapBuffers == NULL ) + GetProcAddress(_glfwLibrary.Libs.gdi32, "DescribePixelFormat"); + _glfwLibrary.Libs.GetPixelFormat = (GETPIXELFORMAT_T) + GetProcAddress(_glfwLibrary.Libs.gdi32, "GetPixelFormat"); + _glfwLibrary.Libs.SetPixelFormat = (SETPIXELFORMAT_T) + GetProcAddress(_glfwLibrary.Libs.gdi32, "SetPixelFormat"); + _glfwLibrary.Libs.SwapBuffers = (SWAPBUFFERS_T) + GetProcAddress(_glfwLibrary.Libs.gdi32, "SwapBuffers"); + + if (_glfwLibrary.Libs.ChoosePixelFormat && + _glfwLibrary.Libs.DescribePixelFormat && + _glfwLibrary.Libs.GetPixelFormat && + _glfwLibrary.Libs.SetPixelFormat && + _glfwLibrary.Libs.SwapBuffers) { - FreeLibrary( _glfwLibrary.Libs.gdi32 ); + FreeLibrary(_glfwLibrary.Libs.gdi32); _glfwLibrary.Libs.gdi32 = NULL; return GL_FALSE; } } else - { return GL_FALSE; - } #endif // _GLFW_NO_DLOAD_GDI32 // winmm.dll (for joystick and timer support) #ifndef _GLFW_NO_DLOAD_WINMM - _glfwLibrary.Libs.winmm = LoadLibrary( "winmm.dll" ); - if( _glfwLibrary.Libs.winmm != NULL ) + _glfwLibrary.Libs.winmm = LoadLibrary("winmm.dll"); + if (_glfwLibrary.Libs.winmm != NULL) { _glfwLibrary.Libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T) - GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetDevCapsA" ); - _glfwLibrary.Libs.joyGetPos = (JOYGETPOS_T) - GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetPos" ); - _glfwLibrary.Libs.joyGetPosEx = (JOYGETPOSEX_T) - GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetPosEx" ); - _glfwLibrary.Libs.timeGetTime = (TIMEGETTIME_T) - GetProcAddress( _glfwLibrary.Libs.winmm, "timeGetTime" ); - if( _glfwLibrary.Libs.joyGetDevCapsA == NULL || - _glfwLibrary.Libs.joyGetPos == NULL || - _glfwLibrary.Libs.joyGetPosEx == NULL || - _glfwLibrary.Libs.timeGetTime == NULL ) + GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetDevCapsA"); + _glfwLibrary.Libs.joyGetPos = (JOYGETPOS_T) + GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPos"); + _glfwLibrary.Libs.joyGetPosEx = (JOYGETPOSEX_T) + GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPosEx"); + _glfwLibrary.Libs.timeGetTime = (TIMEGETTIME_T) + GetProcAddress(_glfwLibrary.Libs.winmm, "timeGetTime"); + + if (_glfwLibrary.Libs.joyGetDevCapsA && + _glfwLibrary.Libs.joyGetPos && + _glfwLibrary.Libs.joyGetPosEx && + _glfwLibrary.Libs.timeGetTime) { - FreeLibrary( _glfwLibrary.Libs.winmm ); + FreeLibrary(_glfwLibrary.Libs.winmm); _glfwLibrary.Libs.winmm = NULL; return GL_FALSE; } } else - { return GL_FALSE; - } #endif // _GLFW_NO_DLOAD_WINMM return GL_TRUE; @@ -116,22 +109,22 @@ static int _glfwInitLibraries( void ) // Unload used libraries (DLLs) //======================================================================== -static void _glfwFreeLibraries( void ) +static void freeLibraries(void) { // gdi32.dll #ifndef _GLFW_NO_DLOAD_GDI32 - if( _glfwLibrary.Libs.gdi32 != NULL ) + if (_glfwLibrary.Libs.gdi32 != NULL) { - FreeLibrary( _glfwLibrary.Libs.gdi32 ); + FreeLibrary(_glfwLibrary.Libs.gdi32); _glfwLibrary.Libs.gdi32 = NULL; } #endif // _GLFW_NO_DLOAD_GDI32 // winmm.dll #ifndef _GLFW_NO_DLOAD_WINMM - if( _glfwLibrary.Libs.winmm != NULL ) + if (_glfwLibrary.Libs.winmm != NULL) { - FreeLibrary( _glfwLibrary.Libs.winmm ); + FreeLibrary(_glfwLibrary.Libs.winmm); _glfwLibrary.Libs.winmm = NULL; } #endif // _GLFW_NO_DLOAD_WINMM @@ -142,82 +135,65 @@ static void _glfwFreeLibraries( void ) // Terminate GLFW when exiting application //======================================================================== -void _glfwTerminate_atexit( void ) +static void glfw_atexit(void) { glfwTerminate(); } - -//************************************************************************ -//**** Platform implementation functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Initialize various GLFW state //======================================================================== -int _glfwPlatformInit( void ) +int _glfwPlatformInit(void) { OSVERSIONINFO osi; // To make SetForegroundWindow() work as we want, we need to fiddle // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early // as possible in the hope of still being the foreground process) - SystemParametersInfo( SPI_GETFOREGROUNDLOCKTIMEOUT, 0, - &_glfwLibrary.Sys.foregroundLockTimeout, 0 ); - SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0, - SPIF_SENDCHANGE ); + SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, + &_glfwLibrary.Sys.foregroundLockTimeout, 0); + SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, + SPIF_SENDCHANGE); // Check which OS version we are running - osi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); - GetVersionEx( &osi ); + osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osi); + _glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN; - if( osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) + + if (osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { - if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10 ) - { + if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10) _glfwLibrary.Sys.winVer = _GLFW_WIN_95; - } - else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90 ) - { + else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90) _glfwLibrary.Sys.winVer = _GLFW_WIN_98; - } - else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90 ) - { + else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90) _glfwLibrary.Sys.winVer = _GLFW_WIN_ME; - } - else if( osi.dwMajorVersion >= 4 ) - { + else if (osi.dwMajorVersion >= 4) _glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_9x; - } } - else if( osi.dwPlatformId == VER_PLATFORM_WIN32_NT ) + else if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT) { - if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0 ) - { + if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0) _glfwLibrary.Sys.winVer = _GLFW_WIN_NT4; - } - else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0 ) - { + else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0) _glfwLibrary.Sys.winVer = _GLFW_WIN_2K; - } - else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1 ) - { + else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1) _glfwLibrary.Sys.winVer = _GLFW_WIN_XP; - } - else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2 ) - { + else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2) _glfwLibrary.Sys.winVer = _GLFW_WIN_NET_SERVER; - } - else if( osi.dwMajorVersion >= 5 ) - { + else if (osi.dwMajorVersion >= 5) _glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_NT; - } } // Do we have Unicode support? - if( _glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4 ) + if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4) { // Windows NT/2000/XP/.NET has Unicode support _glfwLibrary.Sys.hasUnicode = GL_TRUE; @@ -229,25 +205,23 @@ int _glfwPlatformInit( void ) } // Load libraries (DLLs) - if( !_glfwInitLibraries() ) - { + if (!_glfwInitLibraries()) return GL_FALSE; - } // With the Borland C++ compiler, we want to disable FPU exceptions // (this is recommended for OpenGL applications under Windows) #ifdef __BORLANDC__ - _control87( MCW_EM, MCW_EM ); + _control87(MCW_EM, MCW_EM); #endif // Retrieve GLFW instance handle - _glfwLibrary.instance = GetModuleHandle( NULL ); + _glfwLibrary.instance = GetModuleHandle(NULL); // System keys are not disabled _glfwWin.keyboardHook = NULL; // Install atexit() routine - atexit( _glfwTerminate_atexit ); + atexit(glfw_atexit); // Start the timer _glfwInitTimer(); @@ -260,21 +234,21 @@ int _glfwPlatformInit( void ) // Close window and shut down library //======================================================================== -int _glfwPlatformTerminate( void ) +int _glfwPlatformTerminate(void) { // Close OpenGL window glfwCloseWindow(); // Enable system keys again (if they were disabled) - glfwEnable( GLFW_SYSTEM_KEYS ); + glfwEnable(GLFW_SYSTEM_KEYS); // Unload libraries (DLLs) _glfwFreeLibraries(); // Restore FOREGROUNDLOCKTIMEOUT system setting - SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, - (LPVOID)_glfwLibrary.Sys.foregroundLockTimeout, - SPIF_SENDCHANGE ); + SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, + (LPVOID) _glfwLibrary.Sys.foregroundLockTimeout, + SPIF_SENDCHANGE); return GL_TRUE; } diff --git a/src/win32/win32_joystick.c b/src/win32/win32_joystick.c index d30469e0..74855ca3 100644 --- a/src/win32/win32_joystick.c +++ b/src/win32/win32_joystick.c @@ -31,36 +31,30 @@ #include "internal.h" -//************************************************************************ -//**** GLFW internal functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Return GL_TRUE if joystick is present, else return GL_FALSE. //======================================================================== -static int _glfwJoystickPresent( int joy ) +static GLboolean isJoystickPresent(int joy) { JOYINFO ji; // Windows NT 4.0 MMSYSTEM only supports 2 sticks (other Windows // versions support 16 sticks) - if( _glfwLibrary.Sys.winVer == _GLFW_WIN_NT4 && joy > GLFW_JOYSTICK_2 ) - { + if (_glfwLibrary.Sys.winVer == _GLFW_WIN_NT4 && joy > GLFW_JOYSTICK_2) return GL_FALSE; - } // Is it a valid stick ID (Windows don't support more than 16 sticks)? - if( joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16 ) - { + if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16) return GL_FALSE; - } // Is the joystick present? - if( _glfw_joyGetPos( joy - GLFW_JOYSTICK_1, &ji ) != JOYERR_NOERROR ) - { + if (_glfw_joyGetPos(joy - GLFW_JOYSTICK_1, &ji) != JOYERR_NOERROR) return GL_FALSE; - } return GL_TRUE; } @@ -70,57 +64,50 @@ static int _glfwJoystickPresent( int joy ) // Calculate joystick position //======================================================================== -static float _glfwCalcJoystickPos( DWORD pos, DWORD min, DWORD max ) +static float calcJoystickPos(DWORD pos, DWORD min, DWORD max) { float fpos = (float) pos; float fmin = (float) min; float fmax = (float) max; - return (2.0f*(fpos - fmin) / (fmax - fmin)) - 1.0f; + + return (2.f * (fpos - fmin) / (fmax - fmin)) - 1.f; } - -//************************************************************************ -//**** Platform implementation functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Determine joystick capabilities //======================================================================== -int _glfwPlatformGetJoystickParam( int joy, int param ) +int _glfwPlatformGetJoystickParam(int joy, int param) { JOYCAPS jc; -// return 0; - - // Is joystick present? - if( !_glfwJoystickPresent( joy ) ) - { + if (!isJoystickPresent(joy)) return 0; - } // We got this far, the joystick is present - if( param == GLFW_PRESENT ) - { + if (param == GLFW_PRESENT) return GL_TRUE; - } // Get joystick capabilities - _glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) ); + _glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS)); - switch( param ) + switch (param) { - case GLFW_AXES: - // Return number of joystick axes - return jc.wNumAxes; + case GLFW_AXES: + // Return number of joystick axes + return jc.wNumAxes; - case GLFW_BUTTONS: - // Return number of joystick axes - return jc.wNumButtons; + case GLFW_BUTTONS: + // Return number of joystick axes + return jc.wNumButtons; - default: - break; + default: + break; } return 0; @@ -131,63 +118,44 @@ int _glfwPlatformGetJoystickParam( int joy, int param ) // Get joystick axis positions //======================================================================== -int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes ) +int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) { - JOYCAPS jc; + JOYCAPS jc; JOYINFOEX ji; - int axis; + int axis; -// return 0; - - // Is joystick present? - if( !_glfwJoystickPresent( joy ) ) - { + if (!isJoystickPresent(joy)) return 0; - } // Get joystick capabilities - _glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) ); + _glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS)); // Get joystick state - ji.dwSize = sizeof( JOYINFOEX ); + ji.dwSize = sizeof(JOYINFOEX); ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV; - _glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji ); + _glfw_joyGetPosEx(joy - GLFW_JOYSTICK_1, &ji); // Get position values for all axes axis = 0; - if( axis < numaxes ) - { - pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwXpos, jc.wXmin, - jc.wXmax ); - } - if( axis < numaxes ) - { - pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwYpos, jc.wYmin, - jc.wYmax ); - } - if( axis < numaxes && jc.wCaps & JOYCAPS_HASZ ) - { - pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwZpos, jc.wZmin, - jc.wZmax ); - } - if( axis < numaxes && jc.wCaps & JOYCAPS_HASR ) - { - pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwRpos, jc.wRmin, - jc.wRmax ); - } - if( axis < numaxes && jc.wCaps & JOYCAPS_HASU ) - { - pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwUpos, jc.wUmin, - jc.wUmax ); - } - if( axis < numaxes && jc.wCaps & JOYCAPS_HASV ) - { - pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwVpos, jc.wVmin, - jc.wVmax ); - } + if (axis < numaxes) + pos[axis++] = _glfwCalcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax); + + if (axis < numaxes) + pos[axis++] = -_glfwCalcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax); + + if (axis < numaxes && jc.wCaps & JOYCAPS_HASZ) + pos[axis++] = _glfwCalcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax); + + if (axis < numaxes && jc.wCaps & JOYCAPS_HASR) + pos[axis++] = _glfwCalcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax); + + if (axis < numaxes && jc.wCaps & JOYCAPS_HASU) + pos[axis++] = _glfwCalcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax); + + if (axis < numaxes && jc.wCaps & JOYCAPS_HASV) + pos[axis++] = -_glfwCalcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax); - // Return number of returned axes return axis; } @@ -196,36 +164,31 @@ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes ) // Get joystick button states //======================================================================== -int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons, - int numbuttons ) +int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, + int numbuttons) { - JOYCAPS jc; + JOYCAPS jc; JOYINFOEX ji; - int button; + int button; -// return 0; - - // Is joystick present? - if( !_glfwJoystickPresent( joy ) ) - { + if (!isJoystickPresent(joy)) return 0; - } // Get joystick capabilities - _glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) ); + _glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS)); // Get joystick state - ji.dwSize = sizeof( JOYINFOEX ); + ji.dwSize = sizeof(JOYINFOEX); ji.dwFlags = JOY_RETURNBUTTONS; - _glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji ); + _glfw_joyGetPosEx(joy - GLFW_JOYSTICK_1, &ji); // Get states of all requested buttons button = 0; - while( button < numbuttons && button < (int) jc.wNumButtons ) + while (button < numbuttons && button < (int) jc.wNumButtons) { - buttons[ button ] = (unsigned char) + buttons[button] = (unsigned char) (ji.dwButtons & (1UL << button) ? GLFW_PRESS : GLFW_RELEASE); - button ++; + button++; } return button; diff --git a/src/win32/win32_time.c b/src/win32/win32_time.c index 7c52f011..d11e5d4d 100644 --- a/src/win32/win32_time.c +++ b/src/win32/win32_time.c @@ -31,29 +31,29 @@ #include "internal.h" -//************************************************************************ -//**** GLFW internal functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Initialise timer //======================================================================== -void _glfwInitTimer( void ) +void _glfwInitTimer(void) { __int64 freq; // Check if we have a performance counter - if( QueryPerformanceFrequency( (LARGE_INTEGER *)&freq ) ) + if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq)) { // Performance counter is available => use it! _glfwLibrary.Timer.HasPerformanceCounter = GL_TRUE; // Counter resolution is 1 / counter frequency - _glfwLibrary.Timer.Resolution = 1.0 / (double)freq; + _glfwLibrary.Timer.Resolution = 1.0 / (double) freq; // Set start time for timer - QueryPerformanceCounter( (LARGE_INTEGER *)&_glfwLibrary.Timer.t0_64 ); + QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Timer.t0_64); } else { @@ -69,28 +69,26 @@ void _glfwInitTimer( void ) } -//************************************************************************ -//**** Platform implementation functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Return timer value in seconds //======================================================================== -double _glfwPlatformGetTime( void ) +double _glfwPlatformGetTime(void) { - double t; + double t; __int64 t_64; - if( _glfwLibrary.Timer.HasPerformanceCounter ) + if (_glfwLibrary.Timer.HasPerformanceCounter) { - QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 ); + QueryPerformanceCounter((LARGE_INTEGER*) &t_64); t = (double)(t_64 - _glfwLibrary.Timer.t0_64); } else - { t = (double)(_glfw_timeGetTime() - _glfwLibrary.Timer.t0_32); - } // Calculate the current time in seconds return t * _glfwLibrary.Timer.Resolution; @@ -101,18 +99,16 @@ double _glfwPlatformGetTime( void ) // Set timer value in seconds //======================================================================== -void _glfwPlatformSetTime( double t ) +void _glfwPlatformSetTime(double t) { __int64 t_64; - if( _glfwLibrary.Timer.HasPerformanceCounter ) + if (_glfwLibrary.Timer.HasPerformanceCounter) { - QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 ); - _glfwLibrary.Timer.t0_64 = t_64 - (__int64)(t/_glfwLibrary.Timer.Resolution); + QueryPerformanceCounter((LARGE_INTEGER*) &t_64); + _glfwLibrary.Timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Timer.Resolution); } else - { - _glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t*1000.0); - } + _glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0); } diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c index ff3a89c5..6f5e22fa 100644 --- a/src/win32/win32_window.c +++ b/src/win32/win32_window.c @@ -31,36 +31,31 @@ #include "internal.h" - -//************************************************************************ -//**** GLFW internal functions **** -//************************************************************************ - // We use versioned window class names in order not to cause conflicts // between applications using different versions of GLFW -#define _GLFW_WNDCLASSNAME "GLFW27" +#define _GLFW_WNDCLASSNAME "GLFW30" //======================================================================== // Enable/disable minimize/restore animations //======================================================================== -static int setMinMaxAnimations( int enable ) +static int setMinMaxAnimations(int enable) { ANIMATIONINFO AI; int old_enable; // Get old animation setting - AI.cbSize = sizeof( ANIMATIONINFO ); - SystemParametersInfo( SPI_GETANIMATION, AI.cbSize, &AI, 0 ); + AI.cbSize = sizeof(ANIMATIONINFO); + SystemParametersInfo(SPI_GETANIMATION, AI.cbSize, &AI, 0); old_enable = AI.iMinAnimate; // If requested, change setting - if( old_enable != enable ) + if (old_enable != enable) { AI.iMinAnimate = enable; - SystemParametersInfo( SPI_SETANIMATION, AI.cbSize, &AI, - SPIF_SENDCHANGE ); + SystemParametersInfo(SPI_SETANIMATION, AI.cbSize, &AI, + SPIF_SENDCHANGE); } return old_enable; @@ -73,22 +68,22 @@ static int setMinMaxAnimations( int enable ) // we have to go through some really bizarre measures to achieve this //======================================================================== -static void setForegroundWindow( HWND hWnd ) +static void setForegroundWindow(HWND hWnd) { int try_count = 0; int old_animate; // Try the standard approach first... - BringWindowToTop( hWnd ); - SetForegroundWindow( hWnd ); + BringWindowToTop(hWnd); + SetForegroundWindow(hWnd); // If it worked, return now - if( hWnd == GetForegroundWindow() ) + if (hWnd == GetForegroundWindow()) { // Try to modify the system settings (since this is the foreground // process, we are allowed to do this) - SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0, - SPIF_SENDCHANGE ); + SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, + SPIF_SENDCHANGE); return; } @@ -99,33 +94,33 @@ static void setForegroundWindow( HWND hWnd ) // zoom animations to make it look a bit better at least). // Turn off minimize/restore animations - old_animate = setMinMaxAnimations( 0 ); + old_animate = setMinMaxAnimations(0); // We try this a few times, just to be on the safe side of things... do { // Iconify & restore - ShowWindow( hWnd, SW_HIDE ); - ShowWindow( hWnd, SW_SHOWMINIMIZED ); - ShowWindow( hWnd, SW_SHOWNORMAL ); + ShowWindow(hWnd, SW_HIDE); + ShowWindow(hWnd, SW_SHOWMINIMIZED); + ShowWindow(hWnd, SW_SHOWNORMAL); // Try to get focus - BringWindowToTop( hWnd ); - SetForegroundWindow( hWnd ); + BringWindowToTop(hWnd); + SetForegroundWindow(hWnd); // We do not want to keep going on forever, so we keep track of // how many times we tried - try_count ++; + try_count++; } - while( hWnd != GetForegroundWindow() && try_count <= 3 ); + while (hWnd != GetForegroundWindow() && try_count <= 3); // Restore the system minimize/restore animation setting - (void) setMinMaxAnimations( old_animate ); + setMinMaxAnimations(old_animate); // Try to modify the system settings (since this is now hopefully the // foreground process, we are probably allowed to do this) - SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0, - SPIF_SENDCHANGE ); + SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, + SPIF_SENDCHANGE); } @@ -138,7 +133,7 @@ static int getPixelFormatAttrib(int pixelFormat, int attrib) { int value = 0; - if( !_glfwWin.GetPixelFormatAttribivARB( _glfwWin.DC, pixelFormat, 0, 1, &attrib, &value) ) + if (!_glfwWin.GetPixelFormatAttribivARB(_glfwWin.DC, pixelFormat, 0, 1, &attrib, &value)) { // NOTE: We should probably handle this error somehow return 0; @@ -152,109 +147,95 @@ static int getPixelFormatAttrib(int pixelFormat, int attrib) // Return a list of available and usable framebuffer configs //======================================================================== -static _GLFWfbconfig *getFBConfigs( unsigned int *found ) +static _GLFWfbconfig* getFBConfigs(unsigned int* found) { - _GLFWfbconfig *result; + _GLFWfbconfig* result; PIXELFORMATDESCRIPTOR pfd; int i, count; *found = 0; - if( _glfwWin.has_WGL_ARB_pixel_format ) - { - count = getPixelFormatAttrib( 1, WGL_NUMBER_PIXEL_FORMATS_ARB ); - } + if (_glfwWin.has_WGL_ARB_pixel_format) + count = getPixelFormatAttrib(1, WGL_NUMBER_PIXEL_FORMATS_ARB); else - { - count = _glfw_DescribePixelFormat( _glfwWin.DC, 1, sizeof( PIXELFORMATDESCRIPTOR ), NULL ); - } + count = _glfw_DescribePixelFormat(_glfwWin.DC, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); - if( !count ) + if (!count) { - fprintf( stderr, "No Win32 pixel formats available\n" ); + fprintf(stderr, "No Win32 pixel formats available\n"); return NULL; } - result = (_GLFWfbconfig*) malloc( sizeof( _GLFWfbconfig ) * count ); - if( !result ) + result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); + if (!result) { - fprintf(stderr, "Out of memory"); + fprintf(stderr, "Out of memory\n"); return NULL; } - for( i = 1; i <= count; i++ ) + for (i = 1; i <= count; i++) { - if( _glfwWin.has_WGL_ARB_pixel_format ) + if (_glfwWin.has_WGL_ARB_pixel_format) { // Get pixel format attributes through WGL_ARB_pixel_format - if( !getPixelFormatAttrib( i, WGL_SUPPORT_OPENGL_ARB ) || - !getPixelFormatAttrib( i, WGL_DRAW_TO_WINDOW_ARB ) || - !getPixelFormatAttrib( i, WGL_DOUBLE_BUFFER_ARB ) ) + // Only consider doublebuffered OpenGL pixel formats for windows + if (!getPixelFormatAttrib(i, WGL_SUPPORT_OPENGL_ARB) || + !getPixelFormatAttrib(i, WGL_DRAW_TO_WINDOW_ARB) || + !getPixelFormatAttrib(i, WGL_DOUBLE_BUFFER_ARB)) { - // Only consider doublebuffered OpenGL pixel formats for windows continue; } - if( getPixelFormatAttrib( i, WGL_PIXEL_TYPE_ARB ) != WGL_TYPE_RGBA_ARB ) - { - // Only consider RGBA pixel formats + // Only consider RGBA pixel formats + if (getPixelFormatAttrib(i, WGL_PIXEL_TYPE_ARB) != WGL_TYPE_RGBA_ARB) continue; - } - result[*found].redBits = getPixelFormatAttrib( i, WGL_RED_BITS_ARB ); - result[*found].greenBits = getPixelFormatAttrib( i, WGL_GREEN_BITS_ARB ); - result[*found].blueBits = getPixelFormatAttrib( i, WGL_BLUE_BITS_ARB ); - result[*found].alphaBits = getPixelFormatAttrib( i, WGL_ALPHA_BITS_ARB ); + result[*found].redBits = getPixelFormatAttrib(i, WGL_RED_BITS_ARB); + result[*found].greenBits = getPixelFormatAttrib(i, WGL_GREEN_BITS_ARB); + result[*found].blueBits = getPixelFormatAttrib(i, WGL_BLUE_BITS_ARB); + result[*found].alphaBits = getPixelFormatAttrib(i, WGL_ALPHA_BITS_ARB); - result[*found].depthBits = getPixelFormatAttrib( i, WGL_DEPTH_BITS_ARB ); - result[*found].stencilBits = getPixelFormatAttrib( i, WGL_STENCIL_BITS_ARB ); + result[*found].depthBits = getPixelFormatAttrib(i, WGL_DEPTH_BITS_ARB); + result[*found].stencilBits = getPixelFormatAttrib(i, WGL_STENCIL_BITS_ARB); - result[*found].accumRedBits = getPixelFormatAttrib( i, WGL_ACCUM_RED_BITS_ARB ); - result[*found].accumGreenBits = getPixelFormatAttrib( i, WGL_ACCUM_GREEN_BITS_ARB ); - result[*found].accumBlueBits = getPixelFormatAttrib( i, WGL_ACCUM_BLUE_BITS_ARB ); - result[*found].accumAlphaBits = getPixelFormatAttrib( i, WGL_ACCUM_ALPHA_BITS_ARB ); + result[*found].accumRedBits = getPixelFormatAttrib(i, WGL_ACCUM_RED_BITS_ARB); + result[*found].accumGreenBits = getPixelFormatAttrib(i, WGL_ACCUM_GREEN_BITS_ARB); + result[*found].accumBlueBits = getPixelFormatAttrib(i, WGL_ACCUM_BLUE_BITS_ARB); + result[*found].accumAlphaBits = getPixelFormatAttrib(i, WGL_ACCUM_ALPHA_BITS_ARB); - result[*found].auxBuffers = getPixelFormatAttrib( i, WGL_AUX_BUFFERS_ARB ); - result[*found].stereo = getPixelFormatAttrib( i, WGL_STEREO_ARB ); + result[*found].auxBuffers = getPixelFormatAttrib(i, WGL_AUX_BUFFERS_ARB); + result[*found].stereo = getPixelFormatAttrib(i, WGL_STEREO_ARB); - if( _glfwWin.has_WGL_ARB_multisample ) - { - result[*found].samples = getPixelFormatAttrib( i, WGL_SAMPLES_ARB ); - } + if (_glfwWin.has_WGL_ARB_multisample) + result[*found].samples = getPixelFormatAttrib(i, WGL_SAMPLES_ARB); else - { result[*found].samples = 0; - } } else { // Get pixel format attributes through old-fashioned PFDs - if( !_glfw_DescribePixelFormat( _glfwWin.DC, i, sizeof( PIXELFORMATDESCRIPTOR ), &pfd ) ) + if (!_glfw_DescribePixelFormat(_glfwWin.DC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) + continue; + + // Only consider doublebuffered OpenGL pixel formats for windows + if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) || + !(pfd.dwFlags & PFD_SUPPORT_OPENGL) || + !(pfd.dwFlags & PFD_DOUBLEBUFFER)) { continue; } - if( !( pfd.dwFlags & PFD_DRAW_TO_WINDOW ) || - !( pfd.dwFlags & PFD_SUPPORT_OPENGL ) || - !( pfd.dwFlags & PFD_DOUBLEBUFFER ) ) - { - // Only consider doublebuffered OpenGL pixel formats for windows - continue; - } - - if( !( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) && - ( pfd.dwFlags & PFD_GENERIC_FORMAT ) ) + if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) && + (pfd.dwFlags & PFD_GENERIC_FORMAT)) { continue; } - if( pfd.iPixelType != PFD_TYPE_RGBA ) - { - // Only RGBA pixel formats considered + // Only RGBA pixel formats considered + if (pfd.iPixelType != PFD_TYPE_RGBA) continue; - } result[*found].redBits = pfd.cRedBits; result[*found].greenBits = pfd.cGreenBits; @@ -270,7 +251,7 @@ static _GLFWfbconfig *getFBConfigs( unsigned int *found ) result[*found].accumAlphaBits = pfd.cAccumAlphaBits; result[*found].auxBuffers = pfd.cAuxBuffers; - result[*found].stereo = ( pfd.dwFlags & PFD_STEREO ) ? GL_TRUE : GL_FALSE; + result[*found].stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; // PFD pixel formats do not support FSAA result[*found].samples = 0; @@ -289,26 +270,22 @@ static _GLFWfbconfig *getFBConfigs( unsigned int *found ) // Creates an OpenGL context on the specified device context //======================================================================== -static HGLRC createContext( HDC dc, const _GLFWwndconfig* wndconfig, int pixelFormat ) +static HGLRC createContext(HDC dc, const _GLFWwndconfig* wndconfig, int pixelFormat) { PIXELFORMATDESCRIPTOR pfd; int flags, i = 0, attribs[7]; - if( !_glfw_DescribePixelFormat( dc, pixelFormat, sizeof(pfd), &pfd ) ) - { + if (!_glfw_DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd)) return NULL; - } - if( !_glfw_SetPixelFormat( dc, pixelFormat, &pfd ) ) - { + if (!_glfw_SetPixelFormat(dc, pixelFormat, &pfd)) return NULL; - } - if( _glfwWin.has_WGL_ARB_create_context ) + if (_glfwWin.has_WGL_ARB_create_context) { // Use the newer wglCreateContextAttribsARB - if( wndconfig->glMajor != 1 || wndconfig->glMinor != 0 ) + if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0) { // Request an explicitly versioned context @@ -318,34 +295,26 @@ static HGLRC createContext( HDC dc, const _GLFWwndconfig* wndconfig, int pixelFo attribs[i++] = wndconfig->glMinor; } - if( wndconfig->glForward || wndconfig->glDebug ) + if (wndconfig->glForward || wndconfig->glDebug) { flags = 0; - if( wndconfig->glForward ) - { + if (wndconfig->glForward) flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - } - if( wndconfig->glDebug ) - { + if (wndconfig->glDebug) flags |= WGL_CONTEXT_DEBUG_BIT_ARB; - } attribs[i++] = WGL_CONTEXT_FLAGS_ARB; attribs[i++] = flags; } - if( wndconfig->glProfile ) + if (wndconfig->glProfile) { - if( wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE ) - { + if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) flags = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; - } else - { flags = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - } attribs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB; attribs[i++] = flags; @@ -353,10 +322,10 @@ static HGLRC createContext( HDC dc, const _GLFWwndconfig* wndconfig, int pixelFo attribs[i++] = 0; - return _glfwWin.CreateContextAttribsARB( dc, NULL, attribs ); + return _glfwWin.CreateContextAttribsARB(dc, NULL, attribs); } - return wglCreateContext( dc ); + return wglCreateContext(dc); } @@ -364,7 +333,7 @@ static HGLRC createContext( HDC dc, const _GLFWwndconfig* wndconfig, int pixelFo // Translates a Windows key to the corresponding GLFW key //======================================================================== -static int translateKey( WPARAM wParam, LPARAM lParam ) +static int translateKey(WPARAM wParam, LPARAM lParam) { MSG next_msg; DWORD msg_time; @@ -373,11 +342,11 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) // Check for numeric keypad keys // Note: This way we always force "NumLock = ON", which at least // enables GLFW users to detect numeric keypad keys - int hiFlags = HIWORD( lParam ); + int hiFlags = HIWORD(lParam); - if ( !( hiFlags & 0x100 ) ) + if (!(hiFlags & 0x100)) { - switch( MapVirtualKey( hiFlags & 0xFF, 1 ) ) + switch (MapVirtualKey(hiFlags & 0xFF, 1)) { case VK_INSERT: return GLFW_KEY_KP_0; case VK_END: return GLFW_KEY_KP_1; @@ -398,7 +367,7 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) } // Check which key was pressed or released - switch( wParam ) + switch (wParam) { // The SHIFT keys require special handling case VK_SHIFT: @@ -406,11 +375,9 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) // Compare scan code for this key with that of VK_RSHIFT in // order to determine which shift key was pressed (left or // right) - scan_code = MapVirtualKey( VK_RSHIFT, 0 ); - if( ((lParam & 0x01ff0000) >> 16) == scan_code ) - { + scan_code = MapVirtualKey(VK_RSHIFT, 0); + if (((lParam & 0x01ff0000) >> 16) == scan_code) return GLFW_KEY_RSHIFT; - } return GLFW_KEY_LSHIFT; } @@ -419,23 +386,21 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) case VK_CONTROL: { // Is this an extended key (i.e. right key)? - if( lParam & 0x01000000 ) - { + if (lParam & 0x01000000) return GLFW_KEY_RCTRL; - } // Here is a trick: "Alt Gr" sends LCTRL, then RALT. We only // want the RALT message, so we try to see if the next message // is a RALT message. In that case, this is a false LCTRL! msg_time = GetMessageTime(); - if( PeekMessage( &next_msg, NULL, 0, 0, PM_NOREMOVE ) ) + if (PeekMessage(&next_msg, NULL, 0, 0, PM_NOREMOVE)) { - if( next_msg.message == WM_KEYDOWN || - next_msg.message == WM_SYSKEYDOWN ) + if (next_msg.message == WM_KEYDOWN || + next_msg.message == WM_SYSKEYDOWN) { - if( next_msg.wParam == VK_MENU && + if (next_msg.wParam == VK_MENU && (next_msg.lParam & 0x01000000) && - next_msg.time == msg_time ) + next_msg.time == msg_time) { // Next message is a RALT down message, which // means that this is NOT a proper LCTRL message! @@ -451,10 +416,8 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) case VK_MENU: { // Is this an extended key (i.e. right key)? - if( lParam & 0x01000000 ) - { + if (lParam & 0x01000000) return GLFW_KEY_RALT; - } return GLFW_KEY_LALT; } @@ -463,10 +426,8 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) case VK_RETURN: { // Is this an extended key (i.e. right key)? - if( lParam & 0x01000000 ) - { + if (lParam & 0x01000000) return GLFW_KEY_KP_ENTER; - } return GLFW_KEY_ENTER; } @@ -541,21 +502,17 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) default: { // Convert to printable character (ISO-8859-1 or Unicode) - wParam = MapVirtualKey( (UINT) wParam, 2 ) & 0x0000FFFF; + wParam = MapVirtualKey((UINT) wParam, 2) & 0x0000FFFF; // Make sure that the character is uppercase - if( _glfwLibrary.Sys.hasUnicode ) - { - wParam = (WPARAM) CharUpperW( (LPWSTR) wParam ); - } + if (_glfwLibrary.Sys.hasUnicode) + wParam = (WPARAM) CharUpperW((LPWSTR) wParam); else - { - wParam = (WPARAM) CharUpperA( (LPSTR) wParam ); - } + wParam = (WPARAM) CharUpperA((LPSTR) wParam); // Valid ISO-8859-1 character? - if( (wParam >= 32 && wParam <= 126) || - (wParam >= 160 && wParam <= 255) ) + if ((wParam >= 32 && wParam <= 126) || + (wParam >= 160 && wParam <= 255)) { return (int) wParam; } @@ -570,24 +527,24 @@ static int translateKey( WPARAM wParam, LPARAM lParam ) // Translates a Windows key to Unicode //======================================================================== -static void translateChar( DWORD wParam, DWORD lParam, int action ) +static void translateChar(DWORD wParam, DWORD lParam, int action) { - BYTE keyboard_state[ 256 ]; - UCHAR char_buf[ 10 ]; - WCHAR unicode_buf[ 10 ]; - UINT scan_code; - int i, num_chars, unicode; + BYTE keyboard_state[256]; + UCHAR char_buf[10]; + WCHAR unicode_buf[10]; + UINT scan_code; + int i, num_chars, unicode; - GetKeyboardState( keyboard_state ); + GetKeyboardState(keyboard_state); // Derive scan code from lParam and action scan_code = (lParam & 0x01ff0000) >> 16; - if( action == GLFW_RELEASE ) + if (action == GLFW_RELEASE) { scan_code |= 0x8000000; } - if( _glfwLibrary.Sys.hasUnicode ) + if (_glfwLibrary.Sys.hasUnicode) { num_chars = ToUnicode( wParam, // virtual-key code @@ -613,17 +570,13 @@ static void translateChar( DWORD wParam, DWORD lParam, int action ) } // Report characters - for( i = 0; i < num_chars; i++ ) + for (i = 0; i < num_chars; i++) { // Get next character from buffer - if( unicode ) - { - _glfwInputChar( (int) unicode_buf[ i ], action ); - } + if (unicode) + _glfwInputChar((int) unicode_buf[i], action); else - { - _glfwInputChar( (int) char_buf[ i ], action ); - } + _glfwInputChar((int) char_buf[i], action); } } @@ -632,12 +585,12 @@ static void translateChar( DWORD wParam, DWORD lParam, int action ) // Window callback function (handles window events) //======================================================================== -static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam ) +static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, + WPARAM wParam, LPARAM lParam) { int wheelDelta, iconified; - switch( uMsg ) + switch (uMsg) { // Window activate message? (iconification?) case WM_ACTIVATE: @@ -647,60 +600,59 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, iconified = HIWORD(wParam) ? GL_TRUE : GL_FALSE; // Were we deactivated/iconified? - if( (!_glfwWin.active || iconified) && !_glfwWin.iconified ) + if ((!_glfwWin.active || iconified) && !_glfwWin.iconified) { _glfwInputDeactivation(); // If we are in fullscreen mode we need to iconify - if( _glfwWin.opened && _glfwWin.fullscreen ) + if (_glfwWin.opened && _glfwWin.fullscreen) { // Do we need to manually iconify? - if( !iconified ) + if (!iconified) { // Minimize window - CloseWindow( _glfwWin.window ); + CloseWindow(_glfwWin.window); iconified = GL_TRUE; } // Restore the original desktop resolution - ChangeDisplaySettings( NULL, CDS_FULLSCREEN ); + ChangeDisplaySettings(NULL, CDS_FULLSCREEN); } // Unlock mouse if locked - if( !_glfwWin.oldMouseLockValid ) + if (!_glfwWin.oldMouseLockValid) { _glfwWin.oldMouseLock = _glfwWin.mouseLock; _glfwWin.oldMouseLockValid = GL_TRUE; - glfwEnable( GLFW_MOUSE_CURSOR ); + glfwEnable(GLFW_MOUSE_CURSOR); } } - else if( _glfwWin.active || !iconified ) + else if (_glfwWin.active || !iconified) { // If we are in fullscreen mode we need to maximize - if( _glfwWin.opened && _glfwWin.fullscreen && _glfwWin.iconified ) + if (_glfwWin.opened && _glfwWin.fullscreen && _glfwWin.iconified) { // Change display settings to the user selected mode - _glfwSetVideoModeMODE( _glfwWin.modeID ); + _glfwSetVideoModeMODE(_glfwWin.modeID); // Do we need to manually restore window? - if( iconified ) + if (iconified) { // Restore window - OpenIcon( _glfwWin.window ); + OpenIcon(_glfwWin.window); iconified = GL_FALSE; // Activate window - ShowWindow( hWnd, SW_SHOW ); - setForegroundWindow( _glfwWin.window ); - SetFocus( _glfwWin.window ); + ShowWindow(hWnd, SW_SHOW); + setForegroundWindow(_glfwWin.window); + SetFocus(_glfwWin.window); } } // Lock mouse, if necessary - if( _glfwWin.oldMouseLockValid && _glfwWin.oldMouseLock ) - { - glfwDisable( GLFW_MOUSE_CURSOR ); - } + if (_glfwWin.oldMouseLockValid && _glfwWin.oldMouseLock) + glfwDisable(GLFW_MOUSE_CURSOR); + _glfwWin.oldMouseLockValid = GL_FALSE; } @@ -710,21 +662,19 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, case WM_SYSCOMMAND: { - switch( wParam & 0xfff0 ) + switch (wParam & 0xfff0) { case SC_SCREENSAVE: case SC_MONITORPOWER: { - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { - // Disallow screen saver and screen blanking if we are - // running in fullscreen mode + // We are running in fullscreen mode, so disallow + // screen saver and screen blanking return 0; } else - { break; - } } // User trying to access application menu using ALT? @@ -738,19 +688,18 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, { // Translate this to WM_QUIT so that we can handle all cases in the // same place - PostQuitMessage( 0 ); + PostQuitMessage(0); return 0; } case WM_KEYDOWN: case WM_SYSKEYDOWN: { - _glfwInputKey( translateKey( wParam, lParam ), GLFW_PRESS ); + _glfwInputKey(translateKey(wParam, lParam), GLFW_PRESS); + + if (_glfwWin.charCallback) + translateChar((DWORD) wParam, (DWORD) lParam, GLFW_PRESS); - if( _glfwWin.charCallback ) - { - translateChar( (DWORD) wParam, (DWORD) lParam, GLFW_PRESS ); - } return 0; } @@ -758,75 +707,91 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, case WM_SYSKEYUP: { // Special trick: release both shift keys on SHIFT up event - if( wParam == VK_SHIFT ) + if (wParam == VK_SHIFT) { - _glfwInputKey( GLFW_KEY_LSHIFT, GLFW_RELEASE ); - _glfwInputKey( GLFW_KEY_RSHIFT, GLFW_RELEASE ); + _glfwInputKey(GLFW_KEY_LSHIFT, GLFW_RELEASE); + _glfwInputKey(GLFW_KEY_RSHIFT, GLFW_RELEASE); } else - { - _glfwInputKey( translateKey( wParam, lParam ), GLFW_RELEASE ); - } + _glfwInputKey(translateKey(wParam, lParam), GLFW_RELEASE); - if( _glfwWin.charCallback ) - { - translateChar( (DWORD) wParam, (DWORD) lParam, GLFW_RELEASE ); - } + if (_glfwWin.charCallback) + translateChar((DWORD) wParam, (DWORD) lParam, GLFW_RELEASE); return 0; } case WM_LBUTTONDOWN: + { SetCapture(hWnd); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS); return 0; + } + case WM_RBUTTONDOWN: + { SetCapture(hWnd); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS); return 0; + } + case WM_MBUTTONDOWN: + { SetCapture(hWnd); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS); return 0; + } + case WM_XBUTTONDOWN: { - if( HIWORD(wParam) == XBUTTON1 ) + if (HIWORD(wParam) == XBUTTON1) { SetCapture(hWnd); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_4, GLFW_PRESS ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_4, GLFW_PRESS); } - else if( HIWORD(wParam) == XBUTTON2 ) + else if (HIWORD(wParam) == XBUTTON2) { SetCapture(hWnd); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_5, GLFW_PRESS ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_5, GLFW_PRESS); } + return 1; } case WM_LBUTTONUP: + { ReleaseCapture(); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE); return 0; + } + case WM_RBUTTONUP: + { ReleaseCapture(); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE); return 0; + } + case WM_MBUTTONUP: + { ReleaseCapture(); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE); return 0; + } + case WM_XBUTTONUP: { - if( HIWORD(wParam) == XBUTTON1 ) + if (HIWORD(wParam) == XBUTTON1) { ReleaseCapture(); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_4, GLFW_RELEASE ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_4, GLFW_RELEASE); } - else if( HIWORD(wParam) == XBUTTON2 ) + else if (HIWORD(wParam) == XBUTTON2) { ReleaseCapture(); - _glfwInputMouseClick( GLFW_MOUSE_BUTTON_5, GLFW_RELEASE ); + _glfwInputMouseClick(GLFW_MOUSE_BUTTON_5, GLFW_RELEASE); } + return 1; } @@ -838,10 +803,10 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, NewMouseX = (int)((short)LOWORD(lParam)); NewMouseY = (int)((short)HIWORD(lParam)); - if( NewMouseX != _glfwInput.OldMouseX || - NewMouseY != _glfwInput.OldMouseY ) + if (NewMouseX != _glfwInput.OldMouseX || + NewMouseY != _glfwInput.OldMouseY) { - if( _glfwWin.mouseLock ) + if (_glfwWin.mouseLock) { _glfwInput.MousePosX += NewMouseX - _glfwInput.OldMouseX; @@ -853,30 +818,32 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, _glfwInput.MousePosX = NewMouseX; _glfwInput.MousePosY = NewMouseY; } + _glfwInput.OldMouseX = NewMouseX; _glfwInput.OldMouseY = NewMouseY; _glfwInput.MouseMoved = GL_TRUE; - if( _glfwWin.mousePosCallback ) + if (_glfwWin.mousePosCallback) { - _glfwWin.mousePosCallback( _glfwInput.MousePosX, - _glfwInput.MousePosY ); + _glfwWin.mousePosCallback(_glfwInput.MousePosX, + _glfwInput.MousePosY); } } + return 0; } case WM_MOUSEWHEEL: { // WM_MOUSEWHEEL is not supported under Windows 95 - if( _glfwLibrary.Sys.winVer != _GLFW_WIN_95 ) + if (_glfwLibrary.Sys.winVer != _GLFW_WIN_95) { wheelDelta = (((int)wParam) >> 16) / WHEEL_DELTA; _glfwInput.WheelPos += wheelDelta; - if( _glfwWin.mouseWheelCallback ) - { - _glfwWin.mouseWheelCallback( _glfwInput.WheelPos ); - } + + if (_glfwWin.mouseWheelCallback) + _glfwWin.mouseWheelCallback(_glfwInput.WheelPos); + return 0; } break; @@ -888,32 +855,27 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, _glfwWin.height = HIWORD(lParam); // If the mouse is locked, update the clipping rect - if( _glfwWin.mouseLock ) + if (_glfwWin.mouseLock) { RECT ClipWindowRect; - if( GetWindowRect( _glfwWin.window, &ClipWindowRect ) ) - { - ClipCursor( &ClipWindowRect ); - } + if (GetWindowRect(_glfwWin.window, &ClipWindowRect)) + ClipCursor(&ClipWindowRect); } - if( _glfwWin.windowSizeCallback ) - { - _glfwWin.windowSizeCallback( LOWORD(lParam), HIWORD(lParam) ); - } + if (_glfwWin.windowSizeCallback) + _glfwWin.windowSizeCallback(LOWORD(lParam), HIWORD(lParam)); + return 0; } case WM_MOVE: { // If the mouse is locked, update the clipping rect - if( _glfwWin.mouseLock ) + if (_glfwWin.mouseLock) { RECT ClipWindowRect; - if( GetWindowRect( _glfwWin.window, &ClipWindowRect ) ) - { - ClipCursor( &ClipWindowRect ); - } + if (GetWindowRect(_glfwWin.window, &ClipWindowRect)) + ClipCursor(&ClipWindowRect); } return 0; } @@ -921,10 +883,9 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, // Was the window contents damaged? case WM_PAINT: { - if( _glfwWin.windowRefreshCallback ) - { + if (_glfwWin.windowRefreshCallback) _glfwWin.windowRefreshCallback(); - } + break; } @@ -937,7 +898,7 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, } // Pass all unhandled messages to DefWindowProc - return DefWindowProc( hWnd, uMsg, wParam, lParam ); + return DefWindowProc(hWnd, uMsg, wParam, lParam); } @@ -945,19 +906,19 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg, // Translate client window size to full window size (including window borders) //======================================================================== -static void getFullWindowSize( int clientWidth, int clientHeight, - int *fullWidth, int *fullHeight ) +static void getFullWindowSize(int clientWidth, int clientHeight, + int* fullWidth, int* fullHeight) { RECT rect; // Create a window rectangle - rect.left = (long)0; - rect.right = (long)clientWidth - 1; - rect.top = (long)0; - rect.bottom = (long)clientHeight - 1; + rect.left = (long) 0; + rect.right = (long) clientWidth - 1; + rect.top = (long) 0; + rect.bottom = (long) clientHeight - 1; // Adjust according to window styles - AdjustWindowRectEx( &rect, _glfwWin.dwStyle, FALSE, _glfwWin.dwExStyle ); + AdjustWindowRectEx(&rect, _glfwWin.dwStyle, FALSE, _glfwWin.dwExStyle); // Calculate width and height of full window *fullWidth = rect.right - rect.left + 1; @@ -973,7 +934,7 @@ static void getFullWindowSize( int clientWidth, int clientHeight, // decreasing the possibility of forgetting to add one without the other. //======================================================================== -static void initWGLExtensions( void ) +static void initWGLExtensions(void) { // This needs to include every function pointer loaded below _glfwWin.SwapIntervalEXT = NULL; @@ -990,41 +951,37 @@ static void initWGLExtensions( void ) _glfwWin.has_WGL_ARB_create_context = GL_FALSE; _glfwWin.GetExtensionsStringEXT = (WGLGETEXTENSIONSSTRINGEXT_T) - wglGetProcAddress( "wglGetExtensionsStringEXT" ); - if( !_glfwWin.GetExtensionsStringEXT ) + wglGetProcAddress("wglGetExtensionsStringEXT"); + if (!_glfwWin.GetExtensionsStringEXT) { _glfwWin.GetExtensionsStringARB = (WGLGETEXTENSIONSSTRINGARB_T) - wglGetProcAddress( "wglGetExtensionsStringARB" ); - if( !_glfwWin.GetExtensionsStringARB ) - { + wglGetProcAddress("wglGetExtensionsStringARB"); + if (!_glfwWin.GetExtensionsStringARB) return; - } } - if( _glfwPlatformExtensionSupported( "WGL_ARB_multisample" ) ) - { + if (_glfwPlatformExtensionSupported("WGL_ARB_multisample")) _glfwWin.has_WGL_ARB_multisample = GL_TRUE; - } - if( _glfwPlatformExtensionSupported( "WGL_ARB_create_context" ) ) + if (_glfwPlatformExtensionSupported("WGL_ARB_create_context")) { _glfwWin.has_WGL_ARB_create_context = GL_TRUE; _glfwWin.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) - wglGetProcAddress( "wglCreateContextAttribsARB" ); + wglGetProcAddress("wglCreateContextAttribsARB"); } - if( _glfwPlatformExtensionSupported( "WGL_EXT_swap_control" ) ) + if (_glfwPlatformExtensionSupported("WGL_EXT_swap_control")) { _glfwWin.has_WGL_EXT_swap_control = GL_TRUE; _glfwWin.SwapIntervalEXT = (WGLSWAPINTERVALEXT_T) - wglGetProcAddress( "wglSwapIntervalEXT" ); + wglGetProcAddress("wglSwapIntervalEXT"); } - if( _glfwPlatformExtensionSupported( "WGL_ARB_pixel_format" ) ) + if (_glfwPlatformExtensionSupported("WGL_ARB_pixel_format")) { _glfwWin.has_WGL_ARB_pixel_format = GL_TRUE; _glfwWin.GetPixelFormatAttribivARB = (WGLGETPIXELFORMATATTRIBIVARB_T) - wglGetProcAddress( "wglGetPixelFormatAttribivARB" ); + wglGetProcAddress("wglGetPixelFormatAttribivARB"); } } @@ -1033,7 +990,7 @@ static void initWGLExtensions( void ) // Registers the GLFW window class //======================================================================== -static ATOM registerWindowClass( void ) +static ATOM registerWindowClass(void) { WNDCLASS wc; @@ -1043,20 +1000,20 @@ static ATOM registerWindowClass( void ) wc.cbClsExtra = 0; // No extra class data wc.cbWndExtra = 0; // No extra window data wc.hInstance = _glfwLibrary.instance; // Set instance - wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load arrow pointer + wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load arrow pointer wc.hbrBackground = NULL; // No background wc.lpszMenuName = NULL; // No menu wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name // Load user-provided icon if available - wc.hIcon = LoadIcon( _glfwLibrary.instance, "GLFW_ICON" ); - if( !wc.hIcon ) + wc.hIcon = LoadIcon(_glfwLibrary.instance, "GLFW_ICON"); + if (!wc.hIcon) { // Load default icon - wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); + wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); } - return RegisterClass( &wc ); + return RegisterClass(&wc); } @@ -1064,31 +1021,31 @@ static ATOM registerWindowClass( void ) // Returns the closest matching pixel format, or zero on error //======================================================================== -static int choosePixelFormat( const _GLFWfbconfig *fbconfig ) +static int choosePixelFormat(const _GLFWfbconfig* fbconfig) { unsigned int fbcount; int pixelFormat; - _GLFWfbconfig *fbconfigs; - const _GLFWfbconfig *closest; + _GLFWfbconfig* fbconfigs; + const _GLFWfbconfig* closest; - fbconfigs = getFBConfigs( &fbcount ); - if( !fbconfigs ) + fbconfigs = getFBConfigs(&fbcount); + if (!fbconfigs) { - fprintf( stderr, "Failed to find any usable GLFWFBConfigs\n" ); + fprintf(stderr, "Failed to find any usable GLFWFBConfigs\n"); return 0; } - closest = _glfwChooseFBConfig( fbconfig, fbconfigs, fbcount ); - if( !closest ) + closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); + if (!closest) { - fprintf( stderr, "Failed to select a GLFWFBConfig from the alternatives\n" ); - free( fbconfigs ); + fprintf(stderr, "Failed to select a GLFWFBConfig from the alternatives\n"); + free(fbconfigs); return 0; } pixelFormat = (int) closest->platformID; - free( fbconfigs ); + free(fbconfigs); fbconfigs = NULL; closest = NULL; @@ -1100,24 +1057,24 @@ static int choosePixelFormat( const _GLFWfbconfig *fbconfig ) // Creates the GLFW window and rendering context //======================================================================== -static int createWindow( const _GLFWwndconfig *wndconfig, - const _GLFWfbconfig *fbconfig ) +static int createWindow(const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig) { DWORD dwStyle, dwExStyle; int pixelFormat, fullWidth, fullHeight; RECT wa; POINT pos; - _glfwWin.DC = NULL; + _glfwWin.DC = NULL; _glfwWin.context = NULL; _glfwWin.window = NULL; // Set common window styles - dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; + dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; dwExStyle = WS_EX_APPWINDOW; // Set window style, depending on fullscreen mode - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { dwStyle |= WS_POPUP; @@ -1125,9 +1082,9 @@ static int createWindow( const _GLFWwndconfig *wndconfig, // (SetForegroundWindow doesn't work properly under // Win98/ME/2K/.NET/+) /* - if( _glfwLibrary.Sys.WinVer != _GLFW_WIN_95 && + if (_glfwLibrary.Sys.WinVer != _GLFW_WIN_95 && _glfwLibrary.Sys.WinVer != _GLFW_WIN_NT4 && - _glfwLibrary.Sys.WinVer != _GLFW_WIN_XP ) + _glfwLibrary.Sys.WinVer != _GLFW_WIN_XP) { dwStyle |= WS_MINIMIZE; } @@ -1137,9 +1094,9 @@ static int createWindow( const _GLFWwndconfig *wndconfig, { dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; - if( !wndconfig->windowNoResize ) + if (!wndconfig->windowNoResize) { - dwStyle |= ( WS_MAXIMIZEBOX | WS_SIZEBOX ); + dwStyle |= (WS_MAXIMIZEBOX | WS_SIZEBOX); dwExStyle |= WS_EX_WINDOWEDGE; } } @@ -1149,70 +1106,66 @@ static int createWindow( const _GLFWwndconfig *wndconfig, _glfwWin.dwExStyle = dwExStyle; // Adjust window size for frame and title bar - getFullWindowSize( _glfwWin.width, _glfwWin.height, &fullWidth, &fullHeight ); + getFullWindowSize(_glfwWin.width, _glfwWin.height, &fullWidth, &fullHeight); // Adjust window position to working area (e.g. if the task bar is at // the top of the display). Fullscreen windows are always opened in // the upper left corner regardless of the desktop working area. - if( _glfwWin.fullscreen ) - { + if (_glfwWin.fullscreen) wa.left = wa.top = 0; - } else - { - SystemParametersInfo( SPI_GETWORKAREA, 0, &wa, 0 ); - } + SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0); - _glfwWin.window = CreateWindowEx( _glfwWin.dwExStyle, // Extended style - _GLFW_WNDCLASSNAME, // Class name - "GLFW Window", // Window title - _glfwWin.dwStyle, // Defined window style - wa.left, wa.top, // Window position - fullWidth, // Decorated window width - fullHeight, // Decorated window height - NULL, // No parent window - NULL, // No menu - _glfwLibrary.instance, // Instance - NULL ); // Nothing to WM_CREATE + _glfwWin.window = CreateWindowEx(_glfwWin.dwExStyle, // Extended style + _GLFW_WNDCLASSNAME, // Class name + "GLFW Window", // Window title + _glfwWin.dwStyle, // Defined window style + wa.left, wa.top, // Window position + fullWidth, // Decorated window width + fullHeight, // Decorated window height + NULL, // No parent window + NULL, // No menu + _glfwLibrary.instance, // Instance + NULL); // Nothing to WM_CREATE - if( !_glfwWin.window ) + if (!_glfwWin.window) { - fprintf( stderr, "Unable to create Win32 window\n" ); + fprintf(stderr, "Unable to create Win32 window\n"); return GL_FALSE; } - _glfwWin.DC = GetDC( _glfwWin.window ); - if( !_glfwWin.DC ) + _glfwWin.DC = GetDC(_glfwWin.window); + if (!_glfwWin.DC) { - fprintf( stderr, "Unable to retrieve GLFW window DC\n" ); + fprintf(stderr, "Unable to retrieve GLFW window DC\n"); return GL_FALSE; } - pixelFormat = choosePixelFormat( fbconfig ); - if( !pixelFormat ) + pixelFormat = choosePixelFormat(fbconfig); + if (!pixelFormat) { - fprintf( stderr, "Unable to find a usable pixel format\n" ); + fprintf(stderr, "Unable to find a usable pixel format\n"); return GL_FALSE; } - _glfwWin.context = createContext( _glfwWin.DC, wndconfig, pixelFormat ); - if( !_glfwWin.context ) + _glfwWin.context = createContext(_glfwWin.DC, wndconfig, pixelFormat); + if (!_glfwWin.context) { - fprintf( stderr, "Unable to create OpenGL context\n" ); + fprintf(stderr, "Unable to create OpenGL context\n"); return GL_FALSE; } - if( !wglMakeCurrent( _glfwWin.DC, _glfwWin.context ) ) + if (!wglMakeCurrent(_glfwWin.DC, _glfwWin.context)) { - fprintf( stderr, "Unable to make OpenGL context current\n" ); + fprintf(stderr, "Unable to make OpenGL context current\n"); return GL_FALSE; } initWGLExtensions(); // Initialize mouse position data - GetCursorPos( &pos ); - ScreenToClient( _glfwWin.window, &pos ); + GetCursorPos(&pos); + ScreenToClient(_glfwWin.window, &pos); _glfwInput.OldMouseX = _glfwInput.MousePosX = pos.x; _glfwInput.OldMouseY = _glfwInput.MousePosY = pos.y; @@ -1224,87 +1177,87 @@ static int createWindow( const _GLFWwndconfig *wndconfig, // Destroys the GLFW window and rendering context //======================================================================== -static void destroyWindow( void ) +static void destroyWindow(void) { - if( _glfwWin.context ) + if (_glfwWin.context) { - wglMakeCurrent( NULL, NULL ); - wglDeleteContext( _glfwWin.context ); + wglMakeCurrent(NULL, NULL); + wglDeleteContext(_glfwWin.context); _glfwWin.context = NULL; } - if( _glfwWin.DC ) + if (_glfwWin.DC) { - ReleaseDC( _glfwWin.window, _glfwWin.DC ); + ReleaseDC(_glfwWin.window, _glfwWin.DC); _glfwWin.DC = NULL; } - if( _glfwWin.window ) + if (_glfwWin.window) { - if( _glfwLibrary.Sys.winVer <= _GLFW_WIN_NT4 ) + if (_glfwLibrary.Sys.winVer <= _GLFW_WIN_NT4) { // Note: Hiding the window first fixes an annoying W98/NT4 // remaining icon bug for fullscreen displays - ShowWindow( _glfwWin.window, SW_HIDE ); + ShowWindow(_glfwWin.window, SW_HIDE); } - DestroyWindow( _glfwWin.window ); + DestroyWindow(_glfwWin.window); _glfwWin.window = NULL; } } -//************************************************************************ -//**** Platform implementation functions **** -//************************************************************************ +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// //======================================================================== // Here is where the window is created, and the OpenGL rendering context is // created //======================================================================== -int _glfwPlatformOpenWindow( int width, int height, - const _GLFWwndconfig *wndconfig, - const _GLFWfbconfig *fbconfig ) +int _glfwPlatformOpenWindow(int width, int height, + const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig) { GLboolean recreateContext = GL_FALSE; // Clear platform specific GLFW window state - _glfwWin.classAtom = 0; + _glfwWin.classAtom = 0; _glfwWin.oldMouseLockValid = GL_FALSE; _glfwWin.desiredRefreshRate = wndconfig->refreshRate; _glfwWin.classAtom = registerWindowClass(); - if( !_glfwWin.classAtom ) + if (!_glfwWin.classAtom) { - fprintf( stderr, "Failed to register GLFW window class\n" ); + fprintf(stderr, "Failed to register GLFW window class\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { - _glfwSetVideoMode( &_glfwWin.width, &_glfwWin.height, + _glfwSetVideoMode(&_glfwWin.width, &_glfwWin.height, fbconfig->redBits, fbconfig->greenBits, fbconfig->blueBits, - wndconfig->refreshRate ); + wndconfig->refreshRate); } initWGLExtensions(); - if( !createWindow( wndconfig, fbconfig ) ) + if (!createWindow(wndconfig, fbconfig)) { - fprintf( stderr, "Failed to create GLFW window\n" ); + fprintf(stderr, "Failed to create GLFW window\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } - if( wndconfig->glMajor > 2 ) + if (wndconfig->glMajor > 2) { - if( !_glfwWin.has_WGL_ARB_create_context ) + if (!_glfwWin.has_WGL_ARB_create_context) { - fprintf( stderr, "OpenGL 3.0+ is not supported\n" ); + fprintf(stderr, "OpenGL 3.0+ is not supported\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } @@ -1312,19 +1265,19 @@ int _glfwPlatformOpenWindow( int width, int height, recreateContext = GL_TRUE; } - if( fbconfig->samples > 0 ) + if (fbconfig->samples > 0) { // We want FSAA, but can we get it? // FSAA is not a hard constraint, so otherwise we just don't care - if( _glfwWin.has_WGL_ARB_multisample && _glfwWin.has_WGL_ARB_pixel_format ) + if (_glfwWin.has_WGL_ARB_multisample && _glfwWin.has_WGL_ARB_pixel_format) { // We appear to have both the FSAA extension and the means to ask for it recreateContext = GL_TRUE; } } - if( recreateContext ) + if (recreateContext) { // Some window hints require us to re-create the context using WGL // extensions retrieved through the current context, as we cannot check @@ -1343,23 +1296,23 @@ int _glfwPlatformOpenWindow( int width, int height, destroyWindow(); - if( !createWindow( wndconfig, fbconfig ) ) + if (!createWindow(wndconfig, fbconfig)) { - fprintf( stderr, "Unable to re-create GLFW window\n" ); + fprintf(stderr, "Unable to re-create GLFW window\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } } - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { // Place the window above all topmost windows - SetWindowPos( _glfwWin.window, HWND_TOPMOST, 0,0,0,0, - SWP_NOMOVE | SWP_NOSIZE ); + SetWindowPos(_glfwWin.window, HWND_TOPMOST, 0,0,0,0, + SWP_NOMOVE | SWP_NOSIZE); } - setForegroundWindow( _glfwWin.window ); - SetFocus( _glfwWin.window ); + setForegroundWindow(_glfwWin.window); + SetFocus(_glfwWin.window); return GL_TRUE; } @@ -1369,20 +1322,20 @@ int _glfwPlatformOpenWindow( int width, int height, // Properly kill the window / video display //======================================================================== -void _glfwPlatformCloseWindow( void ) +void _glfwPlatformCloseWindow(void) { destroyWindow(); - if( _glfwWin.classAtom ) + if (_glfwWin.classAtom) { - UnregisterClass( _GLFW_WNDCLASSNAME, _glfwLibrary.instance ); + UnregisterClass(_GLFW_WNDCLASSNAME, _glfwLibrary.instance); _glfwWin.classAtom = 0; } - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { // Restore original desktop resolution - ChangeDisplaySettings( NULL, CDS_FULLSCREEN ); + ChangeDisplaySettings(NULL, CDS_FULLSCREEN); } } @@ -1391,9 +1344,9 @@ void _glfwPlatformCloseWindow( void ) // Set the window title //======================================================================== -void _glfwPlatformSetWindowTitle( const char *title ) +void _glfwPlatformSetWindowTitle(const char* title) { - (void) SetWindowText( _glfwWin.window, title ); + SetWindowText(_glfwWin.window, title); } @@ -1401,75 +1354,73 @@ void _glfwPlatformSetWindowTitle( const char *title ) // Set the window size. //======================================================================== -void _glfwPlatformSetWindowSize( int width, int height ) +void _glfwPlatformSetWindowSize(int width, int height) { int bpp, mode = 0, refresh; int sizechanged = GL_FALSE; GLint drawbuffer; GLfloat clearcolor[4]; - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { // Get some info about the current mode DEVMODE dm; // Get current BPP settings - dm.dmSize = sizeof( DEVMODE ); - if( EnumDisplaySettings( NULL, _glfwWin.modeID, &dm ) ) + dm.dmSize = sizeof(DEVMODE); + if (EnumDisplaySettings(NULL, _glfwWin.modeID, &dm)) { // Get bpp bpp = dm.dmBitsPerPel; // Get closest match for target video mode refresh = _glfwWin.desiredRefreshRate; - mode = _glfwGetClosestVideoModeBPP( &width, &height, &bpp, - &refresh ); + mode = _glfwGetClosestVideoModeBPP(&width, &height, &bpp, + &refresh); } else - { mode = _glfwWin.modeID; - } } else { // If we are in windowed mode, adjust the window size to // compensate for window decorations - getFullWindowSize( width, height, &width, &height ); + getFullWindowSize(width, height, &width, &height); } // Change window size before changing fullscreen mode? - if( _glfwWin.fullscreen && (width > _glfwWin.width) ) + if (_glfwWin.fullscreen && (width > _glfwWin.width)) { - SetWindowPos( _glfwWin.window, HWND_TOP, 0, 0, width, height, - SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER ); + SetWindowPos(_glfwWin.window, HWND_TOP, 0, 0, width, height, + SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER); sizechanged = GL_TRUE; } // Change fullscreen video mode? - if( _glfwWin.fullscreen && mode != _glfwWin.modeID ) + if (_glfwWin.fullscreen && mode != _glfwWin.modeID) { - _glfwSetVideoModeMODE( mode ); + _glfwSetVideoModeMODE(mode); // Clear the front buffer to black (avoid ugly desktop remains in // our OpenGL window) - glGetIntegerv( GL_DRAW_BUFFER, &drawbuffer ); - glGetFloatv( GL_COLOR_CLEAR_VALUE, clearcolor ); - glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); - glClear( GL_COLOR_BUFFER_BIT ); - if( drawbuffer == GL_BACK ) + glGetIntegerv(GL_DRAW_BUFFER, &drawbuffer); + glGetFloatv(GL_COLOR_CLEAR_VALUE, clearcolor); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT); + if (drawbuffer == GL_BACK) { - _glfw_SwapBuffers( _glfwWin.DC ); + _glfw_SwapBuffers(_glfwWin.DC); } - glClearColor( clearcolor[0], clearcolor[1], clearcolor[2], - clearcolor[3] ); + glClearColor(clearcolor[0], clearcolor[1], clearcolor[2], + clearcolor[3]); } // Set window size (if not already changed) - if( !sizechanged ) + if (!sizechanged) { - SetWindowPos( _glfwWin.window, HWND_TOP, 0, 0, width, height, - SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER ); + SetWindowPos(_glfwWin.window, HWND_TOP, 0, 0, width, height, + SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER); } } @@ -1478,10 +1429,10 @@ void _glfwPlatformSetWindowSize( int width, int height ) // Set the window position //======================================================================== -void _glfwPlatformSetWindowPos( int x, int y ) +void _glfwPlatformSetWindowPos(int x, int y) { - (void) SetWindowPos( _glfwWin.window, HWND_TOP, x, y, 0, 0, - SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER ); + (void) SetWindowPos(_glfwWin.window, HWND_TOP, x, y, 0, 0, + SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); } @@ -1489,25 +1440,25 @@ void _glfwPlatformSetWindowPos( int x, int y ) // Window iconification //======================================================================== -void _glfwPlatformIconifyWindow( void ) +void _glfwPlatformIconifyWindow(void) { // Iconify window - CloseWindow( _glfwWin.window ); + CloseWindow(_glfwWin.window); _glfwWin.iconified = GL_TRUE; // If we are in fullscreen mode we need to change video modes - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { // Change display settings to the desktop resolution - ChangeDisplaySettings( NULL, CDS_FULLSCREEN ); + ChangeDisplaySettings(NULL, CDS_FULLSCREEN); } // Unlock mouse - if( !_glfwWin.oldMouseLockValid ) + if (!_glfwWin.oldMouseLockValid) { _glfwWin.oldMouseLock = _glfwWin.mouseLock; _glfwWin.oldMouseLockValid = GL_TRUE; - glfwEnable( GLFW_MOUSE_CURSOR ); + glfwEnable(GLFW_MOUSE_CURSOR); } } @@ -1516,31 +1467,30 @@ void _glfwPlatformIconifyWindow( void ) // Window un-iconification //======================================================================== -void _glfwPlatformRestoreWindow( void ) +void _glfwPlatformRestoreWindow(void) { // If we are in fullscreen mode we need to change video modes - if( _glfwWin.fullscreen ) + if (_glfwWin.fullscreen) { // Change display settings to the user selected mode - _glfwSetVideoModeMODE( _glfwWin.modeID ); + _glfwSetVideoModeMODE(_glfwWin.modeID); } // Un-iconify window - OpenIcon( _glfwWin.window ); + OpenIcon(_glfwWin.window); // Make sure that our window ends up on top of things - ShowWindow( _glfwWin.window, SW_SHOW ); - setForegroundWindow( _glfwWin.window ); - SetFocus( _glfwWin.window ); + ShowWindow(_glfwWin.window, SW_SHOW); + setForegroundWindow(_glfwWin.window); + SetFocus(_glfwWin.window); // Window is no longer iconified _glfwWin.iconified = GL_FALSE; // Lock mouse, if necessary - if( _glfwWin.oldMouseLockValid && _glfwWin.oldMouseLock ) - { - glfwDisable( GLFW_MOUSE_CURSOR ); - } + if (_glfwWin.oldMouseLockValid && _glfwWin.oldMouseLock) + glfwDisable(GLFW_MOUSE_CURSOR); + _glfwWin.oldMouseLockValid = GL_FALSE; } @@ -1549,9 +1499,9 @@ void _glfwPlatformRestoreWindow( void ) // Swap buffers (double-buffering) //======================================================================== -void _glfwPlatformSwapBuffers( void ) +void _glfwPlatformSwapBuffers(void) { - _glfw_SwapBuffers( _glfwWin.DC ); + _glfw_SwapBuffers(_glfwWin.DC); } @@ -1559,12 +1509,10 @@ void _glfwPlatformSwapBuffers( void ) // Set double buffering swap interval //======================================================================== -void _glfwPlatformSwapInterval( int interval ) +void _glfwPlatformSwapInterval(int interval) { - if( _glfwWin.has_WGL_EXT_swap_control ) - { - _glfwWin.SwapIntervalEXT( interval ); - } + if (_glfwWin.has_WGL_EXT_swap_control) + _glfwWin.SwapIntervalEXT(interval); } @@ -1572,57 +1520,53 @@ void _glfwPlatformSwapInterval( int interval ) // Write back window parameters into GLFW window structure //======================================================================== -void _glfwPlatformRefreshWindowParams( void ) +void _glfwPlatformRefreshWindowParams(void) { PIXELFORMATDESCRIPTOR pfd; DEVMODE dm; int pixelFormat, mode; // Obtain a detailed description of current pixel format - pixelFormat = _glfw_GetPixelFormat( _glfwWin.DC ); + pixelFormat = _glfw_GetPixelFormat(_glfwWin.DC); - if( _glfwWin.has_WGL_ARB_pixel_format ) + if (_glfwWin.has_WGL_ARB_pixel_format) { - if( getPixelFormatAttrib( pixelFormat, WGL_ACCELERATION_ARB ) != - WGL_NO_ACCELERATION_ARB ) + if (getPixelFormatAttrib(pixelFormat, WGL_ACCELERATION_ARB) != + WGL_NO_ACCELERATION_ARB) { _glfwWin.accelerated = GL_TRUE; } else - { _glfwWin.accelerated = GL_FALSE; - } - _glfwWin.redBits = getPixelFormatAttrib( pixelFormat, WGL_RED_BITS_ARB ); - _glfwWin.greenBits = getPixelFormatAttrib( pixelFormat, WGL_GREEN_BITS_ARB ); - _glfwWin.blueBits = getPixelFormatAttrib( pixelFormat, WGL_BLUE_BITS_ARB ); + _glfwWin.redBits = getPixelFormatAttrib(pixelFormat, WGL_RED_BITS_ARB); + _glfwWin.greenBits = getPixelFormatAttrib(pixelFormat, WGL_GREEN_BITS_ARB); + _glfwWin.blueBits = getPixelFormatAttrib(pixelFormat, WGL_BLUE_BITS_ARB); - _glfwWin.alphaBits = getPixelFormatAttrib( pixelFormat, WGL_ALPHA_BITS_ARB ); - _glfwWin.depthBits = getPixelFormatAttrib( pixelFormat, WGL_DEPTH_BITS_ARB ); - _glfwWin.stencilBits = getPixelFormatAttrib( pixelFormat, WGL_STENCIL_BITS_ARB ); + _glfwWin.alphaBits = getPixelFormatAttrib(pixelFormat, WGL_ALPHA_BITS_ARB); + _glfwWin.depthBits = getPixelFormatAttrib(pixelFormat, WGL_DEPTH_BITS_ARB); + _glfwWin.stencilBits = getPixelFormatAttrib(pixelFormat, WGL_STENCIL_BITS_ARB); - _glfwWin.accumRedBits = getPixelFormatAttrib( pixelFormat, WGL_ACCUM_RED_BITS_ARB ); - _glfwWin.accumGreenBits = getPixelFormatAttrib( pixelFormat, WGL_ACCUM_GREEN_BITS_ARB ); - _glfwWin.accumBlueBits = getPixelFormatAttrib( pixelFormat, WGL_ACCUM_BLUE_BITS_ARB ); - _glfwWin.accumAlphaBits = getPixelFormatAttrib( pixelFormat, WGL_ACCUM_ALPHA_BITS_ARB ); + _glfwWin.accumRedBits = getPixelFormatAttrib(pixelFormat, WGL_ACCUM_RED_BITS_ARB); + _glfwWin.accumGreenBits = getPixelFormatAttrib(pixelFormat, WGL_ACCUM_GREEN_BITS_ARB); + _glfwWin.accumBlueBits = getPixelFormatAttrib(pixelFormat, WGL_ACCUM_BLUE_BITS_ARB); + _glfwWin.accumAlphaBits = getPixelFormatAttrib(pixelFormat, WGL_ACCUM_ALPHA_BITS_ARB); - _glfwWin.auxBuffers = getPixelFormatAttrib( pixelFormat, WGL_AUX_BUFFERS_ARB ); - _glfwWin.stereo = getPixelFormatAttrib( pixelFormat, WGL_STEREO_ARB ) ? GL_TRUE : GL_FALSE; + _glfwWin.auxBuffers = getPixelFormatAttrib(pixelFormat, WGL_AUX_BUFFERS_ARB); + _glfwWin.stereo = getPixelFormatAttrib(pixelFormat, WGL_STEREO_ARB) ? GL_TRUE : GL_FALSE; - if( _glfwWin.has_WGL_ARB_multisample ) + if (_glfwWin.has_WGL_ARB_multisample) { - _glfwWin.samples = getPixelFormatAttrib( pixelFormat, WGL_SAMPLES_ARB ); + _glfwWin.samples = getPixelFormatAttrib(pixelFormat, WGL_SAMPLES_ARB); // Should we force 1 to 0 here for consistency, or keep 1 for transparency? } else - { _glfwWin.samples = 0; - } } else { - _glfw_DescribePixelFormat( _glfwWin.DC, pixelFormat, - sizeof(PIXELFORMATDESCRIPTOR), &pfd ); + _glfw_DescribePixelFormat(_glfwWin.DC, pixelFormat, + sizeof(PIXELFORMATDESCRIPTOR), &pfd); // Is current OpenGL context accelerated? _glfwWin.accelerated = (pfd.dwFlags & PFD_GENERIC_ACCELERATED) || @@ -1649,20 +1593,16 @@ void _glfwPlatformRefreshWindowParams( void ) // Get refresh rate mode = _glfwWin.fullscreen ? _glfwWin.modeID : ENUM_CURRENT_SETTINGS; - dm.dmSize = sizeof( DEVMODE ); + dm.dmSize = sizeof(DEVMODE); - if( EnumDisplaySettings( NULL, mode, &dm ) ) + if (EnumDisplaySettings(NULL, mode, &dm)) { _glfwWin.refreshRate = dm.dmDisplayFrequency; - if( _glfwWin.refreshRate <= 1 ) - { + if (_glfwWin.refreshRate <= 1) _glfwWin.refreshRate = 0; - } } else - { _glfwWin.refreshRate = 0; - } } @@ -1670,7 +1610,7 @@ void _glfwPlatformRefreshWindowParams( void ) // Poll for new window and input events //======================================================================== -void _glfwPlatformPollEvents( void ) +void _glfwPlatformPollEvents(void) { MSG msg; int winclosed = GL_FALSE; @@ -1678,7 +1618,7 @@ void _glfwPlatformPollEvents( void ) // Flag: mouse was not moved (will be changed by _glfwGetNextEvent if // there was a mouse move event) _glfwInput.MouseMoved = GL_FALSE; - if( _glfwWin.mouseLock ) + if (_glfwWin.mouseLock) { _glfwInput.OldMouseX = _glfwWin.width/2; _glfwInput.OldMouseY = _glfwWin.height/2; @@ -1690,19 +1630,23 @@ void _glfwPlatformPollEvents( void ) } // Check for new window messages - while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - switch( msg.message ) + switch (msg.message) { // QUIT-message (from close window)? case WM_QUIT: + { winclosed = GL_TRUE; break; + } // Ok, send it to the window message handler default: - DispatchMessage( &msg ); + { + DispatchMessage(&msg); break; + } } } @@ -1710,43 +1654,38 @@ void _glfwPlatformPollEvents( void ) // This is the only async event handling in GLFW, but it solves some // nasty problems. // Caveat: Does not work under Win 9x/ME. - if( _glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4 ) + if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4) { int lshift_down, rshift_down; // Get current state of left and right shift keys - lshift_down = (GetAsyncKeyState( VK_LSHIFT ) >> 15) & 1; - rshift_down = (GetAsyncKeyState( VK_RSHIFT ) >> 15) & 1; + lshift_down = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1; + rshift_down = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1; // See if this differs from our belief of what has happened // (we only have to check for lost key up events) - if( !lshift_down && _glfwInput.Key[ GLFW_KEY_LSHIFT ] == 1 ) - { - _glfwInputKey( GLFW_KEY_LSHIFT, GLFW_RELEASE ); - } - if( !rshift_down && _glfwInput.Key[ GLFW_KEY_RSHIFT ] == 1 ) - { - _glfwInputKey( GLFW_KEY_RSHIFT, GLFW_RELEASE ); - } + if (!lshift_down && _glfwInput.Key[ GLFW_KEY_LSHIFT ] == 1) + _glfwInputKey(GLFW_KEY_LSHIFT, GLFW_RELEASE); + + if (!rshift_down && _glfwInput.Key[ GLFW_KEY_RSHIFT ] == 1) + _glfwInputKey(GLFW_KEY_RSHIFT, GLFW_RELEASE); } // Did we have mouse movement in locked cursor mode? - if( _glfwInput.MouseMoved && _glfwWin.mouseLock ) + if (_glfwInput.MouseMoved && _glfwWin.mouseLock) { - _glfwPlatformSetMouseCursorPos( _glfwWin.width / 2, - _glfwWin.height / 2 ); + _glfwPlatformSetMouseCursorPos(_glfwWin.width / 2, + _glfwWin.height / 2); } // Was there a window close request? - if( winclosed && _glfwWin.windowCloseCallback ) + if (winclosed && _glfwWin.windowCloseCallback) { // Check if the program wants us to close the window winclosed = _glfwWin.windowCloseCallback(); } - if( winclosed ) - { + if (winclosed) glfwCloseWindow(); - } } @@ -1754,7 +1693,7 @@ void _glfwPlatformPollEvents( void ) // _glfwPlatformWaitEvents() - Wait for new window and input events //======================================================================== -void _glfwPlatformWaitEvents( void ) +void _glfwPlatformWaitEvents(void) { WaitMessage(); @@ -1766,20 +1705,18 @@ void _glfwPlatformWaitEvents( void ) // Hide mouse cursor (lock it) //======================================================================== -void _glfwPlatformHideMouseCursor( void ) +void _glfwPlatformHideMouseCursor(void) { RECT ClipWindowRect; - ShowCursor( FALSE ); + ShowCursor(FALSE); // Clip cursor to the window - if( GetWindowRect( _glfwWin.window, &ClipWindowRect ) ) - { - ClipCursor( &ClipWindowRect ); - } + if (GetWindowRect(_glfwWin.window, &ClipWindowRect)) + ClipCursor(&ClipWindowRect); // Capture cursor to user window - SetCapture( _glfwWin.window ); + SetCapture(_glfwWin.window); } @@ -1787,15 +1724,15 @@ void _glfwPlatformHideMouseCursor( void ) // Show mouse cursor (unlock it) //======================================================================== -void _glfwPlatformShowMouseCursor( void ) +void _glfwPlatformShowMouseCursor(void) { // Un-capture cursor ReleaseCapture(); // Release the cursor from the window - ClipCursor( NULL ); + ClipCursor(NULL); - ShowCursor( TRUE ); + ShowCursor(TRUE); } @@ -1803,15 +1740,15 @@ void _glfwPlatformShowMouseCursor( void ) // Set physical mouse cursor position //======================================================================== -void _glfwPlatformSetMouseCursorPos( int x, int y ) +void _glfwPlatformSetMouseCursorPos(int x, int y) { POINT pos; // Convert client coordinates to screen coordinates pos.x = x; pos.y = y; - ClientToScreen( _glfwWin.window, &pos ); + ClientToScreen(_glfwWin.window, &pos); - SetCursorPos( pos.x, pos.y ); + SetCursorPos(pos.x, pos.y); }