source: trunk/nv/core/io_event.hh @ 338

Last change on this file since 338 was 338, checked in by epyon, 11 years ago
  • io_events for controllers
File size: 4.4 KB
Line 
1// Copyright (C) 2012-2014 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7/**
8 * @file io_event.hh
9 * @author Kornel Kisielewicz
10 * @brief
11 */
12
13#ifndef NV_CORE_IO_EVENT_HH
14#define NV_CORE_IO_EVENT_HH
15
16#include <nv/core/common.hh>
17
18namespace nv
19{
20
21        // Generate the key_code enum
22        enum key_code
23        {
24#       define NV_KEY( id, val ) id = val,
25#               include <nv/detail/key_list.inc>
26#       undef NV_KEY
27        };
28       
29        // Generate the mouse_code enum
30        enum mouse_code
31        {
32#       define NV_MOUSE( id, val ) id = val,
33#               include <nv/detail/mouse_list.inc>
34#       undef NV_MOUSE
35        };
36
37        // Generate the io_event_code enum
38        enum io_event_code
39        {
40#       define NV_IO_EVENT( id ) id,
41#               include <nv/detail/io_event_list.inc>
42#       undef NV_IO_EVENT
43        };
44
45        struct key_event
46        {
47                /// Input event ASCII code
48                char8 ascii;
49
50                /// Input event local code
51                key_code code;
52
53                /// True if shift key is present
54                bool shift;
55
56                /// True if control key is present
57                bool control;
58
59                /// True if alt key is present
60                bool alt;
61
62                /// True if pressed
63                bool pressed;
64        };
65
66        struct mouse_button_event
67        {
68                /// X position where mouse was clicked.
69                uint16 x;
70                /// Y position where mouse was clicked.
71                uint16 y;
72                /// Button that was clicked.
73                uint32 button;
74                /// True if pressed
75                bool pressed;
76                /// Mouse button code
77                mouse_code code;
78        };
79
80        struct mouse_wheel_event
81        {
82                /// amount scrolled horizontally positive to the right
83                sint32 x;
84                /// amount scrolled vertically
85                sint32 y;
86        };
87
88        struct mouse_move_event
89        {
90                /// X Position the mouse moved to.
91                uint16 x;
92                /// Y Position the mouse moved to.
93                uint16 y;
94                /// Distance in x direction mouse was moved.
95                sint16 rx;
96                /// Distance in y direction mouse was moved.
97                sint16 ry;
98                /// True if pressed
99                bool pressed;
100                /// Mouse button code
101                mouse_code code;
102        };
103
104        struct pad_button_event
105        {
106                /// Pad ID
107                sint32 id;
108                /// Button that is affected
109                uint8 button;
110                /// True if pressed
111                bool pressed;
112        };
113
114        struct pad_axis_event
115        {
116                /// Pad ID
117                sint32 id;
118                /// Axis ID
119                uint8 axis;
120                /// Value
121                sint16 value;
122        };
123
124        struct joy_button_event
125        {
126                /// Joystick ID
127                sint32 id;
128                /// Button that is affected
129                uint8 button;
130                /// True if pressed
131                bool pressed;
132        };
133
134        struct joy_axis_event
135        {
136                /// Joystick ID
137                sint32 id;
138                /// Axis ID
139                uint8 axis;
140                /// Value
141                sint16 value;
142        };
143
144        struct joy_hat_event
145        {
146                /// Joystick ID
147                sint32 id;
148                /// Hat ID
149                uint8 hat;
150                /// Value
151                sint16 value;
152        };
153
154        struct joy_ball_event
155        {
156                /// Joystick ID
157                sint32 id;
158                /// Ball ID
159                uint8 ball;
160                /// Relative X
161                sint16 rx;
162                /// Relative Y
163                sint16 ry;
164        };
165
166        struct resize_event
167        {
168                /// New x size of the object.
169                sint32 x;
170                /// New y size of the object.
171                sint32 y;
172        };
173
174        struct active_event
175        {
176                /// Whether focus was gained or lost.
177                bool gain;
178        };
179
180        struct system_event
181        {
182                uint8  sys_type;
183                uint32 param1;
184                uint32 param2;
185        };
186
187        struct io_event
188        {
189                io_event_code type;
190                union
191                {
192                        key_event          key;
193                        mouse_button_event mbutton;
194                        mouse_move_event   mmove;
195                        mouse_wheel_event  mwheel;
196                        pad_button_event   pbutton;
197                        pad_axis_event     paxis;
198                        joy_button_event   jbutton;
199                        joy_axis_event     jaxis;
200                        joy_hat_event      jhat;
201                        joy_ball_event     jball;
202                        resize_event       resize;
203                        active_event       active;
204                        system_event       system;
205                };
206        };
207
208        /**
209         * Gets the name of the key given the code.
210         *
211         * @param key The code value of the key.
212         * @returns The name of the key.
213         */
214        const char* get_key_name( key_code key );
215
216        /**
217         * Gets the name of the mouse button given the code.
218         *
219         * @param button The code value of the mouse button.
220         * @returns The name of the button.
221         */
222        const char* get_mouse_name( mouse_code button );
223
224        /**
225         * Gets the name of the IO event given the code.
226         *
227         * @param event The code value of the IO event.
228         * @returns The name of the event.
229         */
230        const char* get_io_event_name( io_event_code event );
231
232        /**
233         * Registers all events to the specified database.
234         *
235         * @param db The database to store all event data in.
236         */
237        //void register_io_types( type_database* db );
238
239        void log_event( const io_event& e );
240}
241
242#endif // NV_CORE_IO_EVENT_HH
Note: See TracBrowser for help on using the repository browser.