void UIComponentTreeView::onRender(Renderer* renderer, UIView* view)
{
	// Draw a black background on the ROOT tree view
	if(mSubTreeLevel == 0)
	{
		RectangleShape back;
		back.setRect(view->getBounds());
		back.setColor(Color(36,36,36));
		renderer->draw(back);
	}
	/*else if(mSubTreeLevel == 1)
	{
		RectangleShape back;
		back.setRect(view->getBounds());
		back.setColor(Color::Grass);
		renderer->draw(back);
	}
	else if(mSubTreeLevel == 2)
	{
		RectangleShape back;
		back.setRect(view->getBounds());
		back.setColor(Color::Bittersweet);
		renderer->draw(back);
	}
	else if(mSubTreeLevel == 3)
	{
		RectangleShape back;
		back.setRect(view->getBounds());
		back.setColor(Color::Lavender);
		renderer->draw(back);
	}*/
}
void UIComponentScrollBar::onRender(Renderer* renderer, UIView* view)
{
	RectangleShape scrollBarBackground;
	scrollBarBackground.setSize(17.f, view->getSize().y);
	scrollBarBackground.setPosition(view->getPosition().x + view->getSize().y - 17.f, view->getPosition().y);
	scrollBarBackground.setColor(Color::Blue);
	renderer->draw(scrollBarBackground);

	renderer->draw(scrollBarPaddle);
}
void UIComponentButton::onRender(Renderer* renderer, UIView* view)
{
	if(hovering)
	{
		RectangleShape hoverRect;
		hoverRect.setRect(view->getBounds());
		hoverRect.setColor(mHoverColor);
		if(mTexture)
		{
			hoverRect.setTexture(mHoverTexture);
		}
		renderer->draw(hoverRect);
	}
	else
	{
		RectangleShape hoverRect;
		hoverRect.setRect(view->getBounds());
		hoverRect.setColor(mNormalColor);
		if(mTexture)
		{
			hoverRect.setTexture(mTexture);
		}
		renderer->draw(hoverRect);
	}

	// -- Label
	Text buttonLabel;
	buttonLabel.setFont(*view->mCore->m_defaultFont);
	buttonLabel.setString(mString);
	buttonLabel.setCharacterSize(view->mRect.height / 2);
	buttonLabel.setOrigin(static_cast<int>((buttonLabel.getLocalBounds().width / 2.f ) + 0.5f), static_cast<int>((buttonLabel.getLocalBounds().height / 2.f) + 0.5f));
	buttonLabel.setPosition(static_cast<int>((view->mRect.left + view->mRect.width / 2.f ) + 0.5f), static_cast<int>((view->mRect.top +  view->mRect.height / 2.f) + 0.5f));
	if(buttonLabel.getLocalBounds().width > view->getSize().x * 0.9f)
	{
		// The text is too big and passes the 90% of the button's width
		float diminishRatio = (view->getSize().x * 0.9f) / buttonLabel.getLocalBounds().width;
		buttonLabel.setCharacterSize(static_cast<unsigned int>(static_cast<float>(buttonLabel.getCharacterSize()) * diminishRatio));
		buttonLabel.setOrigin(static_cast<int>((buttonLabel.getLocalBounds().width / 2.f ) + 0.5f), static_cast<int>((buttonLabel.getLocalBounds().height / 2.f) + 0.5f));
	}
	renderer->draw(buttonLabel);
}
void UIComponentTreeViewItem::onRender(Renderer* renderer, UIView* view)
{
	// Render this item full size

	/*RectangleShape back;
	back.setRect(view->getBounds());
	back.setColor(Color::Red);
	renderer->draw(back);*/

	// Render a little expandable flag if it applies
	if(mParent->getChildCount() > 0)
	{
		RectangleShape back;
		back.setRect(mParent->getChild(0)->getBounds());
		back.setSize(5.f, back.getSize().y);
		back.setColor(Color::Red);
		renderer->draw(back);
	}
}
void StateTransitionBlocks::onUpdate(const Time& time)
{
	if(!m_next)
	{
		remainingTime -= time.asSeconds();

		if(remainingTime <= 0.f && !positions.empty())
		{
			vec2 p = positions.back();
			positions.pop_back();

			RectangleShape shape;
			shape.setColor(Color::Black);
			shape.setSize(blockSize,blockSize);
			shape.setPosition(p.x, p.y);
			shapes.push_back(shape);

			remainingTime = 0.005f;
		}

		if(positions.empty())
			m_next = true;
	}
	else
	{
		remainingTime -= time.asSeconds();

		if(remainingTime <= 0.f)
		{
			if(shapes.size() > 0) shapes.pop_back();

			remainingTime = 0.005f;
		}

		if(shapes.empty())
		{
			Log("Transition ended");
			finish();
		}
	}

}