comparison src/video/cocoa/SDL_cocoawindow.m @ 1956:ba0d62354872

Simplified driver window creation code. Implemented several Cocoa window functions
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Jul 2006 21:51:00 +0000
parents 420716272158
children c7803e4c21d3
comparison
equal deleted inserted replaced
1955:8c6106e45fc1 1956:ba0d62354872
193 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_MIDDLE); 193 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_MIDDLE);
194 } 194 }
195 195
196 - (void)mouseMoved:(NSEvent *)theEvent 196 - (void)mouseMoved:(NSEvent *)theEvent
197 { 197 {
198 SDL_Window *window = SDL_GetWindowFromID(_data->windowID);
198 int index; 199 int index;
199 SDL_Mouse *mouse; 200 SDL_Mouse *mouse;
200 NSPoint point; 201 NSPoint point;
201 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]]; 202 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
202 203
205 if (mouse->focus != _data->windowID) { 206 if (mouse->focus != _data->windowID) {
206 SDL_SetMouseFocus(index, _data->windowID); 207 SDL_SetMouseFocus(index, _data->windowID);
207 } 208 }
208 209
209 point = [NSEvent mouseLocation]; 210 point = [NSEvent mouseLocation];
211 if (point.x < rect.origin.x ||
212 point.x > (rect.origin.x + rect.size.width) ||
213 point.y < rect.origin.y ||
214 point.y > (rect.origin.y + rect.size.height)) {
215 if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
216 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
217 }
218 } else {
219 if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
220 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
221 }
222 }
210 point.x = point.x - rect.origin.x; 223 point.x = point.x - rect.origin.x;
211 point.y = rect.size.height - (point.y - rect.origin.y); 224 point.y = rect.size.height - (point.y - rect.origin.y);
212 SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y); 225 SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
213 } 226 }
214 227
215 - (void)scrollWheel:(NSEvent *)theEvent 228 - (void)scrollWheel:(NSEvent *)theEvent
216 { 229 {
217 fprintf(stderr, "scrollWheel\n"); 230 fprintf(stderr, "scrollWheel\n");
218 }
219
220 - (void)mouseEntered:(NSEvent *)theEvent
221 {
222 fprintf(stderr, "mouseEntered\n");
223 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
224 }
225
226 - (void)mouseExited:(NSEvent *)theEvent
227 {
228 fprintf(stderr, "mouseExited\n");
229 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
230 } 231 }
231 232
232 - (void)keyDown:(NSEvent *)theEvent 233 - (void)keyDown:(NSEvent *)theEvent
233 { 234 {
234 fprintf(stderr, "keyDown\n"); 235 fprintf(stderr, "keyDown\n");
280 window->flags &= ~SDL_WINDOW_SHOWN; 281 window->flags &= ~SDL_WINDOW_SHOWN;
281 } 282 }
282 { 283 {
283 unsigned int style = [nswindow styleMask]; 284 unsigned int style = [nswindow styleMask];
284 285
285 if (style == NSBorderlessWindowMask) { 286 if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) {
286 window->flags |= SDL_WINDOW_BORDERLESS; 287 window->flags |= SDL_WINDOW_BORDERLESS;
287 } else { 288 } else {
288 window->flags &= ~SDL_WINDOW_BORDERLESS; 289 window->flags &= ~SDL_WINDOW_BORDERLESS;
289 } 290 }
290 if (style & NSResizableWindowMask) { 291 if (style & NSResizableWindowMask) {
329 NSString *title; 330 NSString *title;
330 int status; 331 int status;
331 332
332 pool = [[NSAutoreleasePool alloc] init]; 333 pool = [[NSAutoreleasePool alloc] init];
333 334
334 if ((window->flags & SDL_WINDOW_FULLSCREEN) || 335 if (window->x == SDL_WINDOWPOS_CENTERED) {
335 window->x == SDL_WINDOWPOS_CENTERED) {
336 rect.origin.x = (CGDisplayPixelsWide(kCGDirectMainDisplay) - window->w) / 2; 336 rect.origin.x = (CGDisplayPixelsWide(kCGDirectMainDisplay) - window->w) / 2;
337 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 337 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
338 rect.origin.x = 0; 338 rect.origin.x = 0;
339 } else { 339 } else {
340 rect.origin.x = window->x; 340 rect.origin.x = window->x;
341 } 341 }
342 if ((window->flags & SDL_WINDOW_FULLSCREEN) || 342 if (window->y == SDL_WINDOWPOS_CENTERED) {
343 window->y == SDL_WINDOWPOS_CENTERED) {
344 rect.origin.y = (CGDisplayPixelsHigh(kCGDirectMainDisplay) - window->h) / 2; 343 rect.origin.y = (CGDisplayPixelsHigh(kCGDirectMainDisplay) - window->h) / 2;
345 } else if (window->y == SDL_WINDOWPOS_UNDEFINED) { 344 } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
346 rect.origin.y = 0; 345 rect.origin.y = 0;
347 } else { 346 } else {
348 rect.origin.y = window->y; 347 rect.origin.y = window->y;
359 if (window->flags & SDL_WINDOW_RESIZABLE) { 358 if (window->flags & SDL_WINDOW_RESIZABLE) {
360 style |= NSResizableWindowMask; 359 style |= NSResizableWindowMask;
361 } 360 }
362 361
363 nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE]; 362 nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
364
365 if (window->flags & SDL_WINDOW_SHOWN) {
366 [nswindow makeKeyAndOrderFront:nil];
367 }
368 if (window->flags & SDL_WINDOW_MAXIMIZED) {
369 [nswindow performZoom:nil];
370 }
371 if (window->flags & SDL_WINDOW_MINIMIZED) {
372 [nswindow performMiniaturize:nil];
373 }
374
375 if (window->title) {
376 title = [[NSString alloc] initWithUTF8String:window->title];
377 [nswindow setTitle:title];
378 [nswindow setMiniwindowTitle:title];
379 [title release];
380 }
381 363
382 [pool release]; 364 [pool release];
383 365
384 if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) { 366 if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
385 [nswindow release]; 367 [nswindow release];
422 { 404 {
423 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 405 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
424 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; 406 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
425 NSString *string; 407 NSString *string;
426 408
427 string = [[NSString alloc] initWithUTF8String:window->title]; 409 if(window->title) {
410 string = [[NSString alloc] initWithUTF8String:window->title];
411 } else {
412 string = [[NSString alloc] init];
413 }
428 [nswindow setTitle:string]; 414 [nswindow setTitle:string];
429 [nswindow setMiniwindowTitle:string];
430 [string release]; 415 [string release];
416
431 [pool release]; 417 [pool release];
432 } 418 }
433 419
434 void 420 void
435 Cocoa_SetWindowPosition(_THIS, SDL_Window * window) 421 Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
465 Cocoa_ShowWindow(_THIS, SDL_Window * window) 451 Cocoa_ShowWindow(_THIS, SDL_Window * window)
466 { 452 {
467 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 453 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
468 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; 454 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
469 455
456 if (![nswindow isMiniaturized]) {
457 [nswindow makeKeyAndOrderFront:nil];
458 }
459 [pool release];
460 }
461
462 void
463 Cocoa_HideWindow(_THIS, SDL_Window * window)
464 {
465 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
466 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
467
468 [nswindow orderOut:nil];
469 [pool release];
470 }
471
472 void
473 Cocoa_RaiseWindow(_THIS, SDL_Window * window)
474 {
475 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
476 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
477
470 [nswindow makeKeyAndOrderFront:nil]; 478 [nswindow makeKeyAndOrderFront:nil];
471 [pool release]; 479 [pool release];
472 } 480 }
473 481
474 void 482 void
475 Cocoa_HideWindow(_THIS, SDL_Window * window)
476 {
477 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
478
479 /* FIXME */
480 }
481
482 void
483 Cocoa_RaiseWindow(_THIS, SDL_Window * window)
484 {
485 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
486 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
487
488 [nswindow makeKeyAndOrderFront:nil];
489 [pool release];
490 }
491
492 void
493 Cocoa_MaximizeWindow(_THIS, SDL_Window * window) 483 Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
494 { 484 {
495 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 485 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
496 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; 486 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
497 487
498 [nswindow performZoom:nil]; 488 [nswindow zoom:nil];
499 [pool release]; 489 [pool release];
500 } 490 }
501 491
502 void 492 void
503 Cocoa_MinimizeWindow(_THIS, SDL_Window * window) 493 Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
504 { 494 {
505 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 495 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
506 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; 496 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
507 497
508 [nswindow performMiniaturize:nil]; 498 [nswindow miniaturize:nil];
509 [pool release]; 499 [pool release];
510 } 500 }
511 501
512 void 502 void
513 Cocoa_RestoreWindow(_THIS, SDL_Window * window) 503 Cocoa_RestoreWindow(_THIS, SDL_Window * window)
514 { 504 {
515 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; 505 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
516 506 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
517 /* FIXME */ 507
508 if ([nswindow isMiniaturized]) {
509 [nswindow deminiaturize:nil];
510 } else if ([nswindow isZoomed]) {
511 [nswindow zoom:nil];
512 }
513 [pool release];
518 } 514 }
519 515
520 void 516 void
521 Cocoa_SetWindowGrab(_THIS, SDL_Window * window) 517 Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
522 { 518 {