From 2271d46b6e8cf57954a4ec8fcefed63f7dc650db Mon Sep 17 00:00:00 2001 From: Holmes Futrell Date: Tue, 22 Jul 2008 22:59:59 +0000 Subject: [PATCH] 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 | 13 ++++++ src/video/uikit/SDL_uikitwindow.m | 78 ++++++++++++++++++++++++------- 2 files changed, 75 insertions(+), 16 deletions(-) diff --git a/src/video/uikit/SDL_uikitwindow.h b/src/video/uikit/SDL_uikitwindow.h index 7167cc7ec..cc2716e2b 100644 --- a/src/video/uikit/SDL_uikitwindow.h +++ b/src/video/uikit/SDL_uikitwindow.h @@ -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 --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index 2bef56548..8ad7b0373 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -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) { - - printf("Create window! UIKIT!\n"); - - uikitWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + SDL_WindowData *data; - if (window->flags & SDL_WINDOW_BORDERLESS) { - /* hide status bar */ - [UIApplication sharedApplication].statusBarHidden = YES; - } + /* 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; + } + + 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: */