comparison src/core/event.h @ 59:52792b863ff7

misc: separate core from game
author David Demelier <markand@malikania.fr>
date Tue, 21 Jan 2020 12:42:33 +0100
parents src/event.h@b815621df3e3
children 6203e1ac9b18
comparison
equal deleted inserted replaced
58:d7d88ac30611 59:52792b863ff7
1 /*
2 * event.h -- event management
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_EVENT_H
20 #define MOLKO_EVENT_H
21
22 /**
23 * \file event.h
24 * \brief Event management.
25 */
26
27 #include <stdbool.h>
28
29 #include "key.h"
30 #include "mouse.h"
31
32 /**
33 * \brief Kind of event.
34 */
35 enum event_type {
36 EVENT_CLICKDOWN, /*!< Mouse click down */
37 EVENT_CLICKUP, /*!< Mouse click released */
38 EVENT_KEYDOWN, /*!< Single key down */
39 EVENT_KEYUP, /*!< Single key released */
40 EVENT_MOUSE, /*!< Mouse moved */
41 EVENT_QUIT, /*!< Quit request */
42 };
43
44 /**
45 * \brief Store events.
46 */
47 union event {
48 enum event_type type; /*!< Which kind of event */
49
50 /**
51 * Store key down/up event.
52 */
53 struct {
54 enum event_type type; /*!< EVENT_KEYDOWN or EVENT_KEYUP */
55 enum key key; /*!< Which key */
56 } key;
57
58 /**
59 * Store mouse motion event.
60 */
61 struct {
62 enum event_type type; /*!< EVENT_MOUSE */
63 enum mouse_button buttons; /*!< OR'ed buttons that are pressed */
64 int x; /*!< Mouse position in x */
65 int y; /*!< Mouse position in y */
66 } mouse;
67
68 /**
69 * Store mouse click event.
70 */
71 struct {
72 enum event_type type; /*!< EVENT_CLICKDOWN or EVENT_CLICKUP */
73 enum mouse_button button; /*!< Unique button that was pressed */
74 int x; /*!< Mouse position in x */
75 int y; /*!< Mouse position in y */
76 } click;
77 };
78
79 /**
80 * Fetch the next event or return false if there are not.
81 *
82 * \param ev the event
83 * \return true if the event was filled or false otherwise
84 */
85 bool
86 event_poll(union event *ev);
87
88 #endif /* !MOLKO_EVENT_H */