1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Begin adapting touch patch

This commit is contained in:
Quinten Lansu 2012-04-17 13:21:45 +02:00 committed by Camilla Berglund
parent a94a84b507
commit 4d2c3a547b
8 changed files with 202 additions and 0 deletions

View File

@ -133,6 +133,7 @@ skills.
- Cameron King - Cameron King
- Peter Knut - Peter Knut
- Eric Larson - Eric Larson
- Quinten Lansu
- Robin Leffmann - Robin Leffmann
- Glenn Lewis - Glenn Lewis
- Shane Liesegang - Shane Liesegang

View File

@ -656,6 +656,7 @@ extern "C" {
#define GLFW_CURSOR 0x00033001 #define GLFW_CURSOR 0x00033001
#define GLFW_STICKY_KEYS 0x00033002 #define GLFW_STICKY_KEYS 0x00033002
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003 #define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
#define GLFW_TOUCH 0x00030004
#define GLFW_CURSOR_NORMAL 0x00034001 #define GLFW_CURSOR_NORMAL 0x00034001
#define GLFW_CURSOR_HIDDEN 0x00034002 #define GLFW_CURSOR_HIDDEN 0x00034002
@ -979,6 +980,27 @@ typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int);
*/ */
typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**);
/*! @brief The function signature for touch start/end 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] xpos The new x-coordinate of the touch.
* @param[in] ypos The new y-coordinate of the touch.
* @ingroup input
*
* @sa glfwSetTouchPosCallback
*/
typedef void (* GLFWtouchposfun)(GLFWwindow*,int,double,double);
/*! @brief The function signature for monitor configuration callbacks. /*! @brief The function signature for monitor configuration callbacks.
* *
* This is the function signature for monitor configuration callback functions. * This is the function signature for monitor configuration callback functions.
@ -3042,6 +3064,36 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cb
*/ */
GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
/*! @brief Sets the touch start/end callback.
*
* This function sets the touch callback, which is called when a touch is
* started or ended.
*
* @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 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. /*! @brief Returns whether the specified joystick is present.
* *
* This function returns whether the specified joystick is present. * This function returns whether the specified joystick is present.

View File

@ -1162,6 +1162,10 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
*ypos = contentRect.size.height - pos.y - 1; *ypos = contentRect.size.height - pos.y - 1;
} }
void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled)
{
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
{ {
_glfwPlatformSetCursorMode(window, window->cursorMode); _glfwPlatformSetCursorMode(window, window->cursorMode);

View File

@ -126,6 +126,18 @@ static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
window->stickyMouseButtons = enabled; window->stickyMouseButtons = enabled;
} }
// Set touch input for the specified window
//
static void setTouchInput(_GLFWwindow* window, int enabled)
{
if (window->touchInput == enabled)
return;
_glfwPlatformSetTouchInput(window, enabled);
window->touchInput = enabled;
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW event API ////// ////// GLFW event API //////
@ -222,6 +234,18 @@ 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)
{
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);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW public API ////// ////// GLFW public API //////
@ -241,6 +265,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
return window->stickyKeys; return window->stickyKeys;
case GLFW_STICKY_MOUSE_BUTTONS: case GLFW_STICKY_MOUSE_BUTTONS:
return window->stickyMouseButtons; return window->stickyMouseButtons;
case GLFW_TOUCH:
return window->touchInput;
default: default:
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode"); _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode");
return 0; return 0;
@ -264,6 +290,9 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
case GLFW_STICKY_MOUSE_BUTTONS: case GLFW_STICKY_MOUSE_BUTTONS:
setStickyMouseButtons(window, value ? GLFW_TRUE : GLFW_FALSE); setStickyMouseButtons(window, value ? GLFW_TRUE : GLFW_FALSE);
break; break;
case GLFW_TOUCH:
setTouchInput(window, value ? GLFW_TRUE : GLFW_FALSE);
break;
default: default:
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode"); _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode");
break; break;
@ -579,6 +608,22 @@ GLFWAPI const char* glfwGetJoystickName(int joy)
return _glfwPlatformGetJoystickName(joy); return _glfwPlatformGetJoystickName(joy);
} }
GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* handle, GLFWtouchfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.touch, 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) GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;

View File

@ -253,6 +253,7 @@ struct _GLFWwindow
// Window input state // Window input state
GLFWbool stickyKeys; GLFWbool stickyKeys;
GLFWbool stickyMouseButtons; GLFWbool stickyMouseButtons;
GLFWbool touchInput;
double cursorPosX, cursorPosY; double cursorPosX, cursorPosY;
int cursorMode; int cursorMode;
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1]; char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
@ -289,6 +290,8 @@ struct _GLFWwindow
GLFWcharfun character; GLFWcharfun character;
GLFWcharmodsfun charmods; GLFWcharmodsfun charmods;
GLFWdropfun drop; GLFWdropfun drop;
GLFWtouchfun touch;
GLFWtouchposfun touchPos;
} callbacks; } callbacks;
// This is defined in the window API's platform.h // This is defined in the window API's platform.h
@ -406,6 +409,14 @@ void _glfwPlatformTerminate(void);
*/ */
const char* _glfwPlatformGetVersionString(void); const char* _glfwPlatformGetVersionString(void);
/*! @brief Sets whether touch input is enabled for the specified window.
* @param[in] window The window whose touch input status to change.
* @param[in] enabled @c GL_TRUE to enable touch input, or @c GL_FALSE to
* disable it.
* @ingroup platform
*/
void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled);
/*! @copydoc glfwGetCursorPos /*! @copydoc glfwGetCursorPos
* @ingroup platform * @ingroup platform
*/ */
@ -774,6 +785,23 @@ void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y);
*/ */
void _glfwInputCursorEnter(_GLFWwindow* window, int entered); 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] 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);
/*! @ingroup event /*! @ingroup event
*/ */
void _glfwInputMonitorChange(void); void _glfwInputMonitorChange(void);

View File

@ -584,6 +584,55 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
return 0; return 0;
} }
case WM_TOUCH:
{
TOUCHINPUT* inputs;
UINT count = LOWORD(wParam);
inputs = (TOUCHINPUT*) malloc(sizeof(TOUCHINPUT) * count);
if (GetTouchInputInfo((HTOUCHINPUT) lParam,
count, inputs, sizeof(TOUCHINPUT)))
{
int i, width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
for (i = 0; i < count; i++)
{
POINT pos;
// Discard any points that lie outside of the client area
pos.x = TOUCH_COORD_TO_PIXEL(inputs[i].x);
pos.y = TOUCH_COORD_TO_PIXEL(inputs[i].y);
ScreenToClient(window->win32.handle, &pos);
if (pos.x < 0 || pos.x >= width ||
pos.y < 0 || pos.y >= height)
{
continue;
}
if (inputs[i].dwFlags & TOUCHEVENTF_DOWN)
_glfwInputTouch(window, (int) inputs[i].dwID, GLFW_PRESS);
else if (inputs[i].dwFlags & TOUCHEVENTF_UP)
_glfwInputTouch(window, (int) inputs[i].dwID, GLFW_RELEASE);
else if (inputs[i].dwFlags & TOUCHEVENTF_MOVE)
{
_glfwInputTouchPos(window, (int) inputs[i].dwID,
inputs[i].x / 100.0,
inputs[i].y / 100.0);
}
}
CloseTouchInputHandle((HTOUCHINPUT) lParam);
}
free(inputs);
break;
}
case WM_PAINT: case WM_PAINT:
{ {
_glfwInputWindowDamage(window); _glfwInputWindowDamage(window);
@ -1138,6 +1187,14 @@ void _glfwPlatformPostEmptyEvent(void)
PostMessage(window->win32.handle, WM_NULL, 0, 0); PostMessage(window->win32.handle, WM_NULL, 0, 0);
} }
void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled)
{
if (enabled)
RegisterTouchWindow(window->win32.handle, 0);
else
UnregisterTouchWindow(window->win32.handle);
}
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
{ {
POINT pos; POINT pos;

View File

@ -1871,6 +1871,10 @@ void _glfwPlatformPostEmptyEvent(void)
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
} }
void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled)
{
}
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
{ {
Window root, child; Window root, child;

View File

@ -438,6 +438,16 @@ static void monitor_callback(GLFWmonitor* monitor, int event)
} }
} }
static void touch_callback(GLFWwindow* window, int touch, int action, double x, double y)
{
printf("%08x at %0.3f: Touch %i %s at %0.3f %0.3f\n",
counter++,
glfwGetTime(),
touch,
get_action_name(action),
x, y);
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
Slot* slots; Slot* slots;
@ -551,6 +561,7 @@ int main(int argc, char** argv)
glfwSetCharCallback(slots[i].window, char_callback); glfwSetCharCallback(slots[i].window, char_callback);
glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetCharModsCallback(slots[i].window, char_mods_callback);
glfwSetDropCallback(slots[i].window, drop_callback); glfwSetDropCallback(slots[i].window, drop_callback);
glfwSetTouchCallback(slots[i].window, touch_callback);
glfwMakeContextCurrent(slots[i].window); glfwMakeContextCurrent(slots[i].window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);