Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added SDL_WindowData for UIKit video driver. Now looks up instances h…

…ere instead of assuming we're referring to a singleton.
  • Loading branch information
Holmes Futrell committed Jul 22, 2008
1 parent 6df8c55 commit 2271d46b6e8cf57954a4ec8fcefed63f7dc650db
Showing with 75 additions and 16 deletions.
  1. +13 −0 src/video/uikit/SDL_uikitwindow.h
  2. +62 −16 src/video/uikit/SDL_uikitwindow.m
@@ -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: */
@@ -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) {

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: */

0 comments on commit 2271d46

Please sign in to comment.