restore runtime compatibility with ios 3.2
authorkoda
Wed, 26 Oct 2011 00:30:35 +0200
changeset 6209 074ab6ebcb3e
parent 6208 b831679e9467
child 6210 923c8414e3af
restore runtime compatibility with ios 3.2
project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/HWUtils.m
project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
project_files/HedgewarsMobile/Classes/TeamConfigViewController.m
project_files/HedgewarsMobile/Classes/UIImageExtra.h
project_files/HedgewarsMobile/Classes/UIImageExtra.m
project_files/HedgewarsMobile/ExtraCategories.h
project_files/HedgewarsMobile/ExtraCategories.m
project_files/HedgewarsMobile/SDL-50560ca58f80.patch
--- a/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m	Wed Oct 26 00:30:35 2011 +0200
@@ -123,6 +123,7 @@
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
     UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str];
+    CGFloat theScale = [[UIScreen mainScreen] safeScale];
 
     NSMutableArray *imgs = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()];
     NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()];
@@ -167,9 +168,9 @@
         [self.view addSubview:button];
         [array addObject:button];
 
-        int size = 32 * [[UIScreen mainScreen] scale];
-        int x_src = ((i*size)/(int)(ammoStoreImage.size.height * [[UIScreen mainScreen] scale]))*size;
-        int y_src = (i*size)%(int)(ammoStoreImage.size.height * [[UIScreen mainScreen] scale]);
+        int size = 32 * theScale;
+        int x_src = ((i*size)/(int)(ammoStoreImage.size.height * theScale))*size;
+        int y_src = (i*size)%(int)(ammoStoreImage.size.height * theScale);
         UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, size, size)];
         [imgs addObject:img];
     }
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Wed Oct 26 00:30:35 2011 +0200
@@ -64,23 +64,24 @@
 // main routine for calling the actual game engine
 -(void) engineLaunch {
     const char *gameArgs[11];
-    NSInteger width, height;
+    CGFloat width, height;
+    CGFloat screenScale = [[UIScreen mainScreen] safeScale];
     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort];
     NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
 
     if (IS_DUALHEAD()) {
         CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds];
-        width = (int) screenBounds.size.width;
-        height = (int) screenBounds.size.height;
+        width = screenBounds.size.width;
+        height = screenBounds.size.height;
     } else {
         CGRect screenBounds = [[UIScreen mainScreen] bounds];
-        width = (int) screenBounds.size.height;
-        height = (int) screenBounds.size.width;
+        width = screenBounds.size.height;
+        height = screenBounds.size.width;
     }
 
-    NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width * (int)[[UIScreen mainScreen] scale]];
-    NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height * (int)[[UIScreen mainScreen] scale]];
+    NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", (int)(width * screenScale)];
+    NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", (int)(height * screenScale)];
     NSString *rotation = [[NSString alloc] initWithString:@"0"];
 
     NSString *modelId = [HWUtils modelType];
--- a/project_files/HedgewarsMobile/Classes/HWUtils.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/HWUtils.m	Wed Oct 26 00:30:35 2011 +0200
@@ -40,7 +40,6 @@
 
         cachedModel = [[NSString stringWithUTF8String:name] retain];
         free(name);
-        DLog(@"Cache now contains: %@",cachedModel);
     }
     return cachedModel;
 }
--- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Wed Oct 26 00:30:35 2011 +0200
@@ -87,11 +87,11 @@
                           NSLocalizedString(@"Style",@""),nil];
         UISegmentedControl *controller = [[UISegmentedControl alloc] initWithItems:array];
         [array release];
-        [controller addTarget:self.tableView action:@selector(reloadData) forControlEvents:UIControlEventValueChanged];
         controller.segmentedControlStyle = UISegmentedControlStyleBar;
         controller.tintColor = [UIColor lightGrayColor];
         controller.selectedSegmentIndex = 0;
         self.topControl = controller;
+        [controller addTarget:self.tableView action:@selector(reloadData) forControlEvents:UIControlEventValueChanged];
         [controller release];
     }
     return topControl;
--- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Wed Oct 26 00:30:35 2011 +0200
@@ -163,10 +163,11 @@
             weaponCell.delegate = self;
         }
 
-        int size = 32 * [[UIScreen mainScreen] scale];
-        int corners = 8 * [[UIScreen mainScreen] scale];
-        int x = ((row*size)/(int)(self.ammoStoreImage.size.height * [[UIScreen mainScreen] scale]))*size;
-        int y = (row*size)%(int)(self.ammoStoreImage.size.height * [[UIScreen mainScreen] scale]);
+        CGFloat theScale = [[UIScreen mainScreen] safeScale];
+        int size = 32 * theScale;
+        int corners = 8 * theScale;
+        int x = ((row*size)/(int)(self.ammoStoreImage.size.height * theScale))*size;
+        int y = (row*size)%(int)(self.ammoStoreImage.size.height * theScale);
 
         UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, size, size)] makeRoundCornersOfSize:CGSizeMake(corners, corners)];
         weaponCell.weaponIcon.image = img;
--- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Wed Oct 26 00:30:35 2011 +0200
@@ -108,35 +108,6 @@
     return numberOfHogs;
 }
 
--(UIImage *)drawHogsRepeated:(NSInteger) manyTimes {
-    NSString *imgString = [[NSString alloc] initWithFormat:@"%@/hedgehog.png",[[NSBundle mainBundle] resourcePath]];
-    UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:imgString];
-    [imgString release];
-    CGFloat screenScale = [[UIScreen mainScreen] scale];
-    int w = hogSprite.size.width * screenScale;
-    int h = hogSprite.size.height * screenScale;
-    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
-    CGContextRef context = CGBitmapContextCreate(NULL, w * 3, h, 8, 4 * w * 3, colorSpace, kCGImageAlphaPremultipliedFirst);
-    
-    // draw the two images in the current context
-    for (int i = 0; i < manyTimes; i++)
-        CGContextDrawImage(context, CGRectMake(i*8*screenScale, 0, w, h), [hogSprite CGImage]);
-    [hogSprite release];
-    
-    // Create bitmap image info from pixel data in current context
-    CGImageRef imageRef = CGBitmapContextCreateImage(context);
-    
-    // Create a new UIImage object
-    UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
-    
-    // Release colorspace, context and bitmap information
-    CGColorSpaceRelease(colorSpace);
-    CGContextRelease(context);
-    CFRelease(imageRef);
-
-    return resultImage;
-}
-
 #pragma mark -
 #pragma mark Table view data source
 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
@@ -174,7 +145,7 @@
         [squareButton setTitle:[hogNumber stringValue] forState:UIControlStateNormal];
         squareButton.ownerDictionary = selectedRow;
 
-        cell.imageView.image = [self drawHogsRepeated:[hogNumber intValue]];
+        cell.imageView.image = [UIImage drawHogsRepeated:[hogNumber intValue]];
         ((HoldTableViewCell *)cell).delegate = self;
     } else {
         cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
@@ -277,7 +248,7 @@
         [squareButton setTitle:[newNumber stringValue] forState:UIControlStateNormal];
         [selectedRow setObject:newNumber forKey:@"number"];
 
-        cell.imageView.image = [self drawHogsRepeated:[newNumber intValue]];
+        cell.imageView.image = [UIImage drawHogsRepeated:[newNumber intValue]];
     }
 }
 
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.h	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.h	Wed Oct 26 00:30:35 2011 +0200
@@ -25,6 +25,7 @@
 @interface UIImage (extra)
 
 +(UIImage *)whiteImage:(CGSize) ofSize;
++(UIImage *)drawHogsRepeated:(NSInteger) manyTimes;
 +(CGSize) imageSizeFromMetadataOf:(NSString *)aFileName;
 
 -(UIImage *)scaleToSize:(CGSize) size;
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Wed Oct 26 00:30:35 2011 +0200
@@ -25,22 +25,30 @@
 @implementation UIImage (extra)
 
 -(UIImage *)scaleToSize:(CGSize) size {
-    DLog(@"warning - this is a very expensive operation, you should avoid using it");
+    // Create a bitmap graphics context; this will also set it as the current context
+    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+    CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, colorSpace, kCGImageAlphaPremultipliedFirst);
 
-    // Create a bitmap graphics context; this will also set it as the current context
-    UIGraphicsBeginImageContextWithOptions(size, NO, [[UIScreen mainScreen] scale]);
+    // draw the image inside the context
+    CGFloat screenScale = [[UIScreen mainScreen] safeScale];
+    CGContextDrawImage(context, CGRectMake(0, 0, size.width*screenScale, size.height*screenScale), self.CGImage);
 
-    // Draw the scaled image in the current context
-    [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
+    // Create bitmap image info from pixel data in current context
+    CGImageRef imageRef = CGBitmapContextCreateImage(context);
 
-    // Create a new image from current context
-    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
+    // Create a new UIImage object
+    UIImage *resultImage;
+    if ([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
+        resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
+    else
+        resultImage = [UIImage imageWithCGImage:imageRef];
 
-    // Pop the current context from the stack
-    UIGraphicsEndImageContext();
+    // Release colorspace, context and bitmap information
+    CGColorSpaceRelease(colorSpace);
+    CGContextRelease(context);
+    CFRelease(imageRef);
 
-    // Return our new scaled image (autoreleased)
-    return scaledImage;
+    return resultImage;
 }
 
 -(UIImage *)mergeWith:(UIImage *)secondImage atPoint:(CGPoint) secondImagePoint {
@@ -48,7 +56,7 @@
         DLog(@"Warning, secondImage == nil");
         return self;
     }
-    CGFloat screenScale = [[UIScreen mainScreen] scale];
+    CGFloat screenScale = [[UIScreen mainScreen] safeScale];
     int w = self.size.width * screenScale;
     int h = self.size.height * screenScale;
     int yOffset = self.size.height - secondImage.size.height + secondImagePoint.y;
@@ -57,26 +65,30 @@
         DLog(@"Cannot have 0 dimesions");
         return self;
     }
-    
+
     // Create a bitmap graphics context; this will also set it as the current context
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGContextRef context = CGBitmapContextCreate(NULL, w, h+yOffset, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
-    
+
     // draw the two images in the current context
     CGContextDrawImage(context, CGRectMake(0, 0, self.size.width*screenScale, self.size.height*screenScale), [self CGImage]);
     CGContextDrawImage(context, CGRectMake(secondImagePoint.x*screenScale, secondImagePoint.y*screenScale, secondImage.size.width*screenScale, secondImage.size.height*screenScale), [secondImage CGImage]);
-    
+
     // Create bitmap image info from pixel data in current context
     CGImageRef imageRef = CGBitmapContextCreateImage(context);
-    
+
     // Create a new UIImage object
-    UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
+    UIImage *resultImage;
+    if ([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
+        resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
+    else
+        resultImage = [UIImage imageWithCGImage:imageRef];
 
     // Release colorspace, context and bitmap information
     CGColorSpaceRelease(colorSpace);
     CGContextRelease(context);
     CFRelease(imageRef);
-   
+
     return resultImage;
 }
 
@@ -190,7 +202,7 @@
 -(UIImage *)makeRoundCornersOfSize:(CGSize) sizewh {
     CGFloat cornerWidth = sizewh.width;
     CGFloat cornerHeight = sizewh.height;
-    CGFloat screenScale = [[UIScreen mainScreen] scale];
+    CGFloat screenScale = [[UIScreen mainScreen] safeScale];
     CGFloat w = self.size.width * screenScale;
     CGFloat h = self.size.height * screenScale;
 
@@ -209,11 +221,14 @@
     CGContextRelease(context);
     CGColorSpaceRelease(colorSpace);
 
-    UIImage *newImage = [UIImage imageWithCGImage:imageMasked scale:screenScale orientation:UIImageOrientationUp];
-
+    UIImage *resultImage;
+    if ([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
+        resultImage = [UIImage imageWithCGImage:imageMasked scale:screenScale orientation:UIImageOrientationUp];
+    else
+        resultImage = [UIImage imageWithCGImage:imageMasked];
     CGImageRelease(imageMasked);
 
-    return newImage;
+    return resultImage;
 }
 
 // by http://www.sixtemia.com/journal/2010/06/23/uiimage-negative-color-effect/
@@ -251,6 +266,39 @@
     return bkgImg;
 }
 
++(UIImage *)drawHogsRepeated:(NSInteger) manyTimes {
+    NSString *imgString = [[NSString alloc] initWithFormat:@"%@/hedgehog.png",[[NSBundle mainBundle] resourcePath]];
+    UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:imgString];
+    [imgString release];
+    CGFloat screenScale = [[UIScreen mainScreen] safeScale];
+    int w = hogSprite.size.width * screenScale;
+    int h = hogSprite.size.height * screenScale;
+    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+    CGContextRef context = CGBitmapContextCreate(NULL, w * 3, h, 8, 4 * w * 3, colorSpace, kCGImageAlphaPremultipliedFirst);
+
+    // draw the two images in the current context
+    for (int i = 0; i < manyTimes; i++)
+        CGContextDrawImage(context, CGRectMake(i*8*screenScale, 0, w, h), [hogSprite CGImage]);
+    [hogSprite release];
+
+    // Create bitmap image info from pixel data in current context
+    CGImageRef imageRef = CGBitmapContextCreateImage(context);
+
+    // Create a new UIImage object
+    UIImage *resultImage;
+    if ([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
+        resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
+    else
+        resultImage = [UIImage imageWithCGImage:imageRef];
+
+    // Release colorspace, context and bitmap information
+    CGColorSpaceRelease(colorSpace);
+    CGContextRelease(context);
+    CFRelease(imageRef);
+
+    return resultImage;
+}
+
 // this routine checks for the PNG size without loading it in memory
 // https://github.com/steipete/PSFramework/blob/master/PSFramework%20Version%200.3/PhotoshopFramework/PSMetaDataFunctions.m
 +(CGSize) imageSizeFromMetadataOf:(NSString *)aFileName {
--- a/project_files/HedgewarsMobile/ExtraCategories.h	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/ExtraCategories.h	Wed Oct 26 00:30:35 2011 +0200
@@ -22,6 +22,13 @@
 #import <Foundation/Foundation.h>
 
 
+@interface UIScreen (safe)
+
+-(CGFloat) safeScale;
+
+@end
+
+
 @interface UITableView (backgroundColor)
 
 -(void) setBackgroundColorForAnyTable:(UIColor *)color;
--- a/project_files/HedgewarsMobile/ExtraCategories.m	Tue Oct 25 22:51:10 2011 +0200
+++ b/project_files/HedgewarsMobile/ExtraCategories.m	Wed Oct 26 00:30:35 2011 +0200
@@ -23,6 +23,19 @@
 #import <QuartzCore/QuartzCore.h>
 #import <CommonCrypto/CommonDigest.h>
 
+
+@implementation UIScreen (safe)
+
+-(CGFloat) safeScale {
+    CGFloat theScale = 1.0f;
+    if ([self respondsToSelector:@selector(scale)])
+         theScale = [self scale];
+    return theScale;
+}
+
+@end
+
+
 @implementation UITableView (backgroundColor)
 
 -(void) setBackgroundColorForAnyTable:(UIColor *) color {