From a0f5982bad411b612642bc608ce826e85d6feaa6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 24 Feb 2013 17:54:35 +0100 Subject: [PATCH] Simplified touch API. --- include/GLFW/glfw3.h | 52 ++++++++++++++------------------------------ src/input.c | 20 +++-------------- src/internal.h | 12 ++-------- src/win32_init.c | 30 ++++++++++++------------- src/win32_window.c | 23 ++++++++++---------- tests/events.c | 2 ++ 6 files changed, 49 insertions(+), 90 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 1b83e04f7..7ec0dab96 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -214,18 +214,18 @@ extern "C" { #define GLFW_VERSION_REVISION 2 /*! @} */ -/*! @name Key and button actions +/*! @name Key, button and touch actions * @{ */ -/*! @brief The key or mouse button was released. +/*! @brief The key or button was released or the touch ended. * - * The key or mouse button was released. + * The key or button was released or the touch ended. * * @ingroup input */ #define GLFW_RELEASE 0 -/*! @brief The key or mouse button was pressed. +/*! @brief The key or button was pressed or the touch started. * - * The key or mouse button was pressed. + * The key or button was pressed or the touch started. * * @ingroup input */ @@ -237,6 +237,10 @@ extern "C" { * @ingroup input */ #define GLFW_REPEAT 2 +/*! @brief The touch was moved. + * @ingroup input + */ +#define GLFW_MOVE 3 /*! @} */ /*! @defgroup keys Keyboard keys @@ -962,26 +966,17 @@ typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int); */ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); -/*! @brief The function signature for touch start/end callbacks. +/*! @brief The function signature for touch callbacks. * @param[in] window The window that received the event. - * @param[in] touch The touch that started or ended. - * @param[in] action One of @ref GLFW_PRESS or @ref GLFW_RELEASE. - * @ingroup input - * - * @sa glfwSetTouchCallback - */ -typedef void (* GLFWtouchfun)(GLFWwindow*,int,int); - -/*! @brief The function signature for touch position callbacks. - * @param[in] window The window that received the event. - * @param[in] touch The touch that moved. + * @param[in] touch The touch that triggered the event. + * @param[in] action One of @ref GLFW_PRESS, @c GLFW_MOVE or @ref GLFW_RELEASE. * @param[in] xpos The new x-coordinate of the touch. * @param[in] ypos The new y-coordinate of the touch. * @ingroup input * - * @sa glfwSetTouchPosCallback + * @sa glfwSetTouchCallback */ -typedef void (* GLFWtouchposfun)(GLFWwindow*,int,double,double); +typedef void (* GLFWtouchfun)(GLFWwindow*,int,int,double,double); /*! @brief The function signature for monitor configuration callbacks. * @@ -2969,10 +2964,10 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cb */ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); -/*! @brief Sets the touch start/end callback. +/*! @brief Sets the touch callback. * * This function sets the touch callback, which is called when a touch is - * started or ended. + * started, ended or moved. * * @param[in] window The window whose callback to set. * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently @@ -2984,21 +2979,6 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); */ GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* window, GLFWtouchfun cbfun); -/*! @brief Sets the touch position callback. - * - * This function sets the touch position callback, which is called when a touch - * moves. - * - * @param[in] window The window whose callback to set. - * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently - * set callback. - * @return The previously set callback, or `NULL` if no callback was set or an - * error occurred. - * - * @ingroup input - */ -GLFWAPI GLFWtouchposfun glfwSetTouchPosCallback(GLFWwindow* window, GLFWtouchposfun cbfun); - /*! @brief Returns whether the specified joystick is present. * * This function returns whether the specified joystick is present. diff --git a/src/input.c b/src/input.c index 3eb82155c..7fad337e7 100644 --- a/src/input.c +++ b/src/input.c @@ -33,7 +33,7 @@ #endif // Internal key state used for sticky keys -#define _GLFW_STICK 3 +#define _GLFW_STICK 4 // Sets the cursor mode for the specified window @@ -234,16 +234,10 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) window->callbacks.drop((GLFWwindow*) window, count, paths); } -void _glfwInputTouch(_GLFWwindow* window, int touch, int action) +void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos) { if (window->callbacks.touch) - window->callbacks.touch((GLFWwindow*) window, touch, action); -} - -void _glfwInputTouchPos(_GLFWwindow* window, int touch, double xpos, double ypos) -{ - if (window->callbacks.touchPos) - window->callbacks.touchPos((GLFWwindow*) window, touch, xpos, ypos); + window->callbacks.touch((GLFWwindow*) window, touch, action, xpos, ypos); } @@ -616,14 +610,6 @@ GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* handle, GLFWtouchfun cbfun return cbfun; } -GLFWAPI GLFWtouchposfun glfwSetTouchPosCallback(GLFWwindow* handle, GLFWtouchposfun cbfun) -{ - _GLFWwindow* window = (_GLFWwindow*) handle; - _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - _GLFW_SWAP_POINTERS(window->callbacks.touchPos, cbfun); - return cbfun; -} - GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) { _GLFWwindow* window = (_GLFWwindow*) handle; diff --git a/src/internal.h b/src/internal.h index ef7cb4303..2c77d528c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -280,7 +280,6 @@ struct _GLFWwindow GLFWcharmodsfun charmods; GLFWdropfun drop; GLFWtouchfun touch; - GLFWtouchposfun touchPos; } callbacks; // This is defined in the window API's platform.h @@ -767,19 +766,12 @@ void _glfwInputCursorEnter(_GLFWwindow* window, int 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 or @c GLFW_RELEASE. - * @ingroup event - */ -void _glfwInputTouch(_GLFWwindow* window, int touch, int action); - -/*! @brief Notifies shared code of a touch movement event. - * @param[in] window The window that received the event. - * @param[in] touch The touch that moved. + * @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 _glfwInputTouchPos(_GLFWwindow* window, int touch, double xpos, double ypos); +void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos); /*! @ingroup event */ diff --git a/src/win32_init.c b/src/win32_init.c index beed97863..720117c73 100755 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -90,21 +90,21 @@ static GLboolean initLibraries(void) } _glfw.win32.user32.instance = LoadLibraryW(L"user32.dll"); - if (_glfw.win32.user32.instance) - { - _glfw.win32.user32.SetProcessDPIAware = (SETPROCESSDPIAWARE_T) - GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware"); - _glfw.win32.user32.ChangeWindowMessageFilterEx = (CHANGEWINDOWMESSAGEFILTEREX_T) - GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx"); - _glfw.win32.user32.GetTouchInputInfo = (GETTOUCHINPUTINFO_T) - GetProcAddress(_glfw.win32.user32.instance, "GetTouchInputInfo"); - _glfw.win32.user32.CloseTouchInputHandle = (CLOSETOUCHINPUTHANDLE_T) - GetProcAddress(_glfw.win32.user32.instance, "CloseTouchInputHandle"); - _glfw.win32.user32.RegisterTouchWindow = (REGISTERTOUCHWINDOW_T) - GetProcAddress(_glfw.win32.user32.instance, "RegisterTouchWindow"); - _glfw.win32.user32.UnregisterTouchWindow = (UNREGISTERTOUCHWINDOW_T) - GetProcAddress(_glfw.win32.user32.instance, "UnregisterTouchWindow"); - } + if (!_glfw.win32.user32.instance) + return GL_FALSE; + + _glfw.win32.user32.SetProcessDPIAware = (SETPROCESSDPIAWARE_T) + GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware"); + _glfw.win32.user32.ChangeWindowMessageFilterEx = (CHANGEWINDOWMESSAGEFILTEREX_T) + GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx"); + _glfw.win32.user32.GetTouchInputInfo = (GETTOUCHINPUTINFO_T) + GetProcAddress(_glfw.win32.user32.instance, "GetTouchInputInfo"); + _glfw.win32.user32.CloseTouchInputHandle = (CLOSETOUCHINPUTHANDLE_T) + GetProcAddress(_glfw.win32.user32.instance, "CloseTouchInputHandle"); + _glfw.win32.user32.RegisterTouchWindow = (REGISTERTOUCHWINDOW_T) + GetProcAddress(_glfw.win32.user32.instance, "RegisterTouchWindow"); + _glfw.win32.user32.UnregisterTouchWindow = (UNREGISTERTOUCHWINDOW_T) + GetProcAddress(_glfw.win32.user32.instance, "UnregisterTouchWindow"); if (_glfw.win32.user32.GetTouchInputInfo && _glfw.win32.user32.CloseTouchInputHandle && diff --git a/src/win32_window.c b/src/win32_window.c index 34c2b39ae..780b054dc 100755 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -542,7 +542,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, for (i = 0; i < count; i++) { + int action; POINT pos; + pos.x = TOUCH_COORD_TO_PIXEL(inputs[i].x) - xpos; pos.y = TOUCH_COORD_TO_PIXEL(inputs[i].y) - ypos; @@ -554,19 +556,16 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, } if (inputs[i].dwFlags & TOUCHEVENTF_DOWN) - _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_PRESS); + action = GLFW_PRESS; + else if (inputs[i].dwFlags & TOUCHEVENTF_UP) + action = GLFW_RELEASE; + else + action = GLFW_MOVE; - if (inputs[i].dwFlags & TOUCHEVENTF_DOWN || - inputs[i].dwFlags & TOUCHEVENTF_UP || - inputs[i].dwFlags & TOUCHEVENTF_MOVE) - { - _glfwInputTouchPos(window, (int) inputs[i].dwID, - inputs[i].x / 100.0 - xpos, - inputs[i].y / 100.0 - ypos); - } - - if (inputs[i].dwFlags & TOUCHEVENTF_UP) - _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_RELEASE); + _glfwInputTouch(window, + (int) inputs[i].dwID, action, + inputs[i].x / 100.0 - xpos, + inputs[i].y / 100.0 - ypos); } _glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam); diff --git a/tests/events.c b/tests/events.c index a757aa546..9c62518f4 100644 --- a/tests/events.c +++ b/tests/events.c @@ -203,6 +203,8 @@ static const char* get_action_name(int action) return "released"; case GLFW_REPEAT: return "repeated"; + case GLFW_MOVE: + return "moved"; } return "caused unknown action";