/*********************************************************************
*	ContainerSemiRelativeUpToDown
*	SOURCE FILE
*	Autor:	Michal Jirouš
*	Datum: 1.7.2008
*	Soubor: container_semirelativeUD.cpp
*	Popis: Kontejner, kam se komponenty ukladaji shora dolu postupne podle
*			jejich vysky
**********************************************************************/

#include "gfg.h"

//definice usporadani
void ContainerSemiRelativeUpToDown::recalculate()
{
	float fNumComponents = (float)m_Components.size();
	float fGlobalXpos = m_ScissorBox.x + m_ScissorBox.w * m_fVerticalPaddingPercents / 2.0f;
	float fWidth = m_ScissorBox.w * ( 1.0f - m_fVerticalPaddingPercents );
	float fHeight = 0;
	float fGlobalYpos = 0;
	
	//okraje komponent
	float fPadding = m_fHorizontalPaddingPercents * m_ScissorBox.h;
	
	float fCurrentYpos = m_ScissorBox.y;
	if( !m_bReverse )
		fCurrentYpos += m_ScissorBox.h;
	

	ContainerElement *first = m_pFirstElement;
	if( !first )
		return;

	//spocitani souradnic komponent
	do
	{
		fHeight = first->m_pComponent->getHeight();
		if( !m_bReverse )
			fCurrentYpos = fCurrentYpos - fPadding - fHeight;
		

		fGlobalYpos = fCurrentYpos + fPadding / 2.0f;

		first->m_pComponent->setPosition( fGlobalXpos, fGlobalYpos );
		first->m_pComponent->setSize( fWidth, fHeight );

		if( m_bReverse )
			fCurrentYpos = fCurrentYpos + fPadding + fHeight;

	}
	while( (first = first->m_pDown) != m_pFirstElement && first  );
}

