Merged Ryan's SDL-gui-backend branch.

Adds three APIs, and implements them on X11, Cocoa, and Windows:

- SDL_CaptureMouse()
- SDL_GetGlobalMouseState()
- SDL_SetWindowHitTest()
This commit is contained in:
Ryan C. Gordon
2014-06-25 17:06:12 -04:00
282 changed files with 30394 additions and 26689 deletions

View File

@@ -83,19 +83,6 @@ static struct
} SDL_EventQ = { NULL, SDL_TRUE };
static SDL_INLINE SDL_bool
SDL_ShouldPollJoystick()
{
#if !SDL_JOYSTICK_DISABLED
if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
SDL_JoystickEventState(SDL_QUERY)) &&
SDL_PrivateJoystickNeedsPolling()) {
return SDL_TRUE;
}
#endif
return SDL_FALSE;
}
/* Public functions */
void
@@ -315,7 +302,6 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
For now we'll guarantee it's valid at least until
the next call to SDL_PeepEvents()
*/
SDL_SysWMEntry *wmmsg;
if (SDL_EventQ.wmmsg_free) {
wmmsg = SDL_EventQ.wmmsg_free;
SDL_EventQ.wmmsg_free = wmmsg->next;
@@ -403,7 +389,7 @@ SDL_PumpEvents(void)
}
#if !SDL_JOYSTICK_DISABLED
/* Check for joystick state change */
if (SDL_ShouldPollJoystick()) {
if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
SDL_JoystickUpdate();
}
#endif
@@ -550,7 +536,7 @@ SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
void
SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
{
if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
if (SDL_EventQ.lock && SDL_LockMutex(SDL_EventQ.lock) == 0) {
SDL_EventEntry *entry, *next;
for (entry = SDL_EventQ.head; entry; entry = next) {
next = entry->next;

View File

@@ -473,7 +473,6 @@ static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
void SDL_GestureProcessEvent(SDL_Event* event)
{
float x,y;
SDL_FloatPoint path[DOLLARNPOINTS];
int index;
int i;
float pathDx, pathDy;
@@ -497,6 +496,8 @@ void SDL_GestureProcessEvent(SDL_Event* event)
/* Finger Up */
if (event->type == SDL_FINGERUP) {
SDL_FloatPoint path[DOLLARNPOINTS];
inTouch->numDownFingers--;
#ifdef ENABLE_DOLLAR

View File

@@ -150,7 +150,20 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
}
}
/* Linux doesn't give you mouse events outside your window unless you grab
the pointer.
Windows doesn't give you mouse events outside your window unless you call
SetCapture().
Both of these are slightly scary changes, so for now we'll punt and if the
mouse leaves the window you'll lose mouse focus and reset button state.
*/
#ifdef SUPPORT_DRAG_OUTSIDE_WINDOW
if (!inWindow && !buttonstate) {
#else
if (!inWindow) {
#endif
if (window == mouse->focus) {
#ifdef DEBUG_MOUSE
printf("Mouse left window, synthesizing move & focus lost event\n");
@@ -191,6 +204,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
int posted;
int xrel;
int yrel;
int x_max = 0, y_max = 0;
if (mouse->relative_mode_warp) {
int center_x = 0, center_y = 0;
@@ -498,11 +512,11 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
if ( window == NULL ) {
if (window == NULL) {
window = mouse->focus;
}
if ( window == NULL ) {
if (window == NULL) {
return;
}
@@ -513,6 +527,16 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
}
}
void
SDL_WarpMouseGlobal(int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->WarpMouseGlobal) {
mouse->WarpMouseGlobal(x, y);
}
}
static SDL_bool
ShouldUseRelativeModeWarp(SDL_Mouse *mouse)
{
@@ -590,42 +614,6 @@ SDL_GetRelativeMouseMode()
return mouse->relative_mode;
}
int
SDL_CaptureMouse(SDL_bool enabled)
{
SDL_Mouse *mouse = SDL_GetMouse();
SDL_Window *focusWindow;
SDL_bool isCaptured;
if (!mouse->CaptureMouse) {
return SDL_Unsupported();
}
focusWindow = SDL_GetKeyboardFocus();
isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE);
if (isCaptured == enabled) {
return 0; /* already done! */
}
if (enabled) {
if (!focusWindow) {
return SDL_SetError("No window has focus");
} else if (mouse->CaptureMouse(focusWindow) == -1) {
return -1; /* CaptureMouse() should call SetError */
}
focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
} else {
if (mouse->CaptureMouse(NULL) == -1) {
return -1; /* CaptureMouse() should call SetError */
}
focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
}
return 0;
}
SDL_Cursor *
SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
int w, int h, int hot_x, int hot_y)

View File

@@ -57,9 +57,12 @@ typedef struct
/* Free a window manager cursor */
void (*FreeCursor) (SDL_Cursor * cursor);
/* Warp the mouse to (x,y) */
/* Warp the mouse to (x,y) within a window */
void (*WarpMouse) (SDL_Window * window, int x, int y);
/* Warp the mouse to (x,y) in screen space */
void (*WarpMouseGlobal) (int x, int y);
/* Set relative mode */
int (*SetRelativeMouseMode) (SDL_bool enabled);