[395] | 1 | // Copyright (C) 2012-2015 ChaosForge Ltd
|
---|
[67] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[67] | 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 |
|
---|
[395] | 16 | #include <nv/common.hh>
|
---|
[447] | 17 | #include <nv/core/types.hh>
|
---|
[67] | 18 |
|
---|
| 19 | namespace 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 | };
|
---|
[78] | 29 |
|
---|
[67] | 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
|
---|
[369] | 49 | uchar8 ascii;
|
---|
[67] | 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;
|
---|
[357] | 65 |
|
---|
| 66 | /// native scan code
|
---|
| 67 | int native;
|
---|
[67] | 68 | };
|
---|
| 69 |
|
---|
| 70 | struct mouse_button_event
|
---|
| 71 | {
|
---|
[110] | 72 | /// X position where mouse was clicked.
|
---|
[67] | 73 | uint16 x;
|
---|
[110] | 74 | /// Y position where mouse was clicked.
|
---|
[67] | 75 | uint16 y;
|
---|
[110] | 76 | /// Button that was clicked.
|
---|
[67] | 77 | uint32 button;
|
---|
| 78 | /// True if pressed
|
---|
| 79 | bool pressed;
|
---|
| 80 | /// Mouse button code
|
---|
| 81 | mouse_code code;
|
---|
| 82 | };
|
---|
| 83 |
|
---|
[304] | 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 |
|
---|
[67] | 92 | struct mouse_move_event
|
---|
| 93 | {
|
---|
[110] | 94 | /// X Position the mouse moved to.
|
---|
[67] | 95 | uint16 x;
|
---|
[110] | 96 | /// Y Position the mouse moved to.
|
---|
[67] | 97 | uint16 y;
|
---|
[110] | 98 | /// Distance in x direction mouse was moved.
|
---|
[67] | 99 | sint16 rx;
|
---|
[110] | 100 | /// Distance in y direction mouse was moved.
|
---|
[67] | 101 | sint16 ry;
|
---|
| 102 | /// True if pressed
|
---|
| 103 | bool pressed;
|
---|
| 104 | /// Mouse button code
|
---|
| 105 | mouse_code code;
|
---|
| 106 | };
|
---|
| 107 |
|
---|
[338] | 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 |
|
---|
[184] | 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 |
|
---|
[93] | 170 | struct resize_event
|
---|
| 171 | {
|
---|
[110] | 172 | /// New x size of the object.
|
---|
[93] | 173 | sint32 x;
|
---|
[110] | 174 | /// New y size of the object.
|
---|
[93] | 175 | sint32 y;
|
---|
| 176 | };
|
---|
| 177 |
|
---|
| 178 | struct active_event
|
---|
| 179 | {
|
---|
[110] | 180 | /// Whether focus was gained or lost.
|
---|
[93] | 181 | bool gain;
|
---|
| 182 | };
|
---|
| 183 |
|
---|
[67] | 184 | struct system_event
|
---|
| 185 | {
|
---|
| 186 | uint8 sys_type;
|
---|
| 187 | uint32 param1;
|
---|
| 188 | uint32 param2;
|
---|
| 189 | };
|
---|
| 190 |
|
---|
[68] | 191 | struct io_event
|
---|
[67] | 192 | {
|
---|
| 193 | io_event_code type;
|
---|
| 194 | union
|
---|
| 195 | {
|
---|
| 196 | key_event key;
|
---|
| 197 | mouse_button_event mbutton;
|
---|
| 198 | mouse_move_event mmove;
|
---|
[304] | 199 | mouse_wheel_event mwheel;
|
---|
[338] | 200 | pad_button_event pbutton;
|
---|
| 201 | pad_axis_event paxis;
|
---|
[184] | 202 | joy_button_event jbutton;
|
---|
| 203 | joy_axis_event jaxis;
|
---|
| 204 | joy_hat_event jhat;
|
---|
| 205 | joy_ball_event jball;
|
---|
[93] | 206 | resize_event resize;
|
---|
| 207 | active_event active;
|
---|
[67] | 208 | system_event system;
|
---|
| 209 | };
|
---|
| 210 | };
|
---|
| 211 |
|
---|
[110] | 212 | /**
|
---|
[132] | 213 | * Gets the name of the key given the code.
|
---|
[110] | 214 | *
|
---|
[132] | 215 | * @param key The code value of the key.
|
---|
| 216 | * @returns The name of the key.
|
---|
[110] | 217 | */
|
---|
[67] | 218 | const char* get_key_name( key_code key );
|
---|
[110] | 219 |
|
---|
| 220 | /**
|
---|
[132] | 221 | * Gets the name of the mouse button given the code.
|
---|
[110] | 222 | *
|
---|
[132] | 223 | * @param button The code value of the mouse button.
|
---|
| 224 | * @returns The name of the button.
|
---|
[110] | 225 | */
|
---|
[67] | 226 | const char* get_mouse_name( mouse_code button );
|
---|
[110] | 227 |
|
---|
| 228 | /**
|
---|
[132] | 229 | * Gets the name of the IO event given the code.
|
---|
[110] | 230 | *
|
---|
[132] | 231 | * @param event The code value of the IO event.
|
---|
| 232 | * @returns The name of the event.
|
---|
[110] | 233 | */
|
---|
[67] | 234 | const char* get_io_event_name( io_event_code event );
|
---|
[110] | 235 |
|
---|
| 236 | /**
|
---|
[132] | 237 | * Registers all events to the specified database.
|
---|
[110] | 238 | *
|
---|
[132] | 239 | * @param db The database to store all event data in.
|
---|
[110] | 240 | */
|
---|
[447] | 241 | void register_io_types( type_database* db );
|
---|
[338] | 242 |
|
---|
| 243 | void log_event( const io_event& e );
|
---|
[67] | 244 | }
|
---|
| 245 |
|
---|
[447] | 246 | NV_RTTI_DECLARE( nv::key_code )
|
---|
| 247 | NV_RTTI_DECLARE( nv::mouse_code )
|
---|
| 248 | NV_RTTI_DECLARE( nv::io_event_code )
|
---|
| 249 | NV_RTTI_DECLARE( nv::key_event )
|
---|
| 250 | NV_RTTI_DECLARE( nv::mouse_button_event )
|
---|
| 251 | NV_RTTI_DECLARE( nv::mouse_wheel_event )
|
---|
| 252 | NV_RTTI_DECLARE( nv::mouse_move_event )
|
---|
| 253 | NV_RTTI_DECLARE( nv::pad_button_event )
|
---|
| 254 | NV_RTTI_DECLARE( nv::pad_axis_event )
|
---|
| 255 | NV_RTTI_DECLARE( nv::joy_button_event )
|
---|
| 256 | NV_RTTI_DECLARE( nv::joy_axis_event )
|
---|
| 257 | NV_RTTI_DECLARE( nv::joy_hat_event )
|
---|
| 258 | NV_RTTI_DECLARE( nv::joy_ball_event )
|
---|
| 259 | NV_RTTI_DECLARE( nv::resize_event )
|
---|
| 260 | NV_RTTI_DECLARE( nv::active_event )
|
---|
| 261 | NV_RTTI_DECLARE( nv::system_event )
|
---|
| 262 | NV_RTTI_DECLARE( nv::io_event )
|
---|
| 263 |
|
---|
| 264 |
|
---|
[319] | 265 | #endif // NV_CORE_IO_EVENT_HH
|
---|