1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-12-03 07:28:51 -05:00
glfw/src/window.c

903 lines
26 KiB
C
Raw Normal View History

2010-09-07 11:34:51 -04:00
//========================================================================
// GLFW - An OpenGL library
2010-09-07 11:34:51 -04:00
// Platform: Any
2010-09-07 11:41:26 -04:00
// API version: 3.0
2010-09-07 11:34:51 -04:00
// WWW: http://www.glfw.org/
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
#include <string.h>
2010-09-09 12:15:32 -04:00
#include <stdlib.h>
2010-09-07 11:34:51 -04:00
2010-09-09 14:59:50 -04:00
//========================================================================
// Return the maxiumum of the specified values
//========================================================================
2010-09-07 11:34:51 -04:00
static int Max(int a, int b)
{
return (a > b) ? a : b;
}
//========================================================================
// Close all GLFW windows with the closed flag set
//========================================================================
static void closeFlaggedWindows(void)
{
_GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; )
{
2010-10-24 12:28:55 -04:00
if (window->closeRequested && _glfwLibrary.windowCloseCallback)
window->closeRequested = _glfwLibrary.windowCloseCallback(window);
2010-09-16 00:02:44 -04:00
if (window->closeRequested)
{
_GLFWwindow* next = window->next;
glfwCloseWindow(window);
window = next;
}
else
window = window->next;
}
}
//========================================================================
// Clear scroll offsets for all windows
//========================================================================
2011-03-04 08:52:12 -05:00
static void clearScrollOffsets(void)
{
_GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next)
{
window->scrollX = 0;
window->scrollY = 0;
}
}
2010-09-09 14:59:50 -04:00
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
2010-09-07 11:34:51 -04:00
//========================================================================
// Reset all window hints to their default values
2010-09-07 11:34:51 -04:00
//========================================================================
void _glfwSetDefaultWindowHints(void)
2010-09-07 11:34:51 -04:00
{
2010-09-08 08:45:52 -04:00
memset(&_glfwLibrary.hints, 0, sizeof(_glfwLibrary.hints));
2010-11-17 08:18:00 -05:00
2011-03-07 08:16:39 -05:00
// The default minimum OpenGL version is 1.0
2010-09-07 11:34:51 -04:00
_glfwLibrary.hints.glMajor = 1;
2010-11-17 08:18:00 -05:00
_glfwLibrary.hints.glMinor = 0;
// The default is to allow window resizing
_glfwLibrary.hints.resizable = GL_TRUE;
2010-09-07 11:34:51 -04:00
}
//========================================================================
// Register window focus events
//========================================================================
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
{
if (activated)
{
if (_glfwLibrary.activeWindow != window)
{
_glfwLibrary.activeWindow = window;
2010-10-24 12:28:55 -04:00
if (_glfwLibrary.windowFocusCallback)
_glfwLibrary.windowFocusCallback(window, activated);
}
}
else
{
if (_glfwLibrary.activeWindow == window)
{
int i;
// Release all pressed keyboard keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_PRESS)
_glfwInputKey(window, i, GLFW_RELEASE);
}
// Release all pressed mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_PRESS)
_glfwInputMouseClick(window, i, GLFW_RELEASE);
}
_glfwLibrary.activeWindow = NULL;
2010-10-24 12:28:55 -04:00
if (_glfwLibrary.windowFocusCallback)
_glfwLibrary.windowFocusCallback(window, activated);
}
}
}
//========================================================================
// Register window position events
//========================================================================
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{
window->positionX = x;
window->positionY = y;
}
//========================================================================
// Register window size events
//========================================================================
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
{
if (window->width == width && window->height == height)
return;
window->width = width;
window->height = height;
if (_glfwLibrary.windowSizeCallback)
_glfwLibrary.windowSizeCallback(window, width, height);
}
//========================================================================
// Register window size events
//========================================================================
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
{
if (window->iconified == iconified)
return;
window->iconified = iconified;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, iconified);
}
//========================================================================
// Register window damage events
//========================================================================
void _glfwInputWindowDamage(_GLFWwindow* window)
{
if (_glfwLibrary.windowRefreshCallback)
_glfwLibrary.windowRefreshCallback(window);
}
2010-09-09 14:59:50 -04:00
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
2010-09-07 11:34:51 -04:00
//========================================================================
// Create the GLFW window and its associated context
//========================================================================
2010-09-13 21:10:45 -04:00
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
2010-10-04 12:17:53 -04:00
int mode, const char* title,
GLFWwindow share)
2010-09-07 11:34:51 -04:00
{
_GLFWfbconfig fbconfig;
_GLFWwndconfig wndconfig;
2010-09-09 12:15:32 -04:00
_GLFWwindow* window;
2010-09-07 11:34:51 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-09 12:15:32 -04:00
return NULL;
}
2011-03-07 08:30:23 -05:00
// We need to copy these values before doing anything that can fail, as the
// window hints should be cleared after each call even if it fails
2010-09-09 12:15:32 -04:00
2010-09-07 11:34:51 -04:00
// Set up desired framebuffer config
fbconfig.redBits = Max(_glfwLibrary.hints.redBits, 0);
fbconfig.greenBits = Max(_glfwLibrary.hints.greenBits, 0);
fbconfig.blueBits = Max(_glfwLibrary.hints.blueBits, 0);
fbconfig.alphaBits = Max(_glfwLibrary.hints.alphaBits, 0);
fbconfig.depthBits = Max(_glfwLibrary.hints.depthBits, 0);
fbconfig.stencilBits = Max(_glfwLibrary.hints.stencilBits, 0);
2010-09-08 08:45:52 -04:00
fbconfig.accumRedBits = Max(_glfwLibrary.hints.accumRedBits, 0);
fbconfig.accumGreenBits = Max(_glfwLibrary.hints.accumGreenBits, 0);
fbconfig.accumBlueBits = Max(_glfwLibrary.hints.accumBlueBits, 0);
fbconfig.accumAlphaBits = Max(_glfwLibrary.hints.accumAlphaBits, 0);
fbconfig.auxBuffers = Max(_glfwLibrary.hints.auxBuffers, 0);
2010-09-07 11:34:51 -04:00
fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE;
2010-09-08 08:45:52 -04:00
fbconfig.samples = Max(_glfwLibrary.hints.samples, 0);
2010-09-07 11:34:51 -04:00
// Set up desired window config
wndconfig.mode = mode;
2010-09-13 21:10:45 -04:00
wndconfig.title = title;
2010-09-08 08:45:52 -04:00
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.glMajor = _glfwLibrary.hints.glMajor;
wndconfig.glMinor = _glfwLibrary.hints.glMinor;
2010-09-07 11:34:51 -04:00
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
wndconfig.glProfile = _glfwLibrary.hints.glProfile;
2011-03-07 14:51:34 -05:00
wndconfig.glRobustness = _glfwLibrary.hints.glRobustness ? GL_TRUE : GL_FALSE;
2010-10-04 12:17:53 -04:00
wndconfig.share = share;
2010-09-07 11:34:51 -04:00
// Reset to default values for the next call
_glfwSetDefaultWindowHints();
2010-09-09 12:15:32 -04:00
// Check the OpenGL bits of the window config
2011-03-07 08:55:11 -05:00
if (!_glfwIsValidContextConfig(&wndconfig))
2010-09-07 11:34:51 -04:00
return GL_FALSE;
2010-09-10 07:24:19 -04:00
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
2010-09-09 12:15:32 -04:00
{
2011-07-27 11:48:56 -04:00
_glfwSetError(GLFW_INVALID_ENUM,
"glfwOpenWindow: Invalid enum for 'mode' parameter");
2010-09-07 11:34:51 -04:00
return GL_FALSE;
2010-09-09 12:15:32 -04:00
}
2010-09-07 11:34:51 -04:00
// Check width & height
2010-09-08 08:45:52 -04:00
if (width > 0 && height <= 0)
2010-09-07 11:34:51 -04:00
{
// Set the window aspect ratio to 4:3
height = (width * 3) / 4;
}
2010-09-08 08:45:52 -04:00
else if (width <= 0 && height > 0)
2010-09-07 11:34:51 -04:00
{
// Set the window aspect ratio to 4:3
width = (height * 4) / 3;
}
2010-09-08 08:45:52 -04:00
else if (width <= 0 && height <= 0)
2010-09-07 11:34:51 -04:00
{
// Default window size
width = 640;
height = 480;
}
2012-02-07 08:58:58 -05:00
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
2011-03-07 08:30:23 -05:00
if (!window)
{
2011-07-27 11:48:56 -04:00
_glfwSetError(GLFW_OUT_OF_MEMORY,
"glfwOpenWindow: Failed to allocate window structure");
2011-03-07 08:30:23 -05:00
return NULL;
}
memset(window, 0, sizeof(_GLFWwindow));
window->next = _glfwLibrary.windowListHead;
_glfwLibrary.windowListHead = window;
2010-09-07 11:34:51 -04:00
// Remember window settings
window->width = width;
window->height = height;
window->mode = mode;
window->cursorMode = GLFW_CURSOR_NORMAL;
window->systemKeys = GL_TRUE;
2010-09-07 11:34:51 -04:00
2011-03-04 11:49:36 -05:00
// Open the actual window and create its context
if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig))
2010-09-09 12:15:32 -04:00
{
glfwCloseWindow(window);
2010-09-07 11:34:51 -04:00
return GL_FALSE;
2010-09-09 12:15:32 -04:00
}
2010-09-07 11:34:51 -04:00
2011-03-04 11:49:36 -05:00
// Cache the actual (as opposed to desired) window parameters
glfwMakeContextCurrent(window);
2010-09-07 11:34:51 -04:00
_glfwPlatformRefreshWindowParams();
2011-03-07 08:55:11 -05:00
if (!_glfwIsValidContext(window, &wndconfig))
2010-09-07 11:34:51 -04:00
{
2010-09-09 12:15:32 -04:00
glfwCloseWindow(window);
2010-09-07 11:34:51 -04:00
return GL_FALSE;
}
2011-03-04 11:49:36 -05:00
// The GLFW specification states that fullscreen windows have the cursor
// captured by default
2010-09-08 08:45:52 -04:00
if (mode == GLFW_FULLSCREEN)
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
2010-09-07 11:34:51 -04:00
2011-03-04 11:49:36 -05:00
// Clearing the front buffer to black to avoid garbage pixels left over
// from previous uses of our bit of VRAM
2010-09-08 08:45:52 -04:00
glClear(GL_COLOR_BUFFER_BIT);
2010-09-07 11:34:51 -04:00
_glfwPlatformSwapBuffers();
2010-09-09 12:15:32 -04:00
return window;
}
2010-09-09 12:42:41 -04:00
//========================================================================
// Returns GL_TRUE if the specified window handle is an actual window
//========================================================================
GLFWAPI int glfwIsWindow(GLFWwindow handle)
2010-09-09 12:42:41 -04:00
{
2010-09-09 18:06:23 -04:00
_GLFWwindow* entry;
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-09 18:06:23 -04:00
2010-09-09 12:42:41 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return GL_FALSE;
}
if (window == NULL)
return GL_FALSE;
2010-09-09 12:42:41 -04:00
2010-09-09 18:06:23 -04:00
for (entry = _glfwLibrary.windowListHead; entry; entry = entry->next)
{
if (entry == window)
return GL_TRUE;
}
return GL_FALSE;
2010-09-09 12:42:41 -04:00
}
2010-09-07 11:34:51 -04:00
//========================================================================
// Set hints for opening the window
//========================================================================
2010-09-08 08:45:52 -04:00
GLFWAPI void glfwOpenWindowHint(int target, int hint)
2010-09-07 11:34:51 -04:00
{
2010-09-08 08:45:52 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
2010-09-08 08:45:52 -04:00
switch (target)
2010-09-07 11:34:51 -04:00
{
case GLFW_RED_BITS:
_glfwLibrary.hints.redBits = hint;
break;
case GLFW_GREEN_BITS:
_glfwLibrary.hints.greenBits = hint;
break;
case GLFW_BLUE_BITS:
_glfwLibrary.hints.blueBits = hint;
break;
case GLFW_ALPHA_BITS:
_glfwLibrary.hints.alphaBits = hint;
break;
case GLFW_DEPTH_BITS:
_glfwLibrary.hints.depthBits = hint;
break;
case GLFW_STENCIL_BITS:
_glfwLibrary.hints.stencilBits = hint;
break;
2010-09-07 11:34:51 -04:00
case GLFW_REFRESH_RATE:
_glfwLibrary.hints.refreshRate = hint;
break;
case GLFW_ACCUM_RED_BITS:
_glfwLibrary.hints.accumRedBits = hint;
break;
case GLFW_ACCUM_GREEN_BITS:
_glfwLibrary.hints.accumGreenBits = hint;
break;
case GLFW_ACCUM_BLUE_BITS:
_glfwLibrary.hints.accumBlueBits = hint;
break;
case GLFW_ACCUM_ALPHA_BITS:
_glfwLibrary.hints.accumAlphaBits = hint;
break;
case GLFW_AUX_BUFFERS:
_glfwLibrary.hints.auxBuffers = hint;
break;
case GLFW_STEREO:
_glfwLibrary.hints.stereo = hint;
break;
case GLFW_WINDOW_RESIZABLE:
_glfwLibrary.hints.resizable = hint;
2010-09-07 11:34:51 -04:00
break;
case GLFW_FSAA_SAMPLES:
_glfwLibrary.hints.samples = hint;
break;
case GLFW_OPENGL_VERSION_MAJOR:
_glfwLibrary.hints.glMajor = hint;
break;
case GLFW_OPENGL_VERSION_MINOR:
_glfwLibrary.hints.glMinor = hint;
break;
case GLFW_OPENGL_FORWARD_COMPAT:
_glfwLibrary.hints.glForward = hint;
break;
case GLFW_OPENGL_DEBUG_CONTEXT:
_glfwLibrary.hints.glDebug = hint;
break;
case GLFW_OPENGL_PROFILE:
_glfwLibrary.hints.glProfile = hint;
break;
2011-03-07 14:51:34 -05:00
case GLFW_OPENGL_ROBUSTNESS:
_glfwLibrary.hints.glRobustness = hint;
break;
2010-09-07 11:34:51 -04:00
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
2010-09-07 11:34:51 -04:00
break;
}
}
//========================================================================
// Properly kill the window / video display
//========================================================================
GLFWAPI void glfwCloseWindow(GLFWwindow handle)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-08 08:45:52 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
2011-03-08 17:14:42 -05:00
// Allow closing of NULL (to match the behavior of free)
if (window == NULL)
return;
2010-09-15 20:05:01 -04:00
// Clear the current context if this window's context is current
2010-09-09 12:15:32 -04:00
if (window == _glfwLibrary.currentWindow)
glfwMakeContextCurrent(NULL);
2010-09-07 11:34:51 -04:00
2010-09-15 20:05:01 -04:00
// Clear the active window pointer if this is the active window
2010-09-11 09:14:57 -04:00
if (window == _glfwLibrary.activeWindow)
_glfwLibrary.activeWindow = NULL;
2010-09-09 12:15:32 -04:00
_glfwPlatformCloseWindow(window);
2010-09-15 20:05:01 -04:00
// Unlink window from global linked list
{
_GLFWwindow** prev = &_glfwLibrary.windowListHead;
while (*prev != window)
prev = &((*prev)->next);
2010-09-09 18:06:23 -04:00
2010-09-15 20:05:01 -04:00
*prev = window->next;
}
2010-09-09 18:30:10 -04:00
2012-02-07 08:58:58 -05:00
free(window);
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Set the window title
2010-09-07 11:34:51 -04:00
//========================================================================
GLFWAPI void glfwSetWindowTitle(GLFWwindow handle, const char* title)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-09 12:15:32 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
2010-09-09 12:15:32 -04:00
_glfwPlatformSetWindowTitle(window, title);
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Get the window size
2010-09-07 11:34:51 -04:00
//========================================================================
GLFWAPI void glfwGetWindowSize(GLFWwindow handle, int* width, int* height)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-09 12:15:32 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-09 12:15:32 -04:00
return;
}
2010-09-09 12:15:32 -04:00
2010-09-08 08:45:52 -04:00
if (width != NULL)
2010-09-09 12:15:32 -04:00
*width = window->width;
2010-09-08 08:45:52 -04:00
if (height != NULL)
2010-09-09 12:15:32 -04:00
*height = window->height;
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Set the window size
2010-09-07 11:34:51 -04:00
//========================================================================
GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->iconified)
{
// TODO: Figure out if this is an error
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
// Don't do anything if the window size did not change
2010-09-09 12:15:32 -04:00
if (width == window->width && height == window->height)
2010-09-07 11:34:51 -04:00
return;
2010-09-09 12:15:32 -04:00
_glfwPlatformSetWindowSize(window, width, height);
2010-09-07 11:34:51 -04:00
2010-09-09 12:15:32 -04:00
if (window->mode == GLFW_FULLSCREEN)
{
// Refresh window parameters (may have changed due to changed video
// modes)
_glfwPlatformRefreshWindowParams();
}
2010-09-07 11:34:51 -04:00
}
2010-09-13 21:53:22 -04:00
//========================================================================
// Get the window position
//========================================================================
2011-02-09 06:57:11 -05:00
GLFWAPI void glfwGetWindowPos(GLFWwindow handle, int* xpos, int* ypos)
2010-09-13 21:53:22 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-13 21:53:22 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-13 21:53:22 -04:00
return;
}
2011-02-09 06:57:11 -05:00
if (xpos != NULL)
*xpos = window->positionX;
2010-09-13 21:53:22 -04:00
2011-02-09 06:57:11 -05:00
if (ypos != NULL)
*ypos = window->positionY;
2010-09-13 21:53:22 -04:00
}
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-07 11:50:43 -04:00
// Set the window position
2010-09-07 11:34:51 -04:00
//========================================================================
2011-02-09 06:57:11 -05:00
GLFWAPI void glfwSetWindowPos(GLFWwindow handle, int xpos, int ypos)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->mode == GLFW_FULLSCREEN || window->iconified)
2010-09-07 11:34:51 -04:00
{
// TODO: Figure out if this is an error
2010-09-07 11:34:51 -04:00
return;
}
2011-02-09 06:57:11 -05:00
_glfwPlatformSetWindowPos(window, xpos, ypos);
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Window iconification
2010-09-07 11:34:51 -04:00
//========================================================================
GLFWAPI void glfwIconifyWindow(GLFWwindow handle)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->iconified)
2010-09-07 11:34:51 -04:00
return;
2010-09-09 12:15:32 -04:00
_glfwPlatformIconifyWindow(window);
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Window un-iconification
2010-09-07 11:34:51 -04:00
//========================================================================
GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (!window->iconified)
2010-09-07 11:34:51 -04:00
return;
2010-09-09 12:15:32 -04:00
_glfwPlatformRestoreWindow(window);
2010-09-07 11:34:51 -04:00
2010-09-09 12:15:32 -04:00
if (window->mode == GLFW_FULLSCREEN)
_glfwPlatformRefreshWindowParams();
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Get window parameter
2010-09-07 11:34:51 -04:00
//========================================================================
GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
2010-09-07 11:34:51 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-08 08:45:52 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return 0;
}
2010-09-07 11:34:51 -04:00
2010-09-08 08:45:52 -04:00
switch (param)
2010-09-07 11:34:51 -04:00
{
case GLFW_ACTIVE:
2010-09-11 09:14:57 -04:00
return window == _glfwLibrary.activeWindow;
2010-09-07 11:34:51 -04:00
case GLFW_ICONIFIED:
2010-09-09 12:15:32 -04:00
return window->iconified;
2010-09-07 11:34:51 -04:00
case GLFW_ACCELERATED:
2010-09-09 12:15:32 -04:00
return window->accelerated;
2010-09-07 11:34:51 -04:00
case GLFW_RED_BITS:
2010-09-09 12:15:32 -04:00
return window->redBits;
2010-09-07 11:34:51 -04:00
case GLFW_GREEN_BITS:
2010-09-09 12:15:32 -04:00
return window->greenBits;
2010-09-07 11:34:51 -04:00
case GLFW_BLUE_BITS:
2010-09-09 12:15:32 -04:00
return window->blueBits;
2010-09-07 11:34:51 -04:00
case GLFW_ALPHA_BITS:
2010-09-09 12:15:32 -04:00
return window->alphaBits;
2010-09-07 11:34:51 -04:00
case GLFW_DEPTH_BITS:
2010-09-09 12:15:32 -04:00
return window->depthBits;
2010-09-07 11:34:51 -04:00
case GLFW_STENCIL_BITS:
2010-09-09 12:15:32 -04:00
return window->stencilBits;
2010-09-07 11:34:51 -04:00
case GLFW_ACCUM_RED_BITS:
2010-09-09 12:15:32 -04:00
return window->accumRedBits;
2010-09-07 11:34:51 -04:00
case GLFW_ACCUM_GREEN_BITS:
2010-09-09 12:15:32 -04:00
return window->accumGreenBits;
2010-09-07 11:34:51 -04:00
case GLFW_ACCUM_BLUE_BITS:
2010-09-09 12:15:32 -04:00
return window->accumBlueBits;
2010-09-07 11:34:51 -04:00
case GLFW_ACCUM_ALPHA_BITS:
2010-09-09 12:15:32 -04:00
return window->accumAlphaBits;
2010-09-07 11:34:51 -04:00
case GLFW_AUX_BUFFERS:
2010-09-09 12:15:32 -04:00
return window->auxBuffers;
2010-09-07 11:34:51 -04:00
case GLFW_STEREO:
2010-09-09 12:15:32 -04:00
return window->stereo;
2010-09-07 11:34:51 -04:00
case GLFW_REFRESH_RATE:
2010-09-09 12:15:32 -04:00
return window->refreshRate;
case GLFW_WINDOW_RESIZABLE:
return window->resizable;
2010-09-07 11:34:51 -04:00
case GLFW_FSAA_SAMPLES:
2010-09-09 12:15:32 -04:00
return window->samples;
2010-09-07 11:34:51 -04:00
case GLFW_OPENGL_VERSION_MAJOR:
2010-09-09 12:15:32 -04:00
return window->glMajor;
2010-09-07 11:34:51 -04:00
case GLFW_OPENGL_VERSION_MINOR:
2010-09-09 12:15:32 -04:00
return window->glMinor;
case GLFW_OPENGL_REVISION:
return window->glRevision;
2010-09-07 11:34:51 -04:00
case GLFW_OPENGL_FORWARD_COMPAT:
2010-09-09 12:15:32 -04:00
return window->glForward;
2010-09-07 11:34:51 -04:00
case GLFW_OPENGL_DEBUG_CONTEXT:
2010-09-09 12:15:32 -04:00
return window->glDebug;
2010-09-07 11:34:51 -04:00
case GLFW_OPENGL_PROFILE:
2010-09-09 12:15:32 -04:00
return window->glProfile;
2011-03-07 14:51:34 -05:00
case GLFW_OPENGL_ROBUSTNESS:
return window->glRobustness;
2010-09-07 11:34:51 -04:00
}
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return 0;
2010-09-07 11:34:51 -04:00
}
2010-09-09 16:44:38 -04:00
//========================================================================
// Set the user pointer for the specified window
//========================================================================
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow handle, void* pointer)
2010-09-09 16:44:38 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-09 16:44:38 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-09 16:44:38 -04:00
return;
}
window->userPointer = pointer;
}
//========================================================================
// Get the user pointer for the specified window
//========================================================================
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle)
2010-09-09 16:44:38 -04:00
{
2011-04-06 14:38:55 -04:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2010-09-09 16:44:38 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
2010-09-09 16:44:38 -04:00
}
return window->userPointer;
}
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-07 11:50:43 -04:00
// Set callback function for window size changes
2010-09-07 11:34:51 -04:00
//========================================================================
2010-10-24 12:28:55 -04:00
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
2010-09-07 11:34:51 -04:00
{
2010-09-09 12:15:32 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
2010-10-24 12:28:55 -04:00
_glfwLibrary.windowSizeCallback = cbfun;
2010-09-07 11:34:51 -04:00
// Call the callback function to let the application know the current
// window size
2010-09-08 08:45:52 -04:00
if (cbfun)
2010-10-24 12:28:55 -04:00
{
_GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next)
cbfun(window, window->width, window->height);
}
2010-09-07 11:34:51 -04:00
}
2011-10-08 17:57:03 -04:00
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-07 11:50:43 -04:00
// Set callback function for window close events
2010-09-07 11:34:51 -04:00
//========================================================================
2010-10-24 12:28:55 -04:00
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun)
2010-09-07 11:34:51 -04:00
{
2010-09-09 12:15:32 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
2010-10-24 12:28:55 -04:00
_glfwLibrary.windowCloseCallback = cbfun;
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Set callback function for window refresh events
2010-09-07 11:34:51 -04:00
//========================================================================
2010-10-24 12:28:55 -04:00
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun)
2010-09-07 11:34:51 -04:00
{
2010-09-09 12:15:32 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
2010-10-24 12:28:55 -04:00
_glfwLibrary.windowRefreshCallback = cbfun;
2010-09-07 11:34:51 -04:00
}
//========================================================================
// Set callback function for window focus events
//========================================================================
2010-10-24 12:28:55 -04:00
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindowfocusfun cbfun)
{
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
2010-10-24 12:28:55 -04:00
_glfwLibrary.windowFocusCallback = cbfun;
}
2010-09-19 20:22:35 -04:00
//========================================================================
// Set callback function for window iconification events
//========================================================================
2010-10-24 12:28:55 -04:00
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindowiconifyfun cbfun)
2010-09-19 20:22:35 -04:00
{
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-19 20:22:35 -04:00
return;
}
2010-10-24 12:28:55 -04:00
_glfwLibrary.windowIconifyCallback = cbfun;
2010-09-19 20:22:35 -04:00
}
2010-09-07 11:34:51 -04:00
//========================================================================
// Poll for new window and input events and close any flagged windows
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-08 08:45:52 -04:00
GLFWAPI void glfwPollEvents(void)
2010-09-07 11:34:51 -04:00
{
2010-09-09 12:15:32 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
clearScrollOffsets();
2010-09-07 11:34:51 -04:00
_glfwPlatformPollEvents();
closeFlaggedWindows();
2010-09-07 11:34:51 -04:00
}
//========================================================================
2010-09-07 11:50:43 -04:00
// Wait for new window and input events
2010-09-07 11:34:51 -04:00
//========================================================================
2010-09-08 08:45:52 -04:00
GLFWAPI void glfwWaitEvents(void)
2010-09-07 11:34:51 -04:00
{
2010-09-09 12:15:32 -04:00
if (!_glfwInitialized)
{
2010-11-23 11:45:23 -05:00
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
2010-09-07 11:34:51 -04:00
return;
}
2010-09-07 11:34:51 -04:00
clearScrollOffsets();
2010-09-07 11:34:51 -04:00
_glfwPlatformWaitEvents();
closeFlaggedWindows();
2010-09-07 11:34:51 -04:00
}