138 /* Check to see if we need to synthesize focus events */ |
138 /* Check to see if we need to synthesize focus events */ |
139 static SDL_bool |
139 static SDL_bool |
140 SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate) |
140 SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate) |
141 { |
141 { |
142 SDL_Mouse *mouse = SDL_GetMouse(); |
142 SDL_Mouse *mouse = SDL_GetMouse(); |
143 int w, h; |
143 SDL_bool inWindow = SDL_TRUE; |
144 SDL_bool inWindow; |
144 |
145 |
145 if ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0) { |
146 SDL_GetWindowSize(window, &w, &h); |
146 int w, h; |
147 if (x < 0 || y < 0 || x >= w || y >= h) { |
147 SDL_GetWindowSize(window, &w, &h); |
148 inWindow = SDL_FALSE; |
148 if (x < 0 || y < 0 || x >= w || y >= h) { |
149 } else { |
149 inWindow = SDL_FALSE; |
150 inWindow = SDL_TRUE; |
150 } |
151 } |
151 } |
152 |
152 |
153 /* Linux doesn't give you mouse events outside your window unless you grab |
|
154 the pointer. |
|
155 |
|
156 Windows doesn't give you mouse events outside your window unless you call |
|
157 SetCapture(). |
|
158 |
|
159 Both of these are slightly scary changes, so for now we'll punt and if the |
|
160 mouse leaves the window you'll lose mouse focus and reset button state. |
|
161 */ |
|
162 #ifdef SUPPORT_DRAG_OUTSIDE_WINDOW |
|
163 if (!inWindow && !buttonstate) { |
|
164 #else |
|
165 if (!inWindow) { |
153 if (!inWindow) { |
166 #endif |
|
167 if (window == mouse->focus) { |
154 if (window == mouse->focus) { |
168 #ifdef DEBUG_MOUSE |
155 #ifdef DEBUG_MOUSE |
169 printf("Mouse left window, synthesizing move & focus lost event\n"); |
156 printf("Mouse left window, synthesizing move & focus lost event\n"); |
170 #endif |
157 #endif |
171 SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y); |
158 SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y); |
202 { |
189 { |
203 SDL_Mouse *mouse = SDL_GetMouse(); |
190 SDL_Mouse *mouse = SDL_GetMouse(); |
204 int posted; |
191 int posted; |
205 int xrel; |
192 int xrel; |
206 int yrel; |
193 int yrel; |
207 int x_max = 0, y_max = 0; |
|
208 |
194 |
209 if (mouse->relative_mode_warp) { |
195 if (mouse->relative_mode_warp) { |
210 int center_x = 0, center_y = 0; |
196 int center_x = 0, center_y = 0; |
211 SDL_GetWindowSize(window, ¢er_x, ¢er_y); |
197 SDL_GetWindowSize(window, ¢er_x, ¢er_y); |
212 center_x /= 2; |
198 center_x /= 2; |
244 } else { |
230 } else { |
245 mouse->x += xrel; |
231 mouse->x += xrel; |
246 mouse->y += yrel; |
232 mouse->y += yrel; |
247 } |
233 } |
248 |
234 |
249 /* !!! FIXME: shouldn't this be (window) instead of (mouse->focus)? */ |
235 /* make sure that the pointers find themselves inside the windows, |
250 SDL_GetWindowSize(mouse->focus, &x_max, &y_max); |
236 unless we have the mouse captured. */ |
251 --x_max; |
237 if ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0) { |
252 --y_max; |
238 int x_max = 0, y_max = 0; |
253 |
239 |
254 /* make sure that the pointers find themselves inside the windows */ |
240 // !!! FIXME: shouldn't this be (window) instead of (mouse->focus)? |
255 if (mouse->x > x_max) { |
241 SDL_GetWindowSize(mouse->focus, &x_max, &y_max); |
256 mouse->x = x_max; |
242 --x_max; |
257 } |
243 --y_max; |
258 if (mouse->x < 0) { |
244 |
259 mouse->x = 0; |
245 if (mouse->x > x_max) { |
260 } |
246 mouse->x = x_max; |
261 |
247 } |
262 if (mouse->y > y_max) { |
248 if (mouse->x < 0) { |
263 mouse->y = y_max; |
249 mouse->x = 0; |
264 } |
250 } |
265 if (mouse->y < 0) { |
251 |
266 mouse->y = 0; |
252 if (mouse->y > y_max) { |
|
253 mouse->y = y_max; |
|
254 } |
|
255 if (mouse->y < 0) { |
|
256 mouse->y = 0; |
|
257 } |
267 } |
258 } |
268 |
259 |
269 mouse->xdelta += xrel; |
260 mouse->xdelta += xrel; |
270 mouse->ydelta += yrel; |
261 mouse->ydelta += yrel; |
271 |
262 |
569 { |
561 { |
570 SDL_Mouse *mouse = SDL_GetMouse(); |
562 SDL_Mouse *mouse = SDL_GetMouse(); |
571 |
563 |
572 return mouse->relative_mode; |
564 return mouse->relative_mode; |
573 } |
565 } |
|
566 |
|
567 int |
|
568 SDL_CaptureMouse(SDL_bool enabled) |
|
569 { |
|
570 SDL_Mouse *mouse = SDL_GetMouse(); |
|
571 SDL_Window *focusWindow; |
|
572 SDL_bool isCaptured; |
|
573 |
|
574 if (!mouse->CaptureMouse) { |
|
575 return SDL_Unsupported(); |
|
576 } |
|
577 |
|
578 focusWindow = SDL_GetKeyboardFocus(); |
|
579 |
|
580 isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE); |
|
581 if (isCaptured == enabled) { |
|
582 return 0; /* already done! */ |
|
583 } |
|
584 |
|
585 if (enabled) { |
|
586 if (!focusWindow) { |
|
587 return SDL_SetError("No window has focus"); |
|
588 } else if (mouse->CaptureMouse(focusWindow) == -1) { |
|
589 return -1; /* CaptureMouse() should call SetError */ |
|
590 } |
|
591 focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE; |
|
592 } else { |
|
593 if (mouse->CaptureMouse(NULL) == -1) { |
|
594 return -1; /* CaptureMouse() should call SetError */ |
|
595 } |
|
596 focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE; |
|
597 } |
|
598 |
|
599 return 0; |
|
600 } |
|
601 |
574 |
602 |
575 SDL_Cursor * |
603 SDL_Cursor * |
576 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, |
604 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, |
577 int w, int h, int hot_x, int hot_y) |
605 int w, int h, int hot_x, int hot_y) |
578 { |
606 { |