turned singleton window instance into member variable instead. Added convenience method for getting singleton app delegate. gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Tue, 22 Jul 2008 23:02:53 +0000
branchgsoc2008_iphone
changeset 240132602672020e
parent 2400 e103b316a4ef
child 2402 1fe89198aba5
turned singleton window instance into member variable instead. Added convenience method for getting singleton app delegate.
src/video/uikit/SDL_uikitappdelegate.h
src/video/uikit/SDL_uikitappdelegate.m
     1.1 --- a/src/video/uikit/SDL_uikitappdelegate.h	Tue Jul 22 23:01:01 2008 +0000
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.h	Tue Jul 22 23:02:53 2008 +0000
     1.3 @@ -1,17 +1,34 @@
     1.4 -//
     1.5 -//  SDLUIKitDelegate.h
     1.6 -//  iPodSDL
     1.7 -//
     1.8 -//  Created by Holmes Futrell on 5/29/08.
     1.9 -//  Copyright 2008 __MyCompanyName__. All rights reserved.
    1.10 -//
    1.11 +/*
    1.12 + SDL - Simple DirectMedia Layer
    1.13 + Copyright (C) 1997-2006 Sam Lantinga
    1.14 + 
    1.15 + This library is free software; you can redistribute it and/or
    1.16 + modify it under the terms of the GNU Lesser General Public
    1.17 + License as published by the Free Software Foundation; either
    1.18 + version 2.1 of the License, or (at your option) any later version.
    1.19 + 
    1.20 + This library is distributed in the hope that it will be useful,
    1.21 + but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.22 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.23 + Lesser General Public License for more details.
    1.24 + 
    1.25 + You should have received a copy of the GNU Lesser General Public
    1.26 + License along with this library; if not, write to the Free Software
    1.27 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.28 + 
    1.29 + Sam Lantinga
    1.30 + slouken@libsdl.org
    1.31 + */
    1.32  
    1.33  #import <UIKit/UIKit.h>
    1.34  #import "SDL_uikitopenglview.h"
    1.35  
    1.36 -@interface SDLUIKitDelegate : NSObject<UIApplicationDelegate> {
    1.37 -	UIWindow *window;
    1.38 -	SDL_uikitopenglview *view;
    1.39 +@interface SDLUIKitDelegate:NSObject < UIApplicationDelegate > {
    1.40 +	UIWindow       *window;
    1.41  }
    1.42  
    1.43 +@property (readwrite, retain) UIWindow *window;
    1.44 +
    1.45 ++(SDLUIKitDelegate *)sharedAppDelegate;
    1.46 +
    1.47  @end
     2.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Tue Jul 22 23:01:01 2008 +0000
     2.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Tue Jul 22 23:02:53 2008 +0000
     2.3 @@ -1,10 +1,24 @@
     2.4 -//
     2.5 -//  SDLUIKitDelegate.m
     2.6 -//  iPodSDL
     2.7 -//
     2.8 -//  Created by Holmes Futrell on 5/29/08.
     2.9 -//  Copyright 2008 __MyCompanyName__. All rights reserved.
    2.10 -//
    2.11 +/*
    2.12 + SDL - Simple DirectMedia Layer
    2.13 + Copyright (C) 1997-2006 Sam Lantinga
    2.14 + 
    2.15 + This library is free software; you can redistribute it and/or
    2.16 + modify it under the terms of the GNU Lesser General Public
    2.17 + License as published by the Free Software Foundation; either
    2.18 + version 2.1 of the License, or (at your option) any later version.
    2.19 + 
    2.20 + This library is distributed in the hope that it will be useful,
    2.21 + but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.22 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.23 + Lesser General Public License for more details.
    2.24 + 
    2.25 + You should have received a copy of the GNU Lesser General Public
    2.26 + License along with this library; if not, write to the Free Software
    2.27 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.28 + 
    2.29 + Sam Lantinga
    2.30 + slouken@libsdl.org
    2.31 +*/
    2.32  
    2.33  #import "SDL_uikitappdelegate.h"
    2.34  #import "SDL_uikitopenglview.h"
    2.35 @@ -16,26 +30,24 @@
    2.36  #undef main
    2.37  #endif
    2.38  
    2.39 -UIWindow *uikitWindow=nil;
    2.40 -SDL_uikitopenglview *uikitEAGLView=nil;
    2.41 -
    2.42  extern int SDL_main(int argc, char *argv[]);
    2.43  static int forward_argc;
    2.44  static char **forward_argv;
    2.45  
    2.46  int main(int argc, char **argv) {
    2.47  
    2.48 +	int i;
    2.49  	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.50  	
    2.51  	/* store arguments */
    2.52  	forward_argc = argc;
    2.53  	forward_argv = (char **)malloc(argc * sizeof(char *));
    2.54 -	int i;
    2.55  	for (i=0; i<argc; i++) {
    2.56  		forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
    2.57  		strcpy(forward_argv[i], argv[i]);
    2.58  	}
    2.59  
    2.60 +	/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
    2.61  	UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate");
    2.62  	
    2.63  	[pool release];
    2.64 @@ -44,6 +56,20 @@
    2.65  
    2.66  @implementation SDLUIKitDelegate
    2.67  
    2.68 +@synthesize window;
    2.69 +
    2.70 +/* convenience method */
    2.71 ++(SDLUIKitDelegate *)sharedAppDelegate {
    2.72 +	/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
    2.73 +	return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
    2.74 +}
    2.75 +
    2.76 +- (id)init {
    2.77 +	self = [super init];
    2.78 +	window = nil;
    2.79 +	return self;
    2.80 +}
    2.81 +
    2.82  - (void)applicationDidFinishLaunching:(UIApplication *)application {
    2.83  			
    2.84  	/* Set working directory to resource path */
    2.85 @@ -67,13 +93,13 @@
    2.86  - (void)applicationWillTerminate:(UIApplication *)application {
    2.87  	
    2.88  	SDL_SendQuit();
    2.89 -	longjmp(*(jump_env()), 1); // hack to prevent automatic termination
    2.90 +	 /* hack to prevent automatic termination.  See SDL_uikitevents.m for details */
    2.91 +	longjmp(*(jump_env()), 1);
    2.92  	
    2.93  }
    2.94  
    2.95  -(void)dealloc {
    2.96 -	[uikitWindow release];
    2.97 -	[uikitEAGLView release]; 
    2.98 +	[window release];
    2.99  	[super dealloc];
   2.100  }
   2.101