예제 #1
0
//-----------------------------------------------------------------------------
// Purpose: relayouts out the panel after any internal changes
//-----------------------------------------------------------------------------
void CMaterialViewPanel::PerformLayout()
{
	// Get the current size, see if it's big enough to view the entire thing
	int iWidth, iHeight;
	GetSize( iWidth, iHeight );

	// In the case of stretching, just stretch to the size and blow off
	// the scrollbars. Same holds true if there's no material
	if (!m_bUseActualSize || !m_pMaterial)
	{
		m_iViewableWidth = iWidth;
		m_iViewableHeight = iHeight;
		m_pHorizontalBar->SetVisible(false);
		m_pVerticalBar->SetVisible(false);
		return;
	}

	// Check the size of the material...
	int iMaterialWidth = m_pMaterial->GetMappingWidth();
	int iMaterialHeight = m_pMaterial->GetMappingHeight();

	// Check if the scroll bars are visible
	bool bHorizScrollVisible = (iMaterialWidth > iWidth);
	bool bVertScrollVisible = (iMaterialHeight > iHeight);

	m_pHorizontalBar->SetVisible(bHorizScrollVisible);
	m_pVerticalBar->SetVisible(bVertScrollVisible);

	// Shrink the bars if both are visible
	m_iViewableWidth = bVertScrollVisible ? iWidth - SCROLLBAR_SIZE - WINDOW_BORDER_WIDTH : iWidth; 
	m_iViewableHeight = bHorizScrollVisible ? iHeight - SCROLLBAR_SIZE - WINDOW_BORDER_WIDTH : iHeight; 

	// Set the position of the horizontal bar...
	if (bHorizScrollVisible)
	{
		m_pHorizontalBar->SetPos(0, iHeight - SCROLLBAR_SIZE);
		m_pHorizontalBar->SetSize( m_iViewableWidth, SCROLLBAR_SIZE );

		m_pHorizontalBar->SetRangeWindow( m_iViewableWidth );
		m_pHorizontalBar->SetRange( 0, iMaterialWidth );	

		// FIXME: Change scroll amount based on how much is not visible?
		m_pHorizontalBar->SetButtonPressedScrollValue( 5 );
	}

	// Set the position of the vertical bar...
	if (bVertScrollVisible)
	{
		m_pVerticalBar->SetPos(iWidth - SCROLLBAR_SIZE, 0);
		m_pVerticalBar->SetSize(SCROLLBAR_SIZE, m_iViewableHeight);

		m_pVerticalBar->SetRangeWindow( m_iViewableHeight );
		m_pVerticalBar->SetRange( 0, iMaterialHeight);	
		m_pVerticalBar->SetButtonPressedScrollValue( 5 );
	}
}
예제 #2
0
//-----------------------------------------------------------------------------
// Renders a material orthographically to screen...
//-----------------------------------------------------------------------------
static void RenderMaterial( const char *pMaterialName )
{
	// So it's not in the very top left
	float x = 100.0f, y = 100.0f;
	// float x = 0.0f, y = 0.0f;

	IMaterial *pMaterial = materials->FindMaterial( pMaterialName, TEXTURE_GROUP_OTHER, false );
	if ( !IsErrorMaterial( pMaterial ) )
	{
		CMatRenderContextPtr pRenderContext( materials );
		pRenderContext->Bind( pMaterial );
		IMesh* pMesh = pRenderContext->GetDynamicMesh( true );

		CMeshBuilder meshBuilder;
		meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

		meshBuilder.Position3f( x, y, 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
		meshBuilder.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( x + pMaterial->GetMappingWidth(), y, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
		meshBuilder.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( x + pMaterial->GetMappingWidth(), y + pMaterial->GetMappingHeight(), 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
		meshBuilder.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( x, y + pMaterial->GetMappingHeight(), 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
		meshBuilder.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.End();
		pMesh->Draw();
	}
}
예제 #3
0
//-----------------------------------------------------------------------------
// paint it actual size
//-----------------------------------------------------------------------------
void CMaterialViewPanel::DrawActualSize( CMeshBuilder &meshBuilder )
{
	// Check the size of the material...
	int iMaterialWidth = m_pMaterial->GetMappingWidth();
	int iMaterialHeight = m_pMaterial->GetMappingHeight();

	Vector2D ul;
	Vector2D lr;
	Vector2D tul;
	Vector2D tlr;

	if (m_iViewableWidth >= iMaterialWidth)
	{
		// Center the material if we've got enough horizontal space
		ul.x = (m_iViewableWidth - iMaterialWidth) * 0.5f;
		lr.x = ul.x + iMaterialWidth;
		tul.x = 0.0f; tlr.x = 1.0f;
	}
	else
	{
		// Use the scrollbars here...
		int val = m_pHorizontalBar->GetValue();
		tul.x = (float)val / (float)iMaterialWidth;
		tlr.x = tul.x + (float)m_iViewableWidth / (float)iMaterialWidth;

		ul.x = 0;
		lr.x = m_iViewableWidth;
	}

	if (m_iViewableHeight >= iMaterialHeight)
	{
		// Center the material if we've got enough vertical space
		ul.y = (m_iViewableHeight - iMaterialHeight) * 0.5f;
		lr.y = ul.y + iMaterialHeight;
		tul.y = 0.0f; tlr.y = 1.0f;
	}
	else
	{
		// Use the scrollbars here...
		int val = m_pVerticalBar->GetValue();

		tul.y = (float)val / (float)iMaterialHeight;
		tlr.y = tul.y + (float)m_iViewableHeight / (float)iMaterialHeight;

		ul.y = 0;
		lr.y = m_iViewableHeight;
	}

	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.Position3f( ul.x, ul.y, 0 );
	meshBuilder.TexCoord2f( 0, tul.x, tul.y );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.Position3f( lr.x, ul.y, 0 );
	meshBuilder.TexCoord2f( 0, tlr.x, tul.y );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.Position3f( lr.x, lr.y, 0 );
	meshBuilder.TexCoord2f( 0, tlr.x, tlr.y );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.Position3f( ul.x, lr.y, 0 );
	meshBuilder.TexCoord2f( 0, tul.x, tlr.y );
	meshBuilder.AdvanceVertex();
}