1 module nudsfml.window.event;
2 
3 import bindbc.sfml.window;
4 
5 import nudsfml.window.keyboard;
6 import nudsfml.window.mouse;
7 import nudsfml.window.sensor;
8 
9 /**
10  * Defines a system event and its parameters.
11  */
12 struct Event
13 {
14     /**
15     * Joystick buttons events parameters
16     * (JoystickButtonPressed, JoystickButtonReleased)
17     */
18     struct JoystickButtonEvent
19     {
20         /// Index of the joystick (in range [0 .. Joystick::Count - 1])
21         uint joystickId;
22 
23         /**
24          * Index of the button that has been pressed
25          * (in range [0 .. Joystick::ButtonCount - 1])
26          */
27         uint button;
28     }
29 
30     /**
31     * Joystick connection events parameters
32     * (JoystickConnected, JoystickDisconnected)
33     */
34     struct JoystickConnectEvent
35     {
36         /// Index of the joystick (in range [0 .. Joystick::Count - 1])
37         uint joystickId;
38     }
39 
40     /**
41      * Joystick connection events parameters
42      * (JoystickConnected, JoystickDisconnected)
43      */
44     struct JoystickMoveEvent
45     {
46         /// Index of the joystick (in range [0 .. Joystick::Count - 1])
47         uint joystickId;
48 
49         /// Axis on which the joystick moved
50         int axis;
51 
52         /// New position on the axis (in range [-100 .. 100])
53         float position;
54     }
55 
56     /**
57      * Keyboard event parameters (KeyPressed, KeyReleased)
58      */
59     struct KeyEvent
60     {
61         /// Code of the key that has been pressed.
62         Keyboard.Key code;
63 
64         /// Is the Alt key pressed?
65         bool alt;
66 
67         /// Is the Control key pressed?
68         bool control;
69 
70         /// Is the Shift key pressed?
71         bool shift;
72 
73         /// Is the System key pressed?
74         bool system;
75     }
76 
77     /**
78      * Mouse buttons events parameters (MouseButtonPressed, MouseButtonReleased)
79      */
80     struct MouseButtonEvent
81     {
82         /// Code of the button that has been pressed.
83         Mouse.Button button;
84 
85         /**
86          * X position of the mouse pointer, relative to the left of the owner
87          * window.
88          */
89         int x;
90 
91         /**
92          * Y position of the mouse pointer, relative to the top of the owner
93          * window.
94          */
95         int y;
96     }
97 
98     /**
99      * Mouse move event parameters (MouseMoved)
100      */
101     struct MouseMoveEvent
102     {
103         /**
104          * X position of the mouse pointer, relative to the left of the owner
105          * window.
106          */
107         int x;
108 
109         /**
110          * Y position of the mouse pointer, relative to the top of the owner
111          * window.
112          */
113         int y;
114     }
115 
116     /**
117      * Mouse wheel events parameters (MouseWheelMoved)
118      */
119     //deprecated("This event is //deprecated and potentially inaccurate. Use MouseWheelScrollEvent instead.")
120     struct MouseWheelEvent
121     {
122         /**
123          * Number of ticks the wheel has moved
124          * (positive is up, negative is down)
125          */
126         int delta;
127 
128         /**
129          * X position of the mouse pointer, relative to the left of the owner
130          * window.
131          */
132         int x;
133 
134         /**
135          * Y position of the mouse pointer, relative to the top of the owner
136          * window.
137          */
138         int y;
139     }
140 
141     /**
142      * Mouse wheel scroll events parameters (MouseWheelScrolled)
143      */
144     struct MouseWheelScrollEvent
145     {
146         /// Which wheel (for mice with multiple ones).
147         Mouse.Wheel wheel;
148 
149         /// Wheel offset. High precision mice may use non-integral offsets.
150         float delta;
151 
152         /**
153          * X position of the mouse pointer, relative to the left of the owner
154          * window.
155          */
156         int x;
157 
158         /**
159          * Y position of the mouse pointer, relative to the top of the owner
160          * window.
161          */
162         int y;
163     }
164 
165     /**
166      * Size events parameters (Resized)
167      */
168     struct SizeEvent
169     {
170         ///New width, in pixels
171         uint width;
172 
173         ///New height, in pixels
174         uint height;
175     }
176 
177     /**
178      * Text event parameters (TextEntered)
179      */
180     struct TextEvent
181     {
182         /// UTF-32 unicode value of the character
183         dchar unicode;
184     }
185 
186     /**
187      * Sensor event parameters
188      */
189     struct SensorEvent
190     {
191         ///Type of the sensor
192         Sensor.Type type;
193 
194         /// Current value of the sensor on X axis
195         float x;
196 
197         /// Current value of the sensor on Y axis
198         float y;
199 
200         /// Current value of the sensor on Z axis
201         float z;
202     }
203 
204     /**
205      * Touch Event parameters
206      */
207     struct TouchEvent
208     {
209         ///Index of the finger in case of multi-touch events.
210         uint finger;
211 
212         /// X position of the touch, relative to the left of the owner window.
213         int x;
214 
215         /// Y position of the touch, relative to the top of the owner window.
216         int y;
217     }
218 
219     /// Type of the event.
220     enum Type {
221         /// The window requested to be closed (no data)
222         Closed,
223         /// The window was resized (data in event.size)
224         Resized,
225         /// The window lost the focus (no data)
226         LostFocus,
227         /// The window gained the focus (no data)
228         GainedFocus,
229         /// A character was entered (data in event.text)
230         TextEntered,
231         /// A key was pressed (data in event.key)
232         KeyPressed,
233         /// A key was released (data in event.key)
234         KeyReleased,
235         /// The mouse wheel was scrolled (data in event.mouseWheel)
236         MouseWheelMoved,
237         /// The mouse wheel was scrolled (data in event.mouseWheelScroll)
238         MouseWheelScrolled,
239         /// A mouse button was pressed (data in event.mouseButton)
240         MouseButtonPressed,
241         /// A mouse button was released (data in event.mouseButton)
242         MouseButtonReleased,
243         /// The mouse cursor moved (data in event.mouseMove)
244         MouseMoved,
245         /// The mouse cursor entered the area of the window (no data)
246         MouseEntered,
247         /// The mouse cursor left the area of the window (no data)
248         MouseLeft,
249         /// A joystick button was pressed (data in event.joystickButton)
250         JoystickButtonPressed,
251         /// A joystick button was released (data in event.joystickButton)
252         JoystickButtonReleased,
253         /// The joystick moved along an axis (data in event.joystickMove)
254         JoystickMoved,
255         /// A joystick was connected (data in event.joystickConnect)
256         JoystickConnected,
257         /// A joystick was disconnected (data in event.joystickConnect)
258         JoystickDisconnected,
259         /// A touch event began (data in event.touch)
260         TouchBegan,
261         /// A touch moved (data in event.touch)
262         TouchMoved,
263         /// A touch ended (data in event.touch)
264         TouchEnded,
265         /// A sensor value changed (data in event.sensor)
266         SensorChanged,
267 
268         ///Keep last -- the total number of event types
269         Count
270     }
271 
272     ///Type of the event
273     Type type;
274 
275     union
276     {
277         /// Size event parameters (Event::Resized)
278         SizeEvent size;
279 
280         /// Key event parameters (Event::KeyPressed, Event::KeyReleased)
281         KeyEvent key;
282 
283         /// Text event parameters (Event::TextEntered)
284         TextEvent text;
285 
286         /// Mouse move event parameters (Event::MouseMoved)
287         MouseMoveEvent mouseMove;
288 
289         /// Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)
290         MouseButtonEvent mouseButton;
291 
292         /// Mouse wheel event parameters (Event::MouseWheelMoved)
293         MouseWheelEvent mouseWheel;
294 
295         /// Mouse wheel scroll event parameters
296         //MouseWheelScrollEvent mouseWheelScroll;
297 
298         /// Joystick move event parameters (Event::JoystickMoved)
299         JoystickMoveEvent joystickMove;
300 
301         /// Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)
302         JoystickButtonEvent joystickButton;
303 
304         /// Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected)
305         JoystickConnectEvent joystickConnect;
306 
307         /// Touch event parameters
308         TouchEvent touch;
309 
310         /// Sensor event Parameters
311         SensorEvent sensor;
312     }
313 }