1 module nudsfml.window.mouse;
2 
3 import bindbc.sfml.window;
4 import bindbc.sfml.system;
5 
6 import nudsfml.system.vector2;
7 import nudsfml.window.window;
8 
9 /**
10 * Give access to the real-time state of the mouse.
11 */
12 final abstract class Mouse {
13     /// Mouse buttons.
14     enum Button {
15         /// The left mouse button
16         Left,
17         /// The right mouse button
18         Right,
19         /// The middle (wheel) mouse button
20         Middle,
21         /// The first extra mouse button
22         XButton1,
23         /// The second extra mouse button
24         XButton2,
25 
26         ///Keep last -- the total number of mouse buttons
27         Count
28 
29     }
30 
31     /// Mouse wheels.
32     enum Wheel {
33         /// Vertically oriented mouse wheel
34         VerticalWheel,
35         /// Horizontally oriented mouse wheel
36         HorizontalWheel
37     }
38 
39     /**
40      * Set the current position of the mouse in desktop coordinates.
41      *
42      * This function sets the global position of the mouse cursor on the
43      * desktop.
44      *
45      * Params:
46      * 		position = New position of the mouse
47      */
48     static void setPosition(Vector2i position) {
49         sfVector2i pos = cast(sfVector2i) position;
50         sfMouse_setPosition(pos,null);
51     }
52 
53     /**
54      * Set the current position of the mouse in window coordinates.
55      *
56      * This function sets the current position of the mouse cursor, relative to the given window.
57      *
58      * Params:
59      * 		position   = New position of the mouse
60      * 		relativeTo = Reference window
61      */
62     static void setPosition(Vector2i position, const(Window) relativeTo) {
63         relativeTo.mouse_SetPosition(position);
64     }
65 
66     /**
67      * Get the current position of the mouse in desktop coordinates.
68      *
69      * This function returns the global position of the mouse cursor on the
70      * desktop.
71      *
72      * Returns: Current position of the mouse.
73      */
74     static Vector2i getPosition() {
75         Vector2i temp = cast(Vector2i) sfMouse_getPosition(null);
76 
77         return temp;
78     }
79 
80     /**
81      * Get the current position of the mouse in window coordinates.
82      *
83      * This function returns the current position of the mouse cursor, relative
84      * to the given window.
85      *
86      * Params:
87      *     relativeTo = Reference window
88      *
89      * Returns: Current position of the mouse.
90      */
91     static Vector2i getPosition(const(Window) relativeTo) {
92         return relativeTo.mouse_getPosition();
93     }
94 
95     /**
96      * Check if a mouse button is pressed.
97      *
98      * Params:
99      * 		button = Button to check
100      *
101      * Returns: true if the button is pressed, false otherwise.
102      */
103     static bool isButtonPressed(Button button) {
104         return (sfMouse_isButtonPressed(cast(sfMouseButton)button)) > 0;
105     }
106 }