MCPcopy Create free account
hub / github.com/TankOs/SFGUI / HandleAbsolutePositionChange

Method HandleAbsolutePositionChange

src/SFGUI/Canvas.cpp:300–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300void 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
343const std::string& Canvas::GetName() const {
344 static const std::string name( "Canvas" );

Callers

nothing calls this directly

Calls 3

SetDestinationOriginMethod · 0.80
GetParentMethod · 0.45
GetAbsolutePositionMethod · 0.45

Tested by

no test coverage detected