comparison src/video/quartz/SDL_QuartzEvents.m @ 4066:58a5055da431 SDL-1.2

More improvements for bug #373 Show the SDL cursor in the window and the arrow cursor outside the window. This is also supposed to show the SDL cursor when activated, but that code isn't working yet...
author Sam Lantinga <slouken@libsdl.org>
date Sat, 14 Jul 2007 08:27:06 +0000
parents 60f677630282
children b8f2db95145e
comparison
equal deleted inserted replaced
4065:0c76e6d1c3d6 4066:58a5055da431
621 QZ_PrivateCocoaToSDL (this, p); 621 QZ_PrivateCocoaToSDL (this, p);
622 } 622 }
623 623
624 void QZ_DoActivate (_THIS) { 624 void QZ_DoActivate (_THIS) {
625 625
626 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ? SDL_APPMOUSEFOCUS : 0)); 626 BOOL isInGameWin = QZ_IsMouseInWindow (this);
627 627
628 /* Hide the cursor if it was hidden by SDL_ShowCursor() */ 628 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (isInGameWin ? SDL_APPMOUSEFOCUS : 0));
629 if (!cursor_should_be_visible) 629
630 QZ_HideMouse (this); 630 /* Reset the cursor state */
631 /* FIXME: This doesn't currently work...
632 Apparently you can't set the cursor inside windowDidBecomeKey
633 */
634 if ( isInGameWin ) {
635 if (cursor_should_be_visible)
636 SDL_SetCursor (NULL);
637 else
638 QZ_HideMouse (this);
639 } else {
640 QZ_ShowMouse (this, [NSCursor arrowCursor]);
641 }
631 642
632 /* Regrab input, only if it was previously grabbed */ 643 /* Regrab input, only if it was previously grabbed */
633 if ( current_grab_mode == SDL_GRAB_ON ) { 644 if ( current_grab_mode == SDL_GRAB_ON ) {
634 645
635 /* Restore cursor location if input was grabbed */ 646 /* Restore cursor location if input was grabbed */
654 /* Reassociate mouse and cursor */ 665 /* Reassociate mouse and cursor */
655 CGAssociateMouseAndMouseCursorPosition (1); 666 CGAssociateMouseAndMouseCursorPosition (1);
656 667
657 /* Show the cursor if it was hidden by SDL_ShowCursor() */ 668 /* Show the cursor if it was hidden by SDL_ShowCursor() */
658 if (!cursor_should_be_visible) 669 if (!cursor_should_be_visible)
659 QZ_ShowMouse (this); 670 QZ_ShowMouse (this, [NSCursor arrowCursor]);
660 } 671 }
661 672
662 void QZ_SleepNotificationHandler (void * refcon, 673 void QZ_SleepNotificationHandler (void * refcon,
663 io_service_t service, 674 io_service_t service,
664 natural_t messageType, 675 natural_t messageType,
868 /* 879 /*
869 Handle grab input+cursor visible by warping the cursor back 880 Handle grab input+cursor visible by warping the cursor back
870 into the game window. This still generates a mouse moved event, 881 into the game window. This still generates a mouse moved event,
871 but not as a result of the warp (so it's in the right direction). 882 but not as a result of the warp (so it's in the right direction).
872 */ 883 */
873 if ( grab_state == QZ_VISIBLE_GRAB && 884 if ( grab_state == QZ_VISIBLE_GRAB && !isInGameWin ) {
874 !isInGameWin ) {
875 885
876 NSPoint p; 886 NSPoint p;
877 QZ_GetMouseLocation (this, &p); 887 QZ_GetMouseLocation (this, &p);
878 888
879 if ( p.x < 0.0 ) 889 if ( p.x < 0.0 )
907 now, handle the condition more gracefully than 917 now, handle the condition more gracefully than
908 before by reassociating cursor and mouse until the 918 before by reassociating cursor and mouse until the
909 cursor enters the window again, making it obvious 919 cursor enters the window again, making it obvious
910 to the user that the grab is broken.*/ 920 to the user that the grab is broken.*/
911 CGAssociateMouseAndMouseCursorPosition (1); 921 CGAssociateMouseAndMouseCursorPosition (1);
912 if (!cursor_should_be_visible) 922
913 QZ_ShowMouse (this); 923 QZ_ShowMouse (this, [NSCursor arrowCursor]);
914 } 924 }
915 else 925 else
916 if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { 926 if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) {
917 927
918 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 928 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
919 if (!cursor_should_be_visible) 929
930 if (cursor_should_be_visible) {
931 SDL_SetCursor (NULL);
932 } else {
920 QZ_HideMouse (this); 933 QZ_HideMouse (this);
934 }
935
921 if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/ 936 if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/
922 QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); 937 QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
923 CGAssociateMouseAndMouseCursorPosition (0); 938 CGAssociateMouseAndMouseCursorPosition (0);
924 } 939 }
925 } 940 }