From 47a09a94bec2d5f6a7f732b57f39348a36443d3e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 26 Dec 2018 14:01:16 -0800 Subject: Added API selection on Mac --- .../Apple/Data/OSX/Base.lproj/Main.storyboard | 49 +++++++++++++- .../Apple/Source/Classes/OSX/AppDelegate.m | 20 ------ .../Classes/OSX/ModeSelectionViewController.h | 30 +++++++++ .../Classes/OSX/ModeSelectionViewController.mm | 78 ++++++++++++++++++++++ Common/NativeApp/CMakeLists.txt | 4 +- 5 files changed, 158 insertions(+), 23 deletions(-) create mode 100644 Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.h create mode 100644 Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm (limited to 'Common/NativeApp') diff --git a/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard b/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard index 7d318c2..d01e912 100644 --- a/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard +++ b/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard @@ -3,6 +3,7 @@ + @@ -126,7 +127,7 @@ - + @@ -137,7 +138,7 @@ - + @@ -169,5 +170,49 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m b/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m index 4e8e0f9..fd52cc4 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m +++ b/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m @@ -7,8 +7,6 @@ */ #import "AppDelegate.h" -#import "GLViewController.h" -#import "MetalViewController.h" @interface AppDelegate () @@ -18,25 +16,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSWindow* mainWindow = [[NSApplication sharedApplication]mainWindow]; - - NSString* error = [[mainWindow contentViewController] getError]; - if(error != nil) - { - NSAlert *alert = [[NSAlert alloc] init]; - [alert addButtonWithTitle:@"OK"]; - [alert setMessageText:@"Failed to start the application"]; - [alert setInformativeText:error]; - [alert setAlertStyle:NSAlertStyleCritical]; - [alert runModal]; - [NSApp terminate:self]; - } - [mainWindow setAcceptsMouseMovedEvents:YES]; - NSString *name = [[mainWindow contentViewController] getAppName]; - if(name != nil) - { - [mainWindow setTitle:name]; - } } - (void)applicationWillTerminate:(NSNotification *)aNotification { diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.h b/Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.h new file mode 100644 index 0000000..3c84ecb --- /dev/null +++ b/Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.h @@ -0,0 +1,30 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + + +#import + +@interface ModeSelectionViewController : NSViewController +{ +} +@end diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm b/Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm new file mode 100644 index 0000000..eed6ca5 --- /dev/null +++ b/Common/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm @@ -0,0 +1,78 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#import "ModeSelectionViewController.h" +#import "GLViewController.h" +#import "MetalViewController.h" + +@implementation ModeSelectionViewController +{ +} + +- (void) setWindowTitle:(NSString*) title +{ + NSWindow* mainWindow = [[NSApplication sharedApplication]mainWindow]; + [mainWindow setTitle:title]; +} + +- (void) terminateApp:(NSString*) error +{ + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:@"OK"]; + [alert setMessageText:@"Failed to start the application"]; + [alert setInformativeText:error]; + [alert setAlertStyle:NSAlertStyleCritical]; + [alert runModal]; + [NSApp terminate:self]; +} + +- (IBAction)goOpenGL:(id)sender +{ + GLViewController* glViewController = [self.storyboard instantiateControllerWithIdentifier:@"GLViewControllerID"]; + NSString* error = [glViewController getError]; + if(error != nil) + { + [self terminateApp:error]; + } + + self.view.window.contentViewController = glViewController; + + NSString* name = [glViewController getAppName]; + [self setWindowTitle:name]; +} + +- (IBAction)goVulkan:(id)sender +{ + MetalViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MetalViewControllerID"]; + NSString* error = [metalViewController getError]; + if(error != nil) + { + [self terminateApp:error]; + } + + self.view.window.contentViewController = metalViewController; + NSString* name = [metalViewController getAppName]; + [self setWindowTitle:name]; +} + +@end diff --git a/Common/NativeApp/CMakeLists.txt b/Common/NativeApp/CMakeLists.txt index d475f2e..a1101ed 100644 --- a/Common/NativeApp/CMakeLists.txt +++ b/Common/NativeApp/CMakeLists.txt @@ -121,7 +121,7 @@ elseif(PLATFORM_LINUX) add_linux_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}") endfunction() - + elseif(PLATFORM_MACOS) set(SOURCE @@ -145,6 +145,7 @@ elseif(PLATFORM_MACOS) ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/GLViewController.mm ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MTKRenderer.mm ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ViewControllerBase.mm + ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ModeSelectionViewController.mm ) set_source_files_properties(${APPLE_SOURCE} PROPERTIES COMPILE_FLAGS "-x objective-c++" @@ -160,6 +161,7 @@ elseif(PLATFORM_MACOS) ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/GLViewController.h ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MTKRenderer.h ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ViewControllerBase.h + ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ModeSelectionViewController.h ) set(APPLE_RESOURCES -- cgit v1.2.3