Add example app runner for iOS
This commit is contained in:
19
examples/Host/iOS/ExampleViewController.h
Normal file
19
examples/Host/iOS/ExampleViewController.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "Host/iOS/OpenVulkanoViewController.h"
|
||||
|
||||
@interface MainMenuViewController : UIViewController
|
||||
@end
|
||||
|
||||
@interface ExampleViewController : OpenVulkanoViewController
|
||||
@property(nonatomic, strong)OpenVulkanoView* renderView;
|
||||
@property size_t exampleId;
|
||||
@end
|
||||
75
examples/Host/iOS/ExampleViewController.mm
Normal file
75
examples/Host/iOS/ExampleViewController.mm
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#import "ExampleViewController.h"
|
||||
|
||||
#include "../../ExampleAppList.hpp"
|
||||
|
||||
@implementation MainMenuViewController
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
CGFloat buttonHeight = 50;
|
||||
CGFloat buttonSpacing = 10;
|
||||
CGFloat topMargin = 50;
|
||||
|
||||
int i = 0;
|
||||
for (const auto& app : OpenVulkano::EXAMPLE_APPS)
|
||||
{
|
||||
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
button.frame = CGRectMake(20,
|
||||
topMargin + i * (buttonHeight + buttonSpacing),
|
||||
self.view.bounds.size.width - 40,
|
||||
buttonHeight);
|
||||
[button setTitle:[NSString stringWithUTF8String:app.first] forState:UIControlStateNormal];
|
||||
button.tag = i;
|
||||
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:button];
|
||||
i++;
|
||||
}
|
||||
|
||||
self.view.frame = [UIScreen mainScreen].bounds;
|
||||
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
}
|
||||
|
||||
- (void)buttonPressed:(UIButton *)sender {
|
||||
ExampleViewController* example = [[ExampleViewController alloc] init];
|
||||
example.exampleId = sender.tag;
|
||||
example.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||
[self presentViewController:example animated:true completion:nil];
|
||||
}
|
||||
|
||||
- (void)viewDidLayoutSubviews {
|
||||
[super viewDidLayoutSubviews];
|
||||
self.view.frame = self.view.superview.bounds;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation ExampleViewController
|
||||
- (void)viewDidLoad {
|
||||
self.renderView = [[OpenVulkanoView alloc] initWithFrame:self.view.frame];
|
||||
self.openVulkanoView = self.renderView;
|
||||
[self.view addSubview:self.renderView];
|
||||
[super viewDidLoad];
|
||||
|
||||
self.view.frame = [UIScreen mainScreen].bounds;
|
||||
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
}
|
||||
|
||||
- (void)viewDidLayoutSubviews {
|
||||
[super viewDidLayoutSubviews];
|
||||
self.view.frame = self.view.superview.bounds;
|
||||
self.renderView.frame = self.view.frame;
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden { return true; }
|
||||
|
||||
- (void *)makeGraphicsApp {
|
||||
return OpenVulkano::EXAMPLE_APPS[self.exampleId].second();
|
||||
}
|
||||
@end
|
||||
57
examples/Host/iOS/main.mm
Normal file
57
examples/Host/iOS/main.mm
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "ExampleViewController.h"
|
||||
#import "Host/iOS/OpenVulkanoAppDelegate.h"
|
||||
|
||||
#include "Base/Logger.hpp"
|
||||
|
||||
@interface SceneDelegate : UIResponder<UIWindowSceneDelegate>
|
||||
@end
|
||||
|
||||
@implementation SceneDelegate
|
||||
@synthesize window = _window;
|
||||
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
|
||||
if ([scene isKindOfClass:[UIWindowScene class]]) {
|
||||
UIWindowScene* wScene = (UIWindowScene*)scene;
|
||||
self.window = [[UIWindow alloc] initWithWindowScene:wScene];
|
||||
|
||||
MainMenuViewController* rootViewController = [[MainMenuViewController alloc] init];
|
||||
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
|
||||
|
||||
self.window.rootViewController = navigationController;
|
||||
[self.window makeKeyAndVisible];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface AppDelegate : OpenVulkanoAppDelegate
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
// Override point for customization after application launch.
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
|
||||
UISceneConfiguration *configuration = [[UISceneConfiguration alloc] initWithName:nil sessionRole:UIWindowSceneSessionRoleApplication];
|
||||
configuration.delegateClass = SceneDelegate.class;
|
||||
return configuration;
|
||||
}
|
||||
@end
|
||||
|
||||
int main(int argCount, char** args)
|
||||
{
|
||||
using namespace OpenVulkano;
|
||||
Logger::SetupLogger();
|
||||
@autoreleasepool
|
||||
{
|
||||
return UIApplicationMain(argCount, args, nil, NSStringFromClass([AppDelegate class]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user