mirror of
https://github.com/glfw/glfw.git
synced 2025-10-05 06:06:36 +00:00
Start on bundling touch points to only perform one callback per touch event.
This commit is contained in:
parent
a31709d6f0
commit
99da7e171b
@ -1103,7 +1103,33 @@ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**);
|
|||||||
*
|
*
|
||||||
* @sa glfwSetTouchCallback
|
* @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.
|
/*! @brief The function signature for monitor configuration callbacks.
|
||||||
*
|
*
|
||||||
|
@ -135,11 +135,12 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
|
|||||||
window->callbacks.drop((GLFWwindow*) window, count, 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)
|
if (window->callbacks.touch)
|
||||||
window->callbacks.touch((GLFWwindow*) window, touch, action, xpos, ypos);
|
window->callbacks.touch((GLFWwindow*)window, id, action, xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwInputJoystickChange(int joy, int event)
|
void _glfwInputJoystickChange(int joy, int event)
|
||||||
{
|
{
|
||||||
if (_glfw.callbacks.joystick)
|
if (_glfw.callbacks.joystick)
|
||||||
@ -621,6 +622,7 @@ GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* handle, GLFWtouchfun cbfun
|
|||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
_GLFW_SWAP_POINTERS(window->callbacks.touch, cbfun);
|
_GLFW_SWAP_POINTERS(window->callbacks.touch, cbfun);
|
||||||
|
setTouchInput(window, 1);
|
||||||
return cbfun;
|
return cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -926,14 +926,14 @@ void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
|
|||||||
void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered);
|
void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered);
|
||||||
|
|
||||||
/*! @brief Notifies shared code of a touch start/end event.
|
/*! @brief Notifies shared code of a touch start/end event.
|
||||||
* @param[in] window The window that received the event.
|
* @param[in] window The window that received the event.
|
||||||
* @param[in] touch The touch that started or ended.
|
* @param[in] id Touch point id
|
||||||
* @param[in] action One of @c GLFW_PRESS, @c GLFW_MOVE or @c GLFW_RELEASE.
|
* @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] xpos The new x-coordinate of the touch.
|
||||||
* @param[in] ypos The new y-coordinate of the touch.
|
* @param[in] ypos The new y-coordinate of the touch.
|
||||||
* @ingroup event
|
* @ingroup event
|
||||||
*/
|
*/
|
||||||
void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos);
|
void _glfwInputTouch(_GLFWwindow* window, int id, int action, double xpos, double ypos);
|
||||||
|
|
||||||
/*! @ingroup event
|
/*! @ingroup event
|
||||||
*/
|
*/
|
||||||
|
@ -837,6 +837,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||||
_glfwPlatformGetWindowPos(window, &xpos, &ypos);
|
_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++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
int action;
|
int action;
|
||||||
@ -856,16 +862,28 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
action = GLFW_PRESS;
|
action = GLFW_PRESS;
|
||||||
else if (inputs[i].dwFlags & TOUCHEVENTF_UP)
|
else if (inputs[i].dwFlags & TOUCHEVENTF_UP)
|
||||||
action = GLFW_RELEASE;
|
action = GLFW_RELEASE;
|
||||||
else
|
else if (inputs[i].dwFlags & TOUCHEVENTF_MOVE)
|
||||||
action = GLFW_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,
|
_glfwInputTouch(window,
|
||||||
(int) inputs[i].dwID, action,
|
(int) inputs[i].dwID,
|
||||||
|
action,
|
||||||
inputs[i].x / 100.0 - xpos,
|
inputs[i].x / 100.0 - xpos,
|
||||||
inputs[i].y / 100.0 - ypos);
|
inputs[i].y / 100.0 - ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam);
|
_glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam);
|
||||||
|
|
||||||
|
free(touchPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(inputs);
|
free(inputs);
|
||||||
|
@ -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",
|
printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n",
|
||||||
counter++,
|
counter++,
|
||||||
glfwGetTime(),
|
glfwGetTime(),
|
||||||
touch,
|
id,
|
||||||
get_action_name(action),
|
get_action_name(action),
|
||||||
x, y);
|
x, y);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user