Fixed issues with the touch coordinates in landscape mode.
authorSam Lantinga <slouken@libsdl.org>
Tue, 15 Nov 2011 01:38:27 -0500
changeset 6079d7135957b216
parent 6078 718b49ec039e
child 6080 eb0e11b096ab
Fixed issues with the touch coordinates in landscape mode.
In landscape mode the frame stays the same, and the transform property is modified with the appropriate rotation.
The touch coordinates are rotated by the transform, so if I want to normalize them by the frame rect, I have to transform the frame rect first.
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/src/video/uikit/SDL_uikitview.h	Thu Nov 10 06:38:26 2011 -0500
     1.2 +++ b/src/video/uikit/SDL_uikitview.h	Tue Nov 15 01:38:27 2011 -0500
     1.3 @@ -50,6 +50,7 @@
     1.4  @public
     1.5      SDL_uikitviewcontroller *viewcontroller;
     1.6  }
     1.7 +- (CGPoint)touchLocation:(UITouch *)touch;
     1.8  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
     1.9  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    1.10  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
     2.1 --- a/src/video/uikit/SDL_uikitview.m	Thu Nov 10 06:38:26 2011 -0500
     2.2 +++ b/src/video/uikit/SDL_uikitview.m	Tue Nov 15 01:38:27 2011 -0500
     2.3 @@ -1,4 +1,4 @@
     2.4 -/*
     2.5 + /*
     2.6    Simple DirectMedia Layer
     2.7    Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     2.8  
     2.9 @@ -60,10 +60,10 @@
    2.10      //EventTouchData* data = (EventTouchData*)(touch.driverdata);
    2.11  
    2.12      touch.x_min = 0;
    2.13 -    touch.x_max = frame.size.width;
    2.14 +    touch.x_max = 1;
    2.15      touch.native_xres = touch.x_max - touch.x_min;
    2.16      touch.y_min = 0;
    2.17 -    touch.y_max = frame.size.height;
    2.18 +    touch.y_max = 1;
    2.19      touch.native_yres = touch.y_max - touch.y_min;
    2.20      touch.pressure_min = 0;
    2.21      touch.pressure_max = 1;
    2.22 @@ -77,6 +77,17 @@
    2.23  
    2.24  }
    2.25  
    2.26 +- (CGPoint)touchLocation:(UITouch *)touch
    2.27 +{
    2.28 +    CGPoint point = [touch locationInView: self];
    2.29 +    CGRect frame = [self frame];
    2.30 +
    2.31 +    frame = CGRectApplyAffineTransform(frame, [self transform]);
    2.32 +    point.x /= frame.size.width;
    2.33 +    point.y /= frame.size.height;
    2.34 +    return point;
    2.35 +}
    2.36 +
    2.37  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    2.38  {
    2.39      NSEnumerator *enumerator = [touches objectEnumerator];
    2.40 @@ -94,7 +105,7 @@
    2.41  
    2.42  #ifdef FIXED_MULTITOUCH
    2.43      while(touch) {
    2.44 -        CGPoint locationInView = [touch locationInView: self];
    2.45 +        CGPoint locationInView = [self touchLocation:touch];
    2.46  
    2.47  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    2.48          //FIXME: TODO: Using touch as the fingerId is potentially dangerous
    2.49 @@ -133,7 +144,7 @@
    2.50  
    2.51  #ifdef FIXED_MULTITOUCH
    2.52      while(touch) {
    2.53 -        CGPoint locationInView = [touch locationInView: self];
    2.54 +        CGPoint locationInView = [self touchLocation:touch];
    2.55  
    2.56  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    2.57          SDL_SendFingerDown(touchId, (long)touch,
    2.58 @@ -181,7 +192,7 @@
    2.59  
    2.60  #ifdef FIXED_MULTITOUCH
    2.61      while(touch) {
    2.62 -        CGPoint locationInView = [touch locationInView: self];
    2.63 +        CGPoint locationInView = [self touchLocation:touch];
    2.64  
    2.65  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    2.66          SDL_SendTouchMotion(touchId, (long)touch,
     3.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Thu Nov 10 06:38:26 2011 -0500
     3.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Tue Nov 15 01:38:27 2011 -0500
     3.3 @@ -138,16 +138,8 @@
     3.4              return;
     3.5      }
     3.6  
     3.7 -    if (w == frame.size.width && h == frame.size.height) {
     3.8 -        return;
     3.9 -    }
    3.10 -
    3.11 -    frame.size.width = w;
    3.12 -    frame.size.height = h;
    3.13 -    frame.origin.x = 0;
    3.14 -    frame.origin.y = 0;
    3.15 -
    3.16      [uiwindow setFrame:frame];
    3.17 +    [data->view setFrame:frame];
    3.18      [data->view updateFrame];
    3.19      SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
    3.20  }