comparison src/video/cocoa/SDL_cocoawindow.m @ 3507:3712547eac4f

The window positions are relative to the origin of the windowing system (upper left of the primary display). Fixed the mouse positions for windowed mouse movement.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Dec 2009 12:08:34 +0000
parents e829b6098435
children a12068b6f44f
comparison
equal deleted inserted replaced
3506:e829b6098435 3507:3712547eac4f
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 disp = CGDisplayBounds(_data->display);
102 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]]; 101 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
103 ConvertNSRect(&rect); 102 ConvertNSRect(&rect);
104 x = (int)rect.origin.x - disp.origin.x; 103 x = (int)rect.origin.x;
105 y = (int)rect.origin.y - disp.origin.y; 104 y = (int)rect.origin.y;
106 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MOVED, x, y); 105 SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MOVED, x, y);
107 } 106 }
108 107
109 - (void)windowDidResize:(NSNotification *)aNotification 108 - (void)windowDidResize:(NSNotification *)aNotification
110 { 109 {
243 rect.size.width = CGDisplayPixelsWide(kCGDirectMainDisplay); 242 rect.size.width = CGDisplayPixelsWide(kCGDirectMainDisplay);
244 rect.size.height = CGDisplayPixelsHigh(kCGDirectMainDisplay); 243 rect.size.height = CGDisplayPixelsHigh(kCGDirectMainDisplay);
245 point.x = point.x - rect.origin.x; 244 point.x = point.x - rect.origin.x;
246 point.y = rect.size.height - point.y; 245 point.y = rect.size.height - point.y;
247 } else { 246 } else {
248 rect = [_data->window contentRectForFrameRect:[_data->window frame]]; 247 point.x -= window->x;
249 point.y = rect.size.height - (point.y - rect.origin.y); 248 point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - window->y;
250 } 249 }
251 if ( point.x < 0 || point.x >= rect.size.width || 250 if ( point.x < 0 || point.x >= window->w ||
252 point.y < 0 || point.y >= rect.size.height ) { 251 point.y < 0 || point.y >= window->h ) {
253 if (mouse->focus != 0) { 252 if (mouse->focus != 0) {
254 SDL_SetMouseFocus(index, 0); 253 SDL_SetMouseFocus(index, 0);
255 } 254 }
256 } else { 255 } else {
257 if (mouse->focus != _data->windowID) { 256 if (mouse->focus != _data->windowID) {
330 data->listener = [[Cocoa_WindowListener alloc] init]; 329 data->listener = [[Cocoa_WindowListener alloc] init];
331 [data->listener listen:data]; 330 [data->listener listen:data];
332 331
333 /* Fill in the SDL window with the window data */ 332 /* Fill in the SDL window with the window data */
334 { 333 {
335 NSRect disp = CGDisplayBounds(data->display);
336 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; 334 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
337 ConvertNSRect(&rect); 335 ConvertNSRect(&rect);
338 window->x = (int)rect.origin.x - disp.origin.x; 336 window->x = (int)rect.origin.x;
339 window->y = (int)rect.origin.y - disp.origin.y; 337 window->y = (int)rect.origin.y;
340 window->w = (int)rect.size.width; 338 window->w = (int)rect.size.width;
341 window->h = (int)rect.size.height; 339 window->h = (int)rect.size.height;
342 } 340 }
343 if ([nswindow isVisible]) { 341 if ([nswindow isVisible]) {
344 window->flags |= SDL_WINDOW_SHOWN; 342 window->flags |= SDL_WINDOW_SHOWN;
399 rect = CGDisplayBounds(displaydata->display); 397 rect = CGDisplayBounds(displaydata->display);
400 if ((window->flags & SDL_WINDOW_FULLSCREEN) 398 if ((window->flags & SDL_WINDOW_FULLSCREEN)
401 || window->x == SDL_WINDOWPOS_CENTERED) { 399 || window->x == SDL_WINDOWPOS_CENTERED) {
402 rect.origin.x += (rect.size.width - window->w) / 2; 400 rect.origin.x += (rect.size.width - window->w) / 2;
403 } else if (window->x != SDL_WINDOWPOS_UNDEFINED) { 401 } else if (window->x != SDL_WINDOWPOS_UNDEFINED) {
404 rect.origin.x += window->x; 402 rect.origin.x = window->x;
405 } 403 }
406 if ((window->flags & SDL_WINDOW_FULLSCREEN) 404 if ((window->flags & SDL_WINDOW_FULLSCREEN)
407 || window->y == SDL_WINDOWPOS_CENTERED) { 405 || window->y == SDL_WINDOWPOS_CENTERED) {
408 rect.origin.y += (rect.size.height - window->h) / 2; 406 rect.origin.y += (rect.size.height - window->h) / 2;
409 } else if (window->x != SDL_WINDOWPOS_UNDEFINED) { 407 } else if (window->x != SDL_WINDOWPOS_UNDEFINED) {
410 rect.origin.y += window->y; 408 rect.origin.y = window->y;
411 } 409 }
412 rect.size.width = window->w; 410 rect.size.width = window->w;
413 rect.size.height = window->h; 411 rect.size.height = window->h;
414 ConvertNSRect(&rect); 412 ConvertNSRect(&rect);
415 413
498 rect = CGDisplayBounds(displaydata->display); 496 rect = CGDisplayBounds(displaydata->display);
499 if ((window->flags & SDL_WINDOW_FULLSCREEN) 497 if ((window->flags & SDL_WINDOW_FULLSCREEN)
500 || window->x == SDL_WINDOWPOS_CENTERED) { 498 || window->x == SDL_WINDOWPOS_CENTERED) {
501 rect.origin.x += (rect.size.width - window->w) / 2; 499 rect.origin.x += (rect.size.width - window->w) / 2;
502 } else { 500 } else {
503 rect.origin.x += window->x; 501 rect.origin.x = window->x;
504 } 502 }
505 if ((window->flags & SDL_WINDOW_FULLSCREEN) 503 if ((window->flags & SDL_WINDOW_FULLSCREEN)
506 || window->y == SDL_WINDOWPOS_CENTERED) { 504 || window->y == SDL_WINDOWPOS_CENTERED) {
507 rect.origin.y += (rect.size.height - window->h) / 2; 505 rect.origin.y += (rect.size.height - window->h) / 2;
508 } else { 506 } else {
509 rect.origin.y += window->y; 507 rect.origin.y = window->y;
510 } 508 }
511 rect.size.width = window->w; 509 rect.size.width = window->w;
512 rect.size.height = window->h; 510 rect.size.height = window->h;
513 ConvertNSRect(&rect); 511 ConvertNSRect(&rect);
514 rect = [nswindow frameRectForContentRect:rect]; 512 rect = [nswindow frameRectForContentRect:rect];