-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathModeSelectionViewController.mm
More file actions
179 lines (152 loc) · 5.46 KB
/
ModeSelectionViewController.mm
File metadata and controls
179 lines (152 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* Copyright 2026 Diligent Graphics LLC
* Copyright 2015-2019 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 "GLView.h"
#import "MetalView.h"
#import "WebGPUView.h"
#import "ViewController.h"
@implementation ModeSelectionViewController
{
}
- (void) setWindowTitle:(NSString*) title forWindow:(NSWindow*) window
{
[window setTitle:title];
}
- (void) maximizeWindow:(NSWindow*)window
{
if (window)
{
// Fill the entire visible screen area (excluding Dock and menu bar)
NSRect screenFrame = window.screen.visibleFrame;
[window setFrame:screenFrame display:YES animate:YES];
}
}
- (void)viewDidLoad
{
#if !GL_SUPPORTED && !GLES_SUPPORTED
((NSButton*)self.view.subviews[0]).enabled = false;
#endif
#if !VULKAN_SUPPORTED
((NSButton*)self.view.subviews[1]).enabled = false;
#endif
#if !METAL_SUPPORTED
((NSButton*)self.view.subviews[2]).enabled = false;
#endif
#if !WEBGPU_SUPPORTED
((NSButton*)self.view.subviews[3]).hidden = true;
#endif
}
- (void)viewDidAppear
{
[super viewDidAppear];
#if !WEBGPU_SUPPORTED
NSWindow* window = self.view.window;
if (window)
{
CGFloat reduction = self.view.subviews[1].frame.origin.y -
self.view.subviews[3].frame.origin.y;
// Switch buttons from Auto Layout to autoresizing masks
// so flexibleMinY keeps them pinned to the top edge
for (NSView* subview in self.view.subviews)
subview.translatesAutoresizingMaskIntoConstraints = YES;
self.view.autoresizesSubviews = YES;
// Shrink window from the bottom (keep top edge fixed)
NSRect frame = window.frame;
frame.origin.y += reduction;
frame.size.height -= reduction;
[window setFrame:frame display:YES];
}
#endif
}
- (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
{
NSWindow* window = self.view.window;
ViewController* glViewController = [self.storyboard instantiateControllerWithIdentifier:@"GLViewControllerID"];
window.contentViewController = glViewController;
GLView* glView = (GLView*)[glViewController view];
NSString* error = [glView getError];
if(error != nil)
{
[self terminateApp:error];
}
NSString* name = [glView getAppName];
[self setWindowTitle:name forWindow:window];
[self maximizeWindow:window];
}
- (IBAction)goVulkan:(id)sender
{
NSWindow* window = self.view.window;
ViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MoltenVKViewControllerID"];
window.contentViewController = metalViewController;
MetalView* mtlView = (MetalView*)[metalViewController view];
NSString* error = [mtlView getError];
if(error != nil)
{
[self terminateApp:error];
}
NSString* name = [mtlView getAppName];
[self setWindowTitle:name forWindow:window];
[self maximizeWindow:window];
}
- (IBAction)goMetal:(id)sender
{
NSWindow* window = self.view.window;
ViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MetalViewControllerID"];
MetalView* mtlView = (MetalView*)[metalViewController view];
window.contentViewController = metalViewController;
NSString* error = [mtlView getError];
if(error != nil)
{
[self terminateApp:error];
}
NSString* name = [mtlView getAppName];
[self setWindowTitle:name forWindow:window];
[self maximizeWindow:window];
}
- (IBAction)goWebGPU:(id)sender
{
NSWindow* window = self.view.window;
ViewController* webgpuViewController = [self.storyboard instantiateControllerWithIdentifier:@"WebGPUViewControllerID"];
WebGPUView* webgpuView = (WebGPUView*)[webgpuViewController view];
window.contentViewController = webgpuViewController;
NSString* error = [webgpuView getError];
if(error != nil)
{
[self terminateApp:error];
}
NSString* name = [webgpuView getAppName];
[self setWindowTitle:name forWindow:window];
[self maximizeWindow:window];
}
@end