# HG changeset patch # User Holmes Futrell # Date 1216767599 0 # Node ID d904584ea86d98c2cb06d2bf181661cb0e8208f0 # Parent 92de010929a6dd39721716bb34db6221ef73e8f9 Added SDL_WindowData for UIKit video driver. Now looks up instances here instead of assuming we're referring to a singleton. diff -r 92de010929a6 -r d904584ea86d src/video/uikit/SDL_uikitwindow.h --- a/src/video/uikit/SDL_uikitwindow.h Fri Jul 18 21:53:52 2008 +0000 +++ b/src/video/uikit/SDL_uikitwindow.h Tue Jul 22 22:59:59 2008 +0000 @@ -25,10 +25,23 @@ #define _SDL_uikitwindow_h #include "../SDL_sysvideo.h" +#import "SDL_uikitopenglview.h" + +typedef struct SDL_WindowData SDL_WindowData; extern int UIKit_CreateWindow(_THIS, SDL_Window *window); extern void UIKit_DestroyWindow(_THIS, SDL_Window * window); +@class UIWindow; + +struct SDL_WindowData +{ + SDL_WindowID windowID; + UIWindow *uiwindow; + SDL_uikitopenglview *view; +}; + + #endif /* _SDL_uikitwindow_h */ /* vi: set ts=4 sw=4 expandtab: */ diff -r 92de010929a6 -r d904584ea86d src/video/uikit/SDL_uikitwindow.m --- 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 #include - +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: */