Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoawindow.m @ 3530:e96be66e3673
The window position is display relative, at least for now...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 06 Dec 2009 08:39:01 +0000 |
parents | 09155ec3e291 |
children | 64ce267332c6 |
comparison
equal
deleted
inserted
replaced
3529:09155ec3e291 | 3530:e96be66e3673 |
---|---|
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_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; | 301 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
302 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; | |
302 SDL_WindowData *data; | 303 SDL_WindowData *data; |
303 | 304 |
304 /* Allocate the window data */ | 305 /* Allocate the window data */ |
305 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); | 306 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); |
306 if (!data) { | 307 if (!data) { |
319 data->listener = [[Cocoa_WindowListener alloc] init]; | 320 data->listener = [[Cocoa_WindowListener alloc] init]; |
320 [data->listener listen:data]; | 321 [data->listener listen:data]; |
321 | 322 |
322 /* Fill in the SDL window with the window data */ | 323 /* Fill in the SDL window with the window data */ |
323 { | 324 { |
325 SDL_Rect bounds; | |
324 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; | 326 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; |
325 ConvertNSRect(&rect); | 327 ConvertNSRect(&rect); |
326 window->x = (int)rect.origin.x; | 328 Cocoa_GetDisplayBounds(_this, display, &bounds); |
327 window->y = (int)rect.origin.y; | 329 window->x = (int)rect.origin.x - bounds.x; |
330 window->y = (int)rect.origin.y - bounds.y; | |
328 window->w = (int)rect.size.width; | 331 window->w = (int)rect.size.width; |
329 window->h = (int)rect.size.height; | 332 window->h = (int)rect.size.height; |
330 } | 333 } |
331 if ([nswindow isVisible]) { | 334 if ([nswindow isVisible]) { |
332 window->flags |= SDL_WINDOW_SHOWN; | 335 window->flags |= SDL_WINDOW_SHOWN; |
390 || window->x == SDL_WINDOWPOS_CENTERED) { | 393 || window->x == SDL_WINDOWPOS_CENTERED) { |
391 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; | 394 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; |
392 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { | 395 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { |
393 rect.origin.x = bounds.x; | 396 rect.origin.x = bounds.x; |
394 } else { | 397 } else { |
395 rect.origin.x = window->x; | 398 rect.origin.x = bounds.x + window->x; |
396 } | 399 } |
397 if ((window->flags & SDL_WINDOW_FULLSCREEN) | 400 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
398 || window->y == SDL_WINDOWPOS_CENTERED) { | 401 || window->y == SDL_WINDOWPOS_CENTERED) { |
399 rect.origin.y = bounds.y + (bounds.h - window->h) / 2; | 402 rect.origin.y = bounds.y + (bounds.h - window->h) / 2; |
400 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { | 403 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { |
401 rect.origin.y = bounds.y; | 404 rect.origin.y = bounds.y; |
402 } else { | 405 } else { |
403 rect.origin.y = window->y; | 406 rect.origin.y = bounds.y + window->y; |
404 } | 407 } |
405 rect.size.width = window->w; | 408 rect.size.width = window->w; |
406 rect.size.height = window->h; | 409 rect.size.height = window->h; |
407 ConvertNSRect(&rect); | 410 ConvertNSRect(&rect); |
408 | 411 |
494 Cocoa_GetDisplayBounds(_this, display, &bounds); | 497 Cocoa_GetDisplayBounds(_this, display, &bounds); |
495 if ((window->flags & SDL_WINDOW_FULLSCREEN) | 498 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
496 || window->x == SDL_WINDOWPOS_CENTERED) { | 499 || window->x == SDL_WINDOWPOS_CENTERED) { |
497 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; | 500 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; |
498 } else { | 501 } else { |
499 rect.origin.x = window->x; | 502 rect.origin.x = bounds.x + window->x; |
500 } | 503 } |
501 if ((window->flags & SDL_WINDOW_FULLSCREEN) | 504 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
502 || window->y == SDL_WINDOWPOS_CENTERED) { | 505 || window->y == SDL_WINDOWPOS_CENTERED) { |
503 rect.origin.y = bounds.y + (bounds.h - window->h) / 2; | 506 rect.origin.y = bounds.y + (bounds.h - window->h) / 2; |
504 } else { | 507 } else { |
505 rect.origin.y = window->y; | 508 rect.origin.y = bounds.y + window->y; |
506 } | 509 } |
507 rect.size.width = window->w; | 510 rect.size.width = window->w; |
508 rect.size.height = window->h; | 511 rect.size.height = window->h; |
509 ConvertNSRect(&rect); | 512 ConvertNSRect(&rect); |
510 rect = [nswindow frameRectForContentRect:rect]; | 513 rect = [nswindow frameRectForContentRect:rect]; |