glfw/lib/enable.c

269 lines
7.8 KiB
C
Raw Normal View History

2010-09-07 15:34:51 +00:00
//========================================================================
// GLFW - An OpenGL framework
// Platform: Any
2010-09-07 15:41:26 +00:00
// API version: 3.0
2010-09-07 15:34:51 +00: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"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//========================================================================
// Enable (show) mouse cursor
//========================================================================
2010-09-09 16:15:32 +00:00
static void enableMouseCursor(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
int centerPosX, centerPosY;
2010-09-09 16:15:32 +00:00
if (_glfwLibrary.cursorLockWindow != window)
2010-09-07 15:34:51 +00:00
return;
// Show mouse cursor
2010-09-09 16:15:32 +00:00
_glfwPlatformShowMouseCursor(window);
2010-09-07 15:34:51 +00:00
2010-09-09 16:15:32 +00:00
centerPosX = window->width / 2;
centerPosY = window->height / 2;
2010-09-07 15:34:51 +00:00
2010-09-09 16:15:32 +00:00
if (centerPosX != window->mousePosX || centerPosY != window->mousePosY)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
2010-09-07 15:34:51 +00:00
2010-09-09 16:15:32 +00:00
window->mousePosX = centerPosX;
window->mousePosY = centerPosY;
2010-09-07 15:34:51 +00:00
2010-09-09 16:15:32 +00:00
if (window->mousePosCallback)
2010-09-07 15:34:51 +00:00
{
window->mousePosCallback(window,
window->mousePosX,
2010-09-09 16:15:32 +00:00
window->mousePosY);
2010-09-07 15:34:51 +00:00
}
}
// From now on the mouse is unlocked
2010-09-09 16:15:32 +00:00
_glfwLibrary.cursorLockWindow = NULL;
2010-09-07 15:34:51 +00:00
}
//========================================================================
// Disable (hide) mouse cursor
//========================================================================
2010-09-09 16:15:32 +00:00
static void disableMouseCursor(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
if (_glfwLibrary.cursorLockWindow)
2010-09-07 15:34:51 +00:00
return;
// Hide mouse cursor
2010-09-09 16:15:32 +00:00
_glfwPlatformHideMouseCursor(window);
2010-09-07 15:34:51 +00:00
// Move cursor to the middle of the window
2010-09-09 16:15:32 +00:00
_glfwPlatformSetMouseCursorPos(window,
window->width / 2,
window->height / 2);
2010-09-07 15:34:51 +00:00
// From now on the mouse is locked
2010-09-09 16:15:32 +00:00
_glfwLibrary.cursorLockWindow = window;
2010-09-07 15:34:51 +00:00
}
//========================================================================
// Enable sticky keys
//========================================================================
2010-09-09 16:15:32 +00:00
static void enableStickyKeys(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
window->stickyKeys = GL_TRUE;
2010-09-07 15:34:51 +00:00
}
//========================================================================
// Disable sticky keys
//========================================================================
2010-09-09 16:15:32 +00:00
static void disableStickyKeys(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
int i;
2010-09-09 16:15:32 +00:00
window->stickyKeys = GL_FALSE;
2010-09-07 15:34:51 +00:00
// Release all sticky keys
2010-09-08 12:45:52 +00:00
for (i = 0; i <= GLFW_KEY_LAST; i++)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
if (window->key[i] == GLFW_STICK)
window->key[i] = GLFW_RELEASE;
2010-09-07 15:34:51 +00:00
}
}
//========================================================================
// Enable sticky mouse buttons
//========================================================================
2010-09-09 16:15:32 +00:00
static void enableStickyMouseButtons(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
window->stickyMouseButtons = GL_TRUE;
2010-09-07 15:34:51 +00:00
}
//========================================================================
// Disable sticky mouse buttons
//========================================================================
2010-09-09 16:15:32 +00:00
static void disableStickyMouseButtons(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
int i;
2010-09-09 16:15:32 +00:00
window->stickyMouseButtons = GL_FALSE;
2010-09-07 15:34:51 +00:00
// Release all sticky mouse buttons
2010-09-08 12:45:52 +00:00
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
if (window->mouseButton[i] == GLFW_STICK)
window->mouseButton[i] = GLFW_RELEASE;
2010-09-07 15:34:51 +00:00
}
}
//========================================================================
// Enable system keys
//========================================================================
2010-09-09 16:15:32 +00:00
static void enableSystemKeys(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
if (!window->sysKeysDisabled)
2010-09-07 15:34:51 +00:00
return;
2010-09-09 16:15:32 +00:00
_glfwPlatformEnableSystemKeys(window);
2010-09-07 15:34:51 +00:00
// Indicate that system keys are no longer disabled
2010-09-09 16:15:32 +00:00
window->sysKeysDisabled = GL_FALSE;
2010-09-07 15:34:51 +00:00
}
//========================================================================
// Disable system keys
//========================================================================
2010-09-09 16:15:32 +00:00
static void disableSystemKeys(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
if (window->sysKeysDisabled)
2010-09-07 15:34:51 +00:00
return;
2010-09-09 16:15:32 +00:00
_glfwPlatformDisableSystemKeys(window);
2010-09-07 15:34:51 +00:00
// Indicate that system keys are now disabled
2010-09-09 16:15:32 +00:00
window->sysKeysDisabled = GL_TRUE;
2010-09-07 15:34:51 +00:00
}
//========================================================================
// Enable key repeat
//========================================================================
2010-09-09 16:15:32 +00:00
static void enableKeyRepeat(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
window->keyRepeat = GL_TRUE;
2010-09-07 15:34:51 +00:00
}
//========================================================================
// Disable key repeat
//========================================================================
2010-09-09 16:15:32 +00:00
static void disableKeyRepeat(_GLFWwindow* window)
2010-09-07 15:34:51 +00:00
{
2010-09-09 16:15:32 +00:00
window->keyRepeat = GL_FALSE;
2010-09-07 15:34:51 +00:00
}
//************************************************************************
//**** GLFW user functions ****
//************************************************************************
//========================================================================
2010-09-09 16:15:32 +00:00
// Enable certain GLFW/window/system functions
2010-09-07 15:34:51 +00:00
//========================================================================
2010-09-09 16:15:32 +00:00
GLFWAPI void glfwEnable(GLFWwindow window, int token)
2010-09-07 15:34:51 +00:00
{
2010-09-08 12:45:52 +00:00
if (!_glfwInitialized)
2010-09-07 15:34:51 +00:00
return;
2010-09-08 12:45:52 +00:00
switch (token)
2010-09-07 15:34:51 +00:00
{
case GLFW_MOUSE_CURSOR:
2010-09-09 16:15:32 +00:00
enableMouseCursor(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_STICKY_KEYS:
2010-09-09 16:15:32 +00:00
enableStickyKeys(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_STICKY_MOUSE_BUTTONS:
2010-09-09 16:15:32 +00:00
enableStickyMouseButtons(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_SYSTEM_KEYS:
2010-09-09 16:15:32 +00:00
enableSystemKeys(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_KEY_REPEAT:
2010-09-09 16:15:32 +00:00
enableKeyRepeat(window);
2010-09-07 15:34:51 +00:00
break;
default:
break;
}
}
//========================================================================
2010-09-09 16:15:32 +00:00
// Disable certain GLFW/window/system functions
2010-09-07 15:34:51 +00:00
//========================================================================
2010-09-09 16:15:32 +00:00
GLFWAPI void glfwDisable(GLFWwindow window, int token)
2010-09-07 15:34:51 +00:00
{
2010-09-08 12:45:52 +00:00
if (!_glfwInitialized)
2010-09-07 15:34:51 +00:00
return;
2010-09-08 12:45:52 +00:00
switch (token)
2010-09-07 15:34:51 +00:00
{
case GLFW_MOUSE_CURSOR:
2010-09-09 16:15:32 +00:00
disableMouseCursor(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_STICKY_KEYS:
2010-09-09 16:15:32 +00:00
disableStickyKeys(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_STICKY_MOUSE_BUTTONS:
2010-09-09 16:15:32 +00:00
disableStickyMouseButtons(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_SYSTEM_KEYS:
2010-09-09 16:15:32 +00:00
disableSystemKeys(window);
2010-09-07 15:34:51 +00:00
break;
case GLFW_KEY_REPEAT:
2010-09-09 16:15:32 +00:00
disableKeyRepeat(window);
2010-09-07 15:34:51 +00:00
break;
default:
break;
}
}