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

Last change on this file since 369 was 369, checked in by epyon, 10 years ago
  • removed all std headers (except cassert) from common.hh
  • sized int types in common.hh with static_assert checks
  • char8 -> uchar8/schar8 and 16/32
  • omitted core->stl includes fixed
File size: 4.4 KB
RevLine 
[319]1// Copyright (C) 2012-2014 ChaosForge Ltd
[67]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
[319]13#ifndef NV_CORE_IO_EVENT_HH
14#define NV_CORE_IO_EVENT_HH
[67]15
[319]16#include <nv/core/common.hh>
[67]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        };
[78]28       
[67]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
[369]48                uchar8 ascii;
[67]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;
[357]64
65                /// native scan code
66                int native;
[67]67        };
68
69        struct mouse_button_event
70        {
[110]71                /// X position where mouse was clicked.
[67]72                uint16 x;
[110]73                /// Y position where mouse was clicked.
[67]74                uint16 y;
[110]75                /// Button that was clicked.
[67]76                uint32 button;
77                /// True if pressed
78                bool pressed;
79                /// Mouse button code
80                mouse_code code;
81        };
82
[304]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
[67]91        struct mouse_move_event
92        {
[110]93                /// X Position the mouse moved to.
[67]94                uint16 x;
[110]95                /// Y Position the mouse moved to.
[67]96                uint16 y;
[110]97                /// Distance in x direction mouse was moved.
[67]98                sint16 rx;
[110]99                /// Distance in y direction mouse was moved.
[67]100                sint16 ry;
101                /// True if pressed
102                bool pressed;
103                /// Mouse button code
104                mouse_code code;
105        };
106
[338]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
[184]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
[93]169        struct resize_event
170        {
[110]171                /// New x size of the object.
[93]172                sint32 x;
[110]173                /// New y size of the object.
[93]174                sint32 y;
175        };
176
177        struct active_event
178        {
[110]179                /// Whether focus was gained or lost.
[93]180                bool gain;
181        };
182
[67]183        struct system_event
184        {
185                uint8  sys_type;
186                uint32 param1;
187                uint32 param2;
188        };
189
[68]190        struct io_event
[67]191        {
192                io_event_code type;
193                union
194                {
195                        key_event          key;
196                        mouse_button_event mbutton;
197                        mouse_move_event   mmove;
[304]198                        mouse_wheel_event  mwheel;
[338]199                        pad_button_event   pbutton;
200                        pad_axis_event     paxis;
[184]201                        joy_button_event   jbutton;
202                        joy_axis_event     jaxis;
203                        joy_hat_event      jhat;
204                        joy_ball_event     jball;
[93]205                        resize_event       resize;
206                        active_event       active;
[67]207                        system_event       system;
208                };
209        };
210
[110]211        /**
[132]212         * Gets the name of the key given the code.
[110]213         *
[132]214         * @param key The code value of the key.
215         * @returns The name of the key.
[110]216         */
[67]217        const char* get_key_name( key_code key );
[110]218
219        /**
[132]220         * Gets the name of the mouse button given the code.
[110]221         *
[132]222         * @param button The code value of the mouse button.
223         * @returns The name of the button.
[110]224         */
[67]225        const char* get_mouse_name( mouse_code button );
[110]226
227        /**
[132]228         * Gets the name of the IO event given the code.
[110]229         *
[132]230         * @param event The code value of the IO event.
231         * @returns The name of the event.
[110]232         */
[67]233        const char* get_io_event_name( io_event_code event );
[110]234
235        /**
[132]236         * Registers all events to the specified database.
[110]237         *
[132]238         * @param db The database to store all event data in.
[110]239         */
[319]240        //void register_io_types( type_database* db );
[338]241
242        void log_event( const io_event& e );
[67]243}
244
[319]245#endif // NV_CORE_IO_EVENT_HH
Note: See TracBrowser for help on using the repository browser.