glfw/src/window.c

748 lines
22 KiB
C
Raw Normal View History

2010-09-07 17:34:51 +02:00
//========================================================================
// GLFW 3.1 - www.glfw.org
2010-09-07 17:34:51 +02:00
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
// Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net>
2010-09-07 17:34:51 +02:00
//
// 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 18:15:32 +02:00
#include <stdlib.h>
2010-09-07 17:34:51 +02:00
2010-09-09 20:59:50 +02:00
//////////////////////////////////////////////////////////////////////////
////// GLFW event API //////
2010-09-09 20:59:50 +02:00
//////////////////////////////////////////////////////////////////////////
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
{
if (focused)
{
2014-04-08 15:50:27 +02:00
_glfw.focusedWindow = window;
2012-09-16 12:42:51 +02:00
2014-04-08 15:50:27 +02:00
if (window->callbacks.focus)
window->callbacks.focus((GLFWwindow*) window, focused);
}
else
{
2014-04-08 15:50:27 +02:00
int i;
_glfw.focusedWindow = NULL;
if (window->callbacks.focus)
window->callbacks.focus((GLFWwindow*) window, focused);
// Release all pressed keyboard keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->keys[i] == GLFW_PRESS)
2014-04-08 15:50:27 +02:00
_glfwInputKey(window, i, 0, GLFW_RELEASE, 0);
}
// Release all pressed mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
2012-09-16 12:42:51 +02:00
{
if (window->mouseButtons[i] == GLFW_PRESS)
2014-04-08 15:50:27 +02:00
_glfwInputMouseClick(window, i, GLFW_RELEASE, 0);
2012-09-16 12:42:51 +02:00
}
}
}
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{
2013-01-15 21:34:26 +01:00
if (window->callbacks.pos)
window->callbacks.pos((GLFWwindow*) window, x, y);
}
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
{
2013-01-15 21:34:26 +01:00
if (window->callbacks.size)
window->callbacks.size((GLFWwindow*) window, width, height);
}
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
{
window->iconified = iconified;
2013-01-15 21:34:26 +01:00
if (window->callbacks.iconify)
window->callbacks.iconify((GLFWwindow*) window, iconified);
}
void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
{
if (window->callbacks.fbsize)
window->callbacks.fbsize((GLFWwindow*) window, width, height);
}
void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
{
window->visible = visible;
}
void _glfwInputWindowDamage(_GLFWwindow* window)
{
2013-01-15 21:34:26 +01:00
if (window->callbacks.refresh)
window->callbacks.refresh((GLFWwindow*) window);
}
void _glfwInputWindowCloseRequest(_GLFWwindow* window)
{
2013-10-17 15:15:40 +02:00
window->closed = GL_TRUE;
2013-01-15 21:34:26 +01:00
if (window->callbacks.close)
window->callbacks.close((GLFWwindow*) window);
}
2010-09-09 20:59:50 +02:00
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
2010-09-07 17:34:51 +02:00
GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
const char* title,
GLFWmonitor* monitor,
GLFWwindow* share)
2010-09-07 17:34:51 +02:00
{
_GLFWfbconfig fbconfig;
_GLFWctxconfig ctxconfig;
2010-09-07 17:34:51 +02:00
_GLFWwndconfig wndconfig;
2010-09-09 18:15:32 +02:00
_GLFWwindow* window;
_GLFWwindow* previous;
2010-09-07 17:34:51 +02:00
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
2013-01-04 07:28:12 +01:00
if (width <= 0 || height <= 0)
{
_glfwInputError(GLFW_INVALID_VALUE, "Invalid window size");
return NULL;
2013-01-04 07:28:12 +01:00
}
2010-09-09 18:15:32 +02:00
2010-09-07 17:34:51 +02:00
// Set up desired framebuffer config
fbconfig.redBits = _glfw.hints.redBits;
fbconfig.greenBits = _glfw.hints.greenBits;
fbconfig.blueBits = _glfw.hints.blueBits;
fbconfig.alphaBits = _glfw.hints.alphaBits;
fbconfig.depthBits = _glfw.hints.depthBits;
fbconfig.stencilBits = _glfw.hints.stencilBits;
fbconfig.accumRedBits = _glfw.hints.accumRedBits;
fbconfig.accumGreenBits = _glfw.hints.accumGreenBits;
fbconfig.accumBlueBits = _glfw.hints.accumBlueBits;
fbconfig.accumAlphaBits = _glfw.hints.accumAlphaBits;
fbconfig.auxBuffers = _glfw.hints.auxBuffers;
2014-09-18 20:40:03 +02:00
fbconfig.stereo = _glfw.hints.stereo ? GL_TRUE : GL_FALSE;
fbconfig.samples = _glfw.hints.samples;
fbconfig.sRGB = _glfw.hints.sRGB;
2014-04-24 19:21:10 +02:00
fbconfig.doublebuffer = _glfw.hints.doublebuffer ? GL_TRUE : GL_FALSE;
2010-09-07 17:34:51 +02:00
// Set up desired window config
wndconfig.width = width;
wndconfig.height = height;
wndconfig.title = title;
wndconfig.resizable = _glfw.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.visible = _glfw.hints.visible ? GL_TRUE : GL_FALSE;
2013-04-08 15:16:32 +02:00
wndconfig.decorated = _glfw.hints.decorated ? GL_TRUE : GL_FALSE;
wndconfig.focused = _glfw.hints.focused ? GL_TRUE : GL_FALSE;
wndconfig.autoIconify = _glfw.hints.autoIconify ? GL_TRUE : GL_FALSE;
2014-05-23 14:01:02 +02:00
wndconfig.floating = _glfw.hints.floating ? GL_TRUE : GL_FALSE;
wndconfig.monitor = (_GLFWmonitor*) monitor;
// Set up desired context config
ctxconfig.api = _glfw.hints.api;
ctxconfig.major = _glfw.hints.major;
ctxconfig.minor = _glfw.hints.minor;
ctxconfig.forward = _glfw.hints.forward ? GL_TRUE : GL_FALSE;
ctxconfig.debug = _glfw.hints.debug ? GL_TRUE : GL_FALSE;
ctxconfig.profile = _glfw.hints.profile;
ctxconfig.robustness = _glfw.hints.robustness;
ctxconfig.release = _glfw.hints.release;
ctxconfig.share = (_GLFWwindow*) share;
2010-09-07 17:34:51 +02:00
// Check the OpenGL bits of the window config
if (!_glfwIsValidContextConfig(&ctxconfig))
return NULL;
2010-09-07 17:34:51 +02:00
window = calloc(1, sizeof(_GLFWwindow));
window->next = _glfw.windowListHead;
_glfw.windowListHead = window;
2011-03-07 14:30:23 +01:00
if (wndconfig.monitor)
{
wndconfig.resizable = GL_TRUE;
wndconfig.visible = GL_TRUE;
wndconfig.focused = GL_TRUE;
2013-05-30 20:42:50 +02:00
// Set up desired video mode
window->videoMode.width = width;
window->videoMode.height = height;
window->videoMode.redBits = _glfw.hints.redBits;
window->videoMode.greenBits = _glfw.hints.greenBits;
window->videoMode.blueBits = _glfw.hints.blueBits;
window->videoMode.refreshRate = _glfw.hints.refreshRate;
}
// Transfer window hints that are persistent settings and not
// just initial states
window->monitor = wndconfig.monitor;
window->resizable = wndconfig.resizable;
window->decorated = wndconfig.decorated;
window->autoIconify = wndconfig.autoIconify;
2014-05-23 14:01:02 +02:00
window->floating = wndconfig.floating;
window->cursorMode = GLFW_CURSOR_NORMAL;
2010-09-07 17:34:51 +02:00
2013-01-04 07:28:12 +01:00
// Save the currently current context so it can be restored later
previous = _glfwPlatformGetCurrentContext();
2013-01-04 07:28:12 +01:00
2011-03-04 17:49:36 +01:00
// Open the actual window and create its context
if (!_glfwPlatformCreateWindow(window, &wndconfig, &ctxconfig, &fbconfig))
2010-09-09 18:15:32 +02:00
{
glfwDestroyWindow((GLFWwindow*) window);
_glfwPlatformMakeContextCurrent(previous);
return NULL;
2010-09-09 18:15:32 +02:00
}
2010-09-07 17:34:51 +02:00
_glfwPlatformMakeContextCurrent(window);
2012-09-23 14:08:36 +02:00
// Retrieve the actual (as opposed to requested) context attributes
if (!_glfwRefreshContextAttribs(&ctxconfig))
2012-08-02 14:42:24 +02:00
{
glfwDestroyWindow((GLFWwindow*) window);
_glfwPlatformMakeContextCurrent(previous);
return NULL;
2012-08-02 14:42:24 +02:00
}
2012-08-03 15:21:49 +02:00
// Verify the context against the requested parameters
if (!_glfwIsValidContext(&ctxconfig))
2010-09-07 17:34:51 +02:00
{
glfwDestroyWindow((GLFWwindow*) window);
_glfwPlatformMakeContextCurrent(previous);
return NULL;
2010-09-07 17:34:51 +02:00
}
2012-09-23 14:08:36 +02:00
// Clearing the front buffer to black to avoid garbage pixels left over
// from previous uses of our bit of VRAM
glClear(GL_COLOR_BUFFER_BIT);
_glfwPlatformSwapBuffers(window);
// Restore the previously current context (or NULL)
_glfwPlatformMakeContextCurrent(previous);
if (wndconfig.monitor)
{
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
window->cursorPosX = width / 2;
window->cursorPosY = height / 2;
_glfwPlatformSetCursorPos(window, window->cursorPosX, window->cursorPosY);
}
else
{
if (wndconfig.visible)
{
if (wndconfig.focused)
_glfwPlatformShowWindow(window);
else
_glfwPlatformUnhideWindow(window);
}
}
return (GLFWwindow*) window;
2010-09-09 18:15:32 +02:00
}
2012-10-22 02:59:05 +02:00
void glfwDefaultWindowHints(void)
{
_GLFW_REQUIRE_INIT();
2012-10-22 02:59:05 +02:00
memset(&_glfw.hints, 0, sizeof(_glfw.hints));
2012-10-22 02:59:05 +02:00
// The default is OpenGL with minimum version 1.0
_glfw.hints.api = GLFW_OPENGL_API;
_glfw.hints.major = 1;
_glfw.hints.minor = 0;
2012-10-22 02:59:05 +02:00
// The default is a focused, visible, resizable window with decorations
_glfw.hints.resizable = GL_TRUE;
_glfw.hints.visible = GL_TRUE;
_glfw.hints.decorated = GL_TRUE;
_glfw.hints.focused = GL_TRUE;
_glfw.hints.autoIconify = GL_TRUE;
2012-10-22 02:59:05 +02:00
// The default is to select the highest available refresh rate
_glfw.hints.refreshRate = GLFW_DONT_CARE;
2014-04-24 19:21:10 +02:00
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
// double buffered
_glfw.hints.redBits = 8;
_glfw.hints.greenBits = 8;
_glfw.hints.blueBits = 8;
_glfw.hints.alphaBits = 8;
_glfw.hints.depthBits = 24;
_glfw.hints.stencilBits = 8;
_glfw.hints.doublebuffer = GL_TRUE;
2012-10-22 02:59:05 +02:00
}
GLFWAPI void glfwWindowHint(int target, int hint)
2010-09-07 17:34:51 +02:00
{
_GLFW_REQUIRE_INIT();
2010-09-07 17:34:51 +02:00
2010-09-08 14:45:52 +02:00
switch (target)
2010-09-07 17:34:51 +02:00
{
case GLFW_RED_BITS:
_glfw.hints.redBits = hint;
break;
case GLFW_GREEN_BITS:
_glfw.hints.greenBits = hint;
break;
case GLFW_BLUE_BITS:
_glfw.hints.blueBits = hint;
break;
case GLFW_ALPHA_BITS:
_glfw.hints.alphaBits = hint;
break;
case GLFW_DEPTH_BITS:
_glfw.hints.depthBits = hint;
break;
case GLFW_STENCIL_BITS:
_glfw.hints.stencilBits = hint;
break;
2010-09-07 17:34:51 +02:00
case GLFW_ACCUM_RED_BITS:
_glfw.hints.accumRedBits = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_ACCUM_GREEN_BITS:
_glfw.hints.accumGreenBits = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_ACCUM_BLUE_BITS:
_glfw.hints.accumBlueBits = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_ACCUM_ALPHA_BITS:
_glfw.hints.accumAlphaBits = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_AUX_BUFFERS:
_glfw.hints.auxBuffers = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_STEREO:
_glfw.hints.stereo = hint;
2010-09-07 17:34:51 +02:00
break;
2013-05-30 20:42:50 +02:00
case GLFW_REFRESH_RATE:
_glfw.hints.refreshRate = hint;
break;
2014-04-24 19:21:10 +02:00
case GLFW_DOUBLEBUFFER:
_glfw.hints.doublebuffer = hint;
break;
case GLFW_RESIZABLE:
_glfw.hints.resizable = hint;
2010-09-07 17:34:51 +02:00
break;
2013-04-08 15:16:32 +02:00
case GLFW_DECORATED:
_glfw.hints.decorated = hint;
break;
case GLFW_FOCUSED:
_glfw.hints.focused = hint;
break;
case GLFW_AUTO_ICONIFY:
_glfw.hints.autoIconify = hint;
break;
2014-05-23 14:01:02 +02:00
case GLFW_FLOATING:
_glfw.hints.floating = hint;
break;
case GLFW_VISIBLE:
_glfw.hints.visible = hint;
break;
case GLFW_SAMPLES:
_glfw.hints.samples = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_SRGB_CAPABLE:
_glfw.hints.sRGB = hint;
break;
case GLFW_CLIENT_API:
_glfw.hints.api = hint;
break;
case GLFW_CONTEXT_VERSION_MAJOR:
_glfw.hints.major = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_CONTEXT_VERSION_MINOR:
_glfw.hints.minor = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_CONTEXT_ROBUSTNESS:
_glfw.hints.robustness = hint;
break;
2010-09-07 17:34:51 +02:00
case GLFW_OPENGL_FORWARD_COMPAT:
_glfw.hints.forward = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_OPENGL_DEBUG_CONTEXT:
_glfw.hints.debug = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_OPENGL_PROFILE:
_glfw.hints.profile = hint;
2010-09-07 17:34:51 +02:00
break;
case GLFW_CONTEXT_RELEASE_BEHAVIOR:
_glfw.hints.release = hint;
break;
2010-09-07 17:34:51 +02:00
default:
_glfwInputError(GLFW_INVALID_ENUM, NULL);
2010-09-07 17:34:51 +02:00
break;
}
}
GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
2010-09-07 17:34:51 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
2010-09-07 17:34:51 +02:00
2011-03-08 23:14:42 +01:00
// Allow closing of NULL (to match the behavior of free)
if (window == NULL)
return;
// Clear all callbacks to avoid exposing a half torn-down window object
2013-01-15 21:34:26 +01:00
memset(&window->callbacks, 0, sizeof(window->callbacks));
// The window's context must not be current on another thread when the
// window is destroyed
if (window == _glfwPlatformGetCurrentContext())
_glfwPlatformMakeContextCurrent(NULL);
2010-09-07 17:34:51 +02:00
// Clear the focused window pointer if this is the focused window
if (window == _glfw.focusedWindow)
_glfw.focusedWindow = NULL;
2010-09-11 15:14:57 +02:00
_glfwPlatformDestroyWindow(window);
2010-09-09 18:15:32 +02:00
2010-09-16 02:05:01 +02:00
// Unlink window from global linked list
{
_GLFWwindow** prev = &_glfw.windowListHead;
2010-09-16 02:05:01 +02:00
while (*prev != window)
prev = &((*prev)->next);
2010-09-10 00:06:23 +02:00
2010-09-16 02:05:01 +02:00
*prev = window->next;
}
2010-09-10 00:30:10 +02:00
2012-02-07 14:58:58 +01:00
free(window);
2010-09-07 17:34:51 +02:00
}
GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(0);
return window->closed;
}
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
window->closed = value;
}
GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
2010-09-07 17:34:51 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
2010-09-09 18:15:32 +02:00
_glfwPlatformSetWindowTitle(window, title);
2010-09-07 17:34:51 +02:00
}
GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
2014-04-07 15:28:32 +02:00
if (xpos)
*xpos = 0;
if (ypos)
*ypos = 0;
_GLFW_REQUIRE_INIT();
_glfwPlatformGetWindowPos(window, xpos, ypos);
}
GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (window->monitor)
{
_glfwInputError(GLFW_INVALID_VALUE,
"Fullscreen windows cannot be positioned");
return;
}
_glfwPlatformSetWindowPos(window, xpos, ypos);
}
GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height)
2010-09-07 17:34:51 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
2014-04-07 15:28:32 +02:00
if (width)
*width = 0;
if (height)
*height = 0;
_GLFW_REQUIRE_INIT();
_glfwPlatformGetWindowSize(window, width, height);
2010-09-07 17:34:51 +02:00
}
GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
2010-09-07 17:34:51 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (window->monitor)
{
window->videoMode.width = width;
window->videoMode.height = height;
}
2010-09-09 18:15:32 +02:00
_glfwPlatformSetWindowSize(window, width, height);
2010-09-07 17:34:51 +02:00
}
GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
2014-04-07 15:28:32 +02:00
if (width)
*width = 0;
if (height)
*height = 0;
2014-04-07 15:28:32 +02:00
_GLFW_REQUIRE_INIT();
_glfwPlatformGetFramebufferSize(window, width, height);
}
2014-03-25 21:30:13 +01:00
GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle,
int* left, int* top,
int* right, int* bottom)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
2014-04-07 15:28:32 +02:00
if (left)
*left = 0;
if (top)
*top = 0;
if (right)
*right = 0;
if (bottom)
*bottom = 0;
2014-03-25 21:30:13 +01:00
_GLFW_REQUIRE_INIT();
_glfwPlatformGetWindowFrameSize(window, left, top, right, bottom);
}
GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
2010-09-07 17:34:51 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
2010-09-09 18:15:32 +02:00
_glfwPlatformIconifyWindow(window);
2010-09-07 17:34:51 +02:00
}
GLFWAPI void glfwRestoreWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
2012-09-11 23:56:44 +02:00
_glfwPlatformRestoreWindow(window);
}
GLFWAPI void glfwShowWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
2012-09-27 21:37:36 +02:00
if (window->monitor)
return;
2012-09-11 23:56:44 +02:00
_glfwPlatformShowWindow(window);
}
GLFWAPI void glfwHideWindow(GLFWwindow* handle)
2010-09-07 17:34:51 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
2012-09-27 21:37:36 +02:00
if (window->monitor)
2010-09-07 17:34:51 +02:00
return;
2012-09-11 23:56:44 +02:00
_glfwPlatformHideWindow(window);
2010-09-07 17:34:51 +02:00
}
GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
2010-09-07 17:34:51 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(0);
2010-09-07 17:34:51 +02:00
switch (attrib)
2010-09-07 17:34:51 +02:00
{
case GLFW_FOCUSED:
return window == _glfw.focusedWindow;
2010-09-07 17:34:51 +02:00
case GLFW_ICONIFIED:
2010-09-09 18:15:32 +02:00
return window->iconified;
case GLFW_RESIZABLE:
return window->resizable;
2013-04-08 15:16:32 +02:00
case GLFW_DECORATED:
return window->decorated;
2014-05-23 14:01:02 +02:00
case GLFW_FLOATING:
return window->floating;
2012-08-21 21:57:13 +02:00
case GLFW_VISIBLE:
return window->visible;
2012-09-30 15:43:26 +02:00
case GLFW_CLIENT_API:
return window->context.api;
case GLFW_CONTEXT_VERSION_MAJOR:
return window->context.major;
case GLFW_CONTEXT_VERSION_MINOR:
return window->context.minor;
case GLFW_CONTEXT_REVISION:
return window->context.revision;
case GLFW_CONTEXT_ROBUSTNESS:
return window->context.robustness;
2010-09-07 17:34:51 +02:00
case GLFW_OPENGL_FORWARD_COMPAT:
return window->context.forward;
2010-09-07 17:34:51 +02:00
case GLFW_OPENGL_DEBUG_CONTEXT:
return window->context.debug;
2010-09-07 17:34:51 +02:00
case GLFW_OPENGL_PROFILE:
return window->context.profile;
case GLFW_CONTEXT_RELEASE_BEHAVIOR:
return window->context.release;
2010-09-07 17:34:51 +02:00
}
_glfwInputError(GLFW_INVALID_ENUM, NULL);
return 0;
2010-09-07 17:34:51 +02:00
}
GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle)
2012-10-02 17:24:18 +02:00
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return (GLFWmonitor*) window->monitor;
2012-10-02 17:24:18 +02:00
}
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer)
2010-09-09 22:44:38 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
2010-09-09 22:44:38 +02:00
window->userPointer = pointer;
}
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
2010-09-09 22:44:38 +02:00
{
2011-04-06 20:38:55 +02:00
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
2010-09-09 22:44:38 +02:00
return window->userPointer;
}
GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
GLFWwindowposfun cbfun)
2012-11-30 13:56:42 +01:00
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.pos, cbfun);
return cbfun;
2012-11-30 13:56:42 +01:00
}
GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
GLFWwindowsizefun cbfun)
2010-09-07 17:34:51 +02:00
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.size, cbfun);
return cbfun;
2010-09-07 17:34:51 +02:00
}
GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
GLFWwindowclosefun cbfun)
2010-09-07 17:34:51 +02:00
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.close, cbfun);
return cbfun;
2010-09-07 17:34:51 +02:00
}
GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
GLFWwindowrefreshfun cbfun)
2010-09-07 17:34:51 +02:00
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.refresh, cbfun);
return cbfun;
2010-09-07 17:34:51 +02:00
}
GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
GLFWwindowfocusfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.focus, cbfun);
return cbfun;
}
GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
GLFWwindowiconifyfun cbfun)
2010-09-20 02:22:35 +02:00
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.iconify, cbfun);
return cbfun;
2010-09-20 02:22:35 +02:00
}
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
GLFWframebuffersizefun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.fbsize, cbfun);
return cbfun;
}
2010-09-08 14:45:52 +02:00
GLFWAPI void glfwPollEvents(void)
2010-09-07 17:34:51 +02:00
{
_GLFW_REQUIRE_INIT();
2010-09-07 17:34:51 +02:00
_glfwPlatformPollEvents();
}
2010-09-08 14:45:52 +02:00
GLFWAPI void glfwWaitEvents(void)
2010-09-07 17:34:51 +02:00
{
_GLFW_REQUIRE_INIT();
2014-02-10 18:16:58 +01:00
if (!_glfw.windowListHead)
return;
2010-09-07 17:34:51 +02:00
_glfwPlatformWaitEvents();
}
2014-02-10 18:16:58 +01:00
GLFWAPI void glfwPostEmptyEvent(void)
{
_GLFW_REQUIRE_INIT();
if (!_glfw.windowListHead)
return;
_glfwPlatformPostEmptyEvent();
}