[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 | {
|
---|
[505] | 48 | /// Associated window ID
|
---|
| 49 | uint32 window_id;
|
---|
| 50 |
|
---|
[67] | 51 | /// Input event ASCII code
|
---|
[369] | 52 | uchar8 ascii;
|
---|
[67] | 53 |
|
---|
| 54 | /// Input event local code
|
---|
| 55 | key_code code;
|
---|
| 56 |
|
---|
| 57 | /// True if shift key is present
|
---|
| 58 | bool shift;
|
---|
| 59 |
|
---|
| 60 | /// True if control key is present
|
---|
| 61 | bool control;
|
---|
| 62 |
|
---|
| 63 | /// True if alt key is present
|
---|
| 64 | bool alt;
|
---|
| 65 |
|
---|
| 66 | /// True if pressed
|
---|
| 67 | bool pressed;
|
---|
[357] | 68 |
|
---|
| 69 | /// native scan code
|
---|
| 70 | int native;
|
---|
[67] | 71 | };
|
---|
| 72 |
|
---|
| 73 | struct mouse_button_event
|
---|
| 74 | {
|
---|
[505] | 75 | /// Associated window ID
|
---|
| 76 | uint32 window_id;
|
---|
| 77 |
|
---|
[110] | 78 | /// X position where mouse was clicked.
|
---|
[67] | 79 | uint16 x;
|
---|
[110] | 80 | /// Y position where mouse was clicked.
|
---|
[67] | 81 | uint16 y;
|
---|
[110] | 82 | /// Button that was clicked.
|
---|
[67] | 83 | uint32 button;
|
---|
| 84 | /// True if pressed
|
---|
| 85 | bool pressed;
|
---|
| 86 | /// Mouse button code
|
---|
| 87 | mouse_code code;
|
---|
| 88 | };
|
---|
| 89 |
|
---|
[304] | 90 | struct mouse_wheel_event
|
---|
| 91 | {
|
---|
[505] | 92 | /// Associated window ID
|
---|
| 93 | uint32 window_id;
|
---|
[304] | 94 | /// amount scrolled horizontally positive to the right
|
---|
| 95 | sint32 x;
|
---|
| 96 | /// amount scrolled vertically
|
---|
| 97 | sint32 y;
|
---|
| 98 | };
|
---|
| 99 |
|
---|
[67] | 100 | struct mouse_move_event
|
---|
| 101 | {
|
---|
[505] | 102 | /// Associated window ID
|
---|
| 103 | uint32 window_id;
|
---|
[110] | 104 | /// X Position the mouse moved to.
|
---|
[67] | 105 | uint16 x;
|
---|
[110] | 106 | /// Y Position the mouse moved to.
|
---|
[67] | 107 | uint16 y;
|
---|
[110] | 108 | /// Distance in x direction mouse was moved.
|
---|
[67] | 109 | sint16 rx;
|
---|
[110] | 110 | /// Distance in y direction mouse was moved.
|
---|
[67] | 111 | sint16 ry;
|
---|
| 112 | /// True if pressed
|
---|
| 113 | bool pressed;
|
---|
| 114 | /// Mouse button code
|
---|
| 115 | mouse_code code;
|
---|
| 116 | };
|
---|
| 117 |
|
---|
[338] | 118 | struct pad_button_event
|
---|
| 119 | {
|
---|
| 120 | /// Pad ID
|
---|
| 121 | sint32 id;
|
---|
| 122 | /// Button that is affected
|
---|
| 123 | uint8 button;
|
---|
| 124 | /// True if pressed
|
---|
| 125 | bool pressed;
|
---|
| 126 | };
|
---|
| 127 |
|
---|
| 128 | struct pad_axis_event
|
---|
| 129 | {
|
---|
| 130 | /// Pad ID
|
---|
| 131 | sint32 id;
|
---|
| 132 | /// Axis ID
|
---|
| 133 | uint8 axis;
|
---|
| 134 | /// Value
|
---|
| 135 | sint16 value;
|
---|
| 136 | };
|
---|
| 137 |
|
---|
[184] | 138 | struct joy_button_event
|
---|
| 139 | {
|
---|
| 140 | /// Joystick ID
|
---|
| 141 | sint32 id;
|
---|
| 142 | /// Button that is affected
|
---|
| 143 | uint8 button;
|
---|
| 144 | /// True if pressed
|
---|
| 145 | bool pressed;
|
---|
| 146 | };
|
---|
| 147 |
|
---|
| 148 | struct joy_axis_event
|
---|
| 149 | {
|
---|
| 150 | /// Joystick ID
|
---|
| 151 | sint32 id;
|
---|
| 152 | /// Axis ID
|
---|
| 153 | uint8 axis;
|
---|
| 154 | /// Value
|
---|
| 155 | sint16 value;
|
---|
| 156 | };
|
---|
| 157 |
|
---|
| 158 | struct joy_hat_event
|
---|
| 159 | {
|
---|
| 160 | /// Joystick ID
|
---|
| 161 | sint32 id;
|
---|
| 162 | /// Hat ID
|
---|
| 163 | uint8 hat;
|
---|
| 164 | /// Value
|
---|
| 165 | sint16 value;
|
---|
| 166 | };
|
---|
| 167 |
|
---|
| 168 | struct joy_ball_event
|
---|
| 169 | {
|
---|
| 170 | /// Joystick ID
|
---|
| 171 | sint32 id;
|
---|
| 172 | /// Ball ID
|
---|
| 173 | uint8 ball;
|
---|
| 174 | /// Relative X
|
---|
| 175 | sint16 rx;
|
---|
| 176 | /// Relative Y
|
---|
| 177 | sint16 ry;
|
---|
| 178 | };
|
---|
| 179 |
|
---|
[93] | 180 | struct resize_event
|
---|
| 181 | {
|
---|
[110] | 182 | /// New x size of the object.
|
---|
[93] | 183 | sint32 x;
|
---|
[110] | 184 | /// New y size of the object.
|
---|
[93] | 185 | sint32 y;
|
---|
| 186 | };
|
---|
| 187 |
|
---|
| 188 | struct active_event
|
---|
| 189 | {
|
---|
[110] | 190 | /// Whether focus was gained or lost.
|
---|
[93] | 191 | bool gain;
|
---|
| 192 | };
|
---|
| 193 |
|
---|
[67] | 194 | struct system_event
|
---|
| 195 | {
|
---|
| 196 | uint8 sys_type;
|
---|
| 197 | uint32 param1;
|
---|
| 198 | uint32 param2;
|
---|
| 199 | };
|
---|
| 200 |
|
---|
[68] | 201 | struct io_event
|
---|
[67] | 202 | {
|
---|
| 203 | io_event_code type;
|
---|
| 204 | union
|
---|
| 205 | {
|
---|
| 206 | key_event key;
|
---|
| 207 | mouse_button_event mbutton;
|
---|
| 208 | mouse_move_event mmove;
|
---|
[304] | 209 | mouse_wheel_event mwheel;
|
---|
[338] | 210 | pad_button_event pbutton;
|
---|
| 211 | pad_axis_event paxis;
|
---|
[184] | 212 | joy_button_event jbutton;
|
---|
| 213 | joy_axis_event jaxis;
|
---|
| 214 | joy_hat_event jhat;
|
---|
| 215 | joy_ball_event jball;
|
---|
[93] | 216 | resize_event resize;
|
---|
| 217 | active_event active;
|
---|
[67] | 218 | system_event system;
|
---|
| 219 | };
|
---|
| 220 | };
|
---|
| 221 |
|
---|
[110] | 222 | /**
|
---|
[132] | 223 | * Gets the name of the key given the code.
|
---|
[110] | 224 | *
|
---|
[132] | 225 | * @param key The code value of the key.
|
---|
| 226 | * @returns The name of the key.
|
---|
[110] | 227 | */
|
---|
[67] | 228 | const char* get_key_name( key_code key );
|
---|
[110] | 229 |
|
---|
| 230 | /**
|
---|
[132] | 231 | * Gets the name of the mouse button given the code.
|
---|
[110] | 232 | *
|
---|
[132] | 233 | * @param button The code value of the mouse button.
|
---|
| 234 | * @returns The name of the button.
|
---|
[110] | 235 | */
|
---|
[67] | 236 | const char* get_mouse_name( mouse_code button );
|
---|
[110] | 237 |
|
---|
| 238 | /**
|
---|
[132] | 239 | * Gets the name of the IO event given the code.
|
---|
[110] | 240 | *
|
---|
[132] | 241 | * @param event The code value of the IO event.
|
---|
| 242 | * @returns The name of the event.
|
---|
[110] | 243 | */
|
---|
[67] | 244 | const char* get_io_event_name( io_event_code event );
|
---|
[110] | 245 |
|
---|
| 246 | /**
|
---|
[132] | 247 | * Registers all events to the specified database.
|
---|
[110] | 248 | *
|
---|
[132] | 249 | * @param db The database to store all event data in.
|
---|
[110] | 250 | */
|
---|
[447] | 251 | void register_io_types( type_database* db );
|
---|
[338] | 252 |
|
---|
| 253 | void log_event( const io_event& e );
|
---|
[67] | 254 | }
|
---|
| 255 |
|
---|
[447] | 256 | NV_RTTI_DECLARE( nv::key_code )
|
---|
| 257 | NV_RTTI_DECLARE( nv::mouse_code )
|
---|
| 258 | NV_RTTI_DECLARE( nv::io_event_code )
|
---|
| 259 | NV_RTTI_DECLARE( nv::key_event )
|
---|
| 260 | NV_RTTI_DECLARE( nv::mouse_button_event )
|
---|
| 261 | NV_RTTI_DECLARE( nv::mouse_wheel_event )
|
---|
| 262 | NV_RTTI_DECLARE( nv::mouse_move_event )
|
---|
| 263 | NV_RTTI_DECLARE( nv::pad_button_event )
|
---|
| 264 | NV_RTTI_DECLARE( nv::pad_axis_event )
|
---|
| 265 | NV_RTTI_DECLARE( nv::joy_button_event )
|
---|
| 266 | NV_RTTI_DECLARE( nv::joy_axis_event )
|
---|
| 267 | NV_RTTI_DECLARE( nv::joy_hat_event )
|
---|
| 268 | NV_RTTI_DECLARE( nv::joy_ball_event )
|
---|
| 269 | NV_RTTI_DECLARE( nv::resize_event )
|
---|
| 270 | NV_RTTI_DECLARE( nv::active_event )
|
---|
| 271 | NV_RTTI_DECLARE( nv::system_event )
|
---|
| 272 | NV_RTTI_DECLARE( nv::io_event )
|
---|
| 273 |
|
---|
| 274 |
|
---|
[319] | 275 | #endif // NV_CORE_IO_EVENT_HH
|
---|