-
Notifications
You must be signed in to change notification settings - Fork 70
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
base: main
Are you sure you want to change the base?
Conversation
include/simple2d.h
Outdated
@@ -130,13 +135,16 @@ typedef struct { | |||
int direction; | |||
int axis; | |||
int value; | |||
int64_t finger_id; | |||
int64_t touch_id; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
any updates? Will it be merged soon? |
any updates on this? |
Another bump for merge |
Pull request for the patch in #59