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

Commit

Permalink
Fixed retina display input scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Sep 18, 2012
1 parent 6c3215c commit 838db7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/video/uikit/SDL_uikitview.h
Expand Up @@ -50,7 +50,7 @@
@public
SDL_uikitviewcontroller *viewcontroller;
}
- (CGPoint)touchLocation:(UITouch *)touch;
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
Expand Down
26 changes: 18 additions & 8 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -76,14 +76,24 @@ - (id)initWithFrame:(CGRect)frame

}

- (CGPoint)touchLocation:(UITouch *)touch
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
{
CGPoint point = [touch locationInView: self];
CGRect frame = [self frame];

frame = CGRectApplyAffineTransform(frame, [self transform]);
point.x /= frame.size.width;
point.y /= frame.size.height;

// Get the display scale and apply that to the input coordinates
SDL_Window *window = self->viewcontroller.window;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
point.x *= displaymodedata->scale;
point.y *= displaymodedata->scale;

if (normalize) {
point.x /= frame.size.width;
point.y /= frame.size.height;
}
return point;
}

Expand All @@ -93,7 +103,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = (UITouch*)[enumerator nextObject];

if (touch) {
CGPoint locationInView = [touch locationInView: self];
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];

/* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
Expand All @@ -104,7 +114,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

#ifdef FIXED_MULTITOUCH
while(touch) {
CGPoint locationInView = [self touchLocation:touch];
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];

#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
//FIXME: TODO: Using touch as the fingerId is potentially dangerous
Expand Down Expand Up @@ -143,7 +153,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

#ifdef FIXED_MULTITOUCH
while(touch) {
CGPoint locationInView = [self touchLocation:touch];
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];

#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
SDL_SendFingerDown(touchId, (long)touch,
Expand Down Expand Up @@ -183,15 +193,15 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = (UITouch*)[enumerator nextObject];

if (touch) {
CGPoint locationInView = [touch locationInView: self];
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];

/* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
}

#ifdef FIXED_MULTITOUCH
while(touch) {
CGPoint locationInView = [self touchLocation:touch];
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];

#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
SDL_SendTouchMotion(touchId, (long)touch,
Expand Down

0 comments on commit 838db7e

Please sign in to comment.