mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-16 04:50:32 +00:00
Override Cocoa app lifecycle defined by SDL
This commit is contained in:
9
AerofoilMac/AerofoilMac/AerofoilAppDelegate.h
Normal file
9
AerofoilMac/AerofoilMac/AerofoilAppDelegate.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface AerofoilAppDelegate : NSObject <NSApplicationDelegate>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
44
AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm
Normal file
44
AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm
Normal file
@@ -0,0 +1,44 @@
|
||||
#import "AerofoilAppDelegate.h"
|
||||
#import "About.h"
|
||||
#include "WindowManager.h"
|
||||
#include "GliderDefines.h" // kPlayMode
|
||||
|
||||
extern short theMode;
|
||||
void DoSettingsMain(void);
|
||||
|
||||
@interface AerofoilAppDelegate ()
|
||||
|
||||
@property (weak) IBOutlet NSMenuItem *aboutAerofoilMenuItem;
|
||||
@property (weak) IBOutlet NSMenuItem *aboutGliderPROMenuItem;
|
||||
@property (weak) IBOutlet NSMenuItem *preferencesMenuItem;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AerofoilAppDelegate
|
||||
|
||||
- (IBAction)showAboutAerofoil:(id)sender {
|
||||
DoAboutFramework();
|
||||
}
|
||||
- (IBAction)showAboutGliderPRO:(id)sender {
|
||||
DoAbout();
|
||||
}
|
||||
- (IBAction)showPreferences:(id)sender {
|
||||
DoSettingsMain();
|
||||
}
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
||||
if (menuItem == _aboutAerofoilMenuItem || menuItem == _aboutGliderPROMenuItem) {
|
||||
return ![self menuItemsDisabled];
|
||||
} else if (menuItem == _preferencesMenuItem) {
|
||||
return ![self menuItemsDisabled];
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)menuItemsDisabled {
|
||||
PortabilityLayer::WindowManager* wm = PortabilityLayer::WindowManager::GetInstance();
|
||||
return theMode == kPlayMode || wm->IsExclusiveWindowVisible();
|
||||
}
|
||||
|
||||
@end
|
||||
9
AerofoilMac/AerofoilMac/AerofoilApplication.h
Normal file
9
AerofoilMac/AerofoilMac/AerofoilApplication.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface AerofoilApplication : NSApplication
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
13
AerofoilMac/AerofoilMac/AerofoilApplication.m
Normal file
13
AerofoilMac/AerofoilMac/AerofoilApplication.m
Normal file
@@ -0,0 +1,13 @@
|
||||
#import "AerofoilApplication.h"
|
||||
#include "SDL.h"
|
||||
|
||||
extern int SDL_SendQuit(void);
|
||||
|
||||
@implementation AerofoilApplication
|
||||
|
||||
- (void)terminate:(id)sender {
|
||||
// TODO: Use Aerofoil method instead of private SDL method
|
||||
SDL_SendQuit();
|
||||
}
|
||||
|
||||
@end
|
||||
6
AerofoilMac/AerofoilMac/MacInit.h
Normal file
6
AerofoilMac/AerofoilMac/MacInit.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef MacInit_h
|
||||
#define MacInit_h
|
||||
|
||||
int MacInit(void);
|
||||
|
||||
#endif /* MacInit_h */
|
||||
22
AerofoilMac/AerofoilMac/MacInit.mm
Normal file
22
AerofoilMac/AerofoilMac/MacInit.mm
Normal file
@@ -0,0 +1,22 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "AerofoilApplication.h"
|
||||
#import "AerofoilAppDelegate.h"
|
||||
#import "MacInit.h"
|
||||
#include "SDL.h"
|
||||
|
||||
int MacInit(void) {
|
||||
// Instantiate NSApp and its delegate first, so SDL chooses those over its own implementation.
|
||||
[AerofoilApplication sharedApplication];
|
||||
[[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp topLevelObjects:nil];
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
|
||||
return -1;
|
||||
|
||||
// Gracefully activate app.
|
||||
//
|
||||
// (SDL forcefully does this via [NSApp activateIgnoringOtherApps:YES],
|
||||
// which isn't consistent with normal Mac apps).
|
||||
[NSApp finishLaunching];
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user