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

Commit

Permalink
Fixed touch coordinates with the new UI bounds calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Sep 19, 2012
1 parent 9f3a1f1 commit a0a38b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/video/uikit/SDL_uikitopengles.m
Expand Up @@ -105,7 +105,13 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
UIWindow *uiwindow = data->uiwindow;

/* construct our view, passing in SDL's OpenGL configuration data */
view = [[SDL_uikitopenglview alloc] initWithFrame: [uiwindow bounds]
CGRect frame;
if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
frame = [displaydata->uiscreen bounds];
} else {
frame = [displaydata->uiscreen applicationFrame];
}
view = [[SDL_uikitopenglview alloc] initWithFrame: frame
scale: displaymodedata->scale
retainBacking: _this->gl_config.retained_backing
rBits: _this->gl_config.red_size
Expand Down
8 changes: 3 additions & 5 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -79,9 +79,6 @@ - (id)initWithFrame:(CGRect)frame
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
{
CGPoint point = [touch locationInView: self];
CGRect frame = [self frame];

frame = CGRectApplyAffineTransform(frame, [self transform]);

// Get the display scale and apply that to the input coordinates
SDL_Window *window = self->viewcontroller.window;
Expand All @@ -91,8 +88,9 @@ - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
point.y *= displaymodedata->scale;

if (normalize) {
point.x /= frame.size.width;
point.y /= frame.size.height;
CGRect bounds = [self bounds];
point.x /= bounds.size.width;
point.y /= bounds.size.height;
}
return point;
}
Expand Down

0 comments on commit a0a38b3

Please sign in to comment.