Skip to content

Commit

Permalink
iOS: Added support for force-touch on capable devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Sep 9, 2015
1 parent 6a32ca7 commit 82c8825
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -123,9 +123,22 @@ - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
return point;
}

- (float)pressureForTouch:(UITouch *)touch
{
#ifdef __IPHONE_9_0
if ([touch respondsToSelector:@selector(force)]) {
return (float) touch.force;
}
#endif

return 1.0f;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
float pressure = [self pressureForTouch:touch];

if (!firstFingerDown) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];

Expand All @@ -140,13 +153,15 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
SDL_TRUE, locationInView.x, locationInView.y, pressure);
}
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
float pressure = [self pressureForTouch:touch];

if (touch == firstFingerDown) {
/* send mouse up */
SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
Expand All @@ -155,7 +170,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
SDL_FALSE, locationInView.x, locationInView.y, pressure);
}
}

Expand All @@ -167,6 +182,8 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
float pressure = [self pressureForTouch:touch];

if (touch == firstFingerDown) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];

Expand All @@ -176,7 +193,7 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
SDL_SendTouchMotion(touchId, (SDL_FingerID)((size_t)touch),
locationInView.x, locationInView.y, 1.0f);
locationInView.x, locationInView.y, pressure);
}
}

Expand Down

0 comments on commit 82c8825

Please sign in to comment.