src/events/SDL_mouse.c
changeset 8955 7a74b402790c
parent 8953 dc80dc0bd22e
child 8963 f94215b55583
     1.1 --- a/src/events/SDL_mouse.c	Wed Jun 25 17:13:43 2014 -0400
     1.2 +++ b/src/events/SDL_mouse.c	Wed Jun 25 17:20:22 2014 -0400
     1.3 @@ -614,6 +614,41 @@
     1.4      return mouse->relative_mode;
     1.5  }
     1.6  
     1.7 +int
     1.8 +SDL_CaptureMouse(SDL_bool enabled)
     1.9 +{
    1.10 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.11 +    SDL_Window *focusWindow;
    1.12 +    SDL_bool isCaptured;
    1.13 +
    1.14 +    if (!mouse->CaptureMouse) {
    1.15 +        return SDL_Unsupported();
    1.16 +    }
    1.17 +
    1.18 +    focusWindow = SDL_GetKeyboardFocus();
    1.19 +
    1.20 +    isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE);
    1.21 +    if (isCaptured == enabled) {
    1.22 +        return 0;  /* already done! */
    1.23 +    }
    1.24 +
    1.25 +    if (enabled) {
    1.26 +        if (!focusWindow) {
    1.27 +            return SDL_SetError("No window has focus");
    1.28 +        } else if (mouse->CaptureMouse(focusWindow) == -1) {
    1.29 +            return -1;  /* CaptureMouse() should call SetError */
    1.30 +        }
    1.31 +        focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
    1.32 +    } else {
    1.33 +        if (mouse->CaptureMouse(NULL) == -1) {
    1.34 +            return -1;  /* CaptureMouse() should call SetError */
    1.35 +        }
    1.36 +        focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
    1.37 +    }
    1.38 +
    1.39 +    return 0;
    1.40 +}
    1.41 +
    1.42  SDL_Cursor *
    1.43  SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
    1.44                   int w, int h, int hot_x, int hot_y)