| 522 | } |
| 523 | |
| 524 | bool SDLInput::HandleEvent(SDLWindow* window, SDL_Event& event) |
| 525 | { |
| 526 | switch (event.type) |
| 527 | { |
| 528 | case SDL_EVENT_MOUSE_MOTION: |
| 529 | { |
| 530 | if (Input::Mouse->IsRelative()) |
| 531 | { |
| 532 | const Float2 mouseDelta(event.motion.xrel, event.motion.yrel); |
| 533 | Input::Mouse->OnMouseMoveRelative(mouseDelta, window); |
| 534 | } |
| 535 | else |
| 536 | { |
| 537 | const Float2 mousePos = window->ClientToScreen({ event.motion.x, event.motion.y }); |
| 538 | Input::Mouse->OnMouseMove(mousePos, window); |
| 539 | } |
| 540 | return true; |
| 541 | } |
| 542 | case SDL_EVENT_WINDOW_MOUSE_LEAVE: |
| 543 | { |
| 544 | Input::Mouse->OnMouseLeave(window); |
| 545 | return true; |
| 546 | } |
| 547 | case SDL_EVENT_MOUSE_BUTTON_DOWN: |
| 548 | case SDL_EVENT_MOUSE_BUTTON_UP: |
| 549 | { |
| 550 | Float2 mousePos = window->ClientToScreen({ event.button.x, event.button.y }); |
| 551 | |
| 552 | // In case of activating the window from non-focused state, we might not have received the motion event yet |
| 553 | if (!Input::Mouse->IsRelative() && event.button.down) |
| 554 | Input::Mouse->OnMouseMove(mousePos, window); |
| 555 | |
| 556 | MouseButton button = MouseButton::None; |
| 557 | if (event.button.button == SDL_BUTTON_LEFT) |
| 558 | button = MouseButton::Left; |
| 559 | else if (event.button.button == SDL_BUTTON_RIGHT) |
| 560 | button = MouseButton::Right; |
| 561 | else if (event.button.button == SDL_BUTTON_MIDDLE) |
| 562 | button = MouseButton::Middle; |
| 563 | else if (event.button.button == SDL_BUTTON_X1) |
| 564 | button = MouseButton::Extended1; |
| 565 | else if (event.button.button == SDL_BUTTON_X2) |
| 566 | button = MouseButton::Extended2; |
| 567 | |
| 568 | if (Input::Mouse->IsRelative()) |
| 569 | { |
| 570 | // Use the previous visible mouse position here, the event or global |
| 571 | // mouse position would cause input to trigger in other editor windows. |
| 572 | mousePos = SDLInputImpl::Mouse->GetOldMousePosition(); |
| 573 | } |
| 574 | |
| 575 | if (!event.button.down) |
| 576 | Input::Mouse->OnMouseUp(mousePos, button, window); |
| 577 | // Prevent sending multiple mouse down event when double-clicking UI elements |
| 578 | else if (event.button.clicks % 2 == 1) |
| 579 | Input::Mouse->OnMouseDown(mousePos, button, window); |
| 580 | else |
| 581 | Input::Mouse->OnMouseDoubleClick(mousePos, button, window); |
no test coverage detected