comparison 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
comparison
equal deleted inserted replaced
46:3dcf26fa9d15 47:45b1c4303f87
1 /* SDLMain.m - main entry point for our Cocoa-ized SDL app
2 Darrell Walisser - dwaliss1@purdue.edu
3
4 Feel free to customize this file to suit your needs
5 */
6
7 #import "SDL.h"
8 #import "SDLMain.h"
9 #import <sys/param.h> /* for MAXPATHLEN */
10 #import <unistd.h>
11
12 static int gArgc;
13 static char **gArgv;
14
15 /* The main class of the application, the application's delegate */
16 @implementation SDLMain
17
18 /* Invoked from the Quit menu item */
19 - (void) quit:(id)sender
20 {
21 SDL_Event event;
22 event.type = SDL_QUIT;
23 SDL_PushEvent(&event);
24 }
25
26 /* Invoked from the "Make fulllscreen" menu item */
27 - (void) makeFullscreen:(id)sender
28 {
29
30 }
31
32 /* Set the working directory to the .app's parent directory */
33 - (void) setupWorkingDirectory
34 {
35 char parentdir[MAXPATHLEN];
36 char *c;
37
38 strncpy ( parentdir, gArgv[0], MAXPATHLEN );
39 c = (char*) parentdir;
40
41 while (*c != '\0') /* go to end */
42 c++;
43
44 while (*c != '/') /* back up to parent */
45 c--;
46
47 *c = '\0'; /* cut off last part (binary name) */
48
49 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
50 assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
51 }
52
53 /* Called when the internal event loop has just started running */
54 - (void) applicationDidFinishLaunching: (NSNotification *) note
55 {
56 /* Set the working directory to the .app's parent directory */
57 [ self setupWorkingDirectory ];
58
59 /* This is passed if we are launched by double-clicking */
60 if ( gArgc >= 2 && strncmp (gArgv[1], "-psn", 4) == 0 )
61 gArgc = 1;
62
63 /* Hand off to main application code */
64 SDL_main (gArgc, gArgv);
65 exit(0);
66 }
67 @end
68
69 #ifdef main
70 # undef main
71 #endif
72
73 /* Main entry point to executible - should *not* be SDL_main! */
74 int main (int argc, char **argv) {
75
76 /* Copy the arguments into a global variable */
77 int i;
78
79 gArgc = argc;
80 gArgv = (char**) malloc (sizeof(*gArgv) * gArgc);
81 assert (gArgv != NULL);
82 for (i = 0; i < gArgc; i++) {
83 gArgv[i] = strdup (argv[i]);
84 }
85
86 NSApplicationMain (argc, argv);
87 return 0;
88 }