Ejemplo n.º 1
0
/// <summary>
/// Completely draws the conformation in m_DrawConformation
/// </summary>
void Algorithm::draw()
{
	int offset = Element::Offset;
	float size = Element::Size;

	sf::RectangleShape m_Shape(sf::Vector2f(size, size));
	m_Shape.setOutlineColor(sf::Color(128, 128, 128, 255));
	m_Shape.setOutlineThickness(1.0);

	if (!m_DrawConformation) return;

	std::vector<Element> elements = m_DrawConformation->getElements();

	sf::RectangleShape connectionLine(sf::Vector2f(size, 2.0f));
	connectionLine.setFillColor(sf::Color::White);
	connectionLine.setPosition(20, offset + size / 2);

	ScreenDirection direction = ScreenDirection::East;

	for (unsigned int i = 0; i < elements.size(); ++i)
	{
		// Map relative direction to screen direction
		direction = calculateDirection(direction, elements[i].getDirection());
		sf::Vector2i position = elements[i].getPosition();

		sf::Color fillColor = elements[i].isHydrophile() ? sf::Color::White : sf::Color::Black;
		m_Shape.setFillColor(fillColor);

		switch (direction)
		{
			case West:
				connectionLine.setPosition(position.x - size, position.y + size / 2.0f);
				connectionLine.setSize(sf::Vector2f(size, 2.0f));
				break;
			case East:
				connectionLine.setPosition(position.x + size, position.y + size / 2.0f);
				connectionLine.setSize(sf::Vector2f(size, 2.0f));
				break;
			case North:
				connectionLine.setPosition(position.x + size / 2.0f, position.y - size);
				connectionLine.setSize(sf::Vector2f(2.0f, size));
				break;
			case South:
				connectionLine.setPosition(position.x + size / 2.0f, position.y + size);
				connectionLine.setSize(sf::Vector2f(2.0f, size));
				break;
			default:
				break;
		}

		// Draw connection line, but exclude last element
		if (i != elements.size() - 1) m_RenderWindow.draw(connectionLine);

		m_Shape.setPosition((sf::Vector2f) elements[i].getPosition());
		m_RenderWindow.draw(m_Shape);
		//elements[i].getRenderer().draw(m_RenderWindow);
	}
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
connectionLine findConnection(const std::vector<connectionLine>& connectionArray, 
                              const kjeqConnection& kC ) 
{
	for( size_t idx = 0; idx < connectionArray.size(); ++idx )
		if( connectionArray[idx].lineId == kC.lineId )
			return connectionArray[idx];
	assert( 0 );
	return connectionLine();
}