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.
This commit is contained in:
parent
f9a731d576
commit
5759a8f1db
3 changed files with 19 additions and 15 deletions
|
@ -50,6 +50,7 @@
|
||||||
@public
|
@public
|
||||||
SDL_uikitviewcontroller *viewcontroller;
|
SDL_uikitviewcontroller *viewcontroller;
|
||||||
}
|
}
|
||||||
|
- (CGPoint)touchLocation:(UITouch *)touch;
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
Simple DirectMedia Layer
|
Simple DirectMedia Layer
|
||||||
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
|
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
@ -60,10 +60,10 @@
|
||||||
//EventTouchData* data = (EventTouchData*)(touch.driverdata);
|
//EventTouchData* data = (EventTouchData*)(touch.driverdata);
|
||||||
|
|
||||||
touch.x_min = 0;
|
touch.x_min = 0;
|
||||||
touch.x_max = frame.size.width;
|
touch.x_max = 1;
|
||||||
touch.native_xres = touch.x_max - touch.x_min;
|
touch.native_xres = touch.x_max - touch.x_min;
|
||||||
touch.y_min = 0;
|
touch.y_min = 0;
|
||||||
touch.y_max = frame.size.height;
|
touch.y_max = 1;
|
||||||
touch.native_yres = touch.y_max - touch.y_min;
|
touch.native_yres = touch.y_max - touch.y_min;
|
||||||
touch.pressure_min = 0;
|
touch.pressure_min = 0;
|
||||||
touch.pressure_max = 1;
|
touch.pressure_max = 1;
|
||||||
|
@ -77,6 +77,17 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (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
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
NSEnumerator *enumerator = [touches objectEnumerator];
|
||||||
|
@ -94,7 +105,7 @@
|
||||||
|
|
||||||
#ifdef FIXED_MULTITOUCH
|
#ifdef FIXED_MULTITOUCH
|
||||||
while(touch) {
|
while(touch) {
|
||||||
CGPoint locationInView = [touch locationInView: self];
|
CGPoint locationInView = [self touchLocation:touch];
|
||||||
|
|
||||||
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
||||||
//FIXME: TODO: Using touch as the fingerId is potentially dangerous
|
//FIXME: TODO: Using touch as the fingerId is potentially dangerous
|
||||||
|
@ -133,7 +144,7 @@
|
||||||
|
|
||||||
#ifdef FIXED_MULTITOUCH
|
#ifdef FIXED_MULTITOUCH
|
||||||
while(touch) {
|
while(touch) {
|
||||||
CGPoint locationInView = [touch locationInView: self];
|
CGPoint locationInView = [self touchLocation:touch];
|
||||||
|
|
||||||
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
||||||
SDL_SendFingerDown(touchId, (long)touch,
|
SDL_SendFingerDown(touchId, (long)touch,
|
||||||
|
@ -181,7 +192,7 @@
|
||||||
|
|
||||||
#ifdef FIXED_MULTITOUCH
|
#ifdef FIXED_MULTITOUCH
|
||||||
while(touch) {
|
while(touch) {
|
||||||
CGPoint locationInView = [touch locationInView: self];
|
CGPoint locationInView = [self touchLocation:touch];
|
||||||
|
|
||||||
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
||||||
SDL_SendTouchMotion(touchId, (long)touch,
|
SDL_SendTouchMotion(touchId, (long)touch,
|
||||||
|
|
|
@ -138,16 +138,8 @@
|
||||||
return;
|
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];
|
[uiwindow setFrame:frame];
|
||||||
|
[data->view setFrame:frame];
|
||||||
[data->view updateFrame];
|
[data->view updateFrame];
|
||||||
SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
|
SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue