[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 |
|
---|
| 18 | namespace 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 |
|
---|
[338] | 104 | struct pad_button_event
|
---|
| 105 | {
|
---|
| 106 | /// Pad ID
|
---|
| 107 | sint32 id;
|
---|
| 108 | /// Button that is affected
|
---|
| 109 | uint8 button;
|
---|
| 110 | /// True if pressed
|
---|
| 111 | bool pressed;
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | struct pad_axis_event
|
---|
| 115 | {
|
---|
| 116 | /// Pad ID
|
---|
| 117 | sint32 id;
|
---|
| 118 | /// Axis ID
|
---|
| 119 | uint8 axis;
|
---|
| 120 | /// Value
|
---|
| 121 | sint16 value;
|
---|
| 122 | };
|
---|
| 123 |
|
---|
[184] | 124 | struct joy_button_event
|
---|
| 125 | {
|
---|
| 126 | /// Joystick ID
|
---|
| 127 | sint32 id;
|
---|
| 128 | /// Button that is affected
|
---|
| 129 | uint8 button;
|
---|
| 130 | /// True if pressed
|
---|
| 131 | bool pressed;
|
---|
| 132 | };
|
---|
| 133 |
|
---|
| 134 | struct joy_axis_event
|
---|
| 135 | {
|
---|
| 136 | /// Joystick ID
|
---|
| 137 | sint32 id;
|
---|
| 138 | /// Axis ID
|
---|
| 139 | uint8 axis;
|
---|
| 140 | /// Value
|
---|
| 141 | sint16 value;
|
---|
| 142 | };
|
---|
| 143 |
|
---|
| 144 | struct joy_hat_event
|
---|
| 145 | {
|
---|
| 146 | /// Joystick ID
|
---|
| 147 | sint32 id;
|
---|
| 148 | /// Hat ID
|
---|
| 149 | uint8 hat;
|
---|
| 150 | /// Value
|
---|
| 151 | sint16 value;
|
---|
| 152 | };
|
---|
| 153 |
|
---|
| 154 | struct joy_ball_event
|
---|
| 155 | {
|
---|
| 156 | /// Joystick ID
|
---|
| 157 | sint32 id;
|
---|
| 158 | /// Ball ID
|
---|
| 159 | uint8 ball;
|
---|
| 160 | /// Relative X
|
---|
| 161 | sint16 rx;
|
---|
| 162 | /// Relative Y
|
---|
| 163 | sint16 ry;
|
---|
| 164 | };
|
---|
| 165 |
|
---|
[93] | 166 | struct resize_event
|
---|
| 167 | {
|
---|
[110] | 168 | /// New x size of the object.
|
---|
[93] | 169 | sint32 x;
|
---|
[110] | 170 | /// New y size of the object.
|
---|
[93] | 171 | sint32 y;
|
---|
| 172 | };
|
---|
| 173 |
|
---|
| 174 | struct active_event
|
---|
| 175 | {
|
---|
[110] | 176 | /// Whether focus was gained or lost.
|
---|
[93] | 177 | bool gain;
|
---|
| 178 | };
|
---|
| 179 |
|
---|
[67] | 180 | struct system_event
|
---|
| 181 | {
|
---|
| 182 | uint8 sys_type;
|
---|
| 183 | uint32 param1;
|
---|
| 184 | uint32 param2;
|
---|
| 185 | };
|
---|
| 186 |
|
---|
[68] | 187 | struct io_event
|
---|
[67] | 188 | {
|
---|
| 189 | io_event_code type;
|
---|
| 190 | union
|
---|
| 191 | {
|
---|
| 192 | key_event key;
|
---|
| 193 | mouse_button_event mbutton;
|
---|
| 194 | mouse_move_event mmove;
|
---|
[304] | 195 | mouse_wheel_event mwheel;
|
---|
[338] | 196 | pad_button_event pbutton;
|
---|
| 197 | pad_axis_event paxis;
|
---|
[184] | 198 | joy_button_event jbutton;
|
---|
| 199 | joy_axis_event jaxis;
|
---|
| 200 | joy_hat_event jhat;
|
---|
| 201 | joy_ball_event jball;
|
---|
[93] | 202 | resize_event resize;
|
---|
| 203 | active_event active;
|
---|
[67] | 204 | system_event system;
|
---|
| 205 | };
|
---|
| 206 | };
|
---|
| 207 |
|
---|
[110] | 208 | /**
|
---|
[132] | 209 | * Gets the name of the key given the code.
|
---|
[110] | 210 | *
|
---|
[132] | 211 | * @param key The code value of the key.
|
---|
| 212 | * @returns The name of the key.
|
---|
[110] | 213 | */
|
---|
[67] | 214 | const char* get_key_name( key_code key );
|
---|
[110] | 215 |
|
---|
| 216 | /**
|
---|
[132] | 217 | * Gets the name of the mouse button given the code.
|
---|
[110] | 218 | *
|
---|
[132] | 219 | * @param button The code value of the mouse button.
|
---|
| 220 | * @returns The name of the button.
|
---|
[110] | 221 | */
|
---|
[67] | 222 | const char* get_mouse_name( mouse_code button );
|
---|
[110] | 223 |
|
---|
| 224 | /**
|
---|
[132] | 225 | * Gets the name of the IO event given the code.
|
---|
[110] | 226 | *
|
---|
[132] | 227 | * @param event The code value of the IO event.
|
---|
| 228 | * @returns The name of the event.
|
---|
[110] | 229 | */
|
---|
[67] | 230 | const char* get_io_event_name( io_event_code event );
|
---|
[110] | 231 |
|
---|
| 232 | /**
|
---|
[132] | 233 | * Registers all events to the specified database.
|
---|
[110] | 234 | *
|
---|
[132] | 235 | * @param db The database to store all event data in.
|
---|
[110] | 236 | */
|
---|
[319] | 237 | //void register_io_types( type_database* db );
|
---|
[338] | 238 |
|
---|
| 239 | void log_event( const io_event& e );
|
---|
[67] | 240 | }
|
---|
| 241 |
|
---|
[319] | 242 | #endif // NV_CORE_IO_EVENT_HH
|
---|