add file picking for osx and ios and implement equirectangular import

This commit is contained in:
2017-12-09 09:07:42 +00:00
parent d18b1103bb
commit f4cd7fdc62
20 changed files with 218 additions and 8 deletions

View File

@@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@interface GameViewController : GLKViewController <UIKeyInput>
@interface GameViewController : GLKViewController <UIKeyInput,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
@public GLKView* glview;
}
@@ -17,5 +17,7 @@
- (void)async_lock;
- (void)async_unlock;
- (void)async_swap;
- (void)pick_photo:(std::function<void(std::string)>) callback;
- (void)registerForKeyboardNotifications;
- (void)unregisterForKeyboardNotifications;
@end

View File

@@ -11,6 +11,15 @@
#import <OpenGLES/ES3/glext.h>
#include "app.h"
@interface GameImagePicker : UIImagePickerController
{
@public std::promise<std::string> promise;
@public std::function<void(std::string)> callback;
}
@end
@implementation GameImagePicker
@end
@interface GameViewController () {
NSLock* gl_lock;
}
@@ -48,6 +57,33 @@ NSThread* lock_thread;
[self.context presentRenderbuffer:GL_RENDERBUFFER];
}
- (void)pick_photo:(std::function<void(std::string)>) callback
{
GameImagePicker *picker = [[GameImagePicker alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker->callback = callback;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *chosenImage = [info[UIImagePickerControllerImageURL] path];
GameImagePicker* p = static_cast<GameImagePicker*>(picker);
std::string path = [chosenImage cStringUsingEncoding:NSUTF8StringEncoding];
p->callback(path);
[picker dismissViewControllerAnimated:YES completion:^{
[self keyboardWillBeHidden:nil];
}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:^{
[self keyboardWillBeHidden:nil];
}];
}
- (void)insertText:(NSString *)text
{
if (const char* cstr = [text cStringUsingEncoding:NSASCIIStringEncoding])
@@ -84,6 +120,18 @@ NSThread* lock_thread;
selector:@selector(keyboardWasHidden:)
name:UIKeyboardDidHideNotification object:nil];
}
- (void)unregisterForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardDidHideNotification object:nil];
}
- (void)keyboardWillBeShown:(NSNotification*)aNotification
{
@@ -94,6 +142,7 @@ NSThread* lock_thread;
{
App::I.redraw = true;
App::I.animate = false;
[self unregisterForKeyboardNotifications];
}
// Called when the UIKeyboardDidShowNotification is sent.
@@ -233,7 +282,7 @@ NSThread* lock_thread;
{
App::I.redraw = true;
[self resignFirstResponder];
[self registerForKeyboardNotifications];
//[self registerForKeyboardNotifications];
}
- (void)viewDidLoad