示例#1
0
//-----------------------------------------------------------------------------
// Purpose: sets a tooltip AND unhides it
//-----------------------------------------------------------------------------
void CHudToolTip::SetTooltip( const char* szToolTip, vgui::VPANEL _owner )
{
	//TGB: remember who set us
	m_Owner = _owner;

	//DevMsg("Called SetText!\n");
	m_Text->SetText(szToolTip);

	//TGB: got some wrapping in here

	//seems we need to do some manual scaling
	const float ratio = (float)ScreenWidth() / 640.0f;

	TextImage *tiptext = m_Text->GetTextImage();
	tiptext->SetWrap( true );
	tiptext->SetDrawWidth( DRAWWIDTH * ratio );
	tiptext->RecalculateNewLinePositions();
	tiptext->ResizeImageToContent();

	int tw, th;
	tiptext->GetSize( tw, th );			//get sizes
	//DevMsg("tooltiptext is %i by %i\n", tw, th);

	//manually resize height of it all to adjust to wrapped text
	const int newHeight = th + 8;
	m_Text->SetTall( newHeight );			//set label
	SetTall( newHeight );		//set element

	//manually resize width and position centrally
	const int newWidth = tw + 5;
	m_Text->SetWide( newWidth );
	SetWide( newWidth + PAD_HOR );

	//half of screen width minus half of element width
	//so if we're 200 wide our left corner is positioned at 220
	const int newX = (ScreenWidth() / 2) - ( GetWide() / 2 ) ;
	//TGB: also set our own height now that we don't proportionalise
	const int newY = ScreenHeight() - newHeight - 30;
	//int px, py;
	//GetPos( px, py );
	SetPos( newX, newY );

	//make sure we can be seen
	SetVisible( true );
	//DevMsg("nW = %i; nH = %i; nX = %i\n", newWidth, newHeight, newX );

	//DevMsg("Tooltip set to %s\n", szToolTip);

	//TGB: always show a tooltip we've set, as it's only logical. Special cases can do their own Hide(true)
	Hide( false );
}
示例#2
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void ListViewPanel::ApplyItemChanges(int itemID)
{
	if ( !m_DataItems.IsValidIndex(itemID) )
		return;
		
	KeyValues *kv = m_DataItems[itemID]->GetData();
	ListViewItem *pLabel = m_DataItems[itemID];

	pLabel->SetText(kv->GetString("text"));
	pLabel->SetTextImageIndex(1);
	pLabel->SetImagePreOffset(1, 5);

	TextImage *pTextImage = pLabel->GetTextImage();
	pTextImage->ResizeImageToContent();

	pLabel->UpdateImage();
	pLabel->SizeToContents();
	pLabel->InvalidateLayout();
}