]> git.localhorst.tv Git - blobs.git/blob - src/io/event.cpp
eating and drinking
[blobs.git] / src / io / event.cpp
1 #include "event.hpp"
2
3 #include <cctype>
4 #include <ostream>
5
6 using std::ostream;
7
8
9 namespace blobs {
10 namespace io {
11
12 ostream &operator <<(ostream &out, const SDL_Event &evt) {
13         switch (evt.type) {
14 #if SDL_VERSION_ATLEAST(2, 0, 4)
15                 case SDL_AUDIODEVICEADDED:
16                         out << "audio device added: " << evt.adevice;
17                         break;
18                 case SDL_AUDIODEVICEREMOVED:
19                         out << "audio device removed: " << evt.adevice;
20                         break;
21 #endif
22                 case SDL_CONTROLLERAXISMOTION:
23                         out << "controller axis motion: " << evt.caxis;
24                         break;
25                 case SDL_CONTROLLERBUTTONDOWN:
26                         out << "controller button down: " << evt.cbutton;
27                         break;
28                 case SDL_CONTROLLERBUTTONUP:
29                         out << "controller button up: " << evt.cbutton;
30                         break;
31                 case SDL_CONTROLLERDEVICEADDED:
32                         out << "controller device added: " << evt.cdevice;
33                         break;
34                 case SDL_CONTROLLERDEVICEREMOVED:
35                         out << "controller device removed: " << evt.cdevice;
36                         break;
37                 case SDL_CONTROLLERDEVICEREMAPPED:
38                         out << "controller device remapped: " << evt.cdevice;
39                         break;
40                 case SDL_DOLLARGESTURE:
41                         out << "dollar gesture: " << evt.dgesture;
42                         break;
43                 case SDL_DOLLARRECORD:
44                         out << "dollar record: " << evt.dgesture;
45                         break;
46                 case SDL_DROPFILE:
47                         out << "drop file: " << evt.drop;
48                         break;
49                 case SDL_FINGERMOTION:
50                         out << "finger motion: " << evt.tfinger;
51                         break;
52                 case SDL_FINGERDOWN:
53                         out << "finger down: " << evt.tfinger;
54                         break;
55                 case SDL_FINGERUP:
56                         out << "finger up: " << evt.tfinger;
57                         break;
58                 case SDL_KEYDOWN:
59                         out << "key down: " << evt.key;
60                         break;
61                 case SDL_KEYUP:
62                         out << "key up: " << evt.key;
63                         break;
64                 case SDL_JOYAXISMOTION:
65                         out << "joystick axis motion: " << evt.jaxis;
66                         break;
67                 case SDL_JOYBALLMOTION:
68                         out << "joystick ball motion: " << evt.jball;
69                         break;
70                 case SDL_JOYHATMOTION:
71                         out << "joystick hat motion: " << evt.jhat;
72                         break;
73                 case SDL_JOYBUTTONDOWN:
74                         out << "joystick button down: " << evt.jbutton;
75                         break;
76                 case SDL_JOYBUTTONUP:
77                         out << "joystick button up: " << evt.jbutton;
78                         break;
79                 case SDL_JOYDEVICEADDED:
80                         out << "joystick device added: " << evt.jdevice;
81                         break;
82                 case SDL_JOYDEVICEREMOVED:
83                         out << "joystick device removed: " << evt.jdevice;
84                         break;
85                 case SDL_MOUSEMOTION:
86                         out << "mouse motion: " << evt.motion;
87                         break;
88                 case SDL_MOUSEBUTTONDOWN:
89                         out << "mouse button down: " << evt.button;
90                         break;
91                 case SDL_MOUSEBUTTONUP:
92                         out << "mouse button up: " << evt.button;
93                         break;
94                 case SDL_MOUSEWHEEL:
95                         out << "mouse wheel: " << evt.wheel;
96                         break;
97                 case SDL_MULTIGESTURE:
98                         out << "multi gesture: " << evt.mgesture;
99                         break;
100                 case SDL_QUIT:
101                         out << "quit: " << evt.quit;
102                         break;
103                 case SDL_SYSWMEVENT:
104                         out << "sys wm: " << evt.syswm;
105                         break;
106                 case SDL_TEXTEDITING:
107                         out << "text editing: " << evt.edit;
108                         break;
109                 case SDL_TEXTINPUT:
110                         out << "text input: " << evt.text;
111                         break;
112                 case SDL_USEREVENT:
113                         out << "user: " << evt.user;
114                         break;
115                 case SDL_WINDOWEVENT:
116                         out << "window: " << evt.window;
117                         break;
118                 default:
119                         out << "unknown";
120                         break;
121         }
122         return out;
123 }
124
125 ostream &operator <<(ostream &out, const SDL_WindowEvent &evt) {
126         switch (evt.event) {
127                 case SDL_WINDOWEVENT_SHOWN:
128                         out << "shown, window ID: " << evt.windowID;
129                         break;
130                 case SDL_WINDOWEVENT_HIDDEN:
131                         out << "hidden, window ID: " << evt.windowID;
132                         break;
133                 case SDL_WINDOWEVENT_EXPOSED:
134                         out << "exposed, window ID: " << evt.windowID;
135                         break;
136                 case SDL_WINDOWEVENT_MOVED:
137                         out << "moved, window ID: " << evt.windowID
138                                 << ", position: " << evt.data1 << ' ' << evt.data2;
139                         break;
140                 case SDL_WINDOWEVENT_RESIZED:
141                         out << "resized, window ID: " << evt.windowID
142                                 << ", size: " << evt.data1 << 'x' << evt.data2;
143                         break;
144                 case SDL_WINDOWEVENT_SIZE_CHANGED:
145                         out << "size changed, window ID: " << evt.windowID
146                                 << ", size: " << evt.data1 << 'x' << evt.data2;
147                         break;
148                 case SDL_WINDOWEVENT_MINIMIZED:
149                         out << "minimized, window ID: " << evt.windowID;
150                         break;
151                 case SDL_WINDOWEVENT_MAXIMIZED:
152                         out << "maximized, window ID: " << evt.windowID;
153                         break;
154                 case SDL_WINDOWEVENT_RESTORED:
155                         out << "restored, window ID: " << evt.windowID;
156                         break;
157                 case SDL_WINDOWEVENT_ENTER:
158                         out << "mouse entered, window ID: " << evt.windowID;
159                         break;
160                 case SDL_WINDOWEVENT_LEAVE:
161                         out << "mouse left, window ID: " << evt.windowID;
162                         break;
163                 case SDL_WINDOWEVENT_FOCUS_GAINED:
164                         out << "focus gained, window ID: " << evt.windowID;
165                         break;
166                 case SDL_WINDOWEVENT_FOCUS_LOST:
167                         out << "focus lost, window ID: " << evt.windowID;
168                         break;
169                 case SDL_WINDOWEVENT_CLOSE:
170                         out << "closed, window ID: " << evt.windowID;
171                         break;
172                 default:
173                         out << "unknown";
174                         break;
175         }
176         return out;
177 }
178
179 ostream &operator <<(ostream &out, const SDL_KeyboardEvent &evt) {
180         out << "window ID: " << evt.windowID
181                 << ", state: " << (evt.state == SDL_PRESSED ? "pressed" : "released")
182                 << ", repeat: " << (evt.repeat ? "yes" : "no")
183                 << ", keysym: " << evt.keysym;
184         return out;
185 }
186
187 ostream &operator <<(ostream &out, const SDL_Keysym &keysym) {
188         out << "scancode: " << int(keysym.scancode)
189                 << ", sym: " << int(keysym.sym)
190                 << " (\"" << SDL_GetKeyName(keysym.sym) << "\")";
191         if (keysym.mod) {
192                 out << ", mod:";
193                 if (keysym.mod & KMOD_LSHIFT) {
194                         out << " LSHIFT";
195                 }
196                 if (keysym.mod & KMOD_RSHIFT) {
197                         out << " RSHIFT";
198                 }
199                 if (keysym.mod & KMOD_LCTRL) {
200                         out << " LCTRL";
201                 }
202                 if (keysym.mod & KMOD_RCTRL) {
203                         out << " RCTRL";
204                 }
205                 if (keysym.mod & KMOD_LALT) {
206                         out << " LALT";
207                 }
208                 if (keysym.mod & KMOD_RALT) {
209                         out << " RALT";
210                 }
211                 if (keysym.mod & KMOD_LGUI) {
212                         out << " LSUPER";
213                 }
214                 if (keysym.mod & KMOD_RGUI) {
215                         out << " RSUPER";
216                 }
217                 if (keysym.mod & KMOD_NUM) {
218                         out << " NUM";
219                 }
220                 if (keysym.mod & KMOD_CAPS) {
221                         out << " CAPS";
222                 }
223                 if (keysym.mod & KMOD_MODE) {
224                         out << " ALTGR";
225                 }
226         }
227         return out;
228 }
229
230 ostream &operator <<(ostream &out, const SDL_TextEditingEvent &evt) {
231         out << "window ID: " << evt.windowID
232                 << ", text: \"" << evt.text
233                 << "\", start: " << evt.start
234                 << ", length: " << evt.length;
235         return out;
236 }
237
238 ostream &operator <<(ostream &out, const SDL_TextInputEvent &evt) {
239         out << "window ID: " << evt.windowID
240                 << ", text: \"" << evt.text << '"';
241         return out;
242 }
243
244 ostream &operator <<(ostream &out, const SDL_MouseMotionEvent &evt) {
245         out << "window ID: " << evt.windowID
246                 << ", mouse ID: " << evt.which
247                 << ", position: " << evt.x << ' ' << evt.y
248                 << ", delta: " << evt.xrel << ' ' << evt.yrel;
249         if (evt.state) {
250                 out << ", buttons:";
251                 if (evt.state & SDL_BUTTON_LMASK) {
252                         out << " left";
253                 }
254                 if (evt.state & SDL_BUTTON_MMASK) {
255                         out << " middle";
256                 }
257                 if (evt.state & SDL_BUTTON_RMASK) {
258                         out << " right";
259                 }
260                 if (evt.state & SDL_BUTTON_X1MASK) {
261                         out << " X1";
262                 }
263                 if (evt.state & SDL_BUTTON_X2MASK) {
264                         out << " X2";
265                 }
266         }
267         return out;
268 }
269
270 ostream &operator <<(ostream &out, const SDL_MouseButtonEvent &evt) {
271         out << "window ID: " << evt.windowID
272                 << ", mouse ID: " << evt.which
273                 << ", button: ";
274         switch (evt.button) {
275                 case SDL_BUTTON_LEFT:
276                         out << "left";
277                         break;
278                 case SDL_BUTTON_MIDDLE:
279                         out << "middle";
280                         break;
281                 case SDL_BUTTON_RIGHT:
282                         out << "right";
283                         break;
284                 case SDL_BUTTON_X1:
285                         out << "X1";
286                         break;
287                 case SDL_BUTTON_X2:
288                         out << "X2";
289                         break;
290                 default:
291                         out << int(evt.button);
292                         break;
293         }
294         out << ", state: " << (evt.state == SDL_PRESSED ? "pressed" : "released")
295                 << ", clicks: " << int(evt.clicks)
296                 << ", position: " << evt.x << ' ' << evt.y;
297         return out;
298 }
299
300 ostream &operator <<(ostream &out, const SDL_MouseWheelEvent &evt) {
301         out << "window ID: " << evt.windowID
302                 << ", mouse ID: " << evt.which
303                 << ", delta: " << evt.x << ' ' << evt.y
304 #if SDL_VERSION_ATLEAST(2, 0, 4)
305                 << ", direction: " << (evt.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped")
306 #endif
307                 ;
308         return out;
309 }
310
311 ostream &operator <<(ostream &out, const SDL_JoyAxisEvent &evt) {
312         out << "joystick ID: " << evt.which
313                 << ", axis ID: " << int(evt.axis)
314                 << ", value: " << (float(evt.value) / 32768.0f);
315         return out;
316 }
317
318 ostream &operator <<(ostream &out, const SDL_JoyBallEvent &evt) {
319         out << "joystick ID: " << evt.which
320                 << ", ball ID: " << int(evt.ball)
321                 << ", delta: " << evt.xrel << ' ' << evt.yrel;
322         return out;
323 }
324
325 ostream &operator <<(ostream &out, const SDL_JoyHatEvent &evt) {
326         out << "joystick ID: " << evt.which
327                 << ", hat ID: " << int(evt.hat)
328                 << ", value: ";
329         switch (evt.value) {
330                 case SDL_HAT_LEFTUP:
331                         out << "left up";
332                         break;
333                 case SDL_HAT_UP:
334                         out << "up";
335                         break;
336                 case SDL_HAT_RIGHTUP:
337                         out << "right up";
338                         break;
339                 case SDL_HAT_LEFT:
340                         out << "left";
341                         break;
342                 case SDL_HAT_CENTERED:
343                         out << "center";
344                         break;
345                 case SDL_HAT_RIGHT:
346                         out << "right";
347                         break;
348                 case SDL_HAT_LEFTDOWN:
349                         out << "left down";
350                         break;
351                 case SDL_HAT_DOWN:
352                         out << "down";
353                         break;
354                 case SDL_HAT_RIGHTDOWN:
355                         out << "right down";
356                         break;
357                 default:
358                         out << "unknown";
359                         break;
360         }
361         return out;
362 }
363
364 ostream &operator <<(ostream &out, const SDL_JoyButtonEvent &evt) {
365         out << "joystick ID: " << evt.which
366                 << ", button ID: " << int(evt.button)
367                 << ", state: " << (evt.state == SDL_PRESSED ? "pressed" : "released");
368         return out;
369 }
370
371 ostream &operator <<(ostream &out, const SDL_JoyDeviceEvent &evt) {
372         out << "joystick ID: " << evt.which;
373         return out;
374 }
375
376 ostream &operator <<(ostream &out, const SDL_ControllerAxisEvent &evt) {
377         out << "controller ID: " << evt.which
378                 << ", axis ID: " << int(evt.axis)
379                 << ", value: " << (float(evt.value) / 32768.0f);
380         return out;
381 }
382
383 ostream &operator <<(ostream &out, const SDL_ControllerButtonEvent &evt) {
384         out << "controller ID: " << evt.which
385                 << ", button ID: " << int(evt.button)
386                 << ", state: " << (evt.state == SDL_PRESSED ? "pressed" : "released");
387         return out;
388 }
389
390 ostream &operator <<(ostream &out, const SDL_ControllerDeviceEvent &evt) {
391         out << "controller ID: " << evt.which;
392         return out;
393 }
394
395 #if SDL_VERSION_ATLEAST(2, 0, 4)
396 ostream &operator <<(ostream &out, const SDL_AudioDeviceEvent &evt) {
397         out << "device ID: " << evt.which
398                 << ", capture: " << (evt.iscapture ? "yes" : "no");
399         return out;
400 }
401 #endif
402
403 ostream &operator <<(ostream &out, const SDL_QuitEvent &evt) {
404         out << "quit";
405         return out;
406 }
407
408 ostream &operator <<(ostream &out, const SDL_UserEvent &evt) {
409         out << "window ID: " << evt.windowID
410                 << ", code: " << evt.code
411                 << ", data 1: " << evt.data1
412                 << ", data 2: " << evt.data2;
413         return out;
414 }
415
416 ostream &operator <<(ostream &out, const SDL_SysWMEvent &evt) {
417         if (evt.msg) {
418                 out << "with message";
419         } else {
420                 out << "without message";
421         }
422         return out;
423 }
424
425 ostream &operator <<(ostream &out, const SDL_TouchFingerEvent &evt) {
426         out << "device ID: " << evt.touchId
427                 << ", finger ID: " << evt.fingerId
428                 << ", position: " << evt.x << ' ' << evt.y
429                 << ", delta: " << evt.dx << ' ' << evt.dy
430                 << ", pressure: " << evt.pressure;
431         return out;
432 }
433
434 ostream &operator <<(ostream &out, const SDL_MultiGestureEvent &evt) {
435         out << "device ID: " << evt.touchId
436                 << ", theta: " << evt.dTheta
437                 << ", distance: " << evt.dDist
438                 << ", position: " << evt.x << ' ' << evt.y
439                 << ", fingers: " << evt.numFingers;
440         return out;
441 }
442
443 ostream &operator <<(ostream &out, const SDL_DollarGestureEvent &evt) {
444         out << "device ID: " << evt.touchId
445                 << ", gesture ID: " << evt.gestureId
446                 << ", fingers: " << evt.numFingers
447                 << ", error: " << evt.error
448                 << ", position: " << evt.x << ' ' << evt.y;
449         return out;
450 }
451
452 ostream &operator <<(ostream &out, const SDL_DropEvent &evt) {
453         out << "file: " << evt.file;
454         return out;
455 }
456
457 }
458 }