comparison src/video/cocoa/SDL_cocoawindow.m @ 4465:3e69e077cb95

Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API. Plus, this lets me start implementing cursor support.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 09 May 2010 20:47:22 -0700
parents 6512cba48440
children 9322f7db8603
comparison
equal deleted inserted replaced
4464:fa77a6429698 4465:3e69e077cb95
124 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0); 124 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
125 } 125 }
126 126
127 - (void)windowDidBecomeKey:(NSNotification *)aNotification 127 - (void)windowDidBecomeKey:(NSNotification *)aNotification
128 { 128 {
129 int index;
130
131 /* We're going to get keyboard events, since we're key. */ 129 /* We're going to get keyboard events, since we're key. */
132 index = _data->videodata->keyboard; 130 SDL_SetKeyboardFocus(_data->window);
133 SDL_SetKeyboardFocus(index, _data->window);
134 } 131 }
135 132
136 - (void)windowDidResignKey:(NSNotification *)aNotification 133 - (void)windowDidResignKey:(NSNotification *)aNotification
137 { 134 {
138 int index;
139 SDL_Mouse *mouse;
140
141 /* Some other window will get mouse events, since we're not key. */ 135 /* Some other window will get mouse events, since we're not key. */
142 index = _data->videodata->mouse; 136 if (SDL_GetMouseFocus() == _data->window) {
143 mouse = SDL_GetMouse(index); 137 SDL_SetMouseFocus(NULL);
144 if (mouse->focus == _data->window) {
145 SDL_SetMouseFocus(index, 0);
146 } 138 }
147 139
148 /* Some other window will get keyboard events, since we're not key. */ 140 /* Some other window will get keyboard events, since we're not key. */
149 index = _data->videodata->keyboard; 141 if (SDL_GetKeyboardFocus() == _data->window) {
150 SDL_SetKeyboardFocus(index, 0); 142 SDL_SetKeyboardFocus(NULL);
143 }
151 } 144 }
152 145
153 - (void)windowDidHide:(NSNotification *)aNotification 146 - (void)windowDidHide:(NSNotification *)aNotification
154 { 147 {
155 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0); 148 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
160 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); 153 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
161 } 154 }
162 155
163 - (void)mouseDown:(NSEvent *)theEvent 156 - (void)mouseDown:(NSEvent *)theEvent
164 { 157 {
165 int index;
166 int button; 158 int button;
167 159
168 index = _data->videodata->mouse;
169 switch ([theEvent buttonNumber]) { 160 switch ([theEvent buttonNumber]) {
170 case 0: 161 case 0:
171 button = SDL_BUTTON_LEFT; 162 button = SDL_BUTTON_LEFT;
172 break; 163 break;
173 case 1: 164 case 1:
178 break; 169 break;
179 default: 170 default:
180 button = [theEvent buttonNumber]; 171 button = [theEvent buttonNumber];
181 break; 172 break;
182 } 173 }
183 SDL_SendMouseButton(index, SDL_PRESSED, button); 174 SDL_SendMouseButton(SDL_PRESSED, button);
184 } 175 }
185 176
186 - (void)rightMouseDown:(NSEvent *)theEvent 177 - (void)rightMouseDown:(NSEvent *)theEvent
187 { 178 {
188 [self mouseDown:theEvent]; 179 [self mouseDown:theEvent];
193 [self mouseDown:theEvent]; 184 [self mouseDown:theEvent];
194 } 185 }
195 186
196 - (void)mouseUp:(NSEvent *)theEvent 187 - (void)mouseUp:(NSEvent *)theEvent
197 { 188 {
198 int index;
199 int button; 189 int button;
200 190
201 index = _data->videodata->mouse;
202 switch ([theEvent buttonNumber]) { 191 switch ([theEvent buttonNumber]) {
203 case 0: 192 case 0:
204 button = SDL_BUTTON_LEFT; 193 button = SDL_BUTTON_LEFT;
205 break; 194 break;
206 case 1: 195 case 1:
211 break; 200 break;
212 default: 201 default:
213 button = [theEvent buttonNumber]; 202 button = [theEvent buttonNumber];
214 break; 203 break;
215 } 204 }
216 SDL_SendMouseButton(index, SDL_RELEASED, button); 205 SDL_SendMouseButton(SDL_RELEASED, button);
217 } 206 }
218 207
219 - (void)rightMouseUp:(NSEvent *)theEvent 208 - (void)rightMouseUp:(NSEvent *)theEvent
220 { 209 {
221 [self mouseUp:theEvent]; 210 [self mouseUp:theEvent];
227 } 216 }
228 217
229 - (void)mouseMoved:(NSEvent *)theEvent 218 - (void)mouseMoved:(NSEvent *)theEvent
230 { 219 {
231 SDL_Window *window = _data->window; 220 SDL_Window *window = _data->window;
232 int index;
233 SDL_Mouse *mouse;
234 NSPoint point; 221 NSPoint point;
235 222
236 index = _data->videodata->mouse;
237 mouse = SDL_GetMouse(index);
238 point = [theEvent locationInWindow]; 223 point = [theEvent locationInWindow];
239 point.y = window->h - point.y; 224 point.y = window->h - point.y;
240 if ( point.x < 0 || point.x >= window->w || 225 if ( point.x < 0 || point.x >= window->w ||
241 point.y < 0 || point.y >= window->h ) { 226 point.y < 0 || point.y >= window->h ) {
242 if (mouse->focus != 0) { 227 if (SDL_GetMouseFocus() == window) {
243 SDL_SetMouseFocus(index, 0); 228 SDL_SetMouseFocus(NULL);
244 } 229 }
245 } else { 230 } else {
246 if (mouse->focus != _data->window) { 231 SDL_SetMouseFocus(_data->window);
247 SDL_SetMouseFocus(index, _data->window); 232 SDL_SendMouseMotion(0, (int)point.x, (int)point.y);
248 }
249 SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y, 0);
250 } 233 }
251 } 234 }
252 235
253 - (void)mouseDragged:(NSEvent *)theEvent 236 - (void)mouseDragged:(NSEvent *)theEvent
254 { 237 {
265 [self mouseMoved:theEvent]; 248 [self mouseMoved:theEvent];
266 } 249 }
267 250
268 - (void)scrollWheel:(NSEvent *)theEvent 251 - (void)scrollWheel:(NSEvent *)theEvent
269 { 252 {
270 int index; 253 SDL_SendMouseWheel((int)([theEvent deltaX]+0.9f), (int)([theEvent deltaY]+0.9f));
271
272 index = _data->videodata->mouse;
273 SDL_SendMouseWheel(index, (int)([theEvent deltaX]+0.9f), (int)([theEvent deltaY]+0.9f));
274 } 254 }
275 255
276 @end 256 @end
277 257
278 @interface SDLWindow : NSWindow 258 @interface SDLWindow : NSWindow
359 window->flags |= SDL_WINDOW_MINIMIZED; 339 window->flags |= SDL_WINDOW_MINIMIZED;
360 } else { 340 } else {
361 window->flags &= ~SDL_WINDOW_MINIMIZED; 341 window->flags &= ~SDL_WINDOW_MINIMIZED;
362 } 342 }
363 if ([nswindow isKeyWindow]) { 343 if ([nswindow isKeyWindow]) {
364 int index = data->videodata->keyboard;
365 window->flags |= SDL_WINDOW_INPUT_FOCUS; 344 window->flags |= SDL_WINDOW_INPUT_FOCUS;
366 SDL_SetKeyboardFocus(index, data->window); 345 SDL_SetKeyboardFocus(data->window);
367 346
368 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { 347 if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
369 /* FIXME */ 348 /* FIXME */
370 } 349 }
371 } 350 }
383 NSWindow *nswindow; 362 NSWindow *nswindow;
384 SDL_VideoDisplay *display = window->display; 363 SDL_VideoDisplay *display = window->display;
385 NSRect rect; 364 NSRect rect;
386 SDL_Rect bounds; 365 SDL_Rect bounds;
387 unsigned int style; 366 unsigned int style;
388 NSString *title;
389 int status;
390 367
391 Cocoa_GetDisplayBounds(_this, display, &bounds); 368 Cocoa_GetDisplayBounds(_this, display, &bounds);
392 if ((window->flags & SDL_WINDOW_FULLSCREEN) 369 if ((window->flags & SDL_WINDOW_FULLSCREEN)
393 || window->x == SDL_WINDOWPOS_CENTERED) { 370 || window->x == SDL_WINDOWPOS_CENTERED) {
394 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; 371 rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
450 Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) 427 Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
451 { 428 {
452 NSAutoreleasePool *pool; 429 NSAutoreleasePool *pool;
453 NSWindow *nswindow = (NSWindow *) data; 430 NSWindow *nswindow = (NSWindow *) data;
454 NSString *title; 431 NSString *title;
455 int status;
456 432
457 pool = [[NSAutoreleasePool alloc] init]; 433 pool = [[NSAutoreleasePool alloc] init];
458 434
459 /* Query the title from the existing window */ 435 /* Query the title from the existing window */
460 title = [nswindow title]; 436 title = [nswindow title];
623 } 599 }
624 600
625 SDL_bool 601 SDL_bool
626 Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) 602 Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
627 { 603 {
628 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; 604 //NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
629 605
630 if (info->version.major <= SDL_MAJOR_VERSION) { 606 if (info->version.major <= SDL_MAJOR_VERSION) {
631 //info->window = nswindow; 607 //info->window = nswindow;
632 return SDL_TRUE; 608 return SDL_TRUE;
633 } else { 609 } else {