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

iOS: some fixes

parent 60343b94
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import "ModelListController.h" #import "ModelListController.h"
#import "Utils.h"
@implementation AppDelegate @implementation AppDelegate
...@@ -20,6 +21,12 @@ ...@@ -20,6 +21,12 @@
self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
} }
compute = false; compute = false;
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
[Utils copyRes];
}
return YES; return YES;
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
@public @public
/* our GModel drawing class */ /* our GModel drawing class */
drawContext *mContext; drawContext *mContext;
BOOL rotate;
} }
- (void)drawView; - (void)drawView;
......
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
break; break;
case 3: case 3:
{ {
rotate = true;
mContext->eventHandler(3,position.x,position.y); mContext->eventHandler(3,position.x,position.y);
} }
break; break;
...@@ -174,7 +175,8 @@ ...@@ -174,7 +175,8 @@
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(backingWidth, backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); CGImageRef imageRef = CGImageCreate(backingWidth, backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
free(buffer);
free(buffer2);
return [UIImage imageWithCGImage:imageRef]; return [UIImage imageWithCGImage:imageRef];
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
models = [[NSMutableArray alloc] init]; models = [[NSMutableArray alloc] init];
NSString *docsPath = [Utils getApplicationDocumentsDirectory]; NSString *docsPath = [Utils getApplicationDocumentsDirectory];
[Utils copyRes];
NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL]; NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL];
for(NSString* doc in docs) { for(NSString* doc in docs) {
NSString *docPath = [NSString stringWithFormat:@"%@/%@/", docsPath, doc]; NSString *docPath = [NSString stringWithFormat:@"%@/%@/", docsPath, doc];
......
...@@ -57,7 +57,8 @@ ...@@ -57,7 +57,8 @@
-(void)viewWillAppear:(BOOL)animated -(void)viewWillAppear:(BOOL)animated
{ {
if(self.initialModel != nil) { //if(self.initialModel != nil) {
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) {
_loadingAlert = [[UIAlertView alloc] initWithTitle:@"Please wait..." message: @"The model is loading" delegate: self cancelButtonTitle: nil otherButtonTitles: nil]; _loadingAlert = [[UIAlertView alloc] initWithTitle:@"Please wait..." message: @"The model is loading" delegate: self cancelButtonTitle: nil otherButtonTitles: nil];
[_loadingAlert show]; [_loadingAlert show];
} }
...@@ -156,7 +157,8 @@ ...@@ -156,7 +157,8 @@
[_progressIndicator startAnimating]; [_progressIndicator startAnimating];
[[UIApplication sharedApplication] cancelAllLocalNotifications]; [[UIApplication sharedApplication] cancelAllLocalNotifications];
dispatch_group_t group = dispatch_group_create(); dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_queue_t queue = dispatch_queue_create("org.geuz.onelab", NULL);
dispatch_group_async(group, queue, ^{
_computeBackgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ _computeBackgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask: _computeBackgroundTaskIdentifier]; [[UIApplication sharedApplication] endBackgroundTask: _computeBackgroundTaskIdentifier];
_computeBackgroundTaskIdentifier = UIBackgroundTaskInvalid; _computeBackgroundTaskIdentifier = UIBackgroundTaskInvalid;
...@@ -178,7 +180,7 @@ ...@@ -178,7 +180,7 @@
_computeBackgroundTaskIdentifier = UIBackgroundTaskInvalid; _computeBackgroundTaskIdentifier = UIBackgroundTaskInvalid;
}); });
dispatch_group_notify(group, dispatch_get_main_queue(), ^{ dispatch_group_notify(group, queue, ^{
[UIApplication sharedApplication].applicationIconBadgeNumber = -1; [UIApplication sharedApplication].applicationIconBadgeNumber = -1;
[_runStopButton setAction:@selector(compute)]; [_runStopButton setAction:@selector(compute)];
[_runStopButton setTitle:@"Run"]; [_runStopButton setTitle:@"Run"];
...@@ -212,7 +214,7 @@ ...@@ -212,7 +214,7 @@
-(void)prevAnimation { animation_prev(); [self requestRender]; } -(void)prevAnimation { animation_prev(); [self requestRender]; }
-(IBAction)pinch:(UIPinchGestureRecognizer *)sender -(IBAction)pinch:(UIPinchGestureRecognizer *)sender
{ {
if([sender numberOfTouches] > 2) return; if(!glView->rotate && [sender numberOfTouches] == 2) {
float mScale = scaleFactor; float mScale = scaleFactor;
if (sender.state == UIGestureRecognizerStateBegan) if (sender.state == UIGestureRecognizerStateBegan)
mScale = scaleFactor; mScale = scaleFactor;
...@@ -224,6 +226,7 @@ ...@@ -224,6 +226,7 @@
} }
mScale = MAX(0.1, mScale); mScale = MAX(0.1, mScale);
glView->mContext->eventHandler(2,mScale); glView->mContext->eventHandler(2,mScale);
}
[glView drawView]; [glView drawView];
} }
...@@ -244,6 +247,7 @@ ...@@ -244,6 +247,7 @@
UITouch *touch = [[event allTouches] anyObject]; UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view]; CGPoint touchPoint = [touch locationInView:self.view];
glView->mContext->eventHandler(4, touchPoint.x, touchPoint.y); glView->mContext->eventHandler(4, touchPoint.x, touchPoint.y);
glView->rotate = false;
} }
- (IBAction)singleTap:(UITapGestureRecognizer *)sender { - (IBAction)singleTap:(UITapGestureRecognizer *)sender {
...@@ -313,14 +317,9 @@ ...@@ -313,14 +317,9 @@
if(buttonIndex == 0) [_errors removeAllObjects]; if(buttonIndex == 0) [_errors removeAllObjects];
else [_errors removeLastObject]; else [_errors removeLastObject];
if(_errors.count > 0) { if(_errors.count > 0) {
[_errorAlert setMessage:[_errors lastObject]]; //[_errorAlert setMessage:[_errors lastObject]];
[_errorAlert show]; [_errorAlert show];
} }
else {
[_errorAlert dismissWithClickedButtonIndex:0 animated:YES];
//[_errorAlert release];
_errorAlert = nil;
}
} }
#pragma mark - Split view #pragma mark - Split view
...@@ -371,10 +370,13 @@ void getBitmap(void *self, const char *text, int textsize, unsigned char **map, ...@@ -371,10 +370,13 @@ void getBitmap(void *self, const char *text, int textsize, unsigned char **map,
[lbl setBackgroundColor:[UIColor clearColor]]; [lbl setBackgroundColor:[UIColor clearColor]];
CGSize lblSize = [[lbl text] sizeWithAttributes:@{NSFontAttributeName:[lbl font]}]; CGSize lblSize = [[lbl text] sizeWithAttributes:@{NSFontAttributeName:[lbl font]}];
*realWidth = lblSize.width; *realWidth = lblSize.width;
int i; int i=2;
for(i=2;i<*realWidth;i*=2); *width = i; while(i<*realWidth) i*=2;
*width = i;
*height = lblSize.height; *height = lblSize.height;
for(i=2;i<*height;i*=2); *height = i; i=2;
while(i<*height) i*=2;
*height = i;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(*width, *height), NO, 0.0); UIGraphicsBeginImageContextWithOptions(CGSizeMake(*width, *height), NO, 0.0);
[lbl.layer renderInContext:UIGraphicsGetCurrentContext()]; [lbl.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
- (void)awakeFromNib - (void)awakeFromNib
{ {
self.clearsSelectionOnViewWillAppear = NO; self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); self.preferredContentSize = CGSizeMake(320.0, 600.0);
[super awakeFromNib]; [super awakeFromNib];
} }
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
[self.navigationController setToolbarHidden:NO]; [self.navigationController setToolbarHidden:NO];
control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]]; control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]];
control.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control]; UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil]; self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil];
......
...@@ -24,11 +24,11 @@ ...@@ -24,11 +24,11 @@
NSString *docPath = [paths objectAtIndex:0]; //Get the docs directory NSString *docPath = [paths objectAtIndex:0]; //Get the docs directory
NSArray *resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:NULL]; NSArray *resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:NULL];
//[[NSFileManager defaultManager] removeItemAtPath:[docPath stringByAppendingString:@"/"] error:nil];
for (NSString* obj in resContents){ for (NSString* obj in resContents){
NSError* error; NSError* error;
if (![[NSFileManager defaultManager] copyItemAtPath:[resPath stringByAppendingPathComponent:obj] toPath:[docPath stringByAppendingPathComponent:obj] error:&error]) if (![[NSFileManager defaultManager] copyItemAtPath:[resPath stringByAppendingPathComponent:obj] toPath:[docPath stringByAppendingPathComponent:obj] error:&error])
NSLog(@"Error: %@", error);; NSLog(@"Error: %@", error);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment