From a71a91db17969cc4149905697dd84e72b1baf330 Mon Sep 17 00:00:00 2001 From: Gavin Hayler Date: Thu, 23 Feb 2012 09:42:53 +0200 Subject: IPHONE: Add aspect ratio correction to iPhone --- backends/platform/iphone/iphone_video.mm | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'backends/platform/iphone/iphone_video.mm') diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm index 387ed7252f..56c74b9ac5 100644 --- a/backends/platform/iphone/iphone_video.mm +++ b/backends/platform/iphone/iphone_video.mm @@ -53,6 +53,8 @@ static long lastTick = 0; static int frames = 0; #endif +static bool _aspectRatioCorrect = false; + #define printOpenGLError() printOglError(__FILE__, __LINE__) int printOglError(const char *file, int line) { @@ -73,6 +75,14 @@ void iPhone_setMouseCursor(unsigned short *buffer) { [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; } +void iPhone_setAspectRatioState(bool enable) { + _aspectRatioCorrect = enable; +} + +bool iPhone_getAspectRatioState() { + return _aspectRatioCorrect; +} + bool iPhone_isHighResDevice() { return _fullHeight > 480; } @@ -485,7 +495,7 @@ const char *iPhone_getDocumentsDir() { int screenWidth, screenHeight; [self setUpOrientation:[[UIDevice currentDevice] orientation] width:&screenWidth height:&screenHeight]; - + //printf("Window: (%d, %d), Surface: (%d, %d), Texture(%d, %d)\n", _fullWidth, _fullHeight, _videoContext.screenWidth, _videoContext.screenHeight, _gameScreenTextureWidth, _gameScreenTextureHeight); if (_screenTexture > 0) { @@ -516,10 +526,22 @@ const char *iPhone_getDocumentsDir() { [[_keyboardView inputView] removeFromSuperview]; } + float adjustedWidth = _videoContext.screenWidth; + float adjustedHeight = _videoContext.screenHeight; + if (_aspectRatioCorrect && ((_videoContext.screenWidth == 320 && _videoContext.screenHeight == 200) + || (_videoContext.screenWidth == 640 && _videoContext.screenHeight == 400)) ) { + if (_videoContext.screenHeight == 200) { + adjustedHeight = 240; + } + if (_videoContext.screenHeight == 400) { + adjustedHeight = 480; + } + } + float overlayPortraitRatio; if (_orientation == UIDeviceOrientationLandscapeLeft || _orientation == UIDeviceOrientationLandscapeRight) { - GLfloat gameScreenRatio = (GLfloat)_videoContext.screenWidth / (GLfloat)_videoContext.screenHeight; + GLfloat gameScreenRatio = (GLfloat)adjustedWidth / (GLfloat)adjustedHeight; GLfloat screenRatio = (GLfloat)screenWidth / (GLfloat)screenHeight; // These are the width/height according to the portrait layout! @@ -548,7 +570,7 @@ const char *iPhone_getDocumentsDir() { _gameScreenRect = CGRectMake(xOffset, yOffset, rectWidth, rectHeight); overlayPortraitRatio = 1.0f; } else { - float ratio = (float)_videoContext.screenHeight / (float)_videoContext.screenWidth; + float ratio = (float)adjustedHeight / (float)adjustedWidth; int height = (int)(screenWidth * ratio); //printf("Making rect (%u, %u)\n", screenWidth, height); _gameScreenRect = CGRectMake(0, 0, screenWidth, height); -- cgit v1.2.3