equal
deleted
inserted
replaced
53 [pool release]; |
53 [pool release]; |
54 return retVal; |
54 return retVal; |
55 } |
55 } |
56 |
56 |
57 @implementation SDLUIKitDelegate |
57 @implementation SDLUIKitDelegate |
|
58 @synthesize uiwindow, window; |
58 |
59 |
59 // convenience method |
60 // convenience method |
60 +(SDLUIKitDelegate *)sharedAppDelegate { |
61 +(SDLUIKitDelegate *)sharedAppDelegate { |
61 // the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method |
62 // the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method |
62 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
63 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
64 |
65 |
65 -(id) init { |
66 -(id) init { |
66 if (self = [super init]){ |
67 if (self = [super init]){ |
67 mainViewController = nil; |
68 mainViewController = nil; |
68 isInGame = NO; |
69 isInGame = NO; |
|
70 self.uiwindow = nil; |
|
71 self.window = NULL; |
69 } |
72 } |
70 return self; |
73 return self; |
71 } |
74 } |
72 |
75 |
73 -(void) dealloc { |
76 -(void) dealloc { |
|
77 SDL_DestroyWindow(self.window); |
|
78 [uiwindow release]; |
74 [mainViewController release]; |
79 [mainViewController release]; |
75 [super dealloc]; |
80 [super dealloc]; |
76 } |
81 } |
77 |
82 |
78 // main routine for calling the actual game engine |
83 // main routine for calling the actual game engine |
87 [setup startThread:@"engineProtocol"]; |
92 [setup startThread:@"engineProtocol"]; |
88 const char **gameArgs = [setup getSettings]; |
93 const char **gameArgs = [setup getSettings]; |
89 [setup release]; |
94 [setup release]; |
90 |
95 |
91 // since the sdlwindow is not yet created, we add the overlayController with a delay |
96 // since the sdlwindow is not yet created, we add the overlayController with a delay |
92 [self performSelector:@selector(displayOverlayLater) withObject:nil afterDelay:4]; |
97 [self performSelector:@selector(displayOverlayLater) withObject:nil afterDelay:1]; |
93 |
98 |
94 // this is the pascal fuction that starts the game (wrapped around isInGame) |
99 // this is the pascal fuction that starts the game (wrapped around isInGame) |
95 isInGame = YES; |
100 isInGame = YES; |
96 Game(gameArgs); |
101 Game(gameArgs); |
97 isInGame = NO; |
102 isInGame = NO; |
115 // override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib) |
120 // override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib) |
116 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
121 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
117 [application setStatusBarHidden:YES]; |
122 [application setStatusBarHidden:YES]; |
118 [application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
123 [application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
119 |
124 |
120 UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
125 uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
121 uiwindow.backgroundColor = [UIColor blackColor]; |
126 uiwindow.backgroundColor = [UIColor blackColor]; |
122 |
127 // needed to keep the app running after a game (gets released in sdl_uikitwindow) |
|
128 [uiwindow retain]; |
|
129 |
123 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
130 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
124 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
131 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
125 else |
132 else |
126 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
133 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
127 |
134 |
144 -(void) applicationWillResignActive:(UIApplication *)application { |
151 -(void) applicationWillResignActive:(UIApplication *)application { |
145 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
152 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
146 if (isInGame) { |
153 if (isInGame) { |
147 HW_pause(); |
154 HW_pause(); |
148 |
155 |
|
156 /* |
149 // Send every window on every screen a MINIMIZED event. |
157 // Send every window on every screen a MINIMIZED event. |
150 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
158 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
151 if (!_this) |
159 if (!_this) |
152 return; |
160 return; |
153 |
161 |
156 const SDL_VideoDisplay *display = &_this->displays[i]; |
164 const SDL_VideoDisplay *display = &_this->displays[i]; |
157 SDL_Window *window; |
165 SDL_Window *window; |
158 for (window = display->windows; window != nil; window = window->next) |
166 for (window = display->windows; window != nil; window = window->next) |
159 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
167 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
160 } |
168 } |
|
169 */ |
161 } |
170 } |
162 } |
171 } |
163 |
172 |
164 -(void) applicationDidBecomeActive:(UIApplication *)application { |
173 -(void) applicationDidBecomeActive:(UIApplication *)application { |
165 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
174 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
166 if (isInGame) { |
175 if (isInGame) { |
167 HW_pause(); |
176 HW_pause(); |
168 |
177 |
|
178 /* |
169 // Send every window on every screen a RESTORED event. |
179 // Send every window on every screen a RESTORED event. |
170 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
180 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
171 if (!_this) |
181 if (!_this) |
172 return; |
182 return; |
173 |
183 |
176 const SDL_VideoDisplay *display = &_this->displays[i]; |
186 const SDL_VideoDisplay *display = &_this->displays[i]; |
177 SDL_Window *window; |
187 SDL_Window *window; |
178 for (window = display->windows; window != nil; window = window->next) |
188 for (window = display->windows; window != nil; window = window->next) |
179 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
189 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
180 } |
190 } |
|
191 */ |
181 } |
192 } |
182 } |
193 } |
183 |
194 |
184 @end |
195 @end |