GameKit  0.0.1a
C++ gamedev tools
Mouse.cpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Mouse.cpp
5  *
6  * Description:
7  *
8  * Created: 20/12/2014 15:39:17
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #include "gk/core/Mouse.hpp"
15 #include "gk/core/SDLHeaders.hpp"
16 
17 namespace gk {
18 
19 Window *Mouse::s_window = nullptr;
20 
22  SDL_WarpMouseInWindow(s_window->window(), s_window->getSize().x / 2, s_window->getSize().y / 2);
23 }
24 
25 void Mouse::setCursorGrabbed(bool grabbed) {
26  SDL_SetRelativeMouseMode((SDL_bool)grabbed);
27 }
28 
29 void Mouse::setCursorVisible(bool visible) {
30  SDL_ShowCursor(visible);
31 }
32 
34  Vector2i pos;
35  SDL_GetMouseState(&pos.x, &pos.y);
36  return pos;
37 }
38 
39 bool Mouse::isInRect(const IntRect &rect) {
40  return rect.contains(getPosition());
41 }
42 
43 } // namespace gk
44 
static Window * s_window
Definition: Mouse.hpp:36
static void resetToWindowCenter()
Definition: Mouse.cpp:21
static void setCursorVisible(bool isVisible)
Definition: Mouse.cpp:29
static bool isInRect(const IntRect &rect)
Definition: Mouse.cpp:39
SDL_Window * window() const
Definition: Window.hpp:40
bool contains(T _x, T _y) const
Check if a point is inside the rectangle&#39;s area.
Definition: Rect.hpp:96
static void setCursorGrabbed(bool isGrabbed)
Definition: Mouse.cpp:25
static Vector2i getPosition()
Definition: Mouse.cpp:33
Vector2u getSize() const override
Definition: Window.hpp:35