diff src/main/macosx/SDLMain.m @ 47:45b1c4303f87

Added initial support for Quartz video (thanks Darrell!)
author Sam Lantinga <slouken@lokigames.com>
date Thu, 07 Jun 2001 14:28:11 +0000
parents
children bd6b0a910a65
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/macosx/SDLMain.m	Thu Jun 07 14:28:11 2001 +0000
@@ -0,0 +1,88 @@
+/*   SDLMain.m - main entry point for our Cocoa-ized SDL app
+       Darrell Walisser - dwaliss1@purdue.edu
+
+    Feel free to customize this file to suit your needs
+*/
+
+#import "SDL.h"
+#import "SDLMain.h"
+#import <sys/param.h> /* for MAXPATHLEN */
+#import <unistd.h>
+
+static int    gArgc;
+static char  **gArgv;
+
+/* The main class of the application, the application's delegate */
+@implementation SDLMain
+
+/* Invoked from the Quit menu item */
+- (void) quit:(id)sender
+{
+    	SDL_Event event;
+	event.type = SDL_QUIT;
+	SDL_PushEvent(&event);
+}
+
+/* Invoked from the "Make fulllscreen" menu item */
+- (void) makeFullscreen:(id)sender
+{
+    
+}
+
+/* Set the working directory to the .app's parent directory */
+- (void) setupWorkingDirectory
+{
+    char parentdir[MAXPATHLEN];
+    char *c;
+    
+    strncpy ( parentdir, gArgv[0], MAXPATHLEN );
+    c = (char*) parentdir;
+    
+    while (*c != '\0')     /* go to end */
+        c++;
+    
+    while (*c != '/')      /* back up to parent */
+        c--;
+    
+    *c = '\0';             /* cut off last part (binary name) */
+    
+    assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
+    assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
+}
+
+/* Called when the internal event loop has just started running */
+- (void) applicationDidFinishLaunching: (NSNotification *) note
+{
+    /* Set the working directory to the .app's parent directory */
+    [ self setupWorkingDirectory ];
+    
+    /* This is passed if we are launched by double-clicking */
+    if ( gArgc >= 2 && strncmp (gArgv[1], "-psn", 4) == 0 )
+        gArgc = 1;
+    
+    /* Hand off to main application code */
+    SDL_main (gArgc, gArgv);
+    exit(0);
+}
+@end
+
+#ifdef main
+#  undef main
+#endif
+
+/* Main entry point to executible - should *not* be SDL_main! */
+int main (int argc, char **argv) {
+
+    /* Copy the arguments into a global variable */
+    int i;
+    
+    gArgc = argc;
+    gArgv = (char**) malloc (sizeof(*gArgv) * gArgc);
+    assert (gArgv != NULL);
+    for (i = 0; i < gArgc; i++) {
+        gArgv[i] = strdup (argv[i]);
+    }
+    
+    NSApplicationMain (argc, argv);
+    return 0;
+}
\ No newline at end of file