Mercurial > molko
comparison src/event.h @ 19:bc1fdff76775
core: implement most useful events, closes #2445
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 08 Jan 2020 13:33:41 +0100 |
parents | |
children | 5519ad48822e |
comparison
equal
deleted
inserted
replaced
18:3ddd3acfe0e9 | 19:bc1fdff76775 |
---|---|
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 #include <stdint.h> | |
29 | |
30 #include "key.h" | |
31 #include "mouse.h" | |
32 | |
33 /** | |
34 * \brief Kind of event. | |
35 */ | |
36 enum event_type { | |
37 EVENT_CLICKDOWN, /*!< Mouse click down */ | |
38 EVENT_CLICKUP, /*!< Mouse click released */ | |
39 EVENT_KEYDOWN, /*!< Single key down */ | |
40 EVENT_KEYUP, /*!< Single key released */ | |
41 EVENT_MOUSE, /*!< Mouse moved */ | |
42 EVENT_QUIT, /*!< Quit request */ | |
43 }; | |
44 | |
45 /** | |
46 * \brief Store events. | |
47 */ | |
48 union event { | |
49 enum event_type type; /*!< Which kind of event */ | |
50 | |
51 struct { | |
52 enum event_type type; /*!< EVENT_KEYDOWN or EVENT_KEYUP */ | |
53 enum key key; /*!< Which key */ | |
54 } key; | |
55 | |
56 struct { | |
57 enum event_type type; /*!< EVENT_MOUSE */ | |
58 enum mouse_button buttons; /*!< OR'ed buttons that are pressed */ | |
59 int32_t x; /*!< Mouse position in x */ | |
60 int32_t y; /*!< Mouse position in y */ | |
61 } mouse; | |
62 | |
63 struct { | |
64 enum event_type type; /*!< EVENT_CLICKDOWN or EVENT_CLICKUP */ | |
65 enum mouse_button button; /*!< Unique button that was pressed */ | |
66 int32_t x; /*!< Mouse position in x */ | |
67 int32_t y; /*!< Mouse position in y */ | |
68 } click; | |
69 }; | |
70 | |
71 /** | |
72 * Fetch the next event or return false if there are not. | |
73 * | |
74 * \param ev the event | |
75 * \return true if the event was filled or false otherwise | |
76 */ | |
77 bool | |
78 event_poll(union event *ev); | |
79 | |
80 #endif /* !MOLKO_EVENT_H */ |