cocoaTouch/SDLOverrides/SDL_uikitwindow.m
changeset 2714 c85ffe57d971
parent 2688 174c94b8ea72
child 3027 32890edaa483
equal deleted inserted replaced
2713:71250942e95b 2714:c85ffe57d971
    37 
    37 
    38 #include <UIKit/UIKit.h>
    38 #include <UIKit/UIKit.h>
    39 #include <Foundation/Foundation.h>
    39 #include <Foundation/Foundation.h>
    40 
    40 
    41 static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) {
    41 static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) {
    42 
    42 	SDL_WindowData *data;
    43     SDL_WindowData *data;
    43 	
    44 		
    44 	/* Allocate the window data */
    45     /* Allocate the window data */
    45 	data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
    46     data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
    46 	if (!data) {
    47     if (!data) {
    47 		SDL_OutOfMemory();
    48         SDL_OutOfMemory();
    48 		return -1;
    49         return -1;
    49 	}
    50     }
    50 	data->window = window;
    51     data->windowID = window->id;
    51 	data->uiwindow = uiwindow;
    52     data->uiwindow = uiwindow;
       
    53 	data->view = nil;
    52 	data->view = nil;
    54 		
    53 	
    55     /* Fill in the SDL window with the window data */
    54 	/* Fill in the SDL window with the window data */
    56 	{
    55 	{
    57         window->x = 0;
    56 		window->x = 0;
    58         window->y = 0;
    57 		window->y = 0;
    59         window->w = (int)uiwindow.frame.size.width;
    58 		window->w = (int)uiwindow.frame.size.width;
    60         window->h = (int)uiwindow.frame.size.height;
    59 		window->h = (int)uiwindow.frame.size.height;
    61     }
    60 	}
    62 	
    61 	
    63 	window->driverdata = data;
    62 	window->driverdata = data;
    64 	
    63 	
    65 	window->flags &= ~SDL_WINDOW_RESIZABLE;		/* window is NEVER resizeable */
    64 	window->flags &= ~SDL_WINDOW_RESIZABLE;		/* window is NEVER resizeable */
    66 	window->flags |= SDL_WINDOW_OPENGL;			/* window is always OpenGL */
    65 	window->flags |= SDL_WINDOW_OPENGL;			/* window is always OpenGL */
    67 	window->flags |= SDL_WINDOW_FULLSCREEN;		/* window is always fullscreen */
    66 	window->flags |= SDL_WINDOW_FULLSCREEN;		/* window is always fullscreen */
    68 	window->flags |= SDL_WINDOW_SHOWN;			/* only one window on iPod touch, always shown */
    67 	window->flags |= SDL_WINDOW_SHOWN;			/* only one window on iPod touch, always shown */
    69 	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */	
    68 	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */	
    70 
    69 	
    71 	/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
    70 	/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
    72 	if (window->flags & SDL_WINDOW_BORDERLESS) {
    71 	if (window->flags & SDL_WINDOW_BORDERLESS) {
    73 		[UIApplication sharedApplication].statusBarHidden = YES;
    72 		[UIApplication sharedApplication].statusBarHidden = YES;
    74 	}
    73 	}
    75 	else {
    74 	else {
    76 		[UIApplication sharedApplication].statusBarHidden = NO;
    75 		[UIApplication sharedApplication].statusBarHidden = NO;
    77 	}
    76 	}
    78 	
    77 	
    79     return 0;
    78 	return 0;
    80 	
    79 	
    81 }
    80 }
    82 
    81 
    83 int UIKit_CreateWindow(_THIS, SDL_Window *window) {
    82 int UIKit_CreateWindow(_THIS, SDL_Window *window) {
    84 	/* We currently only handle single window applications on iPhone 
    83 	/* We currently only handle single window applications on iPhone 
    89 	
    88 	
    90 	// ignore the size user requested, and make a fullscreen window 
    89 	// ignore the size user requested, and make a fullscreen window 
    91 	UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];*/
    90 	UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];*/
    92 	
    91 	
    93 	// since we handle the window with a NIB, we don't need the initialization above
    92 	// since we handle the window with a NIB, we don't need the initialization above
    94 	if (SetupWindowData(_this, window, [SDLUIKitDelegate sharedAppDelegate].window, SDL_TRUE) < 0) {
    93 	if (SetupWindowData(_this, window, [SDLUIKitDelegate sharedAppDelegate].uiwindow, SDL_TRUE) < 0) {
    95 		SDL_SetError("SetupWindowData() failed");
    94 		SDL_SetError("SetupWindowData() failed");
    96         return -1;
    95 		//[uiwindow release];
    97     }	
    96 		return -1;
       
    97 	}	
    98 	
    98 	
    99 	// This saves the main window in the app delegate so event callbacks can do stuff on the window.
    99 	// This saves the main window in the app delegate so event callbacks can do stuff on the window.
   100 	// This assumes a single window application design and needs to be fixed for multiple windows.
   100 	// This assumes a single window application design and needs to be fixed for multiple windows.
   101 	[SDLUIKitDelegate sharedAppDelegate].windowID = window->id;
   101 	[SDLUIKitDelegate sharedAppDelegate].window = window;
   102 
   102 
   103 /*	[SDLUIKitDelegate sharedAppDelegate].window = uiwindow;
   103 	//[SDLUIKitDelegate sharedAppDelegate].uiwindow = uiwindow;
   104 	[uiwindow release]; /* release the window (the app delegate has retained it) */
   104 	//[uiwindow release]; /* release the window (the app delegate has retained it) */
   105 	
   105 	
   106 	return 1;
   106 	return 1;
   107 	
   107 	
   108 }
   108 }
   109 
   109 
   114 	if (data) {
   114 	if (data) {
   115 		SDL_free( window->driverdata );
   115 		SDL_free( window->driverdata );
   116 	}
   116 	}
   117 
   117 
   118 	/* this will also destroy the window */
   118 	/* this will also destroy the window */
   119 	//[SDLUIKitDelegate sharedAppDelegate].window = nil;
   119 	[SDLUIKitDelegate sharedAppDelegate].window = NULL;
   120 	[SDLUIKitDelegate sharedAppDelegate].windowID = 0;
   120 	//[SDLUIKitDelegate sharedAppDelegate].uiwindow = nil;
   121 
   121 
   122 }
   122 }
   123 
   123 
   124 /* vi: set ts=4 sw=4 expandtab: */
   124 /* vi: set ts=4 sw=4 expandtab: */