comparison src/video/cocoa/SDL_cocoawindow.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 e96be66e3673
children 6512cba48440
comparison
equal deleted inserted replaced
3684:cc564f08884f 3685:64ce267332c6
84 [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp]; 84 [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
85 } 85 }
86 86
87 - (BOOL)windowShouldClose:(id)sender 87 - (BOOL)windowShouldClose:(id)sender
88 { 88 {
89 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_CLOSE, 0, 0); 89 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
90 return NO; 90 return NO;
91 } 91 }
92 92
93 - (void)windowDidExpose:(NSNotification *)aNotification 93 - (void)windowDidExpose:(NSNotification *)aNotification
94 { 94 {
95 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_EXPOSED, 0, 0); 95 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
96 } 96 }
97 97
98 - (void)windowDidMove:(NSNotification *)aNotification 98 - (void)windowDidMove:(NSNotification *)aNotification
99 { 99 {
100 int x, y; 100 int x, y;
101 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]]; 101 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
102 ConvertNSRect(&rect); 102 ConvertNSRect(&rect);
103 x = (int)rect.origin.x; 103 x = (int)rect.origin.x;
104 y = (int)rect.origin.y; 104 y = (int)rect.origin.y;
105 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MOVED, x, y); 105 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
106 } 106 }
107 107
108 - (void)windowDidResize:(NSNotification *)aNotification 108 - (void)windowDidResize:(NSNotification *)aNotification
109 { 109 {
110 int w, h; 110 int w, h;
111 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]]; 111 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
112 w = (int)rect.size.width; 112 w = (int)rect.size.width;
113 h = (int)rect.size.height; 113 h = (int)rect.size.height;
114 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_RESIZED, w, h); 114 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
115 } 115 }
116 116
117 - (void)windowDidMiniaturize:(NSNotification *)aNotification 117 - (void)windowDidMiniaturize:(NSNotification *)aNotification
118 { 118 {
119 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MINIMIZED, 0, 0); 119 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
120 } 120 }
121 121
122 - (void)windowDidDeminiaturize:(NSNotification *)aNotification 122 - (void)windowDidDeminiaturize:(NSNotification *)aNotification
123 { 123 {
124 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_RESTORED, 0, 0); 124 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
125 } 125 }
126 126
127 - (void)windowDidBecomeKey:(NSNotification *)aNotification 127 - (void)windowDidBecomeKey:(NSNotification *)aNotification
128 { 128 {
129 int index; 129 int index;
130 130
131 /* We're going to get keyboard events, since we're key. */ 131 /* We're going to get keyboard events, since we're key. */
132 index = _data->videodata->keyboard; 132 index = _data->videodata->keyboard;
133 SDL_SetKeyboardFocus(index, _data->windowID); 133 SDL_SetKeyboardFocus(index, _data->window);
134 } 134 }
135 135
136 - (void)windowDidResignKey:(NSNotification *)aNotification 136 - (void)windowDidResignKey:(NSNotification *)aNotification
137 { 137 {
138 int index; 138 int index;
139 SDL_Mouse *mouse; 139 SDL_Mouse *mouse;
140 140
141 /* Some other window will get mouse events, since we're not key. */ 141 /* Some other window will get mouse events, since we're not key. */
142 index = _data->videodata->mouse; 142 index = _data->videodata->mouse;
143 mouse = SDL_GetMouse(index); 143 mouse = SDL_GetMouse(index);
144 if (mouse->focus == _data->windowID) { 144 if (mouse->focus == _data->window) {
145 SDL_SetMouseFocus(index, 0); 145 SDL_SetMouseFocus(index, 0);
146 } 146 }
147 147
148 /* Some other window will get keyboard events, since we're not key. */ 148 /* Some other window will get keyboard events, since we're not key. */
149 index = _data->videodata->keyboard; 149 index = _data->videodata->keyboard;
150 SDL_SetKeyboardFocus(index, 0); 150 SDL_SetKeyboardFocus(index, 0);
151 } 151 }
152 152
153 - (void)windowDidHide:(NSNotification *)aNotification 153 - (void)windowDidHide:(NSNotification *)aNotification
154 { 154 {
155 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_HIDDEN, 0, 0); 155 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
156 } 156 }
157 157
158 - (void)windowDidUnhide:(NSNotification *)aNotification 158 - (void)windowDidUnhide:(NSNotification *)aNotification
159 { 159 {
160 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_SHOWN, 0, 0); 160 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
161 } 161 }
162 162
163 - (void)mouseDown:(NSEvent *)theEvent 163 - (void)mouseDown:(NSEvent *)theEvent
164 { 164 {
165 int index; 165 int index;
226 [self mouseUp:theEvent]; 226 [self mouseUp:theEvent];
227 } 227 }
228 228
229 - (void)mouseMoved:(NSEvent *)theEvent 229 - (void)mouseMoved:(NSEvent *)theEvent
230 { 230 {
231 SDL_Window *window = SDL_GetWindowFromID(_data->windowID); 231 SDL_Window *window = _data->window;
232 int index; 232 int index;
233 SDL_Mouse *mouse; 233 SDL_Mouse *mouse;
234 NSPoint point; 234 NSPoint point;
235 235
236 index = _data->videodata->mouse; 236 index = _data->videodata->mouse;
241 point.y < 0 || point.y >= window->h ) { 241 point.y < 0 || point.y >= window->h ) {
242 if (mouse->focus != 0) { 242 if (mouse->focus != 0) {
243 SDL_SetMouseFocus(index, 0); 243 SDL_SetMouseFocus(index, 0);
244 } 244 }
245 } else { 245 } else {
246 if (mouse->focus != _data->windowID) { 246 if (mouse->focus != _data->window) {
247 SDL_SetMouseFocus(index, _data->windowID); 247 SDL_SetMouseFocus(index, _data->window);
248 } 248 }
249 SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y, 0); 249 SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y, 0);
250 } 250 }
251 } 251 }
252 252
296 static int 296 static int
297 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) 297 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
298 { 298 {
299 NSAutoreleasePool *pool; 299 NSAutoreleasePool *pool;
300 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 300 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
301 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 301 SDL_VideoDisplay *display = window->display;
302 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; 302 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
303 SDL_WindowData *data; 303 SDL_WindowData *data;
304 304
305 /* Allocate the window data */ 305 /* Allocate the window data */
306 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); 306 data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
307 if (!data) { 307 if (!data) {
308 SDL_OutOfMemory(); 308 SDL_OutOfMemory();
309 return -1; 309 return -1;
310 } 310 }
311 data->windowID = window->id; 311 data->window = window;
312 data->window = nswindow; 312 data->window = nswindow;
313 data->created = created; 313 data->created = created;
314 data->display = displaydata->display; 314 data->display = displaydata->display;
315 data->videodata = videodata; 315 data->videodata = videodata;
316 316
361 window->flags &= ~SDL_WINDOW_MINIMIZED; 361 window->flags &= ~SDL_WINDOW_MINIMIZED;
362 } 362 }
363 if ([nswindow isKeyWindow]) { 363 if ([nswindow isKeyWindow]) {
364 int index = data->videodata->keyboard; 364 int index = data->videodata->keyboard;
365 window->flags |= SDL_WINDOW_INPUT_FOCUS; 365 window->flags |= SDL_WINDOW_INPUT_FOCUS;
366 SDL_SetKeyboardFocus(index, data->windowID); 366 SDL_SetKeyboardFocus(index, data->window);
367 367
368 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { 368 if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
369 /* FIXME */ 369 /* FIXME */
370 } 370 }
371 } 371 }
379 int 379 int
380 Cocoa_CreateWindow(_THIS, SDL_Window * window) 380 Cocoa_CreateWindow(_THIS, SDL_Window * window)
381 { 381 {
382 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 382 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
383 NSWindow *nswindow; 383 NSWindow *nswindow;
384 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 384 SDL_VideoDisplay *display = window->display;
385 NSRect rect; 385 NSRect rect;
386 SDL_Rect bounds; 386 SDL_Rect bounds;
387 unsigned int style; 387 unsigned int style;
388 NSString *title; 388 NSString *title;
389 int status; 389 int status;
488 void 488 void
489 Cocoa_SetWindowPosition(_THIS, SDL_Window * window) 489 Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
490 { 490 {
491 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 491 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
492 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; 492 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
493 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 493 SDL_VideoDisplay *display = window->display;
494 NSRect rect; 494 NSRect rect;
495 SDL_Rect bounds; 495 SDL_Rect bounds;
496 496
497 Cocoa_GetDisplayBounds(_this, display, &bounds); 497 Cocoa_GetDisplayBounds(_this, display, &bounds);
498 if ((window->flags & SDL_WINDOW_FULLSCREEN) 498 if ((window->flags & SDL_WINDOW_FULLSCREEN)