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

Initial touch event support #60

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

grrussel
Copy link
Contributor

@grrussel grrussel commented Jul 2, 2017

Pull request for the patch in #59

@@ -130,13 +135,16 @@ typedef struct {
int direction;
int axis;
int value;
int64_t finger_id;
int64_t touch_id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of int64_t, do you think these should be of type SDL_TouchID and SDL_FingerID, respectively?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not done for SDL_JoystickID either, but I don't think its a big deal except it leaks SDL into Simple2D more than is already done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, didn't even realize joystick ID was an SDL type. Guess I must have copied some code somewhere using int. Looks like they use SDL types for future proofing, but I think it makes sense as a principle not to expose SDL types to users (the ones we use in S2D types are all for internal use) so using regular types make sense here. Might actually change to long long if you're ok with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me

src/window.c Outdated
}

}break;
case SDL_FINGERDOWN:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since SDL_FINGERDOWN and SDL_FINGERUP are identical, save for event.type, I might suggest combining both events like in mouse down/up here. (Reminds me, we can probably do the same for SDL_JOYBUTTONDOWN and SDL_JOYBUTTONUP as well.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined.

src/window.c Outdated
fy = e.tfinger.y * window->height;
dx = e.tfinger.dx * window->width;
dy = e.tfinger.dy * window->height;
S2D_GetMouseOnViewport(window, (int)fx, (int)fy, &mx, &my);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by the multiplication of the window dimensions. Does S2D_GetMouseOnViewport not correctly translate the points in the window? (Since we're using it for more than mouse now, should probably rename it to S2D_GetPointOnViewport or something.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Touch events seem to deliver not positions, but indications of how far in a given dimension the event occurred, normalized between 0 and 1
e.g. 0.5 of x, 0.3 of y
which then need to be translated into coordinates in the window/viewport

The TODO comment "Viewport in scaling" seems to be not relevant - it seems a consequence of scaling the window to a bigger width is then that touch events can occur at a -ve position - since the original 0 axis is no longer flush with the left of the display, that is therefore OK and I had simply gotten confused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't realize that, thanks. Running the test card, my MacBook actually triggers touch events as well, I guess because the touchpad is technically "multi-touch." The x and y coords are off, so I'm going to investigate why that is.

@ravkr
Copy link

ravkr commented Feb 1, 2018

any updates? Will it be merged soon?

@grzegorz-jakubiak
Copy link

any updates on this?

@Gandalf1783
Copy link

Another bump for merge

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

Successfully merging this pull request may close these issues.

None yet

5 participants