From b69f50046b1ef59d0588bf42f0aba7dbbdc7d2c6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 15 Nov 2011 01:38:27 -0500 Subject: [PATCH] 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 | 1 + src/video/uikit/SDL_uikitview.m | 23 +++++++++++++++++------ src/video/uikit/SDL_uikitviewcontroller.m | 10 +--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/video/uikit/SDL_uikitview.h b/src/video/uikit/SDL_uikitview.h index 3532fded6..862855e0d 100644 --- a/src/video/uikit/SDL_uikitview.h +++ b/src/video/uikit/SDL_uikitview.h @@ -50,6 +50,7 @@ @public SDL_uikitviewcontroller *viewcontroller; } +- (CGPoint)touchLocation:(UITouch *)touch; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 18ff7e954..452c49a0a 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -1,4 +1,4 @@ -/* + /* Simple DirectMedia Layer Copyright (C) 1997-2011 Sam Lantinga @@ -60,10 +60,10 @@ - (id)initWithFrame:(CGRect)frame //EventTouchData* data = (EventTouchData*)(touch.driverdata); touch.x_min = 0; - touch.x_max = frame.size.width; + touch.x_max = 1; touch.native_xres = touch.x_max - touch.x_min; touch.y_min = 0; - touch.y_max = frame.size.height; + touch.y_max = 1; touch.native_yres = touch.y_max - touch.y_min; touch.pressure_min = 0; touch.pressure_max = 1; @@ -77,6 +77,17 @@ - (id)initWithFrame:(CGRect)frame } +- (CGPoint)touchLocation:(UITouch *)touch +{ + CGPoint point = [touch locationInView: self]; + CGRect frame = [self frame]; + + frame = CGRectApplyAffineTransform(frame, [self transform]); + point.x /= frame.size.width; + point.y /= frame.size.height; + return point; +} + - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSEnumerator *enumerator = [touches objectEnumerator]; @@ -94,7 +105,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event #ifdef FIXED_MULTITOUCH while(touch) { - CGPoint locationInView = [touch locationInView: self]; + CGPoint locationInView = [self touchLocation:touch]; #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS //FIXME: TODO: Using touch as the fingerId is potentially dangerous @@ -133,7 +144,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event #ifdef FIXED_MULTITOUCH while(touch) { - CGPoint locationInView = [touch locationInView: self]; + CGPoint locationInView = [self touchLocation:touch]; #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS SDL_SendFingerDown(touchId, (long)touch, @@ -181,7 +192,7 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event #ifdef FIXED_MULTITOUCH while(touch) { - CGPoint locationInView = [touch locationInView: self]; + CGPoint locationInView = [self touchLocation:touch]; #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS SDL_SendTouchMotion(touchId, (long)touch, diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index 3c1b95580..4c7dae8ac 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -138,16 +138,8 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO return; } - if (w == frame.size.width && h == frame.size.height) { - return; - } - - frame.size.width = w; - frame.size.height = h; - frame.origin.x = 0; - frame.origin.y = 0; - [uiwindow setFrame:frame]; + [data->view setFrame:frame]; [data->view updateFrame]; SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h); }