110 lines
4.2 KiB
Objective-C
110 lines
4.2 KiB
Objective-C
//
|
|
// AppDelegate.m
|
|
// PanoPainter
|
|
//
|
|
// Created by Omar Mohamed Ali Mudhir on 07/05/17.
|
|
// Copyright © 2017 Omar Mohamed Ali Mudhir. All rights reserved.
|
|
//
|
|
|
|
#import "AppDelegate.h"
|
|
#import "GameViewController.h"
|
|
#include "app.h"
|
|
#include <WTSonarPenDriver.h>
|
|
|
|
void global_exception_handler(NSException* e)
|
|
{
|
|
if (App::I.canvas && App::I.canvas->m_canvas)
|
|
App::I.canvas->m_canvas->project_save_thread(App::I.data_path + "/recovery.ppi");
|
|
|
|
std::terminate();
|
|
}
|
|
|
|
void global_signal_handler(int e)
|
|
{
|
|
if (App::I.canvas && App::I.canvas->m_canvas)
|
|
App::I.canvas->m_canvas->project_save_thread(App::I.data_path + "/recovery.ppi");
|
|
|
|
std::terminate();
|
|
}
|
|
|
|
@interface AppDelegate () {
|
|
GameViewController* view;
|
|
WTSonarPenDriver* sonarpen_driver;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation AppDelegate
|
|
|
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
|
|
{
|
|
App::I.canvas->m_canvas->project_open([url fileSystemRepresentation]);
|
|
return true;
|
|
}
|
|
|
|
- (float)sonarpen_pressure
|
|
{
|
|
return [sonarpen_driver isPenAttached] ? [sonarpen_driver pressure] : 1.f;
|
|
}
|
|
|
|
- (void)penStatusChanged
|
|
{
|
|
switch (sonarpen_driver.state) {
|
|
case WTSonarPenDriverStateInit:
|
|
NSLog(@"Status: Initializing"); break;
|
|
case WTSonarPenDriverStateRunning:
|
|
NSLog(@"Status: Running"); break;
|
|
case WTSonarPenDriverStateCalibrating:
|
|
NSLog(@"Status: Calibrating"); break;
|
|
case WTSonarPenDriverStateNotSonarPen:
|
|
NSLog(@"Status: Not a Sonar Pen"); break;
|
|
case WTSonarPenDriverStateCalibratingMax:
|
|
NSLog(@"Status: Calibrating Max Value"); break;
|
|
case WTSonarPenDriverStateWaitingForPermission:
|
|
NSLog(@"Status: Wait for Permission"); break;
|
|
case WTSonarPenDriverStateNoMicrophonePermission:
|
|
NSLog(@"Status: No Microphone Permission"); break;
|
|
}
|
|
}
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
// Override point for customization after application launch.
|
|
NSSetUncaughtExceptionHandler(&global_exception_handler);
|
|
sonarpen_driver = [[WTSonarPenDriver alloc] initWithApplication:application];
|
|
[sonarpen_driver start];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(penStatusChanged) name:WTSonarPenDriverStateChangedNotification object:nil];
|
|
|
|
view = (GameViewController*)self.window.rootViewController;
|
|
return YES;
|
|
}
|
|
|
|
- (void)applicationWillResignActive:(UIApplication *)application {
|
|
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
|
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
|
App::I.redraw = true;
|
|
[view reset_touch];
|
|
}
|
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
|
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
|
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
|
App::I.redraw = true;
|
|
}
|
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
|
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
|
App::I.redraw = true;
|
|
}
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
|
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
|
App::I.redraw = true;
|
|
}
|
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
|
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
|
App::I.redraw = true;
|
|
}
|
|
|
|
@end
|