///////////////////////////////////////////////////////
| 548 | |
| 549 | //////////////////////////////////////////////////////////// |
| 550 | int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* inputEvent, ActivityStates& states) |
| 551 | { |
| 552 | const std::int32_t device = AInputEvent_getSource(inputEvent); |
| 553 | const std::int32_t action = AMotionEvent_getAction(inputEvent); |
| 554 | |
| 555 | const std::size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; |
| 556 | const std::int32_t id = AMotionEvent_getPointerId(inputEvent, index); |
| 557 | const auto button = static_cast<Mouse::Button>(id); |
| 558 | |
| 559 | int x = static_cast<int>(AMotionEvent_getX(inputEvent, index)); |
| 560 | int y = static_cast<int>(AMotionEvent_getY(inputEvent, index)); |
| 561 | |
| 562 | if (isDown) |
| 563 | { |
| 564 | if (device == AINPUT_SOURCE_MOUSE) |
| 565 | { |
| 566 | if (id >= 0 && id < static_cast<int>(Mouse::ButtonCount)) |
| 567 | states.isButtonPressed[button] = true; |
| 568 | |
| 569 | forwardEvent(Event::MouseButtonPressed{button, {x, y}}); |
| 570 | } |
| 571 | else if (static_cast<unsigned int>(device) & AINPUT_SOURCE_TOUCHSCREEN) |
| 572 | { |
| 573 | Event::TouchBegan touchBegan; |
| 574 | touchBegan.finger = static_cast<unsigned int>(id); |
| 575 | touchBegan.position = {x, y}; |
| 576 | |
| 577 | states.touchEvents[id] = touchBegan.position; |
| 578 | |
| 579 | forwardEvent(touchBegan); |
| 580 | } |
| 581 | } |
| 582 | else |
| 583 | { |
| 584 | if (device == AINPUT_SOURCE_MOUSE) |
| 585 | { |
| 586 | if (id >= 0 && id < static_cast<int>(Mouse::ButtonCount)) |
| 587 | states.isButtonPressed[button] = false; |
| 588 | |
| 589 | forwardEvent(Event::MouseButtonReleased{button, {x, y}}); |
| 590 | } |
| 591 | else if (static_cast<std::uint32_t>(device) & AINPUT_SOURCE_TOUCHSCREEN) |
| 592 | { |
| 593 | states.touchEvents.erase(id); |
| 594 | forwardEvent(Event::TouchEnded{static_cast<unsigned int>(id), {x, y}}); |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | return 1; |
| 599 | } |
| 600 | |
| 601 | |
| 602 | //////////////////////////////////////////////////////////// |