iOS: Added support for force-touch on capable devices.
authorAlex Szpakowski <slime73@gmail.com>
Wed, 09 Sep 2015 19:08:52 -0300
changeset 98612117766ff8d2
parent 9860 858a9b80e18a
child 9862 c3c3cdaf37f9
iOS: Added support for force-touch on capable devices.
src/video/uikit/SDL_uikitview.m
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Wed Sep 09 13:55:11 2015 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Wed Sep 09 19:08:52 2015 -0300
     1.3 @@ -123,9 +123,22 @@
     1.4      return point;
     1.5  }
     1.6  
     1.7 +- (float)pressureForTouch:(UITouch *)touch
     1.8 +{
     1.9 +#ifdef __IPHONE_9_0
    1.10 +    if ([touch respondsToSelector:@selector(force)]) {
    1.11 +        return (float) touch.force;
    1.12 +    }
    1.13 +#endif
    1.14 +
    1.15 +    return 1.0f;
    1.16 +}
    1.17 +
    1.18  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    1.19  {
    1.20      for (UITouch *touch in touches) {
    1.21 +        float pressure = [self pressureForTouch:touch];
    1.22 +
    1.23          if (!firstFingerDown) {
    1.24              CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
    1.25  
    1.26 @@ -140,13 +153,15 @@
    1.27  
    1.28          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    1.29          SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
    1.30 -                      SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
    1.31 +                      SDL_TRUE, locationInView.x, locationInView.y, pressure);
    1.32      }
    1.33  }
    1.34  
    1.35  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    1.36  {
    1.37      for (UITouch *touch in touches) {
    1.38 +        float pressure = [self pressureForTouch:touch];
    1.39 +
    1.40          if (touch == firstFingerDown) {
    1.41              /* send mouse up */
    1.42              SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.43 @@ -155,7 +170,7 @@
    1.44  
    1.45          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    1.46          SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
    1.47 -                      SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
    1.48 +                      SDL_FALSE, locationInView.x, locationInView.y, pressure);
    1.49      }
    1.50  }
    1.51  
    1.52 @@ -167,6 +182,8 @@
    1.53  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    1.54  {
    1.55      for (UITouch *touch in touches) {
    1.56 +        float pressure = [self pressureForTouch:touch];
    1.57 +
    1.58          if (touch == firstFingerDown) {
    1.59              CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
    1.60  
    1.61 @@ -176,7 +193,7 @@
    1.62  
    1.63          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    1.64          SDL_SendTouchMotion(touchId, (SDL_FingerID)((size_t)touch),
    1.65 -                            locationInView.x, locationInView.y, 1.0f);
    1.66 +                            locationInView.x, locationInView.y, pressure);
    1.67      }
    1.68  }
    1.69