Merge branch 'master' into cursor-enter-leave

This commit is contained in:
Camilla Berglund
2012-03-22 12:06:00 +01:00
53 changed files with 3420 additions and 1179 deletions
+191 -55
View File
@@ -31,6 +31,122 @@
#include "internal.h"
//========================================================================
// Sets the cursor mode for the specified window
//========================================================================
static void setCursorMode(_GLFWwindow* window, int mode)
{
int centerPosX, centerPosY;
if (mode != GLFW_CURSOR_NORMAL &&
mode != GLFW_CURSOR_HIDDEN &&
mode != GLFW_CURSOR_CAPTURED)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return;
}
if (window->cursorMode == mode)
return;
centerPosX = window->width / 2;
centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
_glfwInputCursorMotion(window,
centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
window->cursorMode = mode;
}
//========================================================================
// Set sticky keys mode for the specified window
//========================================================================
static void setStickyKeys(_GLFWwindow* window, int enabled)
{
if (window->stickyKeys == enabled)
return;
if (!enabled)
{
int i;
// Release all sticky keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_STICK)
window->key[i] = GLFW_RELEASE;
}
}
window->stickyKeys = enabled;
}
//========================================================================
// Set sticky mouse buttons mode for the specified window
//========================================================================
static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
{
if (window->stickyMouseButtons == enabled)
return;
if (!enabled)
{
int i;
// Release all sticky mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_STICK)
window->mouseButton[i] = GLFW_RELEASE;
}
}
window->stickyMouseButtons = enabled;
}
//========================================================================
// Set system keys for the specified window
//========================================================================
static void setSystemKeys(_GLFWwindow* window, int enabled)
{
if (window->systemKeys == enabled)
return;
if (enabled)
_glfwPlatformEnableSystemKeys(window);
else
_glfwPlatformDisableSystemKeys(window);
window->systemKeys = enabled;
}
//========================================================================
// Set key repeat for the specified window
//========================================================================
static void setKeyRepeat(_GLFWwindow* window, int enabled)
{
window->keyRepeat = enabled;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
@@ -41,7 +157,7 @@
void _glfwInputKey(_GLFWwindow* window, int key, int action)
{
GLboolean keyrepeat = GL_FALSE;
GLboolean repeated = GL_FALSE;
if (key < 0 || key > GLFW_KEY_LAST)
return;
@@ -51,16 +167,16 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
return;
// Register key action
if(action == GLFW_RELEASE && window->stickyKeys)
if (action == GLFW_RELEASE && window->stickyKeys)
window->key[key] = GLFW_STICK;
else
{
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
repeated = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
window->key[key] = (char) action;
}
// Call user callback function
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
if (_glfwLibrary.keyCallback && (window->keyRepeat || !repeated))
_glfwLibrary.keyCallback(window, key, action);
}
@@ -161,6 +277,77 @@ void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Returns the specified input mode of the specified window
//========================================================================
GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
switch (mode)
{
case GLFW_CURSOR_MODE:
return window->cursorMode;
case GLFW_STICKY_KEYS:
return window->stickyKeys;
case GLFW_STICKY_MOUSE_BUTTONS:
return window->stickyMouseButtons;
case GLFW_SYSTEM_KEYS:
return window->systemKeys;
case GLFW_KEY_REPEAT:
return window->keyRepeat;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return 0;
}
}
//========================================================================
// Sets the specified input mode of the specified window
//========================================================================
GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (mode)
{
case GLFW_CURSOR_MODE:
setCursorMode(window, value);
break;
case GLFW_STICKY_KEYS:
setStickyKeys(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_STICKY_MOUSE_BUTTONS:
setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_SYSTEM_KEYS:
setSystemKeys(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_KEY_REPEAT:
setKeyRepeat(window, value ? GL_TRUE : GL_FALSE);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
//========================================================================
// Returns the state of the specified key for the specified window
//========================================================================
@@ -175,10 +362,8 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
return GLFW_RELEASE;
}
// Is it a valid key?
if (key < 0 || key > GLFW_KEY_LAST)
{
// TODO: Decide whether key is a value or enum
_glfwSetError(GLFW_INVALID_ENUM,
"glfwGetKey: The specified key is invalid");
return GLFW_RELEASE;
@@ -209,7 +394,6 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
return GLFW_RELEASE;
}
// Is it a valid mouse button?
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
{
_glfwSetError(GLFW_INVALID_ENUM,
@@ -242,7 +426,6 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
return;
}
// Return mouse position
if (xpos != NULL)
*xpos = window->cursorPosX;
@@ -311,51 +494,6 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
}
//========================================================================
// Sets the cursor mode for the specified window
//========================================================================
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
{
int centerPosX, centerPosY;
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (mode != GLFW_CURSOR_NORMAL &&
mode != GLFW_CURSOR_HIDDEN &&
mode != GLFW_CURSOR_CAPTURED)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return;
}
if (window->cursorMode == mode)
return;
centerPosX = window->width / 2;
centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
_glfwInputCursorMotion(window,
centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
window->cursorMode = mode;
}
//========================================================================
// Set callback function for keyboard input
//========================================================================
@@ -416,7 +554,6 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
return;
}
// Set callback function
_glfwLibrary.mousePosCallback = cbfun;
// Call the callback function to let the application know the current
@@ -459,7 +596,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
return;
}
// Set callback function
_glfwLibrary.scrollCallback = cbfun;
}