| 287 | } |
| 288 | |
| 289 | void Widget::HandleEvent( const sf::Event& event ) { |
| 290 | if( !IsGloballyVisible() ) { |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | // Ignore the event if widget is insensitive |
| 295 | if ( GetState() == State::INSENSITIVE ) { |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | // Ignore the event if another widget is active. |
| 300 | if( !IsActiveWidget() && !IsActiveWidget( PtrConst() ) ) { |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | // Ignore the event if another widget is modal. |
| 305 | if( HasModal() && !IsModal() ) { |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | // Set widget active in context. |
| 310 | Context::Get().SetActiveWidget( shared_from_this() ); |
| 311 | |
| 312 | auto parent = m_parent.lock(); |
| 313 | |
| 314 | auto emit_leave = false; |
| 315 | auto emit_enter = false; |
| 316 | auto emit_move = false; |
| 317 | auto emit_left_click = false; |
| 318 | auto emit_right_click = false; |
| 319 | |
| 320 | try { |
| 321 | if( event.is<sf::Event::MouseLeft>() ) { |
| 322 | if( IsMouseInWidget() ) { |
| 323 | SetMouseInWidget( false ); |
| 324 | |
| 325 | HandleMouseLeave( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() ); |
| 326 | |
| 327 | emit_leave = true; |
| 328 | } |
| 329 | |
| 330 | HandleMouseMoveEvent( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() ); |
| 331 | |
| 332 | SetMouseButtonDown(); |
| 333 | HandleMouseButtonEvent( sf::Mouse::Button::Left, false, std::numeric_limits<int>::min(), std::numeric_limits<int>::min() ); |
| 334 | HandleMouseButtonEvent( sf::Mouse::Button::Right, false, std::numeric_limits<int>::min(), std::numeric_limits<int>::min() ); |
| 335 | |
| 336 | if( emit_leave ) { |
| 337 | GetSignals().Emit( OnMouseLeave ); |
| 338 | } |
| 339 | } |
| 340 | else if( const auto* mouseMoved = event.getIf<sf::Event::MouseMoved>() ) { |
| 341 | // Check if pointer inside of widget's allocation. |
| 342 | if( GetAllocation().contains( sf::Vector2f( mouseMoved->position ) ) ) { |
| 343 | // Check for enter event. |
| 344 | if( !IsMouseInWidget() ) { |
| 345 | SetMouseInWidget( true ); |
| 346 | |