comparison src/video/cocoa/SDL_cocoawindow.m @ 5251:58265e606e4e

Window coordinates are in the global space and windows are not tied to a particular display. Also added Ctrl-Enter keybinding to the test code to toggle fullscreen mode for testing.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 10 Feb 2011 14:44:25 -0800
parents 9e9940eae455
children 7a963be087ef
comparison
equal deleted inserted replaced
5250:329d435f97f4 5251:58265e606e4e
401 static int 401 static int
402 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) 402 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
403 { 403 {
404 NSAutoreleasePool *pool; 404 NSAutoreleasePool *pool;
405 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 405 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
406 SDL_VideoDisplay *display = window->display;
407 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
408 SDL_WindowData *data; 406 SDL_WindowData *data;
409 407
410 /* Allocate the window data */ 408 /* Allocate the window data */
411 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); 409 data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
412 if (!data) { 410 if (!data) {
414 return -1; 412 return -1;
415 } 413 }
416 data->window = window; 414 data->window = window;
417 data->nswindow = nswindow; 415 data->nswindow = nswindow;
418 data->created = created; 416 data->created = created;
419 data->display = displaydata->display;
420 data->videodata = videodata; 417 data->videodata = videodata;
421 418
422 pool = [[NSAutoreleasePool alloc] init]; 419 pool = [[NSAutoreleasePool alloc] init];
423 420
424 /* Create an event listener for the window */ 421 /* Create an event listener for the window */
436 #endif 433 #endif
437 [nswindow setContentView: contentView]; 434 [nswindow setContentView: contentView];
438 [contentView release]; 435 [contentView release];
439 436
440 ConvertNSRect(&rect); 437 ConvertNSRect(&rect);
441 Cocoa_GetDisplayBounds(_this, display, &bounds); 438 window->x = (int)rect.origin.x;
442 window->x = (int)rect.origin.x - bounds.x; 439 window->y = (int)rect.origin.y;
443 window->y = (int)rect.origin.y - bounds.y;
444 window->w = (int)rect.size.width; 440 window->w = (int)rect.size.width;
445 window->h = (int)rect.size.height; 441 window->h = (int)rect.size.height;
446 } 442 }
447 if ([nswindow isVisible]) { 443 if ([nswindow isVisible]) {
448 window->flags |= SDL_WINDOW_SHOWN; 444 window->flags |= SDL_WINDOW_SHOWN;
491 int 487 int
492 Cocoa_CreateWindow(_THIS, SDL_Window * window) 488 Cocoa_CreateWindow(_THIS, SDL_Window * window)
493 { 489 {
494 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 490 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
495 NSWindow *nswindow; 491 NSWindow *nswindow;
496 SDL_VideoDisplay *display = window->display; 492 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
497 NSRect rect; 493 NSRect rect;
498 SDL_Rect bounds; 494 SDL_Rect bounds;
499 unsigned int style; 495 unsigned int style;
500 496
501 Cocoa_GetDisplayBounds(_this, display, &bounds); 497 Cocoa_GetDisplayBounds(_this, display, &bounds);
502 if ((window->flags & SDL_WINDOW_FULLSCREEN) 498 if ((window->flags & SDL_WINDOW_FULLSCREEN)
503 || window->x == SDL_WINDOWPOS_CENTERED) { 499 || SDL_WINDOWPOS_ISCENTERED(window->x)) {
504 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; 500 rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
505 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 501 } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
506 rect.origin.x = bounds.x; 502 rect.origin.x = bounds.x;
507 } else { 503 } else {
508 rect.origin.x = bounds.x + window->x; 504 rect.origin.x = window->x;
509 } 505 }
510 if ((window->flags & SDL_WINDOW_FULLSCREEN) 506 if ((window->flags & SDL_WINDOW_FULLSCREEN)
511 || window->y == SDL_WINDOWPOS_CENTERED) { 507 || SDL_WINDOWPOS_ISCENTERED(window->y)) {
512 rect.origin.y = bounds.y + (bounds.h - window->h) / 2; 508 rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
513 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 509 } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
514 rect.origin.y = bounds.y; 510 rect.origin.y = bounds.y;
515 } else { 511 } else {
516 rect.origin.y = bounds.y + window->y; 512 rect.origin.y = window->y;
517 } 513 }
518 rect.size.width = window->w; 514 rect.size.width = window->w;
519 rect.size.height = window->h; 515 rect.size.height = window->h;
520 ConvertNSRect(&rect); 516 ConvertNSRect(&rect);
521 517
597 void 593 void
598 Cocoa_SetWindowPosition(_THIS, SDL_Window * window) 594 Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
599 { 595 {
600 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 596 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
601 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; 597 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
602 SDL_VideoDisplay *display = window->display; 598 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
603 NSRect rect; 599 NSRect rect;
604 SDL_Rect bounds; 600 SDL_Rect bounds;
605 601
606 Cocoa_GetDisplayBounds(_this, display, &bounds); 602 Cocoa_GetDisplayBounds(_this, display, &bounds);
607 if ((window->flags & SDL_WINDOW_FULLSCREEN) 603 if ((window->flags & SDL_WINDOW_FULLSCREEN)
608 || window->x == SDL_WINDOWPOS_CENTERED) { 604 || SDL_WINDOWPOS_ISCENTERED(window->x)) {
609 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; 605 rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
610 } else { 606 } else {
611 rect.origin.x = bounds.x + window->x; 607 rect.origin.x = window->x;
612 } 608 }
613 if ((window->flags & SDL_WINDOW_FULLSCREEN) 609 if ((window->flags & SDL_WINDOW_FULLSCREEN)
614 || window->y == SDL_WINDOWPOS_CENTERED) { 610 || SDL_WINDOWPOS_ISCENTERED(window->y)) {
615 rect.origin.y = bounds.y + (bounds.h - window->h) / 2; 611 rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
616 } else { 612 } else {
617 rect.origin.y = bounds.y + window->y; 613 rect.origin.y = window->y;
618 } 614 }
619 rect.size.width = window->w; 615 rect.size.width = window->w;
620 rect.size.height = window->h; 616 rect.size.height = window->h;
621 ConvertNSRect(&rect); 617 ConvertNSRect(&rect);
622 rect = [nswindow frameRectForContentRect:rect]; 618 rect = [nswindow frameRectForContentRect:rect];