comparison src/video/uikit/SDL_uikitwindow.m @ 3685:64ce267332c6

Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 21 Jan 2010 06:21:52 +0000
parents 4ec48602f1db
children 8b03a20b320f
comparison
equal deleted inserted replaced
3684:cc564f08884f 3685:64ce267332c6
39 #include <Foundation/Foundation.h> 39 #include <Foundation/Foundation.h>
40 40
41 static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) { 41 static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) {
42 42
43 SDL_WindowData *data; 43 SDL_WindowData *data;
44 44
45 /* Allocate the window data */ 45 /* Allocate the window data */
46 data = (SDL_WindowData *)SDL_malloc(sizeof(*data)); 46 data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
47 if (!data) { 47 if (!data) {
48 SDL_OutOfMemory(); 48 SDL_OutOfMemory();
49 return -1; 49 return -1;
50 } 50 }
51 data->windowID = window->id; 51 data->window = window;
52 data->uiwindow = uiwindow; 52 data->uiwindow = uiwindow;
53 data->view = nil; 53 data->view = nil;
54 54
55 /* Fill in the SDL window with the window data */ 55 /* Fill in the SDL window with the window data */
56 { 56 {
57 window->x = 0; 57 window->x = 0;
58 window->y = 0; 58 window->y = 0;
59 window->w = (int)uiwindow.frame.size.width; 59 window->w = (int)uiwindow.frame.size.width;
60 window->h = (int)uiwindow.frame.size.height; 60 window->h = (int)uiwindow.frame.size.height;
61 } 61 }
62 62
63 window->driverdata = data; 63 window->driverdata = data;
64 64
65 window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */ 65 window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
66 window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */ 66 window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */
67 window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */ 67 window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
68 window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */ 68 window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */
69 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */ 69 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
70 70
71 /* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */ 71 /* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
72 if (window->flags & SDL_WINDOW_BORDERLESS) { 72 if (window->flags & SDL_WINDOW_BORDERLESS) {
73 [UIApplication sharedApplication].statusBarHidden = YES; 73 [UIApplication sharedApplication].statusBarHidden = YES;
74 } 74 }
75 else { 75 else {
76 [UIApplication sharedApplication].statusBarHidden = NO; 76 [UIApplication sharedApplication].statusBarHidden = NO;
77 } 77 }
78 78
79 return 0; 79 return 0;
80 80
81 } 81 }
82 82
83 int UIKit_CreateWindow(_THIS, SDL_Window *window) { 83 int UIKit_CreateWindow(_THIS, SDL_Window *window) {
84 84
85 /* We currently only handle single window applications on iPhone */ 85 /* We currently only handle single window applications on iPhone */
86 if (nil != [SDLUIKitDelegate sharedAppDelegate].window) { 86 if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
87 SDL_SetError("Window already exists, no multi-window support."); 87 SDL_SetError("Window already exists, no multi-window support.");
88 return -1; 88 return -1;
89 } 89 }
90 90
91 /* ignore the size user requested, and make a fullscreen window */ 91 /* ignore the size user requested, and make a fullscreen window */
92 UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 92 UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
93 93
94 if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) { 94 if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
95 [uiwindow release]; 95 [uiwindow release];
96 return -1; 96 return -1;
97 } 97 }
98 98
99 // This saves the main window in the app delegate so event callbacks can do stuff on the window. 99 // This saves the main window in the app delegate so event callbacks can do stuff on the window.
100 // This assumes a single window application design and needs to be fixed for multiple windows. 100 // This assumes a single window application design and needs to be fixed for multiple windows.
101 [SDLUIKitDelegate sharedAppDelegate].window = uiwindow; 101 [SDLUIKitDelegate sharedAppDelegate].window = window;
102 [SDLUIKitDelegate sharedAppDelegate].windowID = window->id; 102 [SDLUIKitDelegate sharedAppDelegate].uiwindow = uiwindow;
103 [uiwindow release]; /* release the window (the app delegate has retained it) */ 103 [uiwindow release]; /* release the window (the app delegate has retained it) */
104 104
105 return 1; 105 return 1;
106 106
107 } 107 }
108 108
109 void UIKit_DestroyWindow(_THIS, SDL_Window * window) { 109 void UIKit_DestroyWindow(_THIS, SDL_Window * window) {
110 /* don't worry, the delegate will automatically release the window */ 110 /* don't worry, the delegate will automatically release the window */
111 111
112 SDL_WindowData *data = (SDL_WindowData *)window->driverdata; 112 SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
113 if (data) { 113 if (data) {
114 SDL_free( window->driverdata ); 114 SDL_free( window->driverdata );
115 } 115 }
116 116
117 /* this will also destroy the window */ 117 /* this will also destroy the window */
118 [SDLUIKitDelegate sharedAppDelegate].window = nil; 118 [SDLUIKitDelegate sharedAppDelegate].window = NULL;
119 [SDLUIKitDelegate sharedAppDelegate].windowID = 0; 119 [SDLUIKitDelegate sharedAppDelegate].uiwindow = nil;
120
121 } 120 }
122 121
123 /* vi: set ts=4 sw=4 expandtab: */ 122 /* vi: set ts=4 sw=4 expandtab: */