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

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