Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added SDL_WindowData for UIKit video driver. Now looks up instances h…
Browse files Browse the repository at this point in the history
…ere instead of assuming we're referring to a singleton.
  • Loading branch information
Holmes Futrell committed Jul 22, 2008
1 parent 6df8c55 commit 2271d46
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 16 deletions.
13 changes: 13 additions & 0 deletions src/video/uikit/SDL_uikitwindow.h
Expand Up @@ -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: */
78 changes: 62 additions & 16 deletions src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -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.