diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-02-14 04:08:49 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-02-14 04:08:49 +0000 |
| commit | 642013ad23156f6be32dc1144f4d1b448ccea511 (patch) | |
| tree | 35ccecb42a31382e51d9b726ae60b20f82767d18 /Common/NativeApp/Apple/Source | |
| parent | Added the information dialog box when the app cannot run on Mac (diff) | |
| download | DiligentEngine-642013ad23156f6be32dc1144f4d1b448ccea511.tar.gz DiligentEngine-642013ad23156f6be32dc1144f4d1b448ccea511.zip | |
Implemented simple touch handling on iOS
Showing dialog box if the app fails to start on iOS
Diffstat (limited to 'Common/NativeApp/Apple/Source')
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/iOS/AppDelegate.m | 7 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.h | 1 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m | 73 |
3 files changed, 69 insertions, 12 deletions
diff --git a/Common/NativeApp/Apple/Source/Classes/iOS/AppDelegate.m b/Common/NativeApp/Apple/Source/Classes/iOS/AppDelegate.m index 2acd0aa..6aa6648 100644 --- a/Common/NativeApp/Apple/Source/Classes/iOS/AppDelegate.m +++ b/Common/NativeApp/Apple/Source/Classes/iOS/AppDelegate.m @@ -20,6 +20,13 @@ [self.window makeKeyAndVisible]; + NSString *error = [(EAGLView*)self.window.rootViewController.view getError]; + if(error != nil) + { + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed to start the application" message:error delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Whatever", nil]; + [alert show]; + } + [(EAGLView*)self.window.rootViewController.view startAnimation]; return YES; diff --git a/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.h b/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.h index bd5dd1d..fd6b9b9 100644 --- a/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.h +++ b/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.h @@ -20,5 +20,6 @@ - (void) stopAnimation; - (void) terminate; - (void) drawView:(id)sender; +- (NSString*)getError; @end diff --git a/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m b/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m index 679a401..9ddb5f4 100644 --- a/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m +++ b/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m @@ -10,6 +10,7 @@ #include "NativeAppBase.h" #include <memory> +#include <string> @interface EAGLView () { @@ -17,6 +18,7 @@ EAGLContext* _context; NSInteger _animationFrameInterval; CADisplayLink* _displayLink; + std::string _error; } @end @@ -48,14 +50,17 @@ return nil; } - _theApp.reset(CreateApplication()); - // Init our renderer. - _theApp->OnGLContextCreated((__bridge void*)self.layer); - - if (!_theApp) - { - return nil; - } + try + { + _theApp.reset(CreateApplication()); + // Init our renderer. + _theApp->OnGLContextCreated((__bridge void*)self.layer); + } + catch(std::runtime_error &err) + { + _error = err.what(); + _theApp.reset(); + } _animating = FALSE; _animationFrameInterval = 1; @@ -68,14 +73,18 @@ - (void) drawView:(id)sender { [EAGLContext setCurrentContext:_context]; - _theApp->Update(); - _theApp->Render(); - _theApp->Present(); + if(_theApp) + { + _theApp->Update(); + _theApp->Render(); + _theApp->Present(); + } } - (void) layoutSubviews { - _theApp->WindowResize(0, 0); + if(_theApp) + _theApp->WindowResize(0, 0); [self drawView:nil]; } @@ -145,4 +154,44 @@ [EAGLContext setCurrentContext:nil]; } +- (NSString*)getError +{ + return _error.empty() ? nil : [NSString stringWithFormat:@"%s", _error.c_str()]; +} + +- (void)touchesBegan:(NSSet<UITouch *> *)touches + withEvent:(UIEvent *)event; +{ + UITouch *firstTouch = touches.allObjects[0]; + CGPoint location = [firstTouch locationInView:self]; + if(_theApp) + _theApp->OnTouchBegan(location.x, location.y); +} + +- (void)touchesMoved:(NSSet<UITouch *> *)touches + withEvent:(UIEvent *)event; +{ + UITouch *firstTouch = touches.allObjects[0]; + CGPoint location = [firstTouch locationInView:self]; + if(_theApp) + _theApp->OnTouchMoved(location.x, location.y); +} + +- (void)touchesEnded:(NSSet<UITouch *> *)touches + withEvent:(UIEvent *)event; +{ + UITouch *firstTouch = touches.allObjects[0]; + CGPoint location = [firstTouch locationInView:self]; + if(_theApp) + _theApp->OnTouchEnded(location.x, location.y);} + +- (void)touchesCancelled:(NSSet<UITouch *> *)touches + withEvent:(UIEvent *)event; +{ + UITouch *firstTouch = touches.allObjects[0]; + CGPoint location = [firstTouch locationInView:self]; + if(_theApp) + _theApp->OnTouchEnded(location.x, location.y); +} + @end |
