From 30ab9e2058ea01a98b9f82855f155b83830fc619 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Oct 2011 17:13:58 +0200 Subject: [PATCH] Moved input-related functions to input file. --- src/input.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/window.c | 101 ------------------------------------------------- 2 files changed, 105 insertions(+), 101 deletions(-) diff --git a/src/input.c b/src/input.c index 8845b758..763172ea 100644 --- a/src/input.c +++ b/src/input.c @@ -31,6 +31,111 @@ #include "internal.h" +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Register keyboard activity +//======================================================================== + +void _glfwInputKey(_GLFWwindow* window, int key, int action) +{ + GLboolean keyrepeat = GL_FALSE; + + if (key < 0 || key > GLFW_KEY_LAST) + return; + + // Are we trying to release an already released key? + if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS) + return; + + // Register key action + if(action == GLFW_RELEASE && window->stickyKeys) + window->key[key] = GLFW_STICK; + else + { + keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS); + window->key[key] = (char) action; + } + + // Call user callback function + if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat)) + _glfwLibrary.keyCallback(window, key, action); +} + + +//======================================================================== +// Register (keyboard) character activity +//======================================================================== + +void _glfwInputChar(_GLFWwindow* window, int character) +{ + // Valid Unicode (ISO 10646) character? + if (!((character >= 32 && character <= 126) || character >= 160)) + return; + + if (_glfwLibrary.charCallback) + _glfwLibrary.charCallback(window, character); +} + + +//======================================================================== +// Register scroll events +//======================================================================== + +void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset) +{ + window->scrollX += xoffset; + window->scrollY += yoffset; + + if (_glfwLibrary.scrollCallback) + _glfwLibrary.scrollCallback(window, xoffset, yoffset); +} + + +//======================================================================== +// Register mouse button clicks +//======================================================================== + +void _glfwInputMouseClick(_GLFWwindow* window, int button, int action) +{ + if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) + return; + + // Register mouse button action + if (action == GLFW_RELEASE && window->stickyMouseButtons) + window->mouseButton[button] = GLFW_STICK; + else + window->mouseButton[button] = (char) action; + + if (_glfwLibrary.mouseButtonCallback) + _glfwLibrary.mouseButtonCallback(window, button, action); +} + + +//======================================================================== +// Register cursor moves +//======================================================================== + +void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y) +{ + if (window->cursorMode == GLFW_CURSOR_CAPTURED) + { + window->mousePosX += x; + window->mousePosY += y; + } + else + { + window->mousePosX = x; + window->mousePosY = y; + } + + if (_glfwLibrary.mousePosCallback) + _glfwLibrary.mousePosCallback(window, x, y); +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/window.c b/src/window.c index 73d32114..131e41fa 100644 --- a/src/window.c +++ b/src/window.c @@ -103,107 +103,6 @@ void _glfwSetDefaultWindowHints(void) } -//======================================================================== -// Register keyboard activity -//======================================================================== - -void _glfwInputKey(_GLFWwindow* window, int key, int action) -{ - GLboolean keyrepeat = GL_FALSE; - - if (key < 0 || key > GLFW_KEY_LAST) - return; - - // Are we trying to release an already released key? - if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS) - return; - - // Register key action - if(action == GLFW_RELEASE && window->stickyKeys) - window->key[key] = GLFW_STICK; - else - { - keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS); - window->key[key] = (char) action; - } - - // Call user callback function - if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat)) - _glfwLibrary.keyCallback(window, key, action); -} - - -//======================================================================== -// Register (keyboard) character activity -//======================================================================== - -void _glfwInputChar(_GLFWwindow* window, int character) -{ - // Valid Unicode (ISO 10646) character? - if (!((character >= 32 && character <= 126) || character >= 160)) - return; - - if (_glfwLibrary.charCallback) - _glfwLibrary.charCallback(window, character); -} - - -//======================================================================== -// Register scroll events -//======================================================================== - -void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset) -{ - window->scrollX += xoffset; - window->scrollY += yoffset; - - if (_glfwLibrary.scrollCallback) - _glfwLibrary.scrollCallback(window, xoffset, yoffset); -} - - -//======================================================================== -// Register mouse button clicks -//======================================================================== - -void _glfwInputMouseClick(_GLFWwindow* window, int button, int action) -{ - if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) - return; - - // Register mouse button action - if (action == GLFW_RELEASE && window->stickyMouseButtons) - window->mouseButton[button] = GLFW_STICK; - else - window->mouseButton[button] = (char) action; - - if (_glfwLibrary.mouseButtonCallback) - _glfwLibrary.mouseButtonCallback(window, button, action); -} - - -//======================================================================== -// Register cursor moves -//======================================================================== - -void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y) -{ - if (window->cursorMode == GLFW_CURSOR_CAPTURED) - { - window->mousePosX += x; - window->mousePosY += y; - } - else - { - window->mousePosX = x; - window->mousePosY = y; - } - - if (_glfwLibrary.mousePosCallback) - _glfwLibrary.mousePosCallback(window, x, y); -} - - //======================================================================== // Register window focus events //========================================================================