From 3c99653c0953fc653f7046c399dd128c5aa7c94d Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 14 Oct 2019 12:50:41 +0200 Subject: [PATCH 1/2] fix SonarPen for iOS --- PanoPainter/AppDelegate.h | 2 ++ PanoPainter/AppDelegate.m | 32 +++++++++++++++++++++++++------- PanoPainter/GameViewController.m | 25 ++++++++++++++++++------- data/layout.xml | 4 ++++ src/app.h | 2 ++ src/app_layout.cpp | 7 +++++++ src/asset.cpp | 3 ++- 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/PanoPainter/AppDelegate.h b/PanoPainter/AppDelegate.h index 2ea5262..932c73b 100644 --- a/PanoPainter/AppDelegate.h +++ b/PanoPainter/AppDelegate.h @@ -16,6 +16,8 @@ openURL:(NSURL *)url options:(NSDictionary *)options; - (float)sonarpen_pressure; +- (bool)sonarpen_present; - (void)hockeyapp_crash; +- (void)sonarpen_start; @end diff --git a/PanoPainter/AppDelegate.m b/PanoPainter/AppDelegate.m index 0f7698b..d387d78 100644 --- a/PanoPainter/AppDelegate.m +++ b/PanoPainter/AppDelegate.m @@ -18,6 +18,7 @@ @interface AppDelegate () { GameViewController* view; WTSonarPenDriver* sonarpen_driver; + bool sonarpen_started; } @end @@ -35,6 +36,11 @@ [MSCrashes generateTestCrash]; } +- (bool)sonarpen_present +{ + return sonarpen_started && [sonarpen_driver isPenAttached]; +} + - (float)sonarpen_pressure { return [sonarpen_driver isPenAttached] ? [sonarpen_driver pressure] : 1.f; @@ -46,29 +52,41 @@ case WTSonarPenDriverStateInit: NSLog(@"Status: Initializing"); break; case WTSonarPenDriverStateRunning: - NSLog(@"Status: Running"); break; + NSLog(@"Status: Running"); + App::I->message_box("SonarPen", "Your SonarPen is now ready. Have fun!"); + break; case WTSonarPenDriverStateCalibrating: NSLog(@"Status: Calibrating"); break; case WTSonarPenDriverStateNotSonarPen: - NSLog(@"Status: Not a Sonar Pen"); break; + NSLog(@"Status: Not a Sonar Pen"); + App::I->message_box("SonarPen Error", "Couldn't recognize the device attatched to the jack plug as a SonarPen. Please remove it and plug it back in."); + 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; + NSLog(@"Status: No Microphone Permission"); + App::I->message_box("SonarPen Error", "SonarPen could not be started because you didn't allow the microphone permission. Please go to Settings -> PanoPainter and enable Microphone."); + break; } } +- (void)sonarpen_start { + if (sonarpen_started) + return; + sonarpen_driver = [[WTSonarPenDriver alloc] initWithApplication:[UIApplication sharedApplication]]; + [sonarpen_driver start]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(penStatusChanged) name:WTSonarPenDriverStateChangedNotification object:nil]; + sonarpen_started = true; +} + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - //[[BITHockeyManager sharedHockeyManager] configureWithIdentifier:@"c2dccca196294ecca8fd5d58af2738cf"]; + sonarpen_started = false; [MSAppCenter start:@"c2dccca1-9629-4ecc-a8fd-5d58af2738cf" withServices:@[ [MSAnalytics class], [MSCrashes class] ]]; -// 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; diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index 517eaff..74a3225 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -341,12 +341,20 @@ std::set ignored_touch; CGPoint touchLocation = [touch locationInView:self.view]; float scale = self.view.contentScaleFactor; + + float force = touch.force; + AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; + if ([app sonarpen_present]) + force = [app sonarpen_pressure]; + + kEventSource source = ((touch.type == UITouchType::UITouchTypeStylus) || [app sonarpen_present]) ? + kEventSource::Stylus : kEventSource::Touch; - kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch; - if (source == kEventSource::Stylus) + // apple pencil + if (touch.type == UITouchType::UITouchTypeStylus) pen_down = true; - App::I->ui_task_async([touchLocation, scale, f=touch.force, source] { + App::I->ui_task_async([touchLocation, scale, f=force, source] { App::I->mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, f, source, 0); }); t_count = 1; @@ -394,7 +402,7 @@ std::set ignored_touch; App::I->ui_task_async([tt0=t0.type,tt1=t1.type,p0,p1,f0=t0.force,f1=t1.force] { if (tt0 == UITouchType::UITouchTypeStylus) App::I->mouse_move(p0.x, p0.y, f0, kEventSource::Stylus, 0); - if (tt1 == UITouchType::UITouchTypeStylus) + else if (tt1 == UITouchType::UITouchTypeStylus) App::I->mouse_move(p1.x, p1.y, f1, kEventSource::Stylus, 0); }); } @@ -416,8 +424,9 @@ std::set ignored_touch; UITouch *touch = valid_touches[0]; CGPoint touchLocation = [touch locationInView:self.view]; float force = touch.type == UITouchType::UITouchTypeStylus ? touch.force : 1.0f; - //AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; - //force = [app sonarpen_pressure]; + AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; + if ([app sonarpen_present]) + force = [app sonarpen_pressure]; if (t_count == 2) { //App::I->gesture_end(); @@ -425,7 +434,8 @@ std::set ignored_touch; } else { - kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch; + kEventSource source = ((touch.type == UITouchType::UITouchTypeStylus) || [app sonarpen_present]) ? + kEventSource::Stylus : kEventSource::Touch; App::I->ui_task_async([touchLocation, scale, source, force] { App::I->mouse_move(touchLocation.x * scale, touchLocation.y * scale, force, source, 0); }); @@ -480,6 +490,7 @@ std::set ignored_touch; input_enabled = NO; App::I = new App; App::I->ios_view = self; + App::I->ios_app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; App::I->initLog(); //self.preferredFramesPerSecond = 60; diff --git a/data/layout.xml b/data/layout.xml index 4e92493..270044f 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -245,6 +245,10 @@ + + + + diff --git a/src/app.h b/src/app.h index 55ff6c4..30d2ac3 100644 --- a/src/app.h +++ b/src/app.h @@ -22,6 +22,7 @@ #if defined(__OBJC__) && defined(__IOS__) #import #import "GameViewController.h" +#import "AppDelegate.h" #endif #if defined(__OBJC__) && defined(__OSX__) @@ -152,6 +153,7 @@ public: #if defined(__IOS__) && defined(__OBJC__) GameViewController* ios_view; + AppDelegate* ios_app; #elif defined(__OSX__) && defined(__OBJC__) View* osx_view; AppOSX* osx_app; diff --git a/src/app_layout.cpp b/src/app_layout.cpp index c888d8d..59ee7ba 100644 --- a/src/app_layout.cpp +++ b/src/app_layout.cpp @@ -1012,6 +1012,13 @@ void App::init_menu_tools() popup_exp->destroy(); }; +#if __IOS__ + popup_exp->find("sonarpen")->on_click = [this, popup_exp](Node*) { + [ios_app sonarpen_start]; + popup_exp->mouse_release(); + popup_exp->destroy(); + }; +#endif }; } } diff --git a/src/asset.cpp b/src/asset.cpp index 9326dd4..a251831 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -145,7 +145,8 @@ bool Asset::create_dir(const std::string& path) return android_create_dir(path); #elif __IOS__ || __OSX__ return apple_create_dir(path); -else +#else + // TODO: implement for linux and web return false; #endif } From c50cebb220175dc6a2e15996cbca20f8cb32b62d Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 14 Oct 2019 13:23:08 +0200 Subject: [PATCH 2/2] add apple encryption exemption key --- PanoPainter-OSX/Info.plist | 2 ++ PanoPainter/Info.plist | 2 ++ 2 files changed, 4 insertions(+) diff --git a/PanoPainter-OSX/Info.plist b/PanoPainter-OSX/Info.plist index 71b84dd..9b5d5a3 100644 --- a/PanoPainter-OSX/Info.plist +++ b/PanoPainter-OSX/Info.plist @@ -2,6 +2,8 @@ + ITSAppUsesNonExemptEncryption + CFBundleDevelopmentRegion en CFBundleDocumentTypes diff --git a/PanoPainter/Info.plist b/PanoPainter/Info.plist index ad82ecf..cff50df 100644 --- a/PanoPainter/Info.plist +++ b/PanoPainter/Info.plist @@ -2,6 +2,8 @@ + ITSAppUsesNonExemptEncryption + CFBundleDevelopmentRegion en CFBundleDisplayName