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

Last change on this file since 319 was 319, checked in by epyon, 11 years ago
  • created core module and moved all free source files there
  • took the opportunity to update all copyright lines and minor cleanup
  • minor fixes
  • not all examples are up to date
File size: 4.0 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
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        {
[110]68                /// X position where mouse was clicked.
[67]69                uint16 x;
[110]70                /// Y position where mouse was clicked.
[67]71                uint16 y;
[110]72                /// Button that was clicked.
[67]73                uint32 button;
74                /// True if pressed
75                bool pressed;
76                /// Mouse button code
77                mouse_code code;
78        };
79
[304]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
[67]88        struct mouse_move_event
89        {
[110]90                /// X Position the mouse moved to.
[67]91                uint16 x;
[110]92                /// Y Position the mouse moved to.
[67]93                uint16 y;
[110]94                /// Distance in x direction mouse was moved.
[67]95                sint16 rx;
[110]96                /// Distance in y direction mouse was moved.
[67]97                sint16 ry;
98                /// True if pressed
99                bool pressed;
100                /// Mouse button code
101                mouse_code code;
102        };
103
[184]104        struct joy_button_event
105        {
106                /// Joystick ID
107                sint32 id;
108                /// Button that is affected
109                uint8 button;
110                /// True if pressed
111                bool pressed;
112        };
113
114        struct joy_axis_event
115        {
116                /// Joystick ID
117                sint32 id;
118                /// Axis ID
119                uint8 axis;
120                /// Value
121                sint16 value;
122        };
123
124        struct joy_hat_event
125        {
126                /// Joystick ID
127                sint32 id;
128                /// Hat ID
129                uint8 hat;
130                /// Value
131                sint16 value;
132        };
133
134        struct joy_ball_event
135        {
136                /// Joystick ID
137                sint32 id;
138                /// Ball ID
139                uint8 ball;
140                /// Relative X
141                sint16 rx;
142                /// Relative Y
143                sint16 ry;
144        };
145
[93]146        struct resize_event
147        {
[110]148                /// New x size of the object.
[93]149                sint32 x;
[110]150                /// New y size of the object.
[93]151                sint32 y;
152        };
153
154        struct active_event
155        {
[110]156                /// Whether focus was gained or lost.
[93]157                bool gain;
158        };
159
[67]160        struct system_event
161        {
162                uint8  sys_type;
163                uint32 param1;
164                uint32 param2;
165        };
166
[68]167        struct io_event
[67]168        {
169                io_event_code type;
170                union
171                {
172                        key_event          key;
173                        mouse_button_event mbutton;
174                        mouse_move_event   mmove;
[304]175                        mouse_wheel_event  mwheel;
[184]176                        joy_button_event   jbutton;
177                        joy_axis_event     jaxis;
178                        joy_hat_event      jhat;
179                        joy_ball_event     jball;
[93]180                        resize_event       resize;
181                        active_event       active;
[67]182                        system_event       system;
183                };
184        };
185
[110]186        /**
[132]187         * Gets the name of the key given the code.
[110]188         *
[132]189         * @param key The code value of the key.
190         * @returns The name of the key.
[110]191         */
[67]192        const char* get_key_name( key_code key );
[110]193
194        /**
[132]195         * Gets the name of the mouse button given the code.
[110]196         *
[132]197         * @param button The code value of the mouse button.
198         * @returns The name of the button.
[110]199         */
[67]200        const char* get_mouse_name( mouse_code button );
[110]201
202        /**
[132]203         * Gets the name of the IO event given the code.
[110]204         *
[132]205         * @param event The code value of the IO event.
206         * @returns The name of the event.
[110]207         */
[67]208        const char* get_io_event_name( io_event_code event );
[110]209
210        /**
[132]211         * Registers all events to the specified database.
[110]212         *
[132]213         * @param db The database to store all event data in.
[110]214         */
[319]215        //void register_io_types( type_database* db );
[67]216}
217
[319]218#endif // NV_CORE_IO_EVENT_HH
Note: See TracBrowser for help on using the repository browser.