1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 12:18:51 -05:00

Simplify touch API

This commit is contained in:
Camilla Berglund 2013-02-24 17:54:35 +01:00
parent 9301f33d6f
commit 2687622e8d
5 changed files with 37 additions and 87 deletions

View File

@ -232,18 +232,18 @@ extern "C" {
#define GLFW_FALSE 0
/*! @} */
/*! @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
*/
@ -255,6 +255,10 @@ extern "C" {
* @ingroup input
*/
#define GLFW_REPEAT 2
/*! @brief The touch was moved.
* @ingroup input
*/
#define GLFW_MOVE 3
/*! @} */
/*! @defgroup keys Keyboard keys
@ -980,26 +984,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.
*
@ -3064,10 +3059,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
@ -3079,21 +3074,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.

View File

@ -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;

View File

@ -291,7 +291,6 @@ struct _GLFWwindow
GLFWcharmodsfun charmods;
GLFWdropfun drop;
GLFWtouchfun touch;
GLFWtouchposfun touchPos;
} callbacks;
// This is defined in the window API's platform.h
@ -788,19 +787,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
*/

View File

@ -605,7 +605,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;
@ -617,21 +619,18 @@ 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,
_glfwInputTouch(window,
(int) inputs[i].dwID, action,
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);
}
_glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam);
}

View File

@ -204,6 +204,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";
@ -448,21 +450,13 @@ static void monitor_callback(GLFWmonitor* monitor, int event)
}
}
static void touch_callback(GLFWwindow* window, int touch, int action)
static void touch_callback(GLFWwindow* window, int touch, int action, double x, double y)
{
printf("%08x at %0.3f: Touch %i %s\n",
counter++,
glfwGetTime(),
touch,
get_action_name(action));
}
static void touch_pos_callback(GLFWwindow* window, int touch, double x, double y)
{
printf("%08x at %0.3f: Touch %i position: %0.3f %0.3f\n",
printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n",
counter++,
glfwGetTime(),
touch,
get_action_name(action),
x, y);
}
@ -581,7 +575,6 @@ int main(int argc, char** argv)
glfwSetCharModsCallback(slots[i].window, char_mods_callback);
glfwSetDropCallback(slots[i].window, drop_callback);
glfwSetTouchCallback(slots[i].window, touch_callback);
glfwSetTouchPosCallback(slots[i].window, touch_pos_callback);
glfwMakeContextCurrent(slots[i].window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);