コード例 #1
0
ファイル: panel.cpp プロジェクト: BSVino/ViewbackMonitor
void CPanel::Layout( void )
{
	FRect rPanelBounds;
	rPanelBounds.x = 0;
	rPanelBounds.y = 0;
	rPanelBounds.w = GetWidth();
	rPanelBounds.h = GetHeight();

	FRect rAllBounds(0, 0, 0, 0);

	rAllBounds.w = -1;

	size_t iCount = m_apControls.size();
	for (size_t i = 0; i < iCount; i++)
	{
		CBaseControl* pControl = m_apControls[i];
		if (pControl == m_hHorizontalScrollBar)
			continue;

		if (pControl == m_hVerticalScrollBar)
			continue;

		pControl->Layout();

		FRect rControlBounds;
		rControlBounds.x = pControl->GetLeft();
		rControlBounds.y = pControl->GetTop();
		rControlBounds.w = pControl->GetWidth();
		rControlBounds.h = pControl->GetHeight();

		if (rAllBounds.w < 0)
		{
			rAllBounds = rControlBounds;
			continue;
		}

		if (rControlBounds.x < rAllBounds.x)
		{
			float flDifference = rAllBounds.x - rControlBounds.x;
			rAllBounds.x -= flDifference;
			rAllBounds.w += flDifference;
		}

		if (rControlBounds.y < rAllBounds.y)
		{
			float flDifference = rAllBounds.y - rControlBounds.y;
			rAllBounds.y -= flDifference;
			rAllBounds.h += flDifference;
		}

		if (rControlBounds.Right() > rAllBounds.Right())
			rAllBounds.w = rControlBounds.Right() - rAllBounds.x;

		if (rControlBounds.Bottom() > rAllBounds.Bottom())
			rAllBounds.h = rControlBounds.Bottom() - rAllBounds.y;
	}

	rAllBounds.w += 5;
	rAllBounds.h += 5;

	m_rControlBounds = rAllBounds;

	if (m_hVerticalScrollBar)
		m_hVerticalScrollBar->SetVisible((rAllBounds.y < rPanelBounds.y) || (rAllBounds.Bottom() > rPanelBounds.Bottom()));

	if (m_hHorizontalScrollBar)
		m_hHorizontalScrollBar->SetVisible((rAllBounds.x < rPanelBounds.x) || (rAllBounds.Right() > rPanelBounds.Right()));
}