Add SDL_TouchDeviceType enum and SDL_GetTouchDeviceType(SDL_TouchID id).

Touch device types include SDL_TOUCH_DEVICE_DIRECT (a touch screen with window-relative coordinates for touches), SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE (a trackpad-style device with absolute device coordinates), and SDL_TOUCH_DEVICE_INDIRECT_RELATIVE (a trackpad-style device with screen cursor-relative coordinates).

Phone screens are an example of a direct device type. Mac trackpads are the indirect-absolute touch device type. The Apple TV remote is an indirect-relative touch device type.
This commit is contained in:
Alex Szpakowski
2018-11-10 16:15:48 -04:00
parent 2196e5765c
commit 5029d50ea8
15 changed files with 109 additions and 15 deletions

View File

@@ -72,7 +72,7 @@ void Android_InitTouch(void)
if (0 < number) {
for (i = 0; i < number; ++i) {
SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */
SDL_AddTouch((SDL_TouchID) ids[i], SDL_TOUCH_DEVICE_DIRECT, ""); /* no error handling */
}
SDL_free(ids);
}
@@ -97,7 +97,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio
}
touchDeviceId = (SDL_TouchID)touch_device_id_in;
if (SDL_AddTouch(touchDeviceId, "") < 0) {
if (SDL_AddTouch(touchDeviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
}

View File

@@ -1103,7 +1103,17 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
for (NSTouch *touch in touches) {
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
if (SDL_AddTouch(touchId, "") < 0) {
SDL_TouchDeviceType devtype = SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 /* Added in the 10.12.2 SDK. */
if ([touch respondsToSelector:@selector(type)]) {
if ([touch type] == NSTouchTypeDirect) {
devtype = SDL_TOUCH_DEVICE_DIRECT;
}
}
#endif
if (SDL_AddTouch(touchId, devtype, "") < 0) {
return;
}

View File

@@ -428,7 +428,7 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
int preventDefault = 0;
SDL_TouchID deviceId = 1;
if (SDL_AddTouch(deviceId, "") < 0) {
if (SDL_AddTouch(deviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
return 0;
}

View File

@@ -39,7 +39,9 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
@implementation SDL_uikitview {
SDL_Window *sdlwindow;
SDL_TouchID touchId;
SDL_TouchID directTouchId;
SDL_TouchID indirectTouchId;
UITouch * __weak firstFingerDown;
}
@@ -68,12 +70,13 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.autoresizesSubviews = YES;
directTouchId = 1;
indirectTouchId = 2;
#if !TARGET_OS_TV
self.multipleTouchEnabled = YES;
SDL_AddTouch(directTouchId, SDL_TOUCH_DEVICE_DIRECT, "");
#endif
touchId = 1;
SDL_AddTouch(touchId, "");
}
return self;
@@ -135,6 +138,30 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
sdlwindow = window;
}
- (SDL_TouchDeviceType)touchTypeForTouch:(UITouch *)touch
{
#ifdef __IPHONE_9_0
if ([touch respondsToSelector:@selector((type))]) {
if (touch.type == UITouchTypeIndirect) {
return SDL_TOUCH_DEVICE_INDIRECT_RELATIVE;
}
}
#endif
return SDL_TOUCH_DEVICE_DIRECT;
}
- (SDL_TouchID)touchIdForType:(SDL_TouchDeviceType)type
{
switch (type) {
case SDL_TOUCH_DEVICE_DIRECT:
default:
return directTouchId;
case SDL_TOUCH_DEVICE_INDIRECT_RELATIVE:
return indirectTouchId;
}
}
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
{
CGPoint point = [touch locationInView:self];
@@ -162,8 +189,14 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
SDL_TouchID touchId = [self touchIdForType:touchType];
float pressure = [self pressureForTouch:touch];
if (SDL_AddTouch(touchId, touchType, "") < 0) {
continue;
}
if (!firstFingerDown) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
int clicks = (int) touch.tapCount;
@@ -186,8 +219,14 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
SDL_TouchID touchId = [self touchIdForType:touchType];
float pressure = [self pressureForTouch:touch];
if (SDL_AddTouch(touchId, touchType, "") < 0) {
continue;
}
if (touch == firstFingerDown) {
/* send mouse up */
int clicks = (int) touch.tapCount;
@@ -209,8 +248,14 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
SDL_TouchID touchId = [self touchIdForType:touchType];
float pressure = [self pressureForTouch:touch];
if (SDL_AddTouch(touchId, touchType, "") < 0) {
continue;
}
if (touch == firstFingerDown) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];

View File

@@ -614,7 +614,7 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
}
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
SDL_AddTouch(1, "wayland_touch");
SDL_AddTouch(1, SDL_TOUCH_DEVICE_DIRECT, "wayland_touch");
input->touch = wl_seat_get_touch(seat);
wl_touch_set_user_data(input->touch, input);
wl_touch_add_listener(input->touch, &touch_listener,

View File

@@ -89,7 +89,7 @@ touch_handle_touch(void *data,
*/
SDL_TouchID deviceId = 1;
if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) {
if (SDL_AddTouch(deviceId, SDL_TOUCH_DEVICE_DIRECT, "qt_touch_extension") < 0) {
SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
}

View File

@@ -932,7 +932,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
PTOUCHINPUT input = &inputs[i];
const SDL_TouchID touchId = (SDL_TouchID)((size_t)input->hSource);
if (SDL_AddTouch(touchId, "") < 0) {
/* TODO: Can we use GetRawInputDeviceInfo and HID info to
determine if this is a direct or indirect touch device?
*/
if (SDL_AddTouch(touchId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
continue;
}

View File

@@ -44,7 +44,7 @@ static unsigned int WINRT_LeftFingerDown = 0;
void
WINRT_InitTouch(_THIS)
{
SDL_AddTouch(WINRT_TouchID, "");
SDL_AddTouch(WINRT_TouchID, SDL_TOUCH_DEVICE_DIRECT, "");
}

View File

@@ -244,6 +244,7 @@ X11_InitXinput2Multitouch(_THIS)
XIDeviceInfo *dev = &info[i];
for (j = 0; j < dev->num_classes; j++) {
SDL_TouchID touchId;
SDL_TouchDeviceType touchType;
XIAnyClassInfo *class = dev->classes[j];
XITouchClassInfo *t = (XITouchClassInfo*)class;
@@ -251,8 +252,14 @@ X11_InitXinput2Multitouch(_THIS)
if (class->type != XITouchClass)
continue;
if (t->mode == XIDependentTouch) {
touchType = SDL_TOUCH_DEVICE_INDIRECT_RELATIVE;
} else { /* XIDirectTouch */
touchType = SDL_TOUCH_DEVICE_DIRECT;
}
touchId = t->sourceid;
SDL_AddTouch(touchId, dev->name);
SDL_AddTouch(touchId, touchType, dev->name);
}
}
X11_XIFreeDeviceInfo(info);