| 510 | // *********************************************************************** |
| 511 | |
| 512 | void ProcessEvent(SDL_Event* event) { |
| 513 | // Update Input States |
| 514 | switch (event->type) { |
| 515 | case SDL_TEXTINPUT: { |
| 516 | pInputState->textInputString.Append(event->text.text); |
| 517 | break; |
| 518 | } |
| 519 | case SDL_KEYDOWN: { |
| 520 | SDL_Keycode keycode = event->key.keysym.sym; |
| 521 | pInputState->keyDowns[(u64)pInputState->keyCodeToInternalKeyCode[keycode]] = true; |
| 522 | pInputState->keyStates[(u64)pInputState->keyCodeToInternalKeyCode[keycode]] = true; |
| 523 | |
| 524 | ControllerButton button = pInputState->keyboardAltBindings[keycode]; |
| 525 | if (button != ControllerButton::Invalid) { |
| 526 | pInputState->buttonDowns[(u64)button] = true; |
| 527 | pInputState->buttonStates[(u64)button] = true; |
| 528 | } |
| 529 | ControllerAxis axis = pInputState->keyboardAxisBindings[keycode]; |
| 530 | if (axis != ControllerAxis::Invalid) { |
| 531 | Axis& axisData = pInputState->axes[(u64)axis]; |
| 532 | if (axisData.positiveScanCode == keycode) |
| 533 | axisData.positiveInput = true; |
| 534 | else if (axisData.negativeScanCode == keycode) |
| 535 | axisData.negativeInput = true; |
| 536 | axisData.ignoreVirtual = false; |
| 537 | } |
| 538 | break; |
| 539 | } |
| 540 | case SDL_KEYUP: { |
| 541 | SDL_Keycode keycode = event->key.keysym.sym; |
| 542 | pInputState->keyUps[(u64)pInputState->keyCodeToInternalKeyCode[keycode]] = true; |
| 543 | pInputState->keyStates[(u64)pInputState->keyCodeToInternalKeyCode[keycode]] = false; |
| 544 | |
| 545 | ControllerButton button = pInputState->keyboardAltBindings[keycode]; |
| 546 | if (button != ControllerButton::Invalid) { |
| 547 | pInputState->buttonUps[(u64)button] = true; |
| 548 | pInputState->buttonStates[(u64)button] = false; |
| 549 | } |
| 550 | ControllerAxis axis = pInputState->keyboardAxisBindings[keycode]; |
| 551 | if (axis != ControllerAxis::Invalid) { |
| 552 | Axis& axisData = pInputState->axes[(u64)axis]; |
| 553 | if (axisData.positiveScanCode == keycode) |
| 554 | axisData.positiveInput = false; |
| 555 | else if (axisData.negativeScanCode == keycode) |
| 556 | axisData.negativeInput = false; |
| 557 | axisData.ignoreVirtual = false; |
| 558 | } |
| 559 | break; |
| 560 | } |
| 561 | case SDL_CONTROLLERBUTTONDOWN: { |
| 562 | SDL_GameControllerButton sdlButton = (SDL_GameControllerButton)event->cbutton.button; |
| 563 | ControllerButton button = pInputState->primaryBindings[sdlButton]; |
| 564 | if (button != ControllerButton::Invalid) { |
| 565 | pInputState->buttonDowns[(u64)button] = true; |
| 566 | pInputState->buttonStates[(u64)button] = true; |
| 567 | } |
| 568 | break; |
| 569 | } |