Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multitouch for Android #475

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

Multitouch for Android #475

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: Android (All), ARM

Comments on the original bug report:

On 2011-08-29 16:52:52 +0000, Gabriel Jacobo wrote:

Created attachment 691
Multitouch for Android, includes debug stuff, dont use in production

I've tried to adapt the patch for bug # 1159 and this http://forums.libsdl.org/viewtopic.php?t=7474&sid=3f2c638f7321bdcd6007e525a735456d into a working patch that we can apply to main.

It's mostly working except a big problem I've found (that happens at least in my setup)...while I'm getting perfectly valid float coordinates in x,y and pressure from Java (up until Android_OnTouch is called), calls from there on get their float parameters completely corrupted, like there's a different calling convention at work, or different float precision, something that I can't put my finger on...

I've left some debug printfs in the files so it's easier to look at this for anyone wanting to.
The printf inside Android_OnTouch prints valid, logic (as in they make sense) coordinates. But the printfs in SDL_SendFingerDown and SDL_SendTouchMotion print gibberish.

A sample:

Android_OnTouch: touch_device_id_in: 3, pointer_finger_id_in 0, action 2, x 937.267761, y 238.000000, p 1.600000
SDL_SendTouchMotion: id: 3, fingerid 0d, relative 0, xin 4.415300, yin 36893488147419103232.000000, pressurein 4.415300
Android_OnTouch: touch_device_id_in: 3, pointer_finger_id_in 0, action 2, x 979.234985, y 239.000000, p 1.200000
SDL_SendTouchMotion: id: 3, fingerid 0d, relative 0, xin 4.456284, yin 2.000000, pressurein 4.456284

On 2011-08-29 18:32:45 +0000, Gabriel Jacobo wrote:

Created attachment 692
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.

On 2011-08-30 11:40:57 +0000, Gabriel Jacobo wrote:

Created attachment 694
Multitouch for Android

Adding a new version that accounts for two action types that are deprecated but are still being emitted by Android.

On 2011-08-31 05:21:09 +0000, Tim Angus wrote:

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.

On 2011-08-31 05:59:21 +0000, Gabriel Jacobo wrote:

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.

On 2011-08-31 06:16:19 +0000, Tim Angus wrote:

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.

On 2011-08-31 07:07:14 +0000, Gabriel Jacobo wrote:

Created attachment 695
Multitouch for Android

New patch following Tim's advice.

On 2011-10-12 22:28:20 +0000, Ryan C. Gordon wrote:

This patch is now hg changeset f324bd81b52c, thanks!

--ryan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant