Commit 585eb48c authored by Sam Lantinga's avatar Sam Lantinga

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...

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402530
parent 73b9604f
...@@ -623,11 +623,22 @@ static void QZ_GetMouseLocation (_THIS, NSPoint *p) { ...@@ -623,11 +623,22 @@ static void QZ_GetMouseLocation (_THIS, NSPoint *p) {
void QZ_DoActivate (_THIS) { void QZ_DoActivate (_THIS) {
SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ? SDL_APPMOUSEFOCUS : 0)); BOOL isInGameWin = QZ_IsMouseInWindow (this);
/* Hide the cursor if it was hidden by SDL_ShowCursor() */ SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (isInGameWin ? SDL_APPMOUSEFOCUS : 0));
if (!cursor_should_be_visible)
QZ_HideMouse (this); /* Reset the cursor state */
/* FIXME: This doesn't currently work...
Apparently you can't set the cursor inside windowDidBecomeKey
*/
if ( isInGameWin ) {
if (cursor_should_be_visible)
SDL_SetCursor (NULL);
else
QZ_HideMouse (this);
} else {
QZ_ShowMouse (this, [NSCursor arrowCursor]);
}
/* Regrab input, only if it was previously grabbed */ /* Regrab input, only if it was previously grabbed */
if ( current_grab_mode == SDL_GRAB_ON ) { if ( current_grab_mode == SDL_GRAB_ON ) {
...@@ -656,7 +667,7 @@ void QZ_DoDeactivate (_THIS) { ...@@ -656,7 +667,7 @@ void QZ_DoDeactivate (_THIS) {
/* Show the cursor if it was hidden by SDL_ShowCursor() */ /* Show the cursor if it was hidden by SDL_ShowCursor() */
if (!cursor_should_be_visible) if (!cursor_should_be_visible)
QZ_ShowMouse (this); QZ_ShowMouse (this, [NSCursor arrowCursor]);
} }
void QZ_SleepNotificationHandler (void * refcon, void QZ_SleepNotificationHandler (void * refcon,
...@@ -870,8 +881,7 @@ void QZ_PumpEvents (_THIS) ...@@ -870,8 +881,7 @@ void QZ_PumpEvents (_THIS)
into the game window. This still generates a mouse moved event, into the game window. This still generates a mouse moved event,
but not as a result of the warp (so it's in the right direction). but not as a result of the warp (so it's in the right direction).
*/ */
if ( grab_state == QZ_VISIBLE_GRAB && if ( grab_state == QZ_VISIBLE_GRAB && !isInGameWin ) {
!isInGameWin ) {
NSPoint p; NSPoint p;
QZ_GetMouseLocation (this, &p); QZ_GetMouseLocation (this, &p);
...@@ -909,15 +919,20 @@ void QZ_PumpEvents (_THIS) ...@@ -909,15 +919,20 @@ void QZ_PumpEvents (_THIS)
cursor enters the window again, making it obvious cursor enters the window again, making it obvious
to the user that the grab is broken.*/ to the user that the grab is broken.*/
CGAssociateMouseAndMouseCursorPosition (1); CGAssociateMouseAndMouseCursorPosition (1);
if (!cursor_should_be_visible)
QZ_ShowMouse (this); QZ_ShowMouse (this, [NSCursor arrowCursor]);
} }
else else
if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) {
SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
if (!cursor_should_be_visible)
if (cursor_should_be_visible) {
SDL_SetCursor (NULL);
} else {
QZ_HideMouse (this); QZ_HideMouse (this);
}
if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/ if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/
QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
CGAssociateMouseAndMouseCursorPosition (0); CGAssociateMouseAndMouseCursorPosition (0);
......
...@@ -224,7 +224,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height, ...@@ -224,7 +224,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
void QZ_PrivateWarpCursor (_THIS, int x, int y); void QZ_PrivateWarpCursor (_THIS, int x, int y);
void QZ_ChangeGrabState (_THIS, int action); void QZ_ChangeGrabState (_THIS, int action);
void QZ_RegisterForSleepNotifications (_THIS); void QZ_RegisterForSleepNotifications (_THIS);
void QZ_ShowMouse (_THIS); void QZ_ShowMouse (_THIS, NSCursor *cursor);
void QZ_HideMouse (_THIS); void QZ_HideMouse (_THIS);
void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p); void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p);
void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p); void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p);
......
...@@ -90,11 +90,12 @@ outOfMemory: ...@@ -90,11 +90,12 @@ outOfMemory:
return(NULL); return(NULL);
} }
void QZ_ShowMouse (_THIS) { void QZ_ShowMouse (_THIS, NSCursor *cursor) {
if (!cursor_visible) { if (!cursor_visible) {
[ NSCursor unhide ]; [ NSCursor unhide ];
cursor_visible = YES; cursor_visible = YES;
} }
[ cursor set ];
} }
void QZ_HideMouse (_THIS) { void QZ_HideMouse (_THIS) {
...@@ -116,16 +117,15 @@ BOOL QZ_IsMouseInWindow (_THIS) { ...@@ -116,16 +117,15 @@ BOOL QZ_IsMouseInWindow (_THIS) {
int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { int QZ_ShowWMCursor (_THIS, WMcursor *cursor) {
if ( cursor == NULL) { if ( cursor == NULL) {
QZ_HideMouse (this);
if ( cursor_should_be_visible ) { if ( cursor_should_be_visible ) {
QZ_HideMouse (this);
cursor_should_be_visible = NO; cursor_should_be_visible = NO;
QZ_ChangeGrabState (this, QZ_HIDECURSOR); QZ_ChangeGrabState (this, QZ_HIDECURSOR);
} }
} }
else { else {
[ cursor->nscursor set ]; QZ_ShowMouse (this, cursor->nscursor);
if ( ! cursor_should_be_visible ) { if ( ! cursor_should_be_visible ) {
QZ_ShowMouse (this);
cursor_should_be_visible = YES; cursor_should_be_visible = YES;
QZ_ChangeGrabState (this, QZ_SHOWCURSOR); QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment