comparison src/video/quartz/SDL_QuartzWM.m @ 272:d1447a846d80

Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST) From: Darrell Walisser <dwaliss1@purdue.edu> Subject: SDL Quartz video update -better mouse motion events -fixed minification bugs (except OpenGL) -fixed QZ_SetGamma for correct semantics -fade/unfade display before/after rez switch -experimental obscured-check/blind-copy code The obscured code, while it speeds up window drawing substantially, isn't ready yet. The reason is that there doesn't (yet) seem to be a way to know when the window is dragged or when the window suddenly comes to the foreground. Since Carbon windows seem to allow detection of such things, I suspect it is possible through some window server API. Cocoa(NSWindow) has no functions for such things, AFAIK.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 22 Jan 2002 18:46:28 +0000
parents 4125b9859c71
children 72acb06d3721
comparison
equal deleted inserted replaced
271:9631db4d9ee1 272:d1447a846d80
85 } 85 }
86 86
87 return 1; 87 return 1;
88 } 88 }
89 89
90 static void QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y) { 90 /**
91 91 * Coordinate conversion functions, for convenience
92 CGPoint p; 92 * Cocoa sets the origin at the lower left corner of the window/screen
93 93 * SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
94 /* We require absolute screen coordiates for our warp */ 94 * The routines were written so they could be called before SetVideoMode() has finished;
95 p.x = x; 95 * this might have limited usefulness at the moment, but the extra cost is trivial.
96 p.y = h - y; 96 **/
97 97
98 if ( fullscreen ) 98 /* Convert Cocoa screen coordinate to Cocoa window coordinate */
99 /* Already absolute coordinates */ 99 static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
100 CGDisplayMoveCursorToPoint(display_id, p); 100
101 *p = [ qz_window convertScreenToBase:*p ];
102 }
103
104
105 /* Convert Cocoa window coordinate to Cocoa screen coordinate */
106 static void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
107
108 *p = [ qz_window convertBaseToScreen:*p ];
109 }
110
111 /* Convert SDL coordinate to Cocoa coordinate */
112 static void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
113
114 int height;
115
116 if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
117
118 height = CGDisplayPixelsHigh (display_id);
119 }
101 else { 120 else {
102 /* Convert to absolute screen coordinates */ 121
103 NSPoint base, screen; 122 height = NSHeight ( [ qz_window frame ] );
104 base = NSMakePoint (p.x, p.y); 123 if ( [ qz_window styleMask ] & NSTitledWindowMask ) {
105 screen = [ qz_window convertBaseToScreen:base ]; 124
106 p.x = screen.x; 125 height -= 22;
107 p.y = device_height - screen.y; 126 }
108 CGDisplayMoveCursorToPoint (display_id, p); 127 }
109 } 128
110 } 129 p->y = height - p->y;
111 130 }
112 static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) { 131
113 132 /* Convert Cocoa coordinate to SDL coordinate */
133 static void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
134
135 QZ_PrivateSDLToCocoa (this, p);
136 }
137
138 /* Convert SDL coordinate to window server (CoreGraphics) coordinate */
139 static CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
140
141 CGPoint cgp;
142
143 if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
144
145 int height;
146
147 QZ_PrivateSDLToCocoa (this, p);
148 QZ_PrivateLocalToGlobal (this, p);
149
150 height = CGDisplayPixelsHigh (display_id);
151 p->y = height - p->y;
152 }
153
154 cgp.x = p->x;
155 cgp.y = p->y;
156
157 return cgp;
158 }
159
160 /* Convert window server (CoreGraphics) coordinate to SDL coordinate */
161 static void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
162
163 if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
164
165 int height;
166
167 /* Convert CG Global to Cocoa Global */
168 height = CGDisplayPixelsHigh (display_id);
169 p->y = height - p->y;
170
171 QZ_PrivateGlobalToLocal (this, p);
172 QZ_PrivateCocoaToSDL (this, p);
173 }
174 }
175
176 static void QZ_PrivateWarpCursor (_THIS, int x, int y) {
177
178 NSPoint p;
179 CGPoint cgp;
180
181 p = NSMakePoint (x, y);
182 cgp = QZ_PrivateSDLToCG (this, &p);
183 CGDisplayMoveCursorToPoint (display_id, cgp);
184 warp_ticks = SDL_GetTicks();
185 warp_flag = 1;
186 }
187
188 static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
189
114 /* Only allow warping when in foreground */ 190 /* Only allow warping when in foreground */
115 if ( ! inForeground ) 191 if ( ! inForeground )
116 return; 192 return;
117 193
118 /* Do the actual warp */ 194 /* Do the actual warp */
119 QZ_PrivateWarpCursor (this, SDL_VideoSurface->flags & SDL_FULLSCREEN, 195 QZ_PrivateWarpCursor (this, x, y);
120 SDL_VideoSurface->h, x, y);
121
122 /* Generate mouse moved event */
123 SDL_PrivateMouseMotion (SDL_RELEASED, 0, x, y);
124 } 196 }
125 197
126 static void QZ_MoveWMCursor (_THIS, int x, int y) { } 198 static void QZ_MoveWMCursor (_THIS, int x, int y) { }
127 static void QZ_CheckMouseMode (_THIS) { } 199 static void QZ_CheckMouseMode (_THIS) { }
128 200
197 else { 269 else {
198 SDL_SetError ("qz_window already iconified"); 270 SDL_SetError ("qz_window already iconified");
199 return 0; 271 return 0;
200 } 272 }
201 } 273 }
274 static int QZ_IconifyWindow (_THIS) {
275
276 if ( ! [ qz_window isMiniaturized ] ) {
277 [ qz_window miniaturize:nil ];
278 return 1;
279 }
280 else {
281 SDL_SetError ("Quartz window already iconified");
282 return 0;
283 }
284 }
202 285
203 /* 286 /*
204 static int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) { 287 static int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) {
205 info->nsWindowPtr = qz_window; 288 info->nsWindowPtr = qz_window;
206 return 0; 289 return 0;
219 QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); 302 QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
220 CGAssociateMouseAndMouseCursorPosition (0); 303 CGAssociateMouseAndMouseCursorPosition (0);
221 currentGrabMode = SDL_GRAB_ON; 304 currentGrabMode = SDL_GRAB_ON;
222 break; 305 break;
223 case SDL_GRAB_FULLSCREEN: 306 case SDL_GRAB_FULLSCREEN:
307
224 break; 308 break;
225 } 309 }
226 310
227 return currentGrabMode; 311 return currentGrabMode;
228 } 312 }