comparison src/video/uikit/SDL_uikitappdelegate.m @ 2401:32602672020e gsoc2008_iphone

turned singleton window instance into member variable instead. Added convenience method for getting singleton app delegate.
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Tue, 22 Jul 2008 23:02:53 +0000
parents 0381047f2210
children 3fc556a036d8
comparison
equal deleted inserted replaced
2400:e103b316a4ef 2401:32602672020e
1 // 1 /*
2 // SDLUIKitDelegate.m 2 SDL - Simple DirectMedia Layer
3 // iPodSDL 3 Copyright (C) 1997-2006 Sam Lantinga
4 // 4
5 // Created by Holmes Futrell on 5/29/08. 5 This library is free software; you can redistribute it and/or
6 // Copyright 2008 __MyCompanyName__. All rights reserved. 6 modify it under the terms of the GNU Lesser General Public
7 // 7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
8 22
9 #import "SDL_uikitappdelegate.h" 23 #import "SDL_uikitappdelegate.h"
10 #import "SDL_uikitopenglview.h" 24 #import "SDL_uikitopenglview.h"
11 #import <pthread.h> 25 #import <pthread.h>
12 #import "SDL_events_c.h" 26 #import "SDL_events_c.h"
14 28
15 #ifdef main 29 #ifdef main
16 #undef main 30 #undef main
17 #endif 31 #endif
18 32
19 UIWindow *uikitWindow=nil;
20 SDL_uikitopenglview *uikitEAGLView=nil;
21
22 extern int SDL_main(int argc, char *argv[]); 33 extern int SDL_main(int argc, char *argv[]);
23 static int forward_argc; 34 static int forward_argc;
24 static char **forward_argv; 35 static char **forward_argv;
25 36
26 int main(int argc, char **argv) { 37 int main(int argc, char **argv) {
27 38
39 int i;
28 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 40 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
29 41
30 /* store arguments */ 42 /* store arguments */
31 forward_argc = argc; 43 forward_argc = argc;
32 forward_argv = (char **)malloc(argc * sizeof(char *)); 44 forward_argv = (char **)malloc(argc * sizeof(char *));
33 int i;
34 for (i=0; i<argc; i++) { 45 for (i=0; i<argc; i++) {
35 forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char)); 46 forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
36 strcpy(forward_argv[i], argv[i]); 47 strcpy(forward_argv[i], argv[i]);
37 } 48 }
38 49
50 /* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
39 UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate"); 51 UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate");
40 52
41 [pool release]; 53 [pool release];
42 54
43 } 55 }
44 56
45 @implementation SDLUIKitDelegate 57 @implementation SDLUIKitDelegate
58
59 @synthesize window;
60
61 /* convenience method */
62 +(SDLUIKitDelegate *)sharedAppDelegate {
63 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
64 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
65 }
66
67 - (id)init {
68 self = [super init];
69 window = nil;
70 return self;
71 }
46 72
47 - (void)applicationDidFinishLaunching:(UIApplication *)application { 73 - (void)applicationDidFinishLaunching:(UIApplication *)application {
48 74
49 /* Set working directory to resource path */ 75 /* Set working directory to resource path */
50 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; 76 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
65 } 91 }
66 92
67 - (void)applicationWillTerminate:(UIApplication *)application { 93 - (void)applicationWillTerminate:(UIApplication *)application {
68 94
69 SDL_SendQuit(); 95 SDL_SendQuit();
70 longjmp(*(jump_env()), 1); // hack to prevent automatic termination 96 /* hack to prevent automatic termination. See SDL_uikitevents.m for details */
97 longjmp(*(jump_env()), 1);
71 98
72 } 99 }
73 100
74 -(void)dealloc { 101 -(void)dealloc {
75 [uikitWindow release]; 102 [window release];
76 [uikitEAGLView release];
77 [super dealloc]; 103 [super dealloc];
78 } 104 }
79 105
80 @end 106 @end