Added SDL_WindowData for UIKit video driver. Now looks up instances here instead of assuming we're referring to a singleton. gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Tue, 22 Jul 2008 22:59:59 +0000
branchgsoc2008_iphone
changeset 2399d904584ea86d
parent 2398 92de010929a6
child 2400 e103b316a4ef
Added SDL_WindowData for UIKit video driver. Now looks up instances here instead of assuming we're referring to a singleton.
src/video/uikit/SDL_uikitwindow.h
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/src/video/uikit/SDL_uikitwindow.h	Fri Jul 18 21:53:52 2008 +0000
     1.2 +++ b/src/video/uikit/SDL_uikitwindow.h	Tue Jul 22 22:59:59 2008 +0000
     1.3 @@ -25,10 +25,23 @@
     1.4  #define _SDL_uikitwindow_h
     1.5  
     1.6  #include "../SDL_sysvideo.h"
     1.7 +#import "SDL_uikitopenglview.h"
     1.8 +
     1.9 +typedef struct SDL_WindowData SDL_WindowData;
    1.10  
    1.11  extern int UIKit_CreateWindow(_THIS, SDL_Window *window);
    1.12  extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
    1.13  
    1.14 +@class UIWindow;
    1.15 +
    1.16 +struct SDL_WindowData
    1.17 +{
    1.18 +    SDL_WindowID windowID;
    1.19 +    UIWindow *uiwindow;
    1.20 +	SDL_uikitopenglview *view;
    1.21 +};
    1.22 +
    1.23 +
    1.24  #endif /* _SDL_uikitwindow_h */
    1.25  
    1.26  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/video/uikit/SDL_uikitwindow.m	Fri Jul 18 21:53:52 2008 +0000
     2.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Tue Jul 22 22:59:59 2008 +0000
     2.3 @@ -53,36 +53,82 @@
     2.4  #include <UIKit/UIKit.h>
     2.5  #include <Foundation/Foundation.h>
     2.6  
     2.7 +static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) {
     2.8  
     2.9 -
    2.10 -extern UIWindow *uikitWindow;
    2.11 -extern SDL_uikitopenglview *uikitEAGLView;
    2.12 -
    2.13 -int UIKit_CreateWindow(_THIS, SDL_Window *window) {
    2.14 +    SDL_WindowData *data;
    2.15 +		
    2.16 +    /* Allocate the window data */
    2.17 +    data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
    2.18 +    if (!data) {
    2.19 +        SDL_OutOfMemory();
    2.20 +        return -1;
    2.21 +    }
    2.22 +    data->windowID = window->id;
    2.23 +    data->uiwindow = uiwindow;
    2.24 +	data->view = nil;
    2.25 +		
    2.26 +    /* Fill in the SDL window with the window data */
    2.27 +	{
    2.28 +        window->x = 0;
    2.29 +        window->y = 0;
    2.30 +        window->w = (int)uiwindow.frame.size.width;
    2.31 +        window->h = (int)uiwindow.frame.size.height;
    2.32 +    }
    2.33  	
    2.34 -	printf("Create window! UIKIT!\n");
    2.35 -			
    2.36 -	uikitWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    2.37 -		
    2.38 -	if (window->flags & SDL_WINDOW_BORDERLESS) {
    2.39 -		/* hide status bar */
    2.40 -		[UIApplication sharedApplication].statusBarHidden = YES;
    2.41 -	}
    2.42 -		
    2.43 +	window->driverdata = data;
    2.44 +	
    2.45  	window->flags &= ~SDL_WINDOW_RESIZABLE;		/* window is NEVER resizeable */
    2.46  	window->flags |= SDL_WINDOW_OPENGL;			/* window is always OpenGL */
    2.47  	window->flags |= SDL_WINDOW_FULLSCREEN;		/* window is always fullscreen */
    2.48  	window->flags |= SDL_WINDOW_SHOWN;			/* only one window on iPod touch, always shown */
    2.49 -	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */
    2.50 +	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */	
    2.51 +
    2.52 +	/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
    2.53 +	if (window->flags & SDL_WINDOW_BORDERLESS) {
    2.54 +		[UIApplication sharedApplication].statusBarHidden = YES;
    2.55 +	}
    2.56 +	else {
    2.57 +		[UIApplication sharedApplication].statusBarHidden = NO;
    2.58 +	}
    2.59 +	
    2.60 +    return 0;
    2.61 +	
    2.62 +}
    2.63 +
    2.64 +int UIKit_CreateWindow(_THIS, SDL_Window *window) {
    2.65 +		
    2.66 +	/* iPhone applications are single window only */
    2.67 +	if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
    2.68 +		SDL_SetError("Window already exists, no multi-window support.");
    2.69 +		return -1;
    2.70 +	}
    2.71 +	
    2.72 +	/* ignore the size user requested, and make a fullscreen window */
    2.73 +	UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    2.74 +	
    2.75 +	if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
    2.76 +        [uiwindow release];
    2.77 +        return -1;
    2.78 +    }	
    2.79 +	
    2.80 +	[SDLUIKitDelegate sharedAppDelegate].window = uiwindow;
    2.81 +	[uiwindow release]; /* release the window (the app delegate has retained it) */
    2.82  	
    2.83  	return 1;
    2.84  	
    2.85  }
    2.86  
    2.87  void UIKit_DestroyWindow(_THIS, SDL_Window * window) {
    2.88 -	;
    2.89 +	/* don't worry, the delegate will automatically release the window */
    2.90 +	
    2.91 +	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    2.92 +	if (data) {
    2.93 +		SDL_free( window->driverdata );
    2.94 +	}
    2.95 +
    2.96 +	/* this will also destroy the window */
    2.97 +	[SDLUIKitDelegate sharedAppDelegate].window = nil;
    2.98 +
    2.99  }
   2.100  
   2.101 -
   2.102 -
   2.103  /* vi: set ts=4 sw=4 expandtab: */