Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed issues with the touch coordinates in landscape mode.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Nov 15, 2011
1 parent 878a532 commit b69f500
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitview.h
Expand Up @@ -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;
Expand Down
23 changes: 17 additions & 6 deletions src/video/uikit/SDL_uikitview.m
@@ -1,4 +1,4 @@
/*
/*
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions src/video/uikit/SDL_uikitviewcontroller.m
Expand Up @@ -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);
}
Expand Down

0 comments on commit b69f500

Please sign in to comment.