| Summary: | Multitouch for Android | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Gabriel Jacobo <gabomdq> |
| Component: | events | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | icculus, tim |
| Version: | HG 2.0 | ||
| Hardware: | ARM | ||
| OS: | Android (All) | ||
| Attachments: |
Multitouch for Android, includes debug stuff, dont use in production
Multitouch for Android Multitouch for Android Multitouch for Android |
||
|
Description
Gabriel Jacobo
2011-08-29 16:52:52 UTC
Created attachment 692 [details]
Multitouch for Android
That wasn't so hard (I was missing a header) but it took me hours to figure out where the problem was! Multitouch should work with this patch.
Created attachment 694 [details]
Multitouch for Android
Adding a new version that accounts for two action types that are deprecated but are still being emitted by Android.
Looks pretty good, though the values of touch.native_xres and yres are wrong. The correct settings are actually commented out. It seems the original author has missed the point that the values that come out of the touch events are normalised to 0<=x<=32768. This is explained, though not very prominently, in README.touch. The code should look like this:
if (!SDL_GetTouch(touchDeviceId)) {
SDL_Touch touch;
memset( &touch, 0, sizeof(touch) );
touch.id = touchDeviceId;
touch.x_min = 0.0f;
touch.x_max = (float)Android_ScreenWidth;
touch.native_xres = touch.x_max - touch.x_min;
touch.y_min = 0.0f;
touch.y_max = (float)Android_ScreenHeight;
touch.native_yres = touch.y_max - touch.y_min;
touch.pressure_min = 0.0f;
touch.pressure_max = 1.0f;
touch.native_pressureres = touch.pressure_max - touch.pressure_min;
if (SDL_AddTouch(&touch, "") < 0) {
SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
}
}
This brings it inline with how the iOS and X11 touch versions do things. We don't really want to deviate from what other platforms do as that defeats the point of SDL. It's probably also worth removing the commented code in the same function that was responsible for emulating mouse clicks.
To be fair the SDL touch API is quite confusing and perhaps deserves a little bit of a review before it gets deployed/used too much.
I understand, though I'd like to ask (out of curiosity) why was this decision made to normalize the coordinates to 0->32768 instead of a more natural 0->screen resolution or 0->window size, for example, which makes the coordinates in line with the values you get out of mouse events. I don't know. My guess is the original author of the touch API (it was a GsoC project right?) was initially developing for pen based graphics tablets which don't have a screen resolution per se. That's just conjecture though. Created attachment 695 [details]
Multitouch for Android
New patch following Tim's advice.
This patch is now hg changeset f324bd81b52c, thanks! --ryan. |