2008-10-04 06:46:59 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2011-12-31 09:28:07 -05:00
|
|
|
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
2011-04-08 13:03:26 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2008-10-04 06:46:59 +00:00
|
|
|
*/
|
2011-10-31 05:56:58 -04:00
|
|
|
#include "SDL_config.h"
|
|
|
|
|
|
|
|
#if SDL_VIDEO_DRIVER_UIKIT
|
2008-10-04 06:46:59 +00:00
|
|
|
|
2010-05-02 05:08:12 -04:00
|
|
|
#import "../SDL_sysvideo.h"
|
2011-06-10 14:23:36 +01:00
|
|
|
#import "SDL_assert.h"
|
|
|
|
#import "SDL_hints.h"
|
|
|
|
#import "../../SDL_hints_c.h"
|
2010-05-02 05:08:12 -04:00
|
|
|
|
2008-10-04 06:46:59 +00:00
|
|
|
#import "SDL_uikitappdelegate.h"
|
|
|
|
#import "SDL_uikitopenglview.h"
|
|
|
|
#import "SDL_events_c.h"
|
|
|
|
#import "jumphack.h"
|
|
|
|
|
|
|
|
#ifdef main
|
|
|
|
#undef main
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int SDL_main(int argc, char *argv[]);
|
|
|
|
static int forward_argc;
|
|
|
|
static char **forward_argv;
|
2011-09-27 23:49:24 +02:00
|
|
|
static int exit_status;
|
2008-10-04 06:46:59 +00:00
|
|
|
|
2011-09-27 22:51:26 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2011-02-01 08:59:22 -08:00
|
|
|
int i;
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2011-09-27 21:02:26 +02:00
|
|
|
|
2011-02-01 08:59:22 -08:00
|
|
|
/* store arguments */
|
|
|
|
forward_argc = argc;
|
|
|
|
forward_argv = (char **)malloc((argc+1) * sizeof(char *));
|
2011-09-27 22:51:26 +02:00
|
|
|
for (i = 0; i < argc; i++) {
|
2011-02-01 08:59:22 -08:00
|
|
|
forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
|
|
|
|
strcpy(forward_argv[i], argv[i]);
|
|
|
|
}
|
|
|
|
forward_argv[i] = NULL;
|
|
|
|
|
|
|
|
/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
|
2011-04-05 09:50:25 -07:00
|
|
|
UIApplicationMain(argc, argv, NULL, [SDLUIKitDelegate getAppDelegateClassName]);
|
2011-09-27 21:02:26 +02:00
|
|
|
|
2011-09-27 23:49:24 +02:00
|
|
|
/* free the memory we used to hold copies of argc and argv */
|
|
|
|
for (i = 0; i < forward_argc; i++) {
|
|
|
|
free(forward_argv[i]);
|
|
|
|
}
|
|
|
|
free(forward_argv);
|
|
|
|
|
2011-02-01 08:59:22 -08:00
|
|
|
[pool release];
|
2011-09-27 23:49:24 +02:00
|
|
|
return exit_status;
|
2008-10-04 06:46:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 22:51:26 +02:00
|
|
|
static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue, const char *newValue)
|
|
|
|
{
|
2011-06-10 14:23:36 +01:00
|
|
|
SDL_assert(SDL_strcmp(name, SDL_HINT_IDLE_TIMER_DISABLED) == 0);
|
2011-09-27 21:02:26 +02:00
|
|
|
|
2011-06-10 14:23:36 +01:00
|
|
|
BOOL disable = (*newValue != '0');
|
|
|
|
[UIApplication sharedApplication].idleTimerDisabled = disable;
|
|
|
|
}
|
|
|
|
|
2008-10-04 06:46:59 +00:00
|
|
|
@implementation SDLUIKitDelegate
|
|
|
|
|
|
|
|
/* convenience method */
|
2011-11-19 19:23:33 -05:00
|
|
|
+ (id) sharedAppDelegate
|
2011-09-27 22:51:26 +02:00
|
|
|
{
|
2011-02-01 08:59:22 -08:00
|
|
|
/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
|
2011-11-19 19:23:33 -05:00
|
|
|
return [[UIApplication sharedApplication] delegate];
|
2008-10-04 06:46:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 22:51:26 +02:00
|
|
|
+ (NSString *)getAppDelegateClassName
|
|
|
|
{
|
2011-04-05 09:50:25 -07:00
|
|
|
/* subclassing notice: when you subclass this appdelegate, make sure to add a category to override
|
|
|
|
this method and return the actual name of the delegate */
|
|
|
|
return @"SDLUIKitDelegate";
|
|
|
|
}
|
|
|
|
|
2011-09-27 22:51:26 +02:00
|
|
|
- (id)init
|
|
|
|
{
|
2011-02-01 08:59:22 -08:00
|
|
|
self = [super init];
|
|
|
|
return self;
|
2008-10-04 06:46:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 22:51:26 +02:00
|
|
|
- (void)postFinishLaunch
|
|
|
|
{
|
2011-06-10 14:23:36 +01:00
|
|
|
/* register a callback for the idletimer hint */
|
|
|
|
SDL_SetHint(SDL_HINT_IDLE_TIMER_DISABLED, "0");
|
|
|
|
SDL_RegisterHintChangedCb(SDL_HINT_IDLE_TIMER_DISABLED, &SDL_IdleTimerDisabledChanged);
|
2009-11-02 07:55:42 +00:00
|
|
|
|
2011-02-01 08:59:22 -08:00
|
|
|
/* run the user's application, passing argc and argv */
|
2011-09-27 23:49:24 +02:00
|
|
|
exit_status = SDL_main(forward_argc, forward_argv);
|
2011-09-27 21:02:26 +02:00
|
|
|
|
2011-02-01 08:59:22 -08:00
|
|
|
/* exit, passing the return status from the user's application */
|
2011-09-27 23:49:24 +02:00
|
|
|
// exit(exit_status);
|
2009-11-02 07:55:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 22:51:26 +02:00
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
|
|
{
|
2011-02-01 08:59:22 -08:00
|
|
|
/* Set working directory to resource path */
|
|
|
|
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
|
2011-09-27 21:02:26 +02:00
|
|
|
|
2011-04-05 09:50:25 -07:00
|
|
|
[self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
|
2011-03-14 23:04:52 -07:00
|
|
|
|
|
|
|
return YES;
|
2008-10-04 06:46:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 22:51:26 +02:00
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application
|
|
|
|
{
|
2011-02-01 08:59:22 -08:00
|
|
|
SDL_SendQuit();
|
|
|
|
/* hack to prevent automatic termination. See SDL_uikitevents.m for details */
|
|
|
|
longjmp(*(jump_env()), 1);
|
2008-10-04 06:46:59 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 07:36:45 +00:00
|
|
|
- (void) applicationWillResignActive:(UIApplication*)application
|
|
|
|
{
|
2010-05-02 05:08:12 -04:00
|
|
|
//NSLog(@"%@", NSStringFromSelector(_cmd));
|
|
|
|
|
|
|
|
// Send every window on every screen a MINIMIZED event.
|
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-27 21:02:26 +02:00
|
|
|
|
2011-04-05 09:50:25 -07:00
|
|
|
SDL_Window *window;
|
2011-02-11 10:18:34 -08:00
|
|
|
for (window = _this->windows; window != nil; window = window->next) {
|
2012-01-08 13:42:03 -05:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
|
2011-02-11 10:18:34 -08:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
2010-05-02 05:08:12 -04:00
|
|
|
}
|
2009-10-17 07:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationDidBecomeActive:(UIApplication*)application
|
|
|
|
{
|
2010-05-02 05:08:12 -04:00
|
|
|
//NSLog(@"%@", NSStringFromSelector(_cmd));
|
|
|
|
|
|
|
|
// Send every window on every screen a RESTORED event.
|
|
|
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-27 21:02:26 +02:00
|
|
|
|
2011-08-18 22:43:37 +02:00
|
|
|
SDL_Window *window;
|
2011-02-11 10:18:34 -08:00
|
|
|
for (window = _this->windows; window != nil; window = window->next) {
|
2012-01-08 13:42:03 -05:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
|
2011-08-18 22:43:37 +02:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
2010-05-02 05:08:12 -04:00
|
|
|
}
|
2008-10-04 06:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2011-02-01 09:00:47 -08:00
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
|
|
|
|
2011-02-01 09:00:47 -08:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|