Mercurial > sdl-ios-xcode
comparison src/video/uikit/SDL_uikitwindow.m @ 2399:d904584ea86d gsoc2008_iphone
Added SDL_WindowData for UIKit video driver. Now looks up instances here instead of assuming we're referring to a singleton.
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Tue, 22 Jul 2008 22:59:59 +0000 |
parents | 2e4fea4a4416 |
children | ac67f7719ba8 |
comparison
equal
deleted
inserted
replaced
2398:92de010929a6 | 2399:d904584ea86d |
---|---|
51 #import "SDL_renderer_sw.h" | 51 #import "SDL_renderer_sw.h" |
52 | 52 |
53 #include <UIKit/UIKit.h> | 53 #include <UIKit/UIKit.h> |
54 #include <Foundation/Foundation.h> | 54 #include <Foundation/Foundation.h> |
55 | 55 |
56 static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) { | |
56 | 57 |
57 | 58 SDL_WindowData *data; |
58 extern UIWindow *uikitWindow; | 59 |
59 extern SDL_uikitopenglview *uikitEAGLView; | 60 /* Allocate the window data */ |
60 | 61 data = (SDL_WindowData *)SDL_malloc(sizeof(*data)); |
61 int UIKit_CreateWindow(_THIS, SDL_Window *window) { | 62 if (!data) { |
63 SDL_OutOfMemory(); | |
64 return -1; | |
65 } | |
66 data->windowID = window->id; | |
67 data->uiwindow = uiwindow; | |
68 data->view = nil; | |
69 | |
70 /* Fill in the SDL window with the window data */ | |
71 { | |
72 window->x = 0; | |
73 window->y = 0; | |
74 window->w = (int)uiwindow.frame.size.width; | |
75 window->h = (int)uiwindow.frame.size.height; | |
76 } | |
62 | 77 |
63 printf("Create window! UIKIT!\n"); | 78 window->driverdata = data; |
64 | 79 |
65 uikitWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
66 | |
67 if (window->flags & SDL_WINDOW_BORDERLESS) { | |
68 /* hide status bar */ | |
69 [UIApplication sharedApplication].statusBarHidden = YES; | |
70 } | |
71 | |
72 window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */ | 80 window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */ |
73 window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */ | 81 window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */ |
74 window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */ | 82 window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */ |
75 window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */ | 83 window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */ |
76 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */ | 84 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */ |
85 | |
86 /* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */ | |
87 if (window->flags & SDL_WINDOW_BORDERLESS) { | |
88 [UIApplication sharedApplication].statusBarHidden = YES; | |
89 } | |
90 else { | |
91 [UIApplication sharedApplication].statusBarHidden = NO; | |
92 } | |
93 | |
94 return 0; | |
95 | |
96 } | |
97 | |
98 int UIKit_CreateWindow(_THIS, SDL_Window *window) { | |
99 | |
100 /* iPhone applications are single window only */ | |
101 if (nil != [SDLUIKitDelegate sharedAppDelegate].window) { | |
102 SDL_SetError("Window already exists, no multi-window support."); | |
103 return -1; | |
104 } | |
105 | |
106 /* ignore the size user requested, and make a fullscreen window */ | |
107 UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
108 | |
109 if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) { | |
110 [uiwindow release]; | |
111 return -1; | |
112 } | |
113 | |
114 [SDLUIKitDelegate sharedAppDelegate].window = uiwindow; | |
115 [uiwindow release]; /* release the window (the app delegate has retained it) */ | |
77 | 116 |
78 return 1; | 117 return 1; |
79 | 118 |
80 } | 119 } |
81 | 120 |
82 void UIKit_DestroyWindow(_THIS, SDL_Window * window) { | 121 void UIKit_DestroyWindow(_THIS, SDL_Window * window) { |
83 ; | 122 /* don't worry, the delegate will automatically release the window */ |
123 | |
124 SDL_WindowData *data = (SDL_WindowData *)window->driverdata; | |
125 if (data) { | |
126 SDL_free( window->driverdata ); | |
127 } | |
128 | |
129 /* this will also destroy the window */ | |
130 [SDLUIKitDelegate sharedAppDelegate].window = nil; | |
131 | |
84 } | 132 } |
85 | 133 |
86 | |
87 | |
88 /* vi: set ts=4 sw=4 expandtab: */ | 134 /* vi: set ts=4 sw=4 expandtab: */ |