comparison src/video/quartz/SDL_QuartzEvents.m @ 782:dbc5905402b0

*** empty log message ***
author Sam Lantinga <slouken@libsdl.org>
date Sun, 11 Jan 2004 21:43:13 +0000
parents 68c8da837fc0
children 428f688f2ad2
comparison
equal deleted inserted replaced
781:67176351a1b8 782:dbc5905402b0
301 } 301 }
302 302
303 current_mods = newMods; 303 current_mods = newMods;
304 } 304 }
305 305
306 static void QZ_GetMouseLocation (_THIS, NSPoint *p) {
307 *p = [ NSEvent mouseLocation ]; /* global coordinates */
308 if (qz_window)
309 QZ_PrivateGlobalToLocal (this, p);
310 QZ_PrivateCocoaToSDL (this, p);
311 }
312
306 static void QZ_DoActivate (_THIS) 313 static void QZ_DoActivate (_THIS)
307 { 314 {
308 /* Hide the cursor if it was hidden by SDL_ShowCursor() */ 315 /* Hide the cursor if it was hidden by SDL_ShowCursor() */
309 if (!cursor_should_be_visible) 316 if (!cursor_should_be_visible)
310 QZ_HideMouse (this); 317 QZ_HideMouse (this);
319 } 326 }
320 327
321 static void QZ_DoDeactivate (_THIS) { 328 static void QZ_DoDeactivate (_THIS) {
322 329
323 /* Get the current cursor location, for restore on activate */ 330 /* Get the current cursor location, for restore on activate */
324 cursor_loc = [ NSEvent mouseLocation ]; /* global coordinates */ 331 QZ_GetMouseLocation (this, &cursor_loc);
325 if (qz_window)
326 QZ_PrivateGlobalToLocal (this, &cursor_loc);
327 QZ_PrivateCocoaToSDL (this, &cursor_loc);
328 332
329 /* Reassociate mouse and cursor */ 333 /* Reassociate mouse and cursor */
330 CGAssociateMouseAndMouseCursorPosition (1); 334 CGAssociateMouseAndMouseCursorPosition (1);
331 335
332 /* Show the cursor if it was hidden by SDL_ShowCursor() */ 336 /* Show the cursor if it was hidden by SDL_ShowCursor() */
430 inMode: NSDefaultRunLoopMode dequeue:YES ]; 434 inMode: NSDefaultRunLoopMode dequeue:YES ];
431 if (event != nil) { 435 if (event != nil) {
432 436
433 int button; 437 int button;
434 unsigned int type; 438 unsigned int type;
435 BOOL isForGameWin;
436 BOOL isInGameWin; 439 BOOL isInGameWin;
437 440
438 #define DO_MOUSE_DOWN(button) do { \ 441 #define DO_MOUSE_DOWN(button) do { \
439 if ( [ NSApp isActive ] ) { \ 442 if ( [ NSApp isActive ] ) { \
440 if ( isInGameWin ) { \ 443 if ( isInGameWin ) { \
455 } \ 458 } \
456 [ NSApp sendEvent:event ]; \ 459 [ NSApp sendEvent:event ]; \
457 } while(0) 460 } while(0)
458 461
459 type = [ event type ]; 462 type = [ event type ];
460 isForGameWin = (qz_window == [ event window ]);
461 isInGameWin = QZ_IsMouseInWindow (this); 463 isInGameWin = QZ_IsMouseInWindow (this);
464
462 switch (type) { 465 switch (type) {
463 case NSLeftMouseDown: 466 case NSLeftMouseDown:
464 if ( getenv("SDL_HAS3BUTTONMOUSE") ) { 467 if ( getenv("SDL_HAS3BUTTONMOUSE") ) {
465 DO_MOUSE_DOWN (SDL_BUTTON_LEFT); 468 DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
466 } else { 469 } else {
532 use absolute coordinates, this serves to 535 use absolute coordinates, this serves to
533 compensate any inaccuracy in deltas, and 536 compensate any inaccuracy in deltas, and
534 provides the first known mouse position, 537 provides the first known mouse position,
535 since everything after this uses deltas 538 since everything after this uses deltas
536 */ 539 */
537 NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ]; 540 NSPoint p;
538 QZ_PrivateCocoaToSDL (this, &p); 541 QZ_GetMouseLocation (this, &p);
539 SDL_PrivateMouseMotion (0, 0, p.x, p.y); 542 SDL_PrivateMouseMotion (0, 0, p.x, p.y);
540 firstMouseEvent = 0; 543 firstMouseEvent = 0;
541 } 544 }
542 else { 545 else {
543 546
544 /* 547 /*
545 Get the amount moved since the last drag or move event, 548 Get the amount moved since the last drag or move event,
546 add it on for one big move event at the end. 549 add it on for one big move event at the end.
555 but not as a result of the warp (so it's in the right direction). 558 but not as a result of the warp (so it's in the right direction).
556 */ 559 */
557 if ( grab_state == QZ_VISIBLE_GRAB && 560 if ( grab_state == QZ_VISIBLE_GRAB &&
558 !isInGameWin ) { 561 !isInGameWin ) {
559 562
560 NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ]; 563 NSPoint p;
561 QZ_PrivateCocoaToSDL (this, &p); 564 QZ_GetMouseLocation (this, &p);
562 565
563 if ( p.x < 0.0 ) 566 if ( p.x < 0.0 )
564 p.x = 0.0; 567 p.x = 0.0;
565 568
566 if ( p.y < 0.0 ) 569 if ( p.y < 0.0 )