comparison src/video/cocoa/SDL_cocoawindow.m @ 2059:4685ccd33d0e

Fixed mouse enter/leave events for a single window. You lose mouse focus in Cocoa when the window is no longer key.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 28 Oct 2006 16:41:54 +0000
parents 81255f93dfcd
children 003c1b5b07da
comparison
equal deleted inserted replaced
2058:38148947fdcf 2059:4685ccd33d0e
127 127
128 - (void)windowDidBecomeKey:(NSNotification *)aNotification 128 - (void)windowDidBecomeKey:(NSNotification *)aNotification
129 { 129 {
130 int index; 130 int index;
131 131
132 /* We're going to get keyboard events, since we're key. */
132 index = _data->videodata->keyboard; 133 index = _data->videodata->keyboard;
133 SDL_SetKeyboardFocus(index, _data->windowID); 134 SDL_SetKeyboardFocus(index, _data->windowID);
134 } 135 }
135 136
136 - (void)windowDidResignKey:(NSNotification *)aNotification 137 - (void)windowDidResignKey:(NSNotification *)aNotification
137 { 138 {
138 int index; 139 int index;
139 140 SDL_Mouse *mouse;
141
142 /* Some other window will get mouse events, since we're not key. */
143 index = _data->videodata->mouse;
144 mouse = SDL_GetMouse(index);
145 if (mouse->focus == _data->windowID) {
146 SDL_SetMouseFocus(index, 0);
147 }
148
149 /* Some other window will get keyboard events, since we're not key. */
140 index = _data->videodata->keyboard; 150 index = _data->videodata->keyboard;
141 SDL_SetKeyboardFocus(index, 0); 151 SDL_SetKeyboardFocus(index, 0);
142 } 152 }
143 153
144 - (void)windowDidHide:(NSNotification *)aNotification 154 - (void)windowDidHide:(NSNotification *)aNotification
225 NSPoint point; 235 NSPoint point;
226 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]]; 236 NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]];
227 237
228 index = _data->videodata->mouse; 238 index = _data->videodata->mouse;
229 mouse = SDL_GetMouse(index); 239 mouse = SDL_GetMouse(index);
230 if (mouse->focus != _data->windowID) {
231 SDL_SetMouseFocus(index, _data->windowID);
232 }
233 240
234 point = [NSEvent mouseLocation]; 241 point = [NSEvent mouseLocation];
235 point.x = point.x - rect.origin.x; 242 point.x = point.x - rect.origin.x;
236 point.y = rect.size.height - (point.y - rect.origin.y); 243 point.y = rect.size.height - (point.y - rect.origin.y);
237 SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y); 244 if ( point.x < 0 || point.x >= rect.size.width ||
245 point.y < 0 || point.y >= rect.size.height ) {
246 if (mouse->focus != 0) {
247 SDL_SetMouseFocus(index, 0);
248 }
249 } else {
250 if (mouse->focus != _data->windowID) {
251 SDL_SetMouseFocus(index, _data->windowID);
252 }
253 SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
254 }
238 } 255 }
239 256
240 - (void)mouseDragged:(NSEvent *)theEvent 257 - (void)mouseDragged:(NSEvent *)theEvent
241 { 258 {
242 [self mouseMoved:theEvent]; 259 [self mouseMoved:theEvent];