[examples] Terminate app when closing window

This commit is contained in:
Ariel Abreu 2023-04-11 08:14:27 -04:00
parent ea1653793a
commit f61e92d1cc
No known key found for this signature in database
GPG Key ID: C06B805216EDEEED

View File

@ -8,11 +8,28 @@
#import "Renderer/AAPLRenderer.h"
@interface WindowDelegate : NSObject<NSWindowDelegate>
- (void)windowWillClose: (NSNotification*)note;
@end
@implementation WindowDelegate
- (void)windowWillClose: (NSNotification*)note
{
[[NSApplication sharedApplication] terminate: self];
}
@end
int main(int argc, char** argv) {
[NSAutoreleasePool new];
[NSApplication sharedApplication];
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
WindowDelegate* winDelegate = [WindowDelegate new];
NSMenu* menubar = [[NSMenu new] autorelease];
NSMenuItem* appMenuItem = [[NSMenuItem new] autorelease];
@ -52,6 +69,7 @@ int main(int argc, char** argv) {
view.delegate = renderer;
window.contentView = view;
window.delegate = winDelegate;
[NSApp run];