diff src/video/uikit/SDL_uikitwindow.m @ 2399:d904584ea86d gsoc2008_iphone

Added SDL_WindowData for UIKit video driver. Now looks up instances here instead of assuming we're referring to a singleton.
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Tue, 22 Jul 2008 22:59:59 +0000
parents 2e4fea4a4416
children ac67f7719ba8
line wrap: on
line diff
--- a/src/video/uikit/SDL_uikitwindow.m	Fri Jul 18 21:53:52 2008 +0000
+++ b/src/video/uikit/SDL_uikitwindow.m	Tue Jul 22 22:59:59 2008 +0000
@@ -53,36 +53,82 @@
 #include <UIKit/UIKit.h>
 #include <Foundation/Foundation.h>
 
-
+static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) {
 
-extern UIWindow *uikitWindow;
-extern SDL_uikitopenglview *uikitEAGLView;
-
-int UIKit_CreateWindow(_THIS, SDL_Window *window) {
+    SDL_WindowData *data;
+		
+    /* Allocate the window data */
+    data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
+    if (!data) {
+        SDL_OutOfMemory();
+        return -1;
+    }
+    data->windowID = window->id;
+    data->uiwindow = uiwindow;
+	data->view = nil;
+		
+    /* Fill in the SDL window with the window data */
+	{
+        window->x = 0;
+        window->y = 0;
+        window->w = (int)uiwindow.frame.size.width;
+        window->h = (int)uiwindow.frame.size.height;
+    }
 	
-	printf("Create window! UIKIT!\n");
-			
-	uikitWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-		
-	if (window->flags & SDL_WINDOW_BORDERLESS) {
-		/* hide status bar */
-		[UIApplication sharedApplication].statusBarHidden = YES;
-	}
-		
+	window->driverdata = data;
+	
 	window->flags &= ~SDL_WINDOW_RESIZABLE;		/* window is NEVER resizeable */
 	window->flags |= SDL_WINDOW_OPENGL;			/* window is always OpenGL */
 	window->flags |= SDL_WINDOW_FULLSCREEN;		/* window is always fullscreen */
 	window->flags |= SDL_WINDOW_SHOWN;			/* only one window on iPod touch, always shown */
-	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */
+	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */	
+
+	/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
+	if (window->flags & SDL_WINDOW_BORDERLESS) {
+		[UIApplication sharedApplication].statusBarHidden = YES;
+	}
+	else {
+		[UIApplication sharedApplication].statusBarHidden = NO;
+	}
+	
+    return 0;
+	
+}
+
+int UIKit_CreateWindow(_THIS, SDL_Window *window) {
+		
+	/* iPhone applications are single window only */
+	if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
+		SDL_SetError("Window already exists, no multi-window support.");
+		return -1;
+	}
+	
+	/* ignore the size user requested, and make a fullscreen window */
+	UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+	
+	if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
+        [uiwindow release];
+        return -1;
+    }	
+	
+	[SDLUIKitDelegate sharedAppDelegate].window = uiwindow;
+	[uiwindow release]; /* release the window (the app delegate has retained it) */
 	
 	return 1;
 	
 }
 
 void UIKit_DestroyWindow(_THIS, SDL_Window * window) {
-	;
+	/* don't worry, the delegate will automatically release the window */
+	
+	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+	if (data) {
+		SDL_free( window->driverdata );
+	}
+
+	/* this will also destroy the window */
+	[SDLUIKitDelegate sharedAppDelegate].window = nil;
+
 }
 
-
-
 /* vi: set ts=4 sw=4 expandtab: */