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

Last change on this file since 357 was 357, checked in by epyon, 10 years ago
  • common - required msvc version bumped
  • io_event/sdl_input - native scan code added
  • core/allocator.hh - interface added (WIP)
  • core/string_ref.hh - full implementation of efficient string_ref with literal support
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                /// native scan code
66                int native;
67        };
68
69        struct mouse_button_event
70        {
71                /// X position where mouse was clicked.
72                uint16 x;
73                /// Y position where mouse was clicked.
74                uint16 y;
75                /// Button that was clicked.
76                uint32 button;
77                /// True if pressed
78                bool pressed;
79                /// Mouse button code
80                mouse_code code;
81        };
82
83        struct mouse_wheel_event
84        {
85                /// amount scrolled horizontally positive to the right
86                sint32 x;
87                /// amount scrolled vertically
88                sint32 y;
89        };
90
91        struct mouse_move_event
92        {
93                /// X Position the mouse moved to.
94                uint16 x;
95                /// Y Position the mouse moved to.
96                uint16 y;
97                /// Distance in x direction mouse was moved.
98                sint16 rx;
99                /// Distance in y direction mouse was moved.
100                sint16 ry;
101                /// True if pressed
102                bool pressed;
103                /// Mouse button code
104                mouse_code code;
105        };
106
107        struct pad_button_event
108        {
109                /// Pad ID
110                sint32 id;
111                /// Button that is affected
112                uint8 button;
113                /// True if pressed
114                bool pressed;
115        };
116
117        struct pad_axis_event
118        {
119                /// Pad ID
120                sint32 id;
121                /// Axis ID
122                uint8 axis;
123                /// Value
124                sint16 value;
125        };
126
127        struct joy_button_event
128        {
129                /// Joystick ID
130                sint32 id;
131                /// Button that is affected
132                uint8 button;
133                /// True if pressed
134                bool pressed;
135        };
136
137        struct joy_axis_event
138        {
139                /// Joystick ID
140                sint32 id;
141                /// Axis ID
142                uint8 axis;
143                /// Value
144                sint16 value;
145        };
146
147        struct joy_hat_event
148        {
149                /// Joystick ID
150                sint32 id;
151                /// Hat ID
152                uint8 hat;
153                /// Value
154                sint16 value;
155        };
156
157        struct joy_ball_event
158        {
159                /// Joystick ID
160                sint32 id;
161                /// Ball ID
162                uint8 ball;
163                /// Relative X
164                sint16 rx;
165                /// Relative Y
166                sint16 ry;
167        };
168
169        struct resize_event
170        {
171                /// New x size of the object.
172                sint32 x;
173                /// New y size of the object.
174                sint32 y;
175        };
176
177        struct active_event
178        {
179                /// Whether focus was gained or lost.
180                bool gain;
181        };
182
183        struct system_event
184        {
185                uint8  sys_type;
186                uint32 param1;
187                uint32 param2;
188        };
189
190        struct io_event
191        {
192                io_event_code type;
193                union
194                {
195                        key_event          key;
196                        mouse_button_event mbutton;
197                        mouse_move_event   mmove;
198                        mouse_wheel_event  mwheel;
199                        pad_button_event   pbutton;
200                        pad_axis_event     paxis;
201                        joy_button_event   jbutton;
202                        joy_axis_event     jaxis;
203                        joy_hat_event      jhat;
204                        joy_ball_event     jball;
205                        resize_event       resize;
206                        active_event       active;
207                        system_event       system;
208                };
209        };
210
211        /**
212         * Gets the name of the key given the code.
213         *
214         * @param key The code value of the key.
215         * @returns The name of the key.
216         */
217        const char* get_key_name( key_code key );
218
219        /**
220         * Gets the name of the mouse button given the code.
221         *
222         * @param button The code value of the mouse button.
223         * @returns The name of the button.
224         */
225        const char* get_mouse_name( mouse_code button );
226
227        /**
228         * Gets the name of the IO event given the code.
229         *
230         * @param event The code value of the IO event.
231         * @returns The name of the event.
232         */
233        const char* get_io_event_name( io_event_code event );
234
235        /**
236         * Registers all events to the specified database.
237         *
238         * @param db The database to store all event data in.
239         */
240        //void register_io_types( type_database* db );
241
242        void log_event( const io_event& e );
243}
244
245#endif // NV_CORE_IO_EVENT_HH
Note: See TracBrowser for help on using the repository browser.