| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using System.Runtime.InteropServices; |
| | 5 | | using System.Text; |
| | 6 | |
|
| | 7 | | using SDL2; |
| | 8 | | using static SDL2.SDL_events; |
| | 9 | | using static SDL2.SDL_joystick; |
| | 10 | | using static SDL2.SDL_keyboard; |
| | 11 | | using static SDL2.SDL_keycode; |
| | 12 | | using static SDL2.SDL_scancode; |
| | 13 | |
|
| | 14 | | namespace Imagini |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Describes event args shared by all available event types. |
| | 18 | | /// </summary> |
| | 19 | | public abstract class CommonEventArgs : EventArgs |
| | 20 | | { |
| | 21 | | public long Timestamp { get; internal set; } |
| | 22 | | internal CommonEventArgs() => Timestamp = AppBase.TotalTime; |
| | 23 | | internal unsafe CommonEventArgs(SDL_CommonEvent e) => Timestamp = e.timestamp; |
| | 24 | | internal abstract SDL_Event AsEvent(); |
| | 25 | | } |
| | 26 | |
|
| | 27 | | /* Window events */ |
| | 28 | | /// <summary> |
| | 29 | | /// Describes various window state modifications. |
| | 30 | | /// </summary> |
| | 31 | | /// <seealso cref="WindowStateChangeEventArgs" /> |
| | 32 | | /// <seealso cref="Events.WindowEvents" /> |
| | 33 | | public enum WindowStateChange |
| | 34 | | { |
| | 35 | | None, |
| | 36 | | Shown, |
| | 37 | | Hidden, |
| | 38 | | Exposed, |
| | 39 | | Moved, |
| | 40 | | Resized, |
| | 41 | | SizeChanged, |
| | 42 | | Minimized, |
| | 43 | | Maximized, |
| | 44 | | Restored, |
| | 45 | | MouseEnter, |
| | 46 | | MouseLeave, |
| | 47 | | FocusGained, |
| | 48 | | FocusLost, |
| | 49 | | Closed |
| | 50 | | } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Describes window state change event data. |
| | 54 | | /// </summary> |
| | 55 | | /// <seealso cref="Events.WindowEvents" /> |
| | 56 | | public sealed class WindowStateChangeEventArgs : CommonEventArgs |
| | 57 | | { |
| | 58 | | /// <summary> |
| | 59 | | /// The window for which the event was fired. |
| | 60 | | /// </summary> |
| | 61 | | public Window Window { get; private set; } |
| | 62 | | /// <summary> |
| | 63 | | /// Target window state. |
| | 64 | | /// </summary> |
| | 65 | | public WindowStateChange State { get; private set; } |
| | 66 | | /// <summary> |
| | 67 | | /// Contains X coordinate or horizontal size if the window was moved, resized or it's size have changed. |
| | 68 | | /// </summary> |
| | 69 | | public int? X { get; private set; } |
| | 70 | | /// <summary> |
| | 71 | | /// Contains Y coordinate or vertical size if the window was moved, resized or it's size have changed. |
| | 72 | | /// </summary> |
| | 73 | | public int? Y { get; private set; } |
| | 74 | |
|
| | 75 | | /// <summary> |
| | 76 | | /// Creates an event args object. |
| | 77 | | /// </summary> |
| | 78 | | /// <param name="window">Target window. If null, the currently focused one is used.</param> |
| | 79 | | public WindowStateChangeEventArgs(WindowStateChange state, |
| | 80 | | Window window = null, int? x = null, int? y = null) : base() |
| | 81 | | => |
| | 82 | | (this.Window, this.State, this.X, this.Y) = |
| | 83 | | (window ?? Window.Current, state, x, y); |
| | 84 | |
|
| | 85 | | internal WindowStateChangeEventArgs(SDL_WindowEvent e) |
| | 86 | | : base(e) |
| | 87 | | { |
| | 88 | | State = (WindowStateChange)e.@event; |
| | 89 | | Window = Window.GetByID(e.windowID); |
| | 90 | | switch (State) |
| | 91 | | { |
| | 92 | | case WindowStateChange.Moved: |
| | 93 | | case WindowStateChange.Resized: |
| | 94 | | case WindowStateChange.SizeChanged: |
| | 95 | | X = e.data1; Y = e.data2; break; |
| | 96 | | } |
| | 97 | | } |
| | 98 | |
|
| | 99 | | internal override SDL_Event AsEvent() => |
| | 100 | | new SDL_WindowEvent() |
| | 101 | | { |
| | 102 | | type = (uint)SDL_EventType.SDL_WINDOWEVENT, |
| | 103 | | windowID = Window.ID, |
| | 104 | | data1 = X ?? 0, |
| | 105 | | data2 = Y ?? 0 |
| | 106 | | }; |
| | 107 | | } |
| | 108 | |
|
| | 109 | | /* Keyboard events */ |
| | 110 | | /// <summary> |
| | 111 | | /// Keyboard scancode. |
| | 112 | | /// </summary> |
| | 113 | | public enum Scancode // renamed SDL_Scancode |
| | 114 | | { |
| | 115 | |
|
| | 116 | | UNKNOWN = 0, |
| | 117 | | A = 4, |
| | 118 | | B = 5, |
| | 119 | | C = 6, |
| | 120 | | D = 7, |
| | 121 | | E = 8, |
| | 122 | | F = 9, |
| | 123 | | G = 10, |
| | 124 | | H = 11, |
| | 125 | | I = 12, |
| | 126 | | J = 13, |
| | 127 | | K = 14, |
| | 128 | | L = 15, |
| | 129 | | M = 16, |
| | 130 | | N = 17, |
| | 131 | | O = 18, |
| | 132 | | P = 19, |
| | 133 | | Q = 20, |
| | 134 | | R = 21, |
| | 135 | | S = 22, |
| | 136 | | T = 23, |
| | 137 | | U = 24, |
| | 138 | | V = 25, |
| | 139 | | W = 26, |
| | 140 | | X = 27, |
| | 141 | | Y = 28, |
| | 142 | | Z = 29, |
| | 143 | | NUMBER_1 = 30, |
| | 144 | | NUMBER_2 = 31, |
| | 145 | | NUMBER_3 = 32, |
| | 146 | | NUMBER_4 = 33, |
| | 147 | | NUMBER_5 = 34, |
| | 148 | | NUMBER_6 = 35, |
| | 149 | | NUMBER_7 = 36, |
| | 150 | | NUMBER_8 = 37, |
| | 151 | | NUMBER_9 = 38, |
| | 152 | | NUMBER_0 = 39, |
| | 153 | |
|
| | 154 | | RETURN = 40, |
| | 155 | | ESCAPE = 41, |
| | 156 | | BACKSPACE = 42, |
| | 157 | | TAB = 43, |
| | 158 | | SPACE = 44, |
| | 159 | | MINUS = 45, |
| | 160 | | EQUALS = 46, |
| | 161 | | LEFTBRACKET = 47, |
| | 162 | | RIGHTBRACKET = 48, |
| | 163 | | BACKSLASH = 49, |
| | 164 | | NONUSHASH = 50, |
| | 165 | | SEMICOLON = 51, |
| | 166 | | APOSTROPHE = 52, |
| | 167 | | GRAVE = 53, |
| | 168 | | COMMA = 54, |
| | 169 | | PERIOD = 55, |
| | 170 | | SLASH = 56, |
| | 171 | | CAPSLOCK = 57, |
| | 172 | | F1 = 58, |
| | 173 | | F2 = 59, |
| | 174 | | F3 = 60, |
| | 175 | | F4 = 61, |
| | 176 | | F5 = 62, |
| | 177 | | F6 = 63, |
| | 178 | | F7 = 64, |
| | 179 | | F8 = 65, |
| | 180 | | F9 = 66, |
| | 181 | | F10 = 67, |
| | 182 | | F11 = 68, |
| | 183 | | F12 = 69, |
| | 184 | | PRINTSCREEN = 70, |
| | 185 | | SCROLLLOCK = 71, |
| | 186 | | PAUSE = 72, |
| | 187 | | INSERT = 73, |
| | 188 | | HOME = 74, |
| | 189 | | PAGEUP = 75, |
| | 190 | | DELETE = 76, |
| | 191 | | END = 77, |
| | 192 | | PAGEDOWN = 78, |
| | 193 | | RIGHT = 79, |
| | 194 | | LEFT = 80, |
| | 195 | | DOWN = 81, |
| | 196 | | UP = 82, |
| | 197 | | NUMLOCKCLEAR = 83, |
| | 198 | | KP_DIVIDE = 84, |
| | 199 | | KP_MULTIPLY = 85, |
| | 200 | | KP_MINUS = 86, |
| | 201 | | KP_PLUS = 87, |
| | 202 | | KP_ENTER = 88, |
| | 203 | | KP_1 = 89, |
| | 204 | | KP_2 = 90, |
| | 205 | | KP_3 = 91, |
| | 206 | | KP_4 = 92, |
| | 207 | | KP_5 = 93, |
| | 208 | | KP_6 = 94, |
| | 209 | | KP_7 = 95, |
| | 210 | | KP_8 = 96, |
| | 211 | | KP_9 = 97, |
| | 212 | | KP_0 = 98, |
| | 213 | | KP_PERIOD = 99, |
| | 214 | | NONUSBACKSLASH = 100, |
| | 215 | | APPLICATION = 101, |
| | 216 | | POWER = 102, |
| | 217 | | KP_EQUALS = 103, |
| | 218 | | F13 = 104, |
| | 219 | | F14 = 105, |
| | 220 | | F15 = 106, |
| | 221 | | F16 = 107, |
| | 222 | | F17 = 108, |
| | 223 | | F18 = 109, |
| | 224 | | F19 = 110, |
| | 225 | | F20 = 111, |
| | 226 | | F21 = 112, |
| | 227 | | F22 = 113, |
| | 228 | | F23 = 114, |
| | 229 | | F24 = 115, |
| | 230 | | EXECUTE = 116, |
| | 231 | | HELP = 117, |
| | 232 | | MENU = 118, |
| | 233 | | SELECT = 119, |
| | 234 | | STOP = 120, |
| | 235 | | AGAIN = 121, |
| | 236 | | UNDO = 122, |
| | 237 | | CUT = 123, |
| | 238 | | COPY = 124, |
| | 239 | | PASTE = 125, |
| | 240 | | FIND = 126, |
| | 241 | | MUTE = 127, |
| | 242 | | VOLUMEUP = 128, |
| | 243 | | VOLUMEDOWN = 129, |
| | 244 | | KP_COMMA = 133, |
| | 245 | | KP_EQUALSAS400 = 134, |
| | 246 | | INTERNATIONAL1 = 135, |
| | 247 | | INTERNATIONAL2 = 136, |
| | 248 | | INTERNATIONAL3 = 137, |
| | 249 | | INTERNATIONAL4 = 138, |
| | 250 | | INTERNATIONAL5 = 139, |
| | 251 | | INTERNATIONAL6 = 140, |
| | 252 | | INTERNATIONAL7 = 141, |
| | 253 | | INTERNATIONAL8 = 142, |
| | 254 | | INTERNATIONAL9 = 143, |
| | 255 | | LANG1 = 144, |
| | 256 | | LANG2 = 145, |
| | 257 | | LANG3 = 146, |
| | 258 | | LANG4 = 147, |
| | 259 | | LANG5 = 148, |
| | 260 | | LANG6 = 149, |
| | 261 | | LANG7 = 150, |
| | 262 | | LANG8 = 151, |
| | 263 | | LANG9 = 152, |
| | 264 | | ALTERASE = 153, |
| | 265 | | SYSREQ = 154, |
| | 266 | | CANCEL = 155, |
| | 267 | | CLEAR = 156, |
| | 268 | | PRIOR = 157, |
| | 269 | | RETURN2 = 158, |
| | 270 | | SEPARATOR = 159, |
| | 271 | | OUT = 160, |
| | 272 | | OPER = 161, |
| | 273 | | CLEARAGAIN = 162, |
| | 274 | | CRSEL = 163, |
| | 275 | | EXSEL = 164, |
| | 276 | | KP_00 = 176, |
| | 277 | | KP_000 = 177, |
| | 278 | | THOUSANDSSEPARATOR = 178, |
| | 279 | | DECIMALSEPARATOR = 179, |
| | 280 | | CURRENCYUNIT = 180, |
| | 281 | | CURRENCYSUBUNIT = 181, |
| | 282 | | KP_LEFTPAREN = 182, |
| | 283 | | KP_RIGHTPAREN = 183, |
| | 284 | | KP_LEFTBRACE = 184, |
| | 285 | | KP_RIGHTBRACE = 185, |
| | 286 | | KP_TAB = 186, |
| | 287 | | KP_BACKSPACE = 187, |
| | 288 | | KP_A = 188, |
| | 289 | | KP_B = 189, |
| | 290 | | KP_C = 190, |
| | 291 | | KP_D = 191, |
| | 292 | | KP_E = 192, |
| | 293 | | KP_F = 193, |
| | 294 | | KP_XOR = 194, |
| | 295 | | KP_POWER = 195, |
| | 296 | | KP_PERCENT = 196, |
| | 297 | | KP_LESS = 197, |
| | 298 | | KP_GREATER = 198, |
| | 299 | | KP_AMPERSAND = 199, |
| | 300 | | KP_DBLAMPERSAND = 200, |
| | 301 | | KP_VERTICALBAR = 201, |
| | 302 | | KP_DBLVERTICALBAR = 202, |
| | 303 | | KP_COLON = 203, |
| | 304 | | KP_HASH = 204, |
| | 305 | | KP_SPACE = 205, |
| | 306 | | KP_AT = 206, |
| | 307 | | KP_EXCLAM = 207, |
| | 308 | | KP_MEMSTORE = 208, |
| | 309 | | KP_MEMRECALL = 209, |
| | 310 | | KP_MEMCLEAR = 210, |
| | 311 | | KP_MEMADD = 211, |
| | 312 | | KP_MEMSUBTRACT = 212, |
| | 313 | | KP_MEMMULTIPLY = 213, |
| | 314 | | KP_MEMDIVIDE = 214, |
| | 315 | | KP_PLUSMINUS = 215, |
| | 316 | | KP_CLEAR = 216, |
| | 317 | | KP_CLEARENTRY = 217, |
| | 318 | | KP_BINARY = 218, |
| | 319 | | KP_OCTAL = 219, |
| | 320 | | KP_DECIMAL = 220, |
| | 321 | | KP_HEXADECIMAL = 221, |
| | 322 | | LCTRL = 224, |
| | 323 | | LSHIFT = 225, |
| | 324 | | LALT = 226, |
| | 325 | | LGUI = 227, |
| | 326 | | RCTRL = 228, |
| | 327 | | RSHIFT = 229, |
| | 328 | | RALT = 230, |
| | 329 | | RGUI = 231, |
| | 330 | | MODE = 257, |
| | 331 | | AUDIONEXT = 258, |
| | 332 | | AUDIOPREV = 259, |
| | 333 | | AUDIOSTOP = 260, |
| | 334 | | AUDIOPLAY = 261, |
| | 335 | | AUDIOMUTE = 262, |
| | 336 | | MEDIASELECT = 263, |
| | 337 | | WWW = 264, |
| | 338 | | MAIL = 265, |
| | 339 | | CALCULATOR = 266, |
| | 340 | | COMPUTER = 267, |
| | 341 | | AC_SEARCH = 268, |
| | 342 | | AC_HOME = 269, |
| | 343 | | AC_BACK = 270, |
| | 344 | | AC_FORWARD = 271, |
| | 345 | | AC_STOP = 272, |
| | 346 | | AC_REFRESH = 273, |
| | 347 | | AC_BOOKMARKS = 274, |
| | 348 | | BRIGHTNESSDOWN = 275, |
| | 349 | | BRIGHTNESSUP = 276, |
| | 350 | | DISPLAYSWITCH = 277, |
| | 351 | | KBDILLUMTOGGLE = 278, |
| | 352 | | KBDILLUMDOWN = 279, |
| | 353 | | KBDILLUMUP = 280, |
| | 354 | | EJECT = 281, |
| | 355 | | SLEEP = 282, |
| | 356 | | APP1 = 283, |
| | 357 | | APP2 = 284, |
| | 358 | | } |
| | 359 | |
|
| | 360 | | /// <summary> |
| | 361 | | /// Keyboard virtual key. |
| | 362 | | /// </summary> |
| | 363 | | public enum Keycode |
| | 364 | | { |
| | 365 | | UNKNOWN = 0, |
| | 366 | | BACKSPACE = 8, |
| | 367 | | TAB = 9, |
| | 368 | | RETURN = 13, |
| | 369 | | ESCAPE = 27, |
| | 370 | | SPACE = 32, |
| | 371 | | EXCLAIM = 33, |
| | 372 | | QUOTEDBL = 34, |
| | 373 | | HASH = 35, |
| | 374 | | DOLLAR = 36, |
| | 375 | | PERCENT = 37, |
| | 376 | | AMPERSAND = 38, |
| | 377 | | QUOTE = 39, |
| | 378 | | LEFTPAREN = 40, |
| | 379 | | RIGHTPAREN = 41, |
| | 380 | | ASTERISK = 42, |
| | 381 | | PLUS = 43, |
| | 382 | | COMMA = 44, |
| | 383 | | MINUS = 45, |
| | 384 | | PERIOD = 46, |
| | 385 | | SLASH = 47, |
| | 386 | | NUMBER_0 = 48, |
| | 387 | | NUMBER_1 = 49, |
| | 388 | | NUMBER_2 = 50, |
| | 389 | | NUMBER_3 = 51, |
| | 390 | | NUMBER_4 = 52, |
| | 391 | | NUMBER_5 = 53, |
| | 392 | | NUMBER_6 = 54, |
| | 393 | | NUMBER_7 = 55, |
| | 394 | | NUMBER_8 = 56, |
| | 395 | | NUMBER_9 = 57, |
| | 396 | | COLON = 58, |
| | 397 | | SEMICOLON = 59, |
| | 398 | | LESS = 60, |
| | 399 | | EQUALS = 61, |
| | 400 | | GREATER = 62, |
| | 401 | | QUESTION = 63, |
| | 402 | | AT = 64, |
| | 403 | | LEFTBRACKET = 91, |
| | 404 | | BACKSLASH = 92, |
| | 405 | | RIGHTBRACKET = 93, |
| | 406 | | CARET = 94, |
| | 407 | | UNDERSCORE = 95, |
| | 408 | | BACKQUOTE = 96, |
| | 409 | | a = 97, |
| | 410 | | b = 98, |
| | 411 | | c = 99, |
| | 412 | | d = 100, |
| | 413 | | e = 101, |
| | 414 | | f = 102, |
| | 415 | | g = 103, |
| | 416 | | h = 104, |
| | 417 | | i = 105, |
| | 418 | | j = 106, |
| | 419 | | k = 107, |
| | 420 | | l = 108, |
| | 421 | | m = 109, |
| | 422 | | n = 110, |
| | 423 | | o = 111, |
| | 424 | | p = 112, |
| | 425 | | q = 113, |
| | 426 | | r = 114, |
| | 427 | | s = 115, |
| | 428 | | t = 116, |
| | 429 | | u = 117, |
| | 430 | | v = 118, |
| | 431 | | w = 119, |
| | 432 | | x = 120, |
| | 433 | | y = 121, |
| | 434 | | z = 122, |
| | 435 | | DELETE = 127, |
| | 436 | | CAPSLOCK = 1073741881, |
| | 437 | | F1 = 1073741882, |
| | 438 | | F2 = 1073741883, |
| | 439 | | F3 = 1073741884, |
| | 440 | | F4 = 1073741885, |
| | 441 | | F5 = 1073741886, |
| | 442 | | F6 = 1073741887, |
| | 443 | | F7 = 1073741888, |
| | 444 | | F8 = 1073741889, |
| | 445 | | F9 = 1073741890, |
| | 446 | | F10 = 1073741891, |
| | 447 | | F11 = 1073741892, |
| | 448 | | F12 = 1073741893, |
| | 449 | | PRINTSCREEN = 1073741894, |
| | 450 | | SCROLLLOCK = 1073741895, |
| | 451 | | PAUSE = 1073741896, |
| | 452 | | INSERT = 1073741897, |
| | 453 | | HOME = 1073741898, |
| | 454 | | PAGEUP = 1073741899, |
| | 455 | | END = 1073741901, |
| | 456 | | PAGEDOWN = 1073741902, |
| | 457 | | RIGHT = 1073741903, |
| | 458 | | LEFT = 1073741904, |
| | 459 | | DOWN = 1073741905, |
| | 460 | | UP = 1073741906, |
| | 461 | | NUMLOCKCLEAR = 1073741907, |
| | 462 | | KP_DIVIDE = 1073741908, |
| | 463 | | KP_MULTIPLY = 1073741909, |
| | 464 | | KP_MINUS = 1073741910, |
| | 465 | | KP_PLUS = 1073741911, |
| | 466 | | KP_ENTER = 1073741912, |
| | 467 | | KP_1 = 1073741913, |
| | 468 | | KP_2 = 1073741914, |
| | 469 | | KP_3 = 1073741915, |
| | 470 | | KP_4 = 1073741916, |
| | 471 | | KP_5 = 1073741917, |
| | 472 | | KP_6 = 1073741918, |
| | 473 | | KP_7 = 1073741919, |
| | 474 | | KP_8 = 1073741920, |
| | 475 | | KP_9 = 1073741921, |
| | 476 | | KP_0 = 1073741922, |
| | 477 | | KP_PERIOD = 1073741923, |
| | 478 | | APPLICATION = 1073741925, |
| | 479 | | POWER = 1073741926, |
| | 480 | | KP_EQUALS = 1073741927, |
| | 481 | | F13 = 1073741928, |
| | 482 | | F14 = 1073741929, |
| | 483 | | F15 = 1073741930, |
| | 484 | | F16 = 1073741931, |
| | 485 | | F17 = 1073741932, |
| | 486 | | F18 = 1073741933, |
| | 487 | | F19 = 1073741934, |
| | 488 | | F20 = 1073741935, |
| | 489 | | F21 = 1073741936, |
| | 490 | | F22 = 1073741937, |
| | 491 | | F23 = 1073741938, |
| | 492 | | F24 = 1073741939, |
| | 493 | | EXECUTE = 1073741940, |
| | 494 | | HELP = 1073741941, |
| | 495 | | MENU = 1073741942, |
| | 496 | | SELECT = 1073741943, |
| | 497 | | STOP = 1073741944, |
| | 498 | | AGAIN = 1073741945, |
| | 499 | | UNDO = 1073741946, |
| | 500 | | CUT = 1073741947, |
| | 501 | | COPY = 1073741948, |
| | 502 | | PASTE = 1073741949, |
| | 503 | | FIND = 1073741950, |
| | 504 | | MUTE = 1073741951, |
| | 505 | | VOLUMEUP = 1073741952, |
| | 506 | | VOLUMEDOWN = 1073741953, |
| | 507 | | KP_COMMA = 1073741957, |
| | 508 | | KP_EQUALSAS400 = 1073741958, |
| | 509 | | ALTERASE = 1073741977, |
| | 510 | | SYSREQ = 1073741978, |
| | 511 | | CANCEL = 1073741979, |
| | 512 | | CLEAR = 1073741980, |
| | 513 | | PRIOR = 1073741981, |
| | 514 | | RETURN2 = 1073741982, |
| | 515 | | SEPARATOR = 1073741983, |
| | 516 | | OUT = 1073741984, |
| | 517 | | OPER = 1073741985, |
| | 518 | | CLEARAGAIN = 1073741986, |
| | 519 | | CRSEL = 1073741987, |
| | 520 | | EXSEL = 1073741988, |
| | 521 | | KP_00 = 1073742000, |
| | 522 | | KP_000 = 1073742001, |
| | 523 | | THOUSANDSSEPARATOR = 1073742002, |
| | 524 | | DECIMALSEPARATOR = 1073742003, |
| | 525 | | CURRENCYUNIT = 1073742004, |
| | 526 | | CURRENCYSUBUNIT = 1073742005, |
| | 527 | | KP_LEFTPAREN = 1073742006, |
| | 528 | | KP_RIGHTPAREN = 1073742007, |
| | 529 | | KP_LEFTBRACE = 1073742008, |
| | 530 | | KP_RIGHTBRACE = 1073742009, |
| | 531 | | KP_TAB = 1073742010, |
| | 532 | | KP_BACKSPACE = 1073742011, |
| | 533 | | KP_A = 1073742012, |
| | 534 | | KP_B = 1073742013, |
| | 535 | | KP_C = 1073742014, |
| | 536 | | KP_D = 1073742015, |
| | 537 | | KP_E = 1073742016, |
| | 538 | | KP_F = 1073742017, |
| | 539 | | KP_XOR = 1073742018, |
| | 540 | | KP_POWER = 1073742019, |
| | 541 | | KP_PERCENT = 1073742020, |
| | 542 | | KP_LESS = 1073742021, |
| | 543 | | KP_GREATER = 1073742022, |
| | 544 | | KP_AMPERSAND = 1073742023, |
| | 545 | | KP_DBLAMPERSAND = 1073742024, |
| | 546 | | KP_VERTICALBAR = 1073742025, |
| | 547 | | KP_DBLVERTICALBAR = 1073742026, |
| | 548 | | KP_COLON = 1073742027, |
| | 549 | | KP_HASH = 1073742028, |
| | 550 | | KP_SPACE = 1073742029, |
| | 551 | | KP_AT = 1073742030, |
| | 552 | | KP_EXCLAM = 1073742031, |
| | 553 | | KP_MEMSTORE = 1073742032, |
| | 554 | | KP_MEMRECALL = 1073742033, |
| | 555 | | KP_MEMCLEAR = 1073742034, |
| | 556 | | KP_MEMADD = 1073742035, |
| | 557 | | KP_MEMSUBTRACT = 1073742036, |
| | 558 | | KP_MEMMULTIPLY = 1073742037, |
| | 559 | | KP_MEMDIVIDE = 1073742038, |
| | 560 | | KP_PLUSMINUS = 1073742039, |
| | 561 | | KP_CLEAR = 1073742040, |
| | 562 | | KP_CLEARENTRY = 1073742041, |
| | 563 | | KP_BINARY = 1073742042, |
| | 564 | | KP_OCTAL = 1073742043, |
| | 565 | | KP_DECIMAL = 1073742044, |
| | 566 | | KP_HEXADECIMAL = 1073742045, |
| | 567 | | LCTRL = 1073742048, |
| | 568 | | LSHIFT = 1073742049, |
| | 569 | | LALT = 1073742050, |
| | 570 | | LGUI = 1073742051, |
| | 571 | | RCTRL = 1073742052, |
| | 572 | | RSHIFT = 1073742053, |
| | 573 | | RALT = 1073742054, |
| | 574 | | RGUI = 1073742055, |
| | 575 | | MODE = 1073742081, |
| | 576 | | AUDIONEXT = 1073742082, |
| | 577 | | AUDIOPREV = 1073742083, |
| | 578 | | AUDIOSTOP = 1073742084, |
| | 579 | | AUDIOPLAY = 1073742085, |
| | 580 | | AUDIOMUTE = 1073742086, |
| | 581 | | MEDIASELECT = 1073742087, |
| | 582 | | WWW = 1073742088, |
| | 583 | | MAIL = 1073742089, |
| | 584 | | CALCULATOR = 1073742090, |
| | 585 | | COMPUTER = 1073742091, |
| | 586 | | AC_SEARCH = 1073742092, |
| | 587 | | AC_HOME = 1073742093, |
| | 588 | | AC_BACK = 1073742094, |
| | 589 | | AC_FORWARD = 1073742095, |
| | 590 | | AC_STOP = 1073742096, |
| | 591 | | AC_REFRESH = 1073742097, |
| | 592 | | AC_BOOKMARKS = 1073742098, |
| | 593 | | BRIGHTNESSDOWN = 1073742099, |
| | 594 | | BRIGHTNESSUP = 1073742100, |
| | 595 | | DISPLAYSWITCH = 1073742101, |
| | 596 | | KBDILLUMTOGGLE = 1073742102, |
| | 597 | | KBDILLUMDOWN = 1073742103, |
| | 598 | | KBDILLUMUP = 1073742104, |
| | 599 | | EJECT = 1073742105, |
| | 600 | | SLEEP = 1073742106 |
| | 601 | | } |
| | 602 | |
|
| | 603 | | [Flags] |
| | 604 | | /// <summary> |
| | 605 | | /// Keyboard key modifiers. |
| | 606 | | /// </summary> |
| | 607 | | public enum KeyModifier |
| | 608 | | { |
| | 609 | | NONE = 0x0000, |
| | 610 | | LSHIFT = 0x0001, |
| | 611 | | RSHIFT = 0x0002, |
| | 612 | | LCTRL = 0x0040, |
| | 613 | | RCTRL = 0x0080, |
| | 614 | | LALT = 0x0100, |
| | 615 | | RALT = 0x0200, |
| | 616 | | LGUI = 0x0400, |
| | 617 | | RGUI = 0x0800, |
| | 618 | | NUM = 0x1000, |
| | 619 | | CAPS = 0x2000, |
| | 620 | | MODE = 0x4000, |
| | 621 | | RESERVED = 0x8000 |
| | 622 | | } |
| | 623 | |
|
| | 624 | | /// <summary> |
| | 625 | | /// Represents a keyboard key. |
| | 626 | | /// </summary> |
| | 627 | | public struct KeyboardKey |
| | 628 | | { |
| | 629 | | public Scancode Scancode; |
| | 630 | | public Keycode Keycode; |
| | 631 | | public KeyModifier Modifiers; |
| | 632 | |
|
| | 633 | | internal KeyboardKey(SDL_KeyboardEvent e) |
| | 634 | | { |
| | 635 | | Scancode = (Scancode)(int)e.keysym.scancode; |
| | 636 | | Keycode = (Keycode)(int)e.keysym.sym; |
| | 637 | | Modifiers = (KeyModifier)(int)e.keysym.mod; |
| | 638 | | } |
| | 639 | |
|
| | 640 | | internal SDL_Keysym AsKeysym() |
| | 641 | | { |
| | 642 | | return new SDL_Keysym() |
| | 643 | | { |
| | 644 | | scancode = (SDL_Scancode)(int)Scancode, |
| | 645 | | sym = (SDL_Keycode)(int)Keycode, |
| | 646 | | mod = (ushort)Modifiers |
| | 647 | | }; |
| | 648 | | } |
| | 649 | | } |
| | 650 | |
|
| | 651 | | /// <summary> |
| | 652 | | /// Describes keyboard event data. |
| | 653 | | /// </summary> |
| | 654 | | public sealed class KeyboardEventArgs : CommonEventArgs |
| | 655 | | { |
| | 656 | | /// <summary> |
| | 657 | | /// Target window. |
| | 658 | | /// </summary> |
| | 659 | | public Window Window { get; private set; } |
| | 660 | | /// <summary> |
| | 661 | | /// Returns the pressed or released key. |
| | 662 | | /// </summary> |
| | 663 | | public KeyboardKey Key { get; private set; } |
| | 664 | | /// <summary> |
| | 665 | | /// Defines if the key is pressed or released. |
| | 666 | | /// </summary> |
| | 667 | | public bool IsPressed { get; private set; } |
| | 668 | | /// <summary> |
| | 669 | | /// Defines if this is a key repeat |
| | 670 | | /// </summary> |
| | 671 | | public bool IsRepeat { get; private set; } |
| | 672 | | /// <summary> |
| | 673 | | /// Creates a new event args object. |
| | 674 | | /// </summary> |
| | 675 | | /// <param name="window">Target window. If null, the currently focused one is used.</param> |
| | 676 | | public KeyboardEventArgs(KeyboardKey key, bool isPressed, |
| | 677 | | Window window = null, bool isRepeat = false) : base() |
| | 678 | | => |
| | 679 | | (this.Window, this.Key, this.IsPressed, this.IsRepeat) = |
| | 680 | | (window ?? Window.Current, key, isPressed, isRepeat); |
| | 681 | |
|
| | 682 | | internal KeyboardEventArgs(SDL_KeyboardEvent e) |
| | 683 | | : base(e) |
| | 684 | | { |
| | 685 | | Window = Window.GetByID(e.windowID); |
| | 686 | | Key = new KeyboardKey(e); |
| | 687 | | IsPressed = e.state > 0; |
| | 688 | | IsRepeat = e.repeat > 0; |
| | 689 | | } |
| | 690 | |
|
| | 691 | | internal override SDL_Event AsEvent() => |
| | 692 | | new SDL_KeyboardEvent() |
| | 693 | | { |
| | 694 | | type = (uint)(IsPressed ? SDL_EventType.SDL_KEYDOWN : SDL_EventType.SDL_KEYUP), |
| | 695 | | timestamp = (uint)Timestamp, |
| | 696 | | windowID = Window.ID, |
| | 697 | | state = IsPressed ? (byte)1 : (byte)0, |
| | 698 | | repeat = IsRepeat ? (byte)1 : (byte)0, |
| | 699 | | keysym = Key.AsKeysym() |
| | 700 | | }; |
| | 701 | | } |
| | 702 | |
|
| | 703 | | /// <summary> |
| | 704 | | /// Represents a text editing event. |
| | 705 | | /// </summary> |
| | 706 | | public class TextEditingEventArgs : CommonEventArgs |
| | 707 | | { |
| | 708 | | /// <summary> |
| | 709 | | /// Target window. |
| | 710 | | /// </summary> |
| | 711 | | public Window Window { get; private set; } |
| | 712 | | /// <summary> |
| | 713 | | /// The editing text. |
| | 714 | | /// </summary> |
| | 715 | | public string Text { get; private set; } |
| | 716 | | /// <summary> |
| | 717 | | /// The start cursor of the selected editing text. |
| | 718 | | /// </summary> |
| | 719 | | public int Start { get; private set; } |
| | 720 | | /// <summary> |
| | 721 | | /// The length of the selected editing text. |
| | 722 | | /// </summary> |
| | 723 | | public int Length { get; private set; } |
| | 724 | |
|
| | 725 | |
|
| | 726 | | /// <summary> |
| | 727 | | /// Creates a new event args object. |
| | 728 | | /// </summary> |
| | 729 | | /// <param name="window">Target window. If null, the currently focused window is used.</param> |
| | 730 | | public TextEditingEventArgs(string text, int start, int length, Window window = null) |
| | 731 | | : base() => |
| | 732 | | (this.Text, this.Start, this.Length, this.Window) = (text, start, length, Window ?? Window.Current); |
| | 733 | |
|
| | 734 | | internal unsafe TextEditingEventArgs(SDL_TextEditingEvent e) => |
| | 735 | | (this.Text, this.Start, this.Length, this.Window) = |
| | 736 | | (Util.FromNullTerminated(e.text), e.start, e.length, Window.GetByID(e.windowID)); |
| | 737 | |
|
| | 738 | | internal unsafe override SDL_Event AsEvent() |
| | 739 | | { |
| | 740 | | var bytes = Encoding.UTF8.GetBytes(Text); |
| | 741 | | var result = new SDL_TextEditingEvent() |
| | 742 | | { |
| | 743 | | type = (uint)SDL_EventType.SDL_TEXTEDITING, |
| | 744 | | timestamp = (uint)Timestamp, |
| | 745 | | windowID = Window.ID, |
| | 746 | | start = Start, |
| | 747 | | length = Length |
| | 748 | | }; |
| | 749 | | Marshal.Copy(bytes, 0, (IntPtr)result.text, Math.Min(SDL_TEXTINPUTEVENT_TEXT_SIZE, bytes.Length)); |
| | 750 | | return result; |
| | 751 | | } |
| | 752 | | } |
| | 753 | |
|
| | 754 | | /// <summary> |
| | 755 | | /// Represents a text input event. |
| | 756 | | /// </summary> |
| | 757 | | public class TextInputEventArgs : CommonEventArgs |
| | 758 | | { |
| | 759 | | /// <summary> |
| | 760 | | /// Target window. |
| | 761 | | /// </summary> |
| | 762 | | public Window Window { get; private set; } |
| | 763 | | /// <summary> |
| | 764 | | /// Text entered by user. |
| | 765 | | /// </summary> |
| | 766 | | public string Text { get; private set; } |
| | 767 | |
|
| | 768 | | /// <summary> |
| | 769 | | /// Creates a new event args object. |
| | 770 | | /// </summary> |
| | 771 | | /// <param name="text">Text entered by user.</param> |
| | 772 | | /// <param name="window">Target window. If null, the currently focused window is used.</param> |
| | 773 | | public TextInputEventArgs(string text, Window window = null) : base() => |
| | 774 | | (this.Window, this.Text) = (window ?? Window.Current, text); |
| | 775 | |
|
| | 776 | | internal unsafe TextInputEventArgs(SDL_TextInputEvent e) : base(e) => |
| | 777 | | (this.Window, this.Text) = |
| | 778 | | (Window.GetByID(e.windowID), Util.FromNullTerminated(e.text)); |
| | 779 | |
|
| | 780 | | internal unsafe override SDL_Event AsEvent() |
| | 781 | | { |
| | 782 | | var bytes = Encoding.UTF8.GetBytes(Text); |
| | 783 | | var result = new SDL_TextInputEvent() |
| | 784 | | { |
| | 785 | | type = (uint)SDL_EventType.SDL_TEXTINPUT, |
| | 786 | | timestamp = (uint)Timestamp, |
| | 787 | | windowID = Window.ID, |
| | 788 | | }; |
| | 789 | | Marshal.Copy(bytes, 0, (IntPtr)result.text, Math.Min(SDL_TEXTINPUTEVENT_TEXT_SIZE, bytes.Length)); |
| | 790 | | return result; |
| | 791 | | } |
| | 792 | | } |
| | 793 | |
|
| | 794 | | /* Mouse events */ |
| | 795 | | /// <summary> |
| | 796 | | /// Represents a pressed or released mouse button. |
| | 797 | | /// </summary> |
| | 798 | | public enum MouseButton : byte |
| | 799 | | { |
| | 800 | | Left = 1, |
| | 801 | | Middle, |
| | 802 | | Right, |
| | 803 | | X1, |
| | 804 | | X2 |
| | 805 | | } |
| | 806 | |
|
| | 807 | | [Flags] |
| | 808 | | /// <summary> |
| | 809 | | /// Represents all pressed and released mouse buttons. |
| | 810 | | /// </summary> |
| | 811 | | public enum MouseButtons : uint |
| | 812 | | { |
| | 813 | | Left = 0x1, |
| | 814 | | Middle = 0x2, |
| | 815 | | Right = 0x4, |
| | 816 | | X1 = 0x8, |
| | 817 | | X2 = 0xF |
| | 818 | | } |
| | 819 | |
|
| | 820 | | /// <summary> |
| | 821 | | /// Describes mouse move event data. |
| | 822 | | /// </summary> |
| | 823 | | public class MouseMoveEventArgs : CommonEventArgs |
| | 824 | | { |
| | 825 | | /// <summary> |
| | 826 | | /// Target window. |
| | 827 | | /// </summary> |
| | 828 | | public Window Window { get; private set; } |
| | 829 | | /// <summary> |
| | 830 | | /// Mouse button state. |
| | 831 | | /// </summary> |
| | 832 | | public MouseButtons Buttons { get; private set; } |
| | 833 | | /// <summary> |
| | 834 | | /// X coordinate, relative to window. |
| | 835 | | /// </summary> |
| | 836 | | public int X { get; private set; } |
| | 837 | | /// <summary> |
| | 838 | | /// Y coordinate, relative to window. |
| | 839 | | /// </summary> |
| | 840 | | public int Y { get; private set; } |
| | 841 | | /// <summary> |
| | 842 | | /// Relative motion in X direction. |
| | 843 | | /// </summary> |
| | 844 | | public int RelativeX { get; private set; } |
| | 845 | | /// <summary> |
| | 846 | | /// Relative motion in Y direction. |
| | 847 | | /// </summary> |
| | 848 | | public int RelativeY { get; private set; } |
| | 849 | |
|
| | 850 | | /// <summary> |
| | 851 | | /// Creates new event args object. |
| | 852 | | /// </summary> |
| | 853 | | /// <param name="x">X coordinate relative to window.</param> |
| | 854 | | /// <param name="y">Y coordinate relative to window.</param> |
| | 855 | | /// <param name="relX">Relative motion in X direction.</param> |
| | 856 | | /// <param name="relY">Relative motion in Y direction.</param> |
| | 857 | | /// <param name="buttons">Mouse button state.</param> |
| | 858 | | /// <param name="window">Target window. If null, the currently focused one is used.</param> |
| | 859 | | public MouseMoveEventArgs(int x, int y, int relX, int relY, |
| | 860 | | MouseButtons buttons, Window window = null) : base() |
| | 861 | | => |
| | 862 | | (this.X, this.Y, this.RelativeX, this.RelativeY, this.Buttons, this.Window) = |
| | 863 | | (x, y, relX, relY, buttons, window ?? Window.Current); |
| | 864 | |
|
| | 865 | | internal MouseMoveEventArgs(SDL_MouseMotionEvent e) |
| | 866 | | : base(e) |
| | 867 | | { |
| | 868 | | Window = Window.GetByID(e.windowID); |
| | 869 | | X = e.x; Y = e.y; RelativeX = e.xrel; RelativeY = e.yrel; |
| | 870 | | Buttons = (MouseButtons)e.state; |
| | 871 | | } |
| | 872 | |
|
| | 873 | | /// <summary> |
| | 874 | | /// Returns true if the specified button is pressed. |
| | 875 | | /// </summary> |
| | 876 | | public bool IsPressed(MouseButtons button) => Buttons.HasFlag(button); |
| | 877 | |
|
| | 878 | | internal override SDL_Event AsEvent() => |
| | 879 | | new SDL_MouseMotionEvent() |
| | 880 | | { |
| | 881 | | type = (uint)SDL_EventType.SDL_MOUSEMOTION, |
| | 882 | | timestamp = (uint)Timestamp, |
| | 883 | | windowID = Window.ID, |
| | 884 | | which = 0, |
| | 885 | | state = (uint)Buttons, |
| | 886 | | x = X, |
| | 887 | | y = Y, |
| | 888 | | xrel = RelativeX, |
| | 889 | | yrel = RelativeY |
| | 890 | | }; |
| | 891 | | } |
| | 892 | |
|
| | 893 | | /// <summary> |
| | 894 | | /// Describes mouse button state change event data. |
| | 895 | | /// </summary> |
| | 896 | | public class MouseButtonEventArgs : CommonEventArgs |
| | 897 | | { |
| | 898 | | /// <summary> |
| | 899 | | /// Target window. |
| | 900 | | /// </summary> |
| 16 | 901 | | public Window Window { get; private set; } |
| | 902 | | /// <summary> |
| | 903 | | /// The button that changed. |
| | 904 | | /// </summary> |
| 16 | 905 | | public MouseButton Button { get; private set; } |
| | 906 | | /// <summary> |
| | 907 | | /// Indicates if the button was pressed or released. |
| | 908 | | /// </summary> |
| | 909 | | /// <returns></returns> |
| 18 | 910 | | public bool IsPressed { get; private set; } |
| | 911 | | /// <summary> |
| | 912 | | /// Number of clicks. |
| | 913 | | /// </summary> |
| 14 | 914 | | public byte Clicks { get; private set; } |
| | 915 | | /// <summary> |
| | 916 | | /// X coordinate, relative to window. |
| | 917 | | /// </summary> |
| 14 | 918 | | public int X { get; private set; } |
| | 919 | | /// <summary> |
| | 920 | | /// Y coordinate, relative to window. |
| | 921 | | /// </summary> |
| 14 | 922 | | public int Y { get; private set; } |
| | 923 | |
|
| | 924 | | /// <summary> |
| | 925 | | /// Creates a new event args object. |
| | 926 | | /// </summary> |
| | 927 | | /// <param name="button">The button that changed.</param> |
| | 928 | | /// <param name="x">X coordinate, relative to window.</param> |
| | 929 | | /// <param name="y">Y coordinate, relative to window.</param> |
| | 930 | | /// <param name="isPressed">Indicates if the button was pressed or released.</param> |
| | 931 | | /// <param name="window">Target window. If null, the currently focused one is used.</param> |
| | 932 | | /// <param name="clicks">Number of clicks.</param> |
| | 933 | | public MouseButtonEventArgs(MouseButton button, int x, int y, bool isPressed, |
| 2 | 934 | | Window window = null, byte clicks = 1) : base() |
| | 935 | | => |
| 2 | 936 | | (this.Button, this.Window, this.X, this.Y, this.IsPressed, this.Clicks) = |
| 2 | 937 | | (button, window ?? Window.Current, x, y, isPressed, Math.Max((byte)1, clicks)); |
| | 938 | |
|
| | 939 | | internal MouseButtonEventArgs(SDL_MouseButtonEvent e) |
| 2 | 940 | | : base(e) |
| | 941 | | { |
| 2 | 942 | | Button = (MouseButton)e.button; |
| 2 | 943 | | Window = Window.GetByID(e.windowID); |
| 6 | 944 | | X = e.x; Y = e.y; Clicks = Math.Max((byte)1, e.clicks); |
| 2 | 945 | | IsPressed = e.state > 0; |
| 2 | 946 | | } |
| | 947 | |
|
| | 948 | | internal override SDL_Event AsEvent() => |
| 2 | 949 | | new SDL_MouseButtonEvent() |
| 2 | 950 | | { |
| 2 | 951 | | type = (uint)(IsPressed ? SDL_EventType.SDL_MOUSEBUTTONDOWN : |
| 2 | 952 | | SDL_EventType.SDL_MOUSEBUTTONUP), |
| 2 | 953 | | timestamp = (uint)Timestamp, |
| 2 | 954 | | windowID = Window.ID, |
| 2 | 955 | | which = 0, |
| 2 | 956 | | button = (byte)Button, |
| 2 | 957 | | state = IsPressed ? (byte)1 : (byte)0, |
| 2 | 958 | | clicks = (byte)Clicks, |
| 2 | 959 | | x = X, |
| 2 | 960 | | y = Y, |
| 2 | 961 | | }; |
| | 962 | | } |
| | 963 | |
|
| | 964 | | /// <summary> |
| | 965 | | /// Describes mouse wheel scroll event data. |
| | 966 | | /// </summary> |
| | 967 | | public class MouseWheelEventArgs : CommonEventArgs |
| | 968 | | { |
| | 969 | | /// <summary> |
| | 970 | | /// Target window. |
| | 971 | | /// </summary> |
| | 972 | | public Window Window { get; private set; } |
| | 973 | | /// <summary> |
| | 974 | | /// The amount scrolled horizontally, positive to the right and negative to the left. |
| | 975 | | /// </summary> |
| | 976 | | public int X { get; private set; } |
| | 977 | | /// <summary> |
| | 978 | | /// The amount scrolled vertically, positive away from the user and negative toward the user. |
| | 979 | | /// </summary> |
| | 980 | | public int Y { get; private set; } |
| | 981 | |
|
| | 982 | | /// <summary> |
| | 983 | | /// Creates a new event args object. |
| | 984 | | /// </summary> |
| | 985 | | /// <param name="x">The amount scrolled horizontally, positive to the right and negative to the left.</param> |
| | 986 | | /// <param name="y">The amount scrolled vertically, positive away from the user and negative toward the user.</p |
| | 987 | | /// <param name="window">Target window. If null, the currently focused one is used.</param> |
| | 988 | | public MouseWheelEventArgs(int x, int y, Window window = null) : base() => |
| | 989 | | (this.X, this.Y, this.Window) = (x, y, window ?? Window.Current); |
| | 990 | |
|
| | 991 | | internal MouseWheelEventArgs(SDL_MouseWheelEvent e) : base(e) |
| | 992 | | => (this.X, this.Y, this.Window) = (e.x, e.y, Window.GetByID(e.windowID)); |
| | 993 | |
|
| | 994 | | internal override SDL_Event AsEvent() => |
| | 995 | | new SDL_MouseWheelEvent() |
| | 996 | | { |
| | 997 | | type = (uint)SDL_EventType.SDL_MOUSEWHEEL, |
| | 998 | | timestamp = (uint)Timestamp, |
| | 999 | | windowID = Window.ID, |
| | 1000 | | which = 0, |
| | 1001 | | x = X, |
| | 1002 | | y = Y |
| | 1003 | | }; |
| | 1004 | | } |
| | 1005 | |
|
| | 1006 | | /// <summary> |
| | 1007 | | /// Describes joystick axis motion event data. |
| | 1008 | | /// </summary> |
| | 1009 | | public class JoyAxisMotionEventArgs : CommonEventArgs |
| | 1010 | | { |
| | 1011 | | /// <summary> |
| | 1012 | | /// The joystick instance ID. |
| | 1013 | | /// </summary> |
| | 1014 | | public int JoystickID { get; private set; } |
| | 1015 | | /// <summary> |
| | 1016 | | /// Joystick axis index. |
| | 1017 | | /// </summary> |
| | 1018 | | public byte Axis { get; private set; } |
| | 1019 | | /// <summary> |
| | 1020 | | /// The axis value (range: -32768 to 32767) |
| | 1021 | | /// </summary> |
| | 1022 | | public short Value { get; private set; } |
| | 1023 | |
|
| | 1024 | | /// <summary> |
| | 1025 | | /// Creates a new event args object. |
| | 1026 | | /// </summary> |
| | 1027 | | public JoyAxisMotionEventArgs(int joystickId, byte axis, short value) : base() => |
| | 1028 | | (this.JoystickID, this.Axis, this.Value) = (joystickId, axis, value); |
| | 1029 | |
|
| | 1030 | | internal JoyAxisMotionEventArgs(SDL_JoyAxisEvent e) : base(e) => |
| | 1031 | | (this.JoystickID, this.Axis, this.Value) = (e.which, e.axis, e.value); |
| | 1032 | |
|
| | 1033 | | internal override SDL_Event AsEvent() => |
| | 1034 | | new SDL_JoyAxisEvent() |
| | 1035 | | { |
| | 1036 | | type = (uint)SDL_EventType.SDL_JOYAXISMOTION, |
| | 1037 | | timestamp = (uint)Timestamp, |
| | 1038 | | which = JoystickID, |
| | 1039 | | axis = Axis, |
| | 1040 | | value = Value |
| | 1041 | | }; |
| | 1042 | | } |
| | 1043 | |
|
| | 1044 | | /// <summary> |
| | 1045 | | /// Describes joystick trackball motion event data. |
| | 1046 | | /// </summary> |
| | 1047 | | public class JoyBallMotionEventArgs : CommonEventArgs |
| | 1048 | | { |
| | 1049 | | /// <summary> |
| | 1050 | | /// The joystick instance ID. |
| | 1051 | | /// </summary> |
| | 1052 | | public int JoystickID { get; private set; } |
| | 1053 | | /// <summary> |
| | 1054 | | /// Joystick trackball index. |
| | 1055 | | /// </summary> |
| | 1056 | | public byte Ball { get; private set; } |
| | 1057 | | /// <summary> |
| | 1058 | | /// Relative motion in X direction. |
| | 1059 | | /// </summary> |
| | 1060 | | public short RelativeX { get; private set; } |
| | 1061 | | /// <summary> |
| | 1062 | | /// Relative motion in Y direction. |
| | 1063 | | /// </summary> |
| | 1064 | | public short RelativeY { get; private set; } |
| | 1065 | |
|
| | 1066 | | /// <summary> |
| | 1067 | | /// Creates new event args object. |
| | 1068 | | /// </summary> |
| | 1069 | | public JoyBallMotionEventArgs(int joystickId, byte ball, short relX, short relY) |
| | 1070 | | : base() => |
| | 1071 | | (this.JoystickID, this.Ball, this.RelativeX, this.RelativeY) = |
| | 1072 | | (joystickId, ball, relX, relY); |
| | 1073 | |
|
| | 1074 | | internal JoyBallMotionEventArgs(SDL_JoyBallEvent e) : base(e) => |
| | 1075 | | (this.JoystickID, this.Ball, this.RelativeX, this.RelativeY) = |
| | 1076 | | (e.which, e.ball, e.xrel, e.yrel); |
| | 1077 | |
|
| | 1078 | | internal override SDL_Event AsEvent() => |
| | 1079 | | new SDL_JoyBallEvent() |
| | 1080 | | { |
| | 1081 | | type = (uint)SDL_EventType.SDL_JOYBALLMOTION, |
| | 1082 | | timestamp = (uint)Timestamp, |
| | 1083 | | which = JoystickID, |
| | 1084 | | xrel = RelativeX, |
| | 1085 | | yrel = RelativeY |
| | 1086 | | }; |
| | 1087 | | } |
| | 1088 | |
|
| | 1089 | | [Flags] |
| | 1090 | | /// <summary> |
| | 1091 | | /// Describes joystick hat position. |
| | 1092 | | /// </summary> |
| | 1093 | | public enum HatPosition : byte |
| | 1094 | | { |
| | 1095 | | Centered = SDL_HAT_CENTERED, |
| | 1096 | | Up = SDL_HAT_UP, |
| | 1097 | | Right = SDL_HAT_RIGHT, |
| | 1098 | | Down = SDL_HAT_DOWN, |
| | 1099 | | Left = SDL_HAT_LEFT, |
| | 1100 | | RightUp = Right | Up, |
| | 1101 | | RightDown = Right | Down, |
| | 1102 | | LeftUp = Left | Up, |
| | 1103 | | LeftDown = Left | Down |
| | 1104 | | } |
| | 1105 | |
|
| | 1106 | | /// <summary> |
| | 1107 | | /// Describes joystick POV hat motion event data. |
| | 1108 | | /// </summary> |
| | 1109 | | public class JoyHatMotionEventArgs : CommonEventArgs |
| | 1110 | | { |
| | 1111 | | /// <summary> |
| | 1112 | | /// The joystick instance ID. |
| | 1113 | | /// </summary> |
| | 1114 | | public int JoystickID { get; private set; } |
| | 1115 | | /// <summary> |
| | 1116 | | /// Joystick hat index. |
| | 1117 | | /// </summary> |
| | 1118 | | public byte Hat { get; private set; } |
| | 1119 | | /// <summary> |
| | 1120 | | /// Joystick hat position. |
| | 1121 | | /// </summary> |
| | 1122 | | public HatPosition Position { get; private set; } |
| | 1123 | |
|
| | 1124 | | /// <summary> |
| | 1125 | | /// Creates new event args object. |
| | 1126 | | /// </summary> |
| | 1127 | | public JoyHatMotionEventArgs(int joystickId, byte hat, HatPosition pos) |
| | 1128 | | : base() => |
| | 1129 | | (this.JoystickID, this.Hat, this.Position) = (joystickId, hat, pos); |
| | 1130 | |
|
| | 1131 | | internal JoyHatMotionEventArgs(SDL_JoyHatEvent e) : base(e) => |
| | 1132 | | (this.JoystickID, this.Hat, this.Position) = (e.which, e.hat, (HatPosition)e.value); |
| | 1133 | |
|
| | 1134 | | internal override SDL_Event AsEvent() => |
| | 1135 | | new SDL_JoyHatEvent() |
| | 1136 | | { |
| | 1137 | | type = (uint)SDL_EventType.SDL_JOYHATMOTION, |
| | 1138 | | timestamp = (uint)Timestamp, |
| | 1139 | | which = JoystickID, |
| | 1140 | | hat = Hat, |
| | 1141 | | value = (byte)Position |
| | 1142 | | }; |
| | 1143 | | } |
| | 1144 | |
|
| | 1145 | | /// <summary> |
| | 1146 | | /// Describes joystick button press/release event data. |
| | 1147 | | /// </summary> |
| | 1148 | | public class JoyButtonEventArgs : CommonEventArgs |
| | 1149 | | { |
| | 1150 | | /// <summary> |
| | 1151 | | /// The joystick instance id. |
| | 1152 | | /// </summary> |
| | 1153 | | public int JoystickID { get; private set; } |
| | 1154 | | /// <summary> |
| | 1155 | | /// Joystick button index. |
| | 1156 | | /// </summary> |
| | 1157 | | public byte Button { get; private set; } |
| | 1158 | | /// <summary> |
| | 1159 | | /// Indicates if the button was pressed or released. |
| | 1160 | | /// </summary> |
| | 1161 | | public bool IsPressed { get; private set; } |
| | 1162 | |
|
| | 1163 | | /// <summary> |
| | 1164 | | /// Creates new event args object. |
| | 1165 | | /// </summary> |
| | 1166 | | public JoyButtonEventArgs(int joystickId, byte button, bool isPressed) |
| | 1167 | | : base() => |
| | 1168 | | (this.JoystickID, this.Button, this.IsPressed) = (joystickId, button, isPressed); |
| | 1169 | |
|
| | 1170 | | internal JoyButtonEventArgs(SDL_JoyButtonEvent e) : base(e) => |
| | 1171 | | (this.JoystickID, this.Button, this.IsPressed) = |
| | 1172 | | (e.which, e.button, e.state > 0); |
| | 1173 | |
|
| | 1174 | | internal override SDL_Event AsEvent() => |
| | 1175 | | new SDL_JoyButtonEvent() |
| | 1176 | | { |
| | 1177 | | type = (uint)(IsPressed ? SDL_EventType.SDL_JOYBUTTONDOWN : SDL_EventType.SDL_JOYBUTTONUP), |
| | 1178 | | timestamp = (uint)Timestamp, |
| | 1179 | | which = JoystickID, |
| | 1180 | | button = Button, |
| | 1181 | | state = (byte)(IsPressed ? 1 : 0) |
| | 1182 | | }; |
| | 1183 | | } |
| | 1184 | |
|
| | 1185 | | /// <summary> |
| | 1186 | | /// Describes joystick state change event data. |
| | 1187 | | /// </summary> |
| | 1188 | | public class JoyDeviceStateEventArgs : CommonEventArgs |
| | 1189 | | { |
| | 1190 | | /// <summary> |
| | 1191 | | /// The joystick instance id. |
| | 1192 | | /// </summary> |
| | 1193 | | public int JoystickID { get; private set; } |
| | 1194 | | /// <summary> |
| | 1195 | | /// Indicates if the joystick is connected or disconnected. |
| | 1196 | | /// </summary> |
| | 1197 | | /// <returns></returns> |
| | 1198 | | public bool Connected { get; private set; } |
| | 1199 | |
|
| | 1200 | | /// <summary> |
| | 1201 | | /// Creates new event args object. |
| | 1202 | | /// </summary> |
| | 1203 | | public JoyDeviceStateEventArgs(int joystickId, bool connected) : base() => |
| | 1204 | | (this.JoystickID, this.Connected) = (joystickId, connected); |
| | 1205 | |
|
| | 1206 | | internal JoyDeviceStateEventArgs(SDL_JoyDeviceEvent e) : base(e) => |
| | 1207 | | (this.JoystickID, this.Connected) = (e.which, e.type == (uint)SDL_EventType.SDL_JOYDEVICEADDED); |
| | 1208 | |
|
| | 1209 | | internal override SDL_Event AsEvent() => |
| | 1210 | | new SDL_JoyDeviceEvent() |
| | 1211 | | { |
| | 1212 | | type = (uint)(Connected ? SDL_EventType.SDL_JOYDEVICEADDED : SDL_EventType.SDL_JOYDEVICEREMOVED), |
| | 1213 | | timestamp = (uint)Timestamp, |
| | 1214 | | which = JoystickID, |
| | 1215 | | }; |
| | 1216 | | } |
| | 1217 | |
|
| | 1218 | | /// <summary> |
| | 1219 | | /// Defines controller axes. |
| | 1220 | | /// </summary> |
| | 1221 | | public enum ControllerAxis : byte |
| | 1222 | | { |
| | 1223 | | LeftX, |
| | 1224 | | LeftY, |
| | 1225 | | RightX, |
| | 1226 | | RightY, |
| | 1227 | | LeftTrigger, |
| | 1228 | | RightTrigger |
| | 1229 | | } |
| | 1230 | |
|
| | 1231 | | /// <summary> |
| | 1232 | | /// Describes controller buttons. |
| | 1233 | | /// </summary> |
| | 1234 | | public enum ControllerButton : byte |
| | 1235 | | { |
| | 1236 | | A, |
| | 1237 | | B, |
| | 1238 | | X, |
| | 1239 | | Y, |
| | 1240 | | Back, |
| | 1241 | | Guide, |
| | 1242 | | Start, |
| | 1243 | | LeftStick, |
| | 1244 | | RightStick, |
| | 1245 | | LeftShoulder, |
| | 1246 | | RightShoulder, |
| | 1247 | | DPadUp, |
| | 1248 | | DPadDown, |
| | 1249 | | DPadLeft, |
| | 1250 | | DPadRight |
| | 1251 | | } |
| | 1252 | |
|
| | 1253 | | /// <summary> |
| | 1254 | | /// Describes controller axis motion event data. |
| | 1255 | | /// </summary> |
| | 1256 | | public class ControllerAxisEventArgs : CommonEventArgs |
| | 1257 | | { |
| | 1258 | | /// <summary> |
| | 1259 | | /// The controller instance ID. |
| | 1260 | | /// </summary> |
| | 1261 | | public int ControllerID { get; private set; } |
| | 1262 | | /// <summary> |
| | 1263 | | /// The axis which was moved. |
| | 1264 | | /// </summary> |
| | 1265 | | public ControllerAxis Axis { get; private set; } |
| | 1266 | | /// <summary> |
| | 1267 | | /// The axis value (range: -32768 to 32767) |
| | 1268 | | /// </summary> |
| | 1269 | | public short Value { get; private set; } |
| | 1270 | |
|
| | 1271 | | /// <summary> |
| | 1272 | | /// Creates a new event args object. |
| | 1273 | | /// </summary> |
| | 1274 | | public ControllerAxisEventArgs(int id, ControllerAxis axis, short value) |
| | 1275 | | : base() => |
| | 1276 | | (this.ControllerID, this.Axis, this.Value) = (id, axis, value); |
| | 1277 | |
|
| | 1278 | | internal ControllerAxisEventArgs(SDL_ControllerAxisEvent e) : base(e) => |
| | 1279 | | (this.ControllerID, this.Axis, this.Value) = (e.which, (ControllerAxis)e.axis, e.value); |
| | 1280 | |
|
| | 1281 | | internal override SDL_Event AsEvent() => |
| | 1282 | | new SDL_ControllerAxisEvent() |
| | 1283 | | { |
| | 1284 | | type = (uint)SDL_EventType.SDL_CONTROLLERAXISMOTION, |
| | 1285 | | timestamp = (uint)Timestamp, |
| | 1286 | | which = ControllerID, |
| | 1287 | | axis = (byte)Axis, |
| | 1288 | | value = Value |
| | 1289 | | }; |
| | 1290 | | } |
| | 1291 | |
|
| | 1292 | | /// <summary> |
| | 1293 | | /// Describes controller button press/release event data. |
| | 1294 | | /// </summary> |
| | 1295 | | public class ControllerButtonEventArgs : CommonEventArgs |
| | 1296 | | { |
| | 1297 | | /// <summary> |
| | 1298 | | /// The controller instance ID. |
| | 1299 | | /// </summary> |
| | 1300 | | public int ControllerID { get; private set; } |
| | 1301 | | /// <summary> |
| | 1302 | | /// The button which changed state. |
| | 1303 | | /// </summary> |
| | 1304 | | public ControllerButton Button { get; private set; } |
| | 1305 | | /// <summary> |
| | 1306 | | /// Indicates if the button was pressed or released. |
| | 1307 | | /// </summary> |
| | 1308 | | public bool IsPressed { get; private set; } |
| | 1309 | |
|
| | 1310 | | /// <summary> |
| | 1311 | | /// Creates a new event args object. |
| | 1312 | | /// </summary> |
| | 1313 | | public ControllerButtonEventArgs(int id, ControllerButton button, bool pressed) |
| | 1314 | | : base() => |
| | 1315 | | (this.ControllerID, this.Button, this.IsPressed) = (id, button, pressed); |
| | 1316 | |
|
| | 1317 | | internal ControllerButtonEventArgs(SDL_ControllerButtonEvent e) |
| | 1318 | | : base(e) => |
| | 1319 | | (this.ControllerID, this.Button, this.IsPressed) = |
| | 1320 | | (e.which, (ControllerButton)e.button, e.state > 0); |
| | 1321 | |
|
| | 1322 | | internal override SDL_Event AsEvent() => |
| | 1323 | | new SDL_ControllerButtonEvent() |
| | 1324 | | { |
| | 1325 | | type = (uint)(IsPressed ? SDL_EventType.SDL_CONTROLLERBUTTONDOWN : SDL_EventType.SDL_CONTROLLERBUTTONUP) |
| | 1326 | | timestamp = (uint)Timestamp, |
| | 1327 | | which = ControllerID, |
| | 1328 | | button = (byte)Button, |
| | 1329 | | state = (byte)(IsPressed ? 1 : 0) |
| | 1330 | | }; |
| | 1331 | | } |
| | 1332 | |
|
| | 1333 | | /// <summary> |
| | 1334 | | /// Describes controller state change event data. |
| | 1335 | | /// </summary> |
| | 1336 | | public class ControllerDeviceStateEventArgs : CommonEventArgs |
| | 1337 | | { |
| | 1338 | | /// <summary> |
| | 1339 | | /// The controller instance id. |
| | 1340 | | /// </summary> |
| | 1341 | | public int ControllerID { get; private set; } |
| | 1342 | | /// <summary> |
| | 1343 | | /// Indicates if the controller is connected or disconnected. |
| | 1344 | | /// </summary> |
| | 1345 | | public bool Connected { get; private set; } |
| | 1346 | |
|
| | 1347 | | /// <summary> |
| | 1348 | | /// Creates new event args object. |
| | 1349 | | /// </summary> |
| | 1350 | | public ControllerDeviceStateEventArgs(int controllerId, bool connected) : base() => |
| | 1351 | | (this.ControllerID, this.Connected) = (controllerId, connected); |
| | 1352 | |
|
| | 1353 | | internal ControllerDeviceStateEventArgs(SDL_ControllerDeviceEvent e) : base(e) => |
| | 1354 | | (this.ControllerID, this.Connected) = (e.which, e.type == (uint)SDL_EventType.SDL_CONTROLLERDEVICEADDED); |
| | 1355 | |
|
| | 1356 | | internal override SDL_Event AsEvent() => |
| | 1357 | | new SDL_ControllerDeviceEvent() |
| | 1358 | | { |
| | 1359 | | type = (uint)(Connected ? SDL_EventType.SDL_CONTROLLERDEVICEADDED : SDL_EventType.SDL_CONTROLLERDEVICERE |
| | 1360 | | timestamp = (uint)Timestamp, |
| | 1361 | | which = ControllerID, |
| | 1362 | | }; |
| | 1363 | | } |
| | 1364 | |
|
| | 1365 | | /// <summary> |
| | 1366 | | /// Describes types of touch events. |
| | 1367 | | /// </summary> |
| | 1368 | | public enum TouchEventType |
| | 1369 | | { |
| | 1370 | | Motion, |
| | 1371 | | FingerDown, |
| | 1372 | | FingerUp |
| | 1373 | | } |
| | 1374 | |
|
| | 1375 | | /// <summary> |
| | 1376 | | /// Describes touch event data. |
| | 1377 | | /// </summary> |
| | 1378 | | public class TouchFingerEventArgs : CommonEventArgs |
| | 1379 | | { |
| | 1380 | | /// <summary> |
| | 1381 | | /// The event type. |
| | 1382 | | /// </summary> |
| | 1383 | | public TouchEventType Type { get; private set; } |
| | 1384 | | /// <summary> |
| | 1385 | | /// The touch device ID. |
| | 1386 | | /// </summary> |
| | 1387 | | public long DeviceID { get; private set; } |
| | 1388 | | /// <summary> |
| | 1389 | | /// The finger ID. |
| | 1390 | | /// </summary> |
| | 1391 | | public long FingerID { get; private set; } |
| | 1392 | | /// <summary> |
| | 1393 | | /// Normalized in the range 0...1. |
| | 1394 | | /// </summary> |
| | 1395 | | public float X { get; private set; } |
| | 1396 | | /// <summary> |
| | 1397 | | /// Normalized in the range 0...1. |
| | 1398 | | /// </summary> |
| | 1399 | | public float Y { get; private set; } |
| | 1400 | | /// <summary> |
| | 1401 | | /// Normalized in the range 0...1. |
| | 1402 | | /// </summary> |
| | 1403 | | public float DX { get; private set; } |
| | 1404 | | /// <summary> |
| | 1405 | | /// Normalized in the range 0...1. |
| | 1406 | | /// </summary> |
| | 1407 | | public float DY { get; private set; } |
| | 1408 | | /// <summary> |
| | 1409 | | /// Normalized in the range 0...1. |
| | 1410 | | /// </summary> |
| | 1411 | | public float Pressure { get; private set; } |
| | 1412 | |
|
| | 1413 | | private static readonly Dictionary<uint, TouchEventType> s_types = |
| | 1414 | | new Dictionary<uint, TouchEventType>() |
| | 1415 | | { |
| | 1416 | | { (uint)SDL_EventType.SDL_FINGERMOTION, TouchEventType.Motion }, |
| | 1417 | | { (uint)SDL_EventType.SDL_FINGERDOWN, TouchEventType.FingerDown }, |
| | 1418 | | { (uint)SDL_EventType.SDL_FINGERUP, TouchEventType.FingerUp } |
| | 1419 | | }; |
| | 1420 | |
|
| | 1421 | | private static readonly Dictionary<TouchEventType, uint> s_reverseTypes = |
| | 1422 | | s_types.ToDictionary(x => x.Value, x => x.Key); |
| | 1423 | |
|
| | 1424 | | /// <summary> |
| | 1425 | | /// Creates a new event args object. |
| | 1426 | | /// </summary> |
| | 1427 | | public TouchFingerEventArgs(TouchEventType type, long deviceId, long fingerId, |
| | 1428 | | float x, float y, float dx, float dy, float pressure) : base() => |
| | 1429 | | (Type, DeviceID, FingerID, X, Y, DX, DY, Pressure) = |
| | 1430 | | (type, deviceId, fingerId, x, y, dx, dy, pressure); |
| | 1431 | |
|
| | 1432 | | internal TouchFingerEventArgs(SDL_TouchFingerEvent e) : base(e) |
| | 1433 | | { |
| | 1434 | | (DeviceID, FingerID, X, Y, DX, DY, Pressure) = |
| | 1435 | | (e.touchId, e.fingerId, e.x, e.y, e.dx, e.dy, e.pressure); |
| | 1436 | | Type = s_types[e.type]; |
| | 1437 | | } |
| | 1438 | |
|
| | 1439 | | internal override SDL_Event AsEvent() => |
| | 1440 | | new SDL_TouchFingerEvent() |
| | 1441 | | { |
| | 1442 | | type = s_reverseTypes[Type], |
| | 1443 | | timestamp = (uint)Timestamp, |
| | 1444 | | touchId = DeviceID, |
| | 1445 | | fingerId = FingerID, |
| | 1446 | | x = X, |
| | 1447 | | y = Y, |
| | 1448 | | dx = DX, |
| | 1449 | | dy = DY, |
| | 1450 | | pressure = Pressure |
| | 1451 | | }; |
| | 1452 | | } |
| | 1453 | | } |