| 22 | } |
| 23 | |
| 24 | void Desktop::HandleEvent( const sf::Event& event ) { |
| 25 | // Activate context. |
| 26 | Context::Activate( m_context ); |
| 27 | |
| 28 | sf::Vector2f position; |
| 29 | bool check_inside( false ); |
| 30 | Widget::Ptr last_receiver( m_last_receiver.lock() ); |
| 31 | |
| 32 | // If we've got a mouse event, get local mouse position and mark event for being checked against widget's allocation. |
| 33 | const auto onMouseButtonPressedOrRelease = [&]( auto& mouseButtonEvent ) { |
| 34 | m_last_mouse_pos = mouseButtonEvent.position; |
| 35 | position = sf::Vector2f( mouseButtonEvent.position ); |
| 36 | check_inside = true; |
| 37 | }; |
| 38 | if( const auto* mouseMoved = event.getIf<sf::Event::MouseMoved>() ) { |
| 39 | m_last_mouse_pos = mouseMoved->position; |
| 40 | position = sf::Vector2f( mouseMoved->position ); |
| 41 | check_inside = true; |
| 42 | } |
| 43 | else if( auto* mouseButtonPressed = event.getIf<sf::Event::MouseButtonPressed>() ) { |
| 44 | onMouseButtonPressedOrRelease( *mouseButtonPressed ); |
| 45 | } |
| 46 | else if( auto* mouseButtonRelease = event.getIf<sf::Event::MouseButtonReleased>() ) { |
| 47 | onMouseButtonPressedOrRelease( *mouseButtonRelease ); |
| 48 | } |
| 49 | |
| 50 | for( int index = 0; index < static_cast<int>( m_children.size() ); ++index ) { |
| 51 | Widget::Ptr widget( m_children[static_cast<std::size_t>( index )] ); |
| 52 | |
| 53 | // Skip widget if not visible or is insensitive. |
| 54 | if( !widget->IsLocallyVisible() || widget->GetState() == Widget::State::INSENSITIVE ) { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | bool is_inside( widget->GetAllocation().contains( position ) ); |
| 59 | |
| 60 | // If the event is a mouse button press, check if we need to focus another widget. |
| 61 | // If there is a modal widget, skip reordering. |
| 62 | if( |
| 63 | index > 0 && |
| 64 | event.is<sf::Event::MouseButtonPressed>() && |
| 65 | is_inside && |
| 66 | !Widget::HasModal() |
| 67 | ) { |
| 68 | m_children.erase( m_children.begin() + index ); |
| 69 | m_children.push_front( widget ); |
| 70 | |
| 71 | RecalculateWidgetLevels(); |
| 72 | } |
| 73 | |
| 74 | // If inside check is needed, do so for all widgets except the top window. |
| 75 | // Else it would run into trouble when moving the window, for example, |
| 76 | // where the mouse may be outside the widget's allocation. |
| 77 | if( check_inside && !is_inside && index > 0 ) { |
| 78 | continue; |
| 79 | } |
| 80 | |
| 81 | // If last receiver is different from current, fake a mouse move event so |
no test coverage detected