Skip to content
Snippets Groups Projects
Commit 48867c80 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

iOS: fix scale

parent 72757afe
No related branches found
No related tags found
No related merge requests found
...@@ -28,27 +28,24 @@ ...@@ -28,27 +28,24 @@
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder: //The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder - (id)initWithCoder:(NSCoder*)coder
{ {
int w = 320;
int h = 480;
float ver = [[[UIDevice currentDevice] systemVersion] floatValue];
// You can't detect screen resolutions in pre 3.2 devices, but they are all 320x480
if (ver >= 3.2f)
{
UIScreen* mainscr = [UIScreen mainScreen];
w = mainscr.currentMode.size.width;
h = mainscr.currentMode.size.height;
}
if ((self = [super initWithCoder:coder])) { if ((self = [super initWithCoder:coder])) {
// Get the layer // Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
if ((w == 640 && h == 960) || (h == 1536 && w == 2048)) { // Retina display detected
int w = 320;
int h = 480;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2f) { // There is no retina display above 3.2
UIScreen* mainscr = [UIScreen mainScreen];
w = mainscr.currentMode.size.width;
h = mainscr.currentMode.size.height;
}
if ((w == 640 && h == 960) || (h == 1536 && w == 2048)) { // Retina display (iPhone or iPad/iPad mini)
self.contentScaleFactor = 2.0; self.contentScaleFactor = 2.0;
eaglLayer.contentsScale=2; eaglLayer.contentsScale=2;
} }
eaglLayer.opaque = YES; eaglLayer.opaque = YES;
eaglLayer.drawableProperties = eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO],
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO],
kEAGLDrawablePropertyRetainedBacking, kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLColorFormatRGBA8,
kEAGLDrawablePropertyColorFormat, nil]; kEAGLDrawablePropertyColorFormat, nil];
......
...@@ -218,16 +218,19 @@ ...@@ -218,16 +218,19 @@
-(void)prevAnimation { animation_prev(); [self requestRender]; } -(void)prevAnimation { animation_prev(); [self requestRender]; }
-(IBAction)pinch:(UIPinchGestureRecognizer *)sender -(IBAction)pinch:(UIPinchGestureRecognizer *)sender
{ {
if(!glView->rotate && [sender numberOfTouches] == 2) { if(!glView->rotate && [sender numberOfTouches] <= 2) {
float mScale = scaleFactor; float mScale = scaleFactor;
if (sender.state == UIGestureRecognizerStateBegan) if (sender.state == UIGestureRecognizerStateBegan)
mScale = scaleFactor; mScale = scaleFactor;
else if(sender.state == UIGestureRecognizerStateChanged) else if(sender.state == UIGestureRecognizerStateChanged)
mScale = scaleFactor * [sender scale]; mScale = scaleFactor * [sender scale];
else if(sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled){ else if(sender.state == UIGestureRecognizerStateEnded){
scaleFactor *= [sender scale]; scaleFactor *= [sender scale];
mScale = scaleFactor; mScale = scaleFactor;
} }
else if(sender.state == UIGestureRecognizerStateCancelled){
mScale = scaleFactor;
}
mScale = MAX(0.1, mScale); mScale = MAX(0.1, mScale);
glView->mContext->eventHandler(2,mScale); glView->mContext->eventHandler(2,mScale);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment