| 298 | } |
| 299 | |
| 300 | void Canvas::HandleAbsolutePositionChange() { |
| 301 | auto position = Widget::GetAbsolutePosition(); |
| 302 | |
| 303 | auto parent = GetParent(); |
| 304 | |
| 305 | sf::Vector2f parent_position( 0.f, 0.f ); |
| 306 | |
| 307 | while( parent ) { |
| 308 | if( parent->GetName() == "Viewport" ) { |
| 309 | // Try to get the first ancestor of the viewport that is not a viewport itself. |
| 310 | // Add up all allocations while searching. |
| 311 | Container::PtrConst viewport_parent = parent->GetParent(); |
| 312 | |
| 313 | while( viewport_parent && viewport_parent->GetName() == "Viewport" ) { |
| 314 | parent_position += viewport_parent->GetAllocation().position; |
| 315 | |
| 316 | viewport_parent = viewport_parent->GetParent(); |
| 317 | } |
| 318 | |
| 319 | if( !viewport_parent || ( viewport_parent->GetName() == "Viewport" ) ) { |
| 320 | parent_position = sf::Vector2f( 0.f, 0.f ); |
| 321 | break; |
| 322 | } |
| 323 | |
| 324 | parent_position += viewport_parent->GetAbsolutePosition(); |
| 325 | parent_position += parent->GetAllocation().position; |
| 326 | |
| 327 | break; |
| 328 | } |
| 329 | |
| 330 | parent = parent->GetParent(); |
| 331 | } |
| 332 | |
| 333 | m_custom_viewport->SetDestinationOrigin( |
| 334 | sf::Vector2f( |
| 335 | std::floor( parent_position.x + position.x + .5f ), |
| 336 | std::floor( parent_position.y + position.y + .5f ) |
| 337 | ) |
| 338 | ); |
| 339 | |
| 340 | Invalidate(); |
| 341 | } |
| 342 | |
| 343 | const std::string& Canvas::GetName() const { |
| 344 | static const std::string name( "Canvas" ); |
nothing calls this directly
no test coverage detected