From 3a88235f56d653dd5003956709c7d08fa9ad3a03 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 30 Nov 2018 20:41:52 +0100 Subject: [PATCH] implement sharing in iOS, add OpenGL renderer in OSX window --- PanoPainter-OSX/main.cpp | 16 +--------------- PanoPainter/GameViewController.h | 1 + PanoPainter/GameViewController.m | 15 +++++++++++++++ data/layout.xml | 2 +- src/app_events.cpp | 6 ++++++ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/PanoPainter-OSX/main.cpp b/PanoPainter-OSX/main.cpp index 0c5467c..13609f3 100644 --- a/PanoPainter-OSX/main.cpp +++ b/PanoPainter-OSX/main.cpp @@ -92,21 +92,6 @@ std::mutex task_mutex; { NSURL *url = [NSURL fileURLWithPath:file_path]; NSArray *objectsToShare = @[url]; -// -// UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; -// -// // Exclude all activities except AirDrop. -// NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook, -// UIActivityTypePostToWeibo, -// UIActivityTypeMessage, UIActivityTypeMail, -// UIActivityTypePrint, UIActivityTypeCopyToPasteboard, -// UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, -// UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, -// UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo]; -// controller.excludedActivityTypes = excludedActivities; -// -// // Present the controller -// [self presentViewController:controller animated:YES completion:nil]; [airdrop_service performWithItems:objectsToShare]; } - (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope @@ -170,6 +155,7 @@ std::mutex task_mutex; CGLLockContext([[self openGLContext] CGLContextObj]); App::I.init(); + [self.window setTitle:[NSString stringWithFormat:@"%s - %s", g_window_title, glGetString(GL_RENDERER)]]; CGLUnlockContext([[self openGLContext] CGLContextObj]); gl_ready = true; diff --git a/PanoPainter/GameViewController.h b/PanoPainter/GameViewController.h index 4a106e9..e29d85e 100644 --- a/PanoPainter/GameViewController.h +++ b/PanoPainter/GameViewController.h @@ -28,4 +28,5 @@ - (void)registerForKeyboardNotifications; - (void)unregisterForKeyboardNotifications; - (void)crash; +- (void)share_file:(NSString*)file_path; @end diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index 7c54dd0..53d5854 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -70,6 +70,21 @@ std::recursive_mutex lock_mutex; [self.context presentRenderbuffer:GL_RENDERBUFFER]; } +- (void)share_file:(NSString *)file_path +{ + NSURL *url = [NSURL fileURLWithPath:file_path]; + NSArray *objectsToShare = @[url]; + + UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; + + controller.excludedActivityTypes = @[]; + controller.popoverPresentationController.sourceView = self.view; + controller.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/4, 0, 0); + + // Present the controller + [self presentViewController:controller animated:YES completion:nil]; +} + -(void)display_file:(std::string)filename { NSString* filePath = [NSString stringWithUTF8String:filename.c_str()]; diff --git a/data/layout.xml b/data/layout.xml index 19ecb3d..59d9a71 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -873,7 +873,7 @@ Here's a list of what's available in this release. - + diff --git a/src/app_events.cpp b/src/app_events.cpp index 16b6b7b..560c7ee 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -164,8 +164,14 @@ void App::display_file(std::string path) void App::share_file(std::string path) { if (path.empty()) + { + message_box("Sharing failed", "Please save the document before sharing it."); return; + } #ifdef __IOS__ + dispatch_async(dispatch_get_main_queue(), ^{ + [ios_view share_file:[NSString stringWithUTF8String:path.c_str()]]; + }); #elif __OSX__ dispatch_async(dispatch_get_main_queue(), ^{ [osx_view share_file:[NSString stringWithUTF8String:path.c_str()]];