From 99da7e171b0956abd7678edcb02cfd53af470ad6 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Wed, 22 Feb 2017 19:35:47 +0100 Subject: [PATCH] Start on bundling touch points to only perform one callback per touch event. --- include/GLFW/glfw3.h | 28 +++++++++++++++++++++++++++- src/input.c | 8 +++++--- src/internal.h | 16 ++++++++-------- src/win32_window.c | 24 +++++++++++++++++++++--- tests/events.c | 4 ++-- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index eeef38bb2..de22ee2e1 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1103,7 +1103,33 @@ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); * * @sa glfwSetTouchCallback */ -typedef void (* GLFWtouchfun)(GLFWwindow*,int,int,double,double); +typedef void (* GLFWtouchfun)(GLFWwindow*, int, int, double, double); + +/*! @brief Touch point info. +* +* This describes the touch point info. +* +* @sa @ref touch +* +* @since Added in version 3.2.1 (touch branch) +* +* @ingroup touch +*/ +typedef struct GLFWtouch +{ + /*! Touch id + */ + int id; + /*! Touch action + */ + int action; + /*! X position + */ + double x; + /*! Y position + */ + double y; +} GLFWtouch; /*! @brief The function signature for monitor configuration callbacks. * diff --git a/src/input.c b/src/input.c index 47851e10b..e9fc3792f 100644 --- a/src/input.c +++ b/src/input.c @@ -135,11 +135,12 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) window->callbacks.drop((GLFWwindow*) window, count, paths); } -void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos) +void _glfwInputTouch(_GLFWwindow* window, int id, int action, double xpos, double ypos) { - if (window->callbacks.touch) - window->callbacks.touch((GLFWwindow*) window, touch, action, xpos, ypos); + if (window->callbacks.touch) + window->callbacks.touch((GLFWwindow*)window, id, action, xpos, ypos); } + void _glfwInputJoystickChange(int joy, int event) { if (_glfw.callbacks.joystick) @@ -621,6 +622,7 @@ GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* handle, GLFWtouchfun cbfun _GLFWwindow* window = (_GLFWwindow*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.touch, cbfun); + setTouchInput(window, 1); return cbfun; } diff --git a/src/internal.h b/src/internal.h index 357894fe5..6a3c23406 100644 --- a/src/internal.h +++ b/src/internal.h @@ -926,14 +926,14 @@ void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos); void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered); /*! @brief Notifies shared code of a touch start/end event. - * @param[in] window The window that received the event. - * @param[in] touch The touch that started or ended. - * @param[in] action One of @c GLFW_PRESS, @c GLFW_MOVE or @c GLFW_RELEASE. - * @param[in] xpos The new x-coordinate of the touch. - * @param[in] ypos The new y-coordinate of the touch. - * @ingroup event - */ -void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos); +* @param[in] window The window that received the event. +* @param[in] id Touch point id +* @param[in] action One of @c GLFW_PRESS, @c GLFW_MOVE or @c GLFW_RELEASE. +* @param[in] xpos The new x-coordinate of the touch. +* @param[in] ypos The new y-coordinate of the touch. +* @ingroup event +*/ +void _glfwInputTouch(_GLFWwindow* window, int id, int action, double xpos, double ypos); /*! @ingroup event */ diff --git a/src/win32_window.c b/src/win32_window.c index b4cd662a0..cd0b5f517 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -837,6 +837,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, _glfwPlatformGetWindowSize(window, &width, &height); _glfwPlatformGetWindowPos(window, &xpos, &ypos); + //Create storage + GLFWtouch* touchPoints = calloc(count, sizeof(GLFWtouch)); + + //Count valid points + int valid_count = 0; + for (i = 0; i < count; i++) { int action; @@ -856,16 +862,28 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, action = GLFW_PRESS; else if (inputs[i].dwFlags & TOUCHEVENTF_UP) action = GLFW_RELEASE; - else - action = GLFW_MOVE; + else if (inputs[i].dwFlags & TOUCHEVENTF_MOVE) + action = GLFW_MOVE; + else + action = GLFW_REPEAT; + + touchPoints[valid_count].id = (int)inputs[i].dwID; + touchPoints[valid_count].action = action; + touchPoints[valid_count].x = inputs[i].x / 100.0 - xpos; + touchPoints[valid_count].y = inputs[i].y / 100.0 - ypos; + + valid_count++; _glfwInputTouch(window, - (int) inputs[i].dwID, action, + (int) inputs[i].dwID, + action, inputs[i].x / 100.0 - xpos, inputs[i].y / 100.0 - ypos); } _glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam); + + free(touchPoints); } free(inputs); diff --git a/tests/events.c b/tests/events.c index 0b3caa82a..621914dcb 100644 --- a/tests/events.c +++ b/tests/events.c @@ -486,12 +486,12 @@ static void joystick_callback(int joy, int event) } } -static void touch_callback(GLFWwindow* window, int touch, int action, double x, double y) +static void touch_callback(GLFWwindow* window, int id, int action, double x, double y) { printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n", counter++, glfwGetTime(), - touch, + id, get_action_name(action), x, y); }