From a867e5a301a9232c449c9897a9b31ba80be8a01e Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 30 Oct 2005 07:09:56 +0000 Subject: [PATCH] Replace SDLMain.* This still class SDL_main(), for now. --- stepmania/PBProject/SDLMain.h | 12 ---- stepmania/PBProject/SMMain.mm | 126 ++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 12 deletions(-) delete mode 100755 stepmania/PBProject/SDLMain.h create mode 100755 stepmania/PBProject/SMMain.mm diff --git a/stepmania/PBProject/SDLMain.h b/stepmania/PBProject/SDLMain.h deleted file mode 100755 index 4f54d7c6ae..0000000000 --- a/stepmania/PBProject/SDLMain.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SDLMain.m - main entry point for our Cocoa-ized SDL app - Initial Version: Darrell Walisser - Non-NIB-Code & other changes: Max Horn - - Feel free to customize this file to suit your needs -*/ - -#import - -@interface SDLMain : NSObject {} -- (void) startGame:(id)obj; -@end diff --git a/stepmania/PBProject/SMMain.mm b/stepmania/PBProject/SMMain.mm new file mode 100755 index 0000000000..6e57c44a35 --- /dev/null +++ b/stepmania/PBProject/SMMain.mm @@ -0,0 +1,126 @@ +#import +#include "ProductInfo.h" + +// XXX remove these +extern void ExitGame(); +extern "C" +{ + extern int SDL_main(int, char **); +} + +@interface SMApplication : NSApplication +@end + +@interface SMMain : NSObject +{ + int mArgc; + char **mArgv; +} +- (id) initWithArgc:(int)argc argv:(char **)argv; +- (void) startGame:(id)sender; +@end + + +@implementation SMApplication +/* Invoked from the Quit menu item */ +- (void)terminate:(id)sender +{ + ExitGame(); +} + +- (void)sendEvent:(NSEvent *)event +{ + if( [event type] != NSKeyDown ) + [super sendEvent:event]; +} + +@end + +/* The main class of the application, the application's delegate */ +@implementation SMMain + +- (id) initWithArgc:(int)argc argv:(char **)argv +{ + [super init]; + mArgc = argc; + mArgv = argv; + return self; +} + +- (void) startGame:(id)sender +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + /* Hand off to main application code */ + exit( SDL_main(mArgc, mArgv) ); + [pool release]; // not really needed, but shuts gcc up. +} + +/* Called when the internal event loop has just started running */ +- (void) applicationDidFinishLaunching: (NSNotification *) note +{ +#if 1 + [NSThread detachNewThreadSelector:@selector(startGame:) toTarget:self withObject:nil]; +#else + [self startGame:nil]; +#endif +} +@end + +static NSMenuItem *MenuItem( const char *title, SEL action, NSString *code ) +{ + // autorelease these because they'll be retained by the NSMenu + return [[[NSMenuItem alloc] initWithTitle:[NSString stringWithUTF8String:title] + action:action keyEquivalent:code] autorelease]; +} + +static void setupMenus( void ) +{ + NSMenu *mainMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease]; + NSMenu *appMenu = [[[NSMenu alloc] initWithTitle:@PRODUCT_NAME] autorelease]; + NSMenu *windowMenu = [[[NSMenu alloc] initWithTitle:@"Window"] autorelease]; + NSMenuItem *hideOthers = MenuItem( "Hide Others", @selector(hideOtherApplications:), @"h" ); + + [hideOthers setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask ]; + + [appMenu addItem:MenuItem( "About " PRODUCT_NAME, @selector(orderFrontStandardAboutPanel:), @"" )]; + [appMenu addItem:[NSMenuItem separatorItem]]; + [appMenu addItem:MenuItem( "Hide " PRODUCT_NAME, @selector(hide:), @"h" )]; + [appMenu addItem:hideOthers]; + [appMenu addItem:MenuItem( "Show All", @selector(unhideAllApplications:), @"" )]; + [appMenu addItem:MenuItem( "Quit " PRODUCT_NAME, @selector(terminate:), @"q" )]; + + [windowMenu addItem:MenuItem( "Minimize", @selector(performMiniturize:), @"m" )]; + [windowMenu addItem:[NSMenuItem separatorItem]]; + [windowMenu addItem:MenuItem( "Full Screen", @selector(fullscreen:), @"" )]; + + [[mainMenu addItemWithTitle:[appMenu title] action:NULL keyEquivalent:@""] setSubmenu:appMenu]; + [[mainMenu addItemWithTitle:[windowMenu title] action:NULL keyEquivalent:@""] setSubmenu:windowMenu]; + + [NSApp setMainMenu:mainMenu]; + [NSApp setAppleMenu:appMenu]; // this isn't the apple menu, but it doesn't work without this + [NSApp setWindowsMenu:windowMenu]; +} + +int main( int argc, char **argv ) +{ + [SMApplication poseAsClass:[NSApplication class]]; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + SMMain *sm; + + /* Ensure the application object is initialised, this sets NSApp */ + [SMApplication sharedApplication]; + + /* Set up the menubar */ + setupMenus(); + + /* Create SDLMain and make it the app delegate */ + sm = [[SMMain alloc] initWithArgc:argc argv:argv]; + [NSApp setDelegate:sm]; + + [pool release]; + /* Start the main event loop */ + [NSApp run]; + [sm release]; + return 0; +}