comparison src/video/cocoa/SDL_cocoawindow.m @ 3528:59ff7a2beb57

Added an API function to query geometry of multiple monitors: SDL_GetDisplayBounds() Implemented multi-monitor window positions on Windows
author Sam Lantinga <slouken@libsdl.org>
date Sun, 06 Dec 2009 08:03:38 +0000
parents 455a6c47d2c6
children 09155ec3e291
comparison
equal deleted inserted replaced
3527:444cb12cadb6 3528:59ff7a2beb57
376 int 376 int
377 Cocoa_CreateWindow(_THIS, SDL_Window * window) 377 Cocoa_CreateWindow(_THIS, SDL_Window * window)
378 { 378 {
379 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 379 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
380 NSWindow *nswindow; 380 NSWindow *nswindow;
381 SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; 381 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
382 NSRect rect; 382 NSRect rect;
383 SDL_Rect bounds;
383 unsigned int style; 384 unsigned int style;
384 NSString *title; 385 NSString *title;
385 int status; 386 int status;
386 387
387 rect = Cocoa_DisplayBounds(displaydata->display); 388 Cocoa_GetDisplayBounds(_this, display, &bounds);
388 if ((window->flags & SDL_WINDOW_FULLSCREEN) 389 if ((window->flags & SDL_WINDOW_FULLSCREEN)
389 || window->x == SDL_WINDOWPOS_CENTERED) { 390 || window->x == SDL_WINDOWPOS_CENTERED) {
390 rect.origin.x += (rect.size.width - window->w) / 2; 391 rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
391 } else if (window->x != SDL_WINDOWPOS_UNDEFINED) { 392 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
393 rect.origin.x = bounds.x;
394 } else {
392 rect.origin.x = window->x; 395 rect.origin.x = window->x;
393 } 396 }
394 if ((window->flags & SDL_WINDOW_FULLSCREEN) 397 if ((window->flags & SDL_WINDOW_FULLSCREEN)
395 || window->y == SDL_WINDOWPOS_CENTERED) { 398 || window->y == SDL_WINDOWPOS_CENTERED) {
396 rect.origin.y += (rect.size.height - window->h) / 2; 399 rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
397 } else if (window->x != SDL_WINDOWPOS_UNDEFINED) { 400 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
401 rect.origin.y = bounds.y;
402 } else {
398 rect.origin.y = window->y; 403 rect.origin.y = window->y;
399 } 404 }
400 rect.size.width = window->w; 405 rect.size.width = window->w;
401 rect.size.height = window->h; 406 rect.size.height = window->h;
402 ConvertNSRect(&rect); 407 ConvertNSRect(&rect);
480 void 485 void
481 Cocoa_SetWindowPosition(_THIS, SDL_Window * window) 486 Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
482 { 487 {
483 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 488 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
484 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; 489 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
485 SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; 490 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
486 NSRect rect; 491 NSRect rect;
487 492 SDL_Rect bounds;
488 rect = Cocoa_DisplayBounds(displaydata->display); 493
494 Cocoa_GetDisplayBounds(_this, display, &bounds);
489 if ((window->flags & SDL_WINDOW_FULLSCREEN) 495 if ((window->flags & SDL_WINDOW_FULLSCREEN)
490 || window->x == SDL_WINDOWPOS_CENTERED) { 496 || window->x == SDL_WINDOWPOS_CENTERED) {
491 rect.origin.x += (rect.size.width - window->w) / 2; 497 rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
492 } else { 498 } else {
493 rect.origin.x = window->x; 499 rect.origin.x = window->x;
494 } 500 }
495 if ((window->flags & SDL_WINDOW_FULLSCREEN) 501 if ((window->flags & SDL_WINDOW_FULLSCREEN)
496 || window->y == SDL_WINDOWPOS_CENTERED) { 502 || window->y == SDL_WINDOWPOS_CENTERED) {
497 rect.origin.y += (rect.size.height - window->h) / 2; 503 rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
498 } else { 504 } else {
499 rect.origin.y = window->y; 505 rect.origin.y = window->y;
500 } 506 }
501 rect.size.width = window->w; 507 rect.size.width = window->w;
502 rect.size.height = window->h; 508 rect.size.height = window->h;