Ejemplo n.º 1
0
void Container::HandleChildInvalidate( const Widget::PtrConst& child ) const {
	Container::PtrConst parent = GetParent();

	if( parent ) {
		parent->HandleChildInvalidate( child );
	}
}
Ejemplo n.º 2
0
void Widget::Invalidate() const {
	if( m_invalidated ) {
		return;
	}

	m_invalidated = true;

	Container::PtrConst parent = m_parent.lock();

	if( parent ) {
		parent->HandleChildInvalidate( static_cast<Widget::PtrConst>( shared_from_this() ) );
	}
}
Ejemplo n.º 3
0
Widget::WidgetsList SearchContainerForClass( Container::PtrConst container, const std::string& class_name ) {
	Widget::WidgetsList result;

	if( !container ) {
		return result;
	}

	for( const auto& child : container->GetChildren() ) {
		if( child->GetClass() == class_name ) {
			result.push_back( child );
		}

		auto child_container = std::dynamic_pointer_cast<Container>( child );

		if( child_container ) {
			auto child_result = SearchContainerForClass( child_container, class_name );

			// Splice the 2 vectors.
			if( !child_result.empty() ) {
				result.reserve( child_result.size() );
				result.insert( result.end(), child_result.begin(), child_result.end() );
			}
		}
	}

	return result;
}
Ejemplo n.º 4
0
Widget::Ptr SearchContainerForId( Container::PtrConst container, const std::string& id ) {
	if( !container ) {
		return Widget::Ptr();
	}

	for( const auto& child : container->GetChildren() ) {
		if( child->GetId() == id ) {
			return child;
		}

		auto child_container = std::dynamic_pointer_cast<Container>( child );

		if( child_container ) {
			auto widget = SearchContainerForId( child_container, id );

			if( widget ) {
				return widget;
			}
		}
	}

	return Widget::Ptr();
}
Ejemplo n.º 5
0
void GLCanvas::HandleAbsolutePositionChange() {
	sf::Vector2f position = Widget::GetAbsolutePosition();

	Container::PtrConst parent = GetParent();

	sf::Vector2f parent_position( 0.f, 0.f );

	while( parent ) {
		if( parent->GetName() == "Viewport" ) {
			// Try to get the first ancestor of the viewport that is not a viewport itself.
			// Add up all allocations while searching.
			Container::PtrConst viewport_parent = parent->GetParent();

			while( viewport_parent && viewport_parent->GetName() == "Viewport" ) {
				parent_position += sf::Vector2f( viewport_parent->GetAllocation().left, viewport_parent->GetAllocation().top );

				viewport_parent = viewport_parent->GetParent();
			}

			if( !viewport_parent || ( viewport_parent->GetName() == "Viewport" ) ) {
				parent_position = sf::Vector2f( 0.f, 0.f );
				break;
			}

			parent_position += viewport_parent->GetAbsolutePosition();
			parent_position += sf::Vector2f( parent->GetAllocation().left, parent->GetAllocation().top );

			break;
		}

		parent = parent->GetParent();
	}

	m_custom_viewport->SetDestinationOrigin(
		sf::Vector2f(
			std::floor( parent_position.x + position.x + .5f ),
			std::floor( parent_position.y + position.y + .5f )
		)
	);

	Invalidate();
}