comparison src/video/quartz/SDL_QuartzWM.m @ 4070:b8f2db95145e SDL-1.2

Patch from Christian Walther Yes, the idea to use a cursor rectangle instead of [NSCursor set] has occurred to me too, and it does seem to be the most elegant way. Here's my attempt at an implementation
author Sam Lantinga <slouken@libsdl.org>
date Sun, 15 Jul 2007 15:58:00 +0000
parents 58a5055da431
children cb7b118b400a
comparison
equal deleted inserted replaced
4069:f19931785c42 4070:b8f2db95145e
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include "SDL_QuartzVideo.h" 24 #include "SDL_QuartzVideo.h"
25 25 #include "SDL_QuartzWM.h"
26 26
27 struct WMcursor {
28 NSCursor *nscursor;
29 };
30 27
31 void QZ_FreeWMCursor (_THIS, WMcursor *cursor) { 28 void QZ_FreeWMCursor (_THIS, WMcursor *cursor) {
32 29
33 if ( cursor != NULL ) { 30 if ( cursor != NULL ) {
34 [ cursor->nscursor release ]; 31 [ cursor->nscursor release ];
88 if (cursor != NULL) SDL_free(cursor); 85 if (cursor != NULL) SDL_free(cursor);
89 SDL_OutOfMemory(); 86 SDL_OutOfMemory();
90 return(NULL); 87 return(NULL);
91 } 88 }
92 89
93 void QZ_ShowMouse (_THIS, NSCursor *cursor) { 90 void QZ_UpdateCursor (_THIS) {
94 if (!cursor_visible) { 91 BOOL state;
95 [ NSCursor unhide ]; 92
96 cursor_visible = YES; 93 if (cursor_should_be_visible || !(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
97 } 94 state = YES;
98 [ cursor set ]; 95 } else {
99 } 96 state = NO;
100 97 }
101 void QZ_HideMouse (_THIS) { 98 if (state != cursor_visible) {
102 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) { 99 if (state) {
103 [ NSCursor hide ]; 100 [ NSCursor unhide ];
104 cursor_visible = NO; 101 } else {
102 [ NSCursor hide ];
103 }
104 cursor_visible = state;
105 } 105 }
106 } 106 }
107 107
108 BOOL QZ_IsMouseInWindow (_THIS) { 108 BOOL QZ_IsMouseInWindow (_THIS) {
109 if (qz_window == nil || (mode_flags & SDL_FULLSCREEN)) return YES; /*fullscreen*/ 109 if (qz_window == nil || (mode_flags & SDL_FULLSCREEN)) return YES; /*fullscreen*/
115 } 115 }
116 116
117 int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 117 int QZ_ShowWMCursor (_THIS, WMcursor *cursor) {
118 118
119 if ( cursor == NULL) { 119 if ( cursor == NULL) {
120 QZ_HideMouse (this);
121 if ( cursor_should_be_visible ) { 120 if ( cursor_should_be_visible ) {
122 cursor_should_be_visible = NO; 121 cursor_should_be_visible = NO;
123 QZ_ChangeGrabState (this, QZ_HIDECURSOR); 122 QZ_ChangeGrabState (this, QZ_HIDECURSOR);
124 } 123 }
125 } 124 QZ_UpdateCursor(this);
126 else { 125 }
127 QZ_ShowMouse (this, cursor->nscursor); 126 else {
127 if (qz_window ==nil || (mode_flags & SDL_FULLSCREEN)) {
128 [ cursor->nscursor set ];
129 }
130 else {
131 [ qz_window invalidateCursorRectsForView: [ qz_window contentView ] ];
132 }
128 if ( ! cursor_should_be_visible ) { 133 if ( ! cursor_should_be_visible ) {
129 cursor_should_be_visible = YES; 134 cursor_should_be_visible = YES;
130 QZ_ChangeGrabState (this, QZ_SHOWCURSOR); 135 QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
131 } 136 }
137 QZ_UpdateCursor(this);
132 } 138 }
133 139
134 return 1; 140 return 1;
135 } 141 }
136 142