2010-09-07 11:34:51 -04:00
|
|
|
//========================================================================
|
|
|
|
// GLFW - An OpenGL framework
|
|
|
|
// 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"
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
//**** GLFW internal functions ****
|
|
|
|
//************************************************************************
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable (show) mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void enableMouseCursor(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
int centerPosX, centerPosY;
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
if (!_glfwWin.opened || !_glfwWin.mouseLock)
|
2010-09-07 11:34:51 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Show mouse cursor
|
|
|
|
_glfwPlatformShowMouseCursor();
|
|
|
|
|
|
|
|
centerPosX = _glfwWin.width / 2;
|
|
|
|
centerPosY = _glfwWin.height / 2;
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
if (centerPosX != _glfwInput.MousePosX || centerPosY != _glfwInput.MousePosY)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
_glfwPlatformSetMouseCursorPos(centerPosX, centerPosY);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
_glfwInput.MousePosX = centerPosX;
|
|
|
|
_glfwInput.MousePosY = centerPosY;
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
if (_glfwWin.mousePosCallback)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
_glfwWin.mousePosCallback(_glfwInput.MousePosX,
|
|
|
|
_glfwInput.MousePosY);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// From now on the mouse is unlocked
|
|
|
|
_glfwWin.mouseLock = GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Disable (hide) mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void disableMouseCursor(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
if (!_glfwWin.opened || _glfwWin.mouseLock)
|
2010-09-07 11:34:51 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Hide mouse cursor
|
|
|
|
_glfwPlatformHideMouseCursor();
|
|
|
|
|
|
|
|
// Move cursor to the middle of the window
|
2010-09-08 08:45:52 -04:00
|
|
|
_glfwPlatformSetMouseCursorPos(_glfwWin.width >> 1,
|
|
|
|
_glfwWin.height >> 1);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// From now on the mouse is locked
|
|
|
|
_glfwWin.mouseLock = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable sticky keys
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void enableStickyKeys(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
_glfwInput.StickyKeys = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Disable sticky keys
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void disableStickyKeys(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_glfwInput.StickyKeys = 0;
|
|
|
|
|
|
|
|
// Release all sticky keys
|
2010-09-08 08:45:52 -04:00
|
|
|
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
if (_glfwInput.Key[i] == 2)
|
|
|
|
_glfwInput.Key[i] = 0;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable sticky mouse buttons
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void enableStickyMouseButtons(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
_glfwInput.StickyMouseButtons = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Disable sticky mouse buttons
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void disableStickyMouseButtons(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_glfwInput.StickyMouseButtons = 0;
|
|
|
|
|
|
|
|
// Release all sticky mouse buttons
|
2010-09-08 08:45:52 -04:00
|
|
|
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
if (_glfwInput.MouseButton[i] == 2)
|
|
|
|
_glfwInput.MouseButton[i] = 0;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable system keys
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void enableSystemKeys(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
if (!_glfwWin.sysKeysDisabled)
|
2010-09-07 11:34:51 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
_glfwPlatformEnableSystemKeys();
|
|
|
|
|
|
|
|
// Indicate that system keys are no longer disabled
|
|
|
|
_glfwWin.sysKeysDisabled = GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Disable system keys
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void disableSystemKeys(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
if (_glfwWin.sysKeysDisabled)
|
2010-09-07 11:34:51 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
_glfwPlatformDisableSystemKeys();
|
|
|
|
|
|
|
|
// Indicate that system keys are now disabled
|
|
|
|
_glfwWin.sysKeysDisabled = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable key repeat
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void enableKeyRepeat(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
_glfwInput.KeyRepeat = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Disable key repeat
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void disableKeyRepeat(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
_glfwInput.KeyRepeat = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable automatic event polling
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void enableAutoPollEvents(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
_glfwWin.autoPollEvents = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Disable automatic event polling
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
static void disableAutoPollEvents(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
_glfwWin.autoPollEvents = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
//**** GLFW user functions ****
|
|
|
|
//************************************************************************
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Enable certain GLFW/window/system functions.
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
GLFWAPI void glfwEnable(int token)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 11:34:51 -04:00
|
|
|
return;
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
switch (token)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
case GLFW_MOUSE_CURSOR:
|
|
|
|
enableMouseCursor();
|
|
|
|
break;
|
|
|
|
case GLFW_STICKY_KEYS:
|
|
|
|
enableStickyKeys();
|
|
|
|
break;
|
|
|
|
case GLFW_STICKY_MOUSE_BUTTONS:
|
|
|
|
enableStickyMouseButtons();
|
|
|
|
break;
|
|
|
|
case GLFW_SYSTEM_KEYS:
|
|
|
|
enableSystemKeys();
|
|
|
|
break;
|
|
|
|
case GLFW_KEY_REPEAT:
|
|
|
|
enableKeyRepeat();
|
|
|
|
break;
|
|
|
|
case GLFW_AUTO_POLL_EVENTS:
|
|
|
|
enableAutoPollEvents();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Disable certain GLFW/window/system functions.
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
GLFWAPI void glfwDisable(int token)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 08:45:52 -04:00
|
|
|
if (!_glfwInitialized)
|
2010-09-07 11:34:51 -04:00
|
|
|
return;
|
|
|
|
|
2010-09-08 08:45:52 -04:00
|
|
|
switch (token)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
case GLFW_MOUSE_CURSOR:
|
|
|
|
disableMouseCursor();
|
|
|
|
break;
|
|
|
|
case GLFW_STICKY_KEYS:
|
|
|
|
disableStickyKeys();
|
|
|
|
break;
|
|
|
|
case GLFW_STICKY_MOUSE_BUTTONS:
|
|
|
|
disableStickyMouseButtons();
|
|
|
|
break;
|
|
|
|
case GLFW_SYSTEM_KEYS:
|
|
|
|
disableSystemKeys();
|
|
|
|
break;
|
|
|
|
case GLFW_KEY_REPEAT:
|
|
|
|
disableKeyRepeat();
|
|
|
|
break;
|
|
|
|
case GLFW_AUTO_POLL_EVENTS:
|
|
|
|
disableAutoPollEvents();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|