void CNB_Mission_Summary::PerformLayout()
{
	BaseClass::PerformLayout();

	//m_pObjectivesLabel->GetTextImage()->ResizeImageToContent();
	int nLabelWidth = YRES( 168 );

	m_pObjectivesLabel->SetSize( nLabelWidth, 400 );
	m_pObjectivesLabel->GetTextImage()->SetDrawWidth( nLabelWidth );
	m_pObjectivesLabel->InvalidateLayout( true );
	int texwide, texttall;	
	m_pObjectivesLabel->GetTextImage()->ResizeImageToContentMaxWidth( nLabelWidth );
	m_pObjectivesLabel->GetTextImage()->GetContentSize( texwide, texttall );	
	m_pObjectivesLabel->InvalidateLayout( true );

	int x, y, w, h;
	m_pObjectivesLabel->GetBounds( x, y, w, h );

	h = texttall;

	int dw, dh;
	m_pDetailsButton->GetSize( dw, dh );

	h += dh;

	int border = YRES( 10 );
	SetTall( y + h + border );
	m_pBackground->SetTall( y + h + border );

	int bx, by;
	m_pBackgroundInner->GetPos( bx, by );
	m_pBackgroundInner->SetTall( y + h + border - ( by * 2 ) );

	m_pDetailsButton->SetPos( GetWide() - ( dw + border ), GetTall() - ( dh + border ) );
}
void CASW_VGUI_Computer_Menu::PerformLayout()
{
	m_fScale = ScreenHeight() / 768.0f;

	int w = GetParent()->GetWide();
	int h = GetParent()->GetTall();
	SetWide(w);
	SetTall(h);
	SetPos(0, 0);

	if (m_hCurrentPage.Get())
	{
		m_hCurrentPage->SetPos(0,0);
		m_hCurrentPage->InvalidateLayout(true);
	}

	m_pAccessDeniedLabel->SetSize(w, h * 0.3);
	m_pAccessDeniedLabel->SetPos(0, h * 0.25f);
	m_pInsufficientRightsLabel->SetContentAlignment(vgui::Label::a_northwest);
	m_pInsufficientRightsLabel->InvalidateLayout(true);
	int ix, iy;
	m_pInsufficientRightsLabel->GetTextImage()->GetContentSize(ix, iy);
	m_pInsufficientRightsLabel->SetSize(ix, iy);	
	m_pInsufficientRightsLabel->SetPos(w * 0.5f - ix * 0.455f, h * 0.56f);		

	LayoutMenuOptions();
}
VideoPanel::VideoPanel( unsigned int nXPos, unsigned int nYPos, unsigned int nHeight, unsigned int nWidth ) : 
	BaseClass( NULL, "VideoPanel" ),
	m_BIKHandle( BIKHANDLE_INVALID ),
	m_nPlaybackWidth( 0 ),
	m_nPlaybackHeight( 0 )
{
	vgui::VPANEL pParent = enginevgui->GetPanel( PANEL_GAMEUIDLL );
	SetParent( pParent );
	SetVisible( false );
	
	// Must be passed in, off by default
	m_szExitCommand[0] = '\0';

	m_bBlackBackground = true;

	SetKeyBoardInputEnabled( true );
	SetMouseInputEnabled( false );

	SetProportional( false );
	SetVisible( true );
	SetPaintBackgroundEnabled( false );
	SetPaintBorderEnabled( false );
	
	// Set us up
	SetTall( nHeight );
	SetWide( nWidth );
	SetPos( nXPos, nYPos );

	SetScheme(vgui::scheme()->LoadSchemeFromFile( "resource/VideoPanelScheme.res", "VideoPanelScheme"));
	LoadControlSettings("resource/UI/VideoPanel.res");
}
HapticsGraph::HapticsGraph(vgui::VPANEL parent) :
BaseClass( NULL, 50, -3, 3) 
{
	// if created by VPanel, well need to put a frame behind us.
	vgui::Frame *frame = new vgui::Frame(NULL,"hdebug");
	frame->SetPos(24,24);
	SetWide(150);
	SetTall(75);
	frame->SetWide(GetWide());
	frame->SetTall(GetTall()+24);
	SetParent(frame);
}
CASW_VGUI_Edit_Emitter_SaveDialog::CASW_VGUI_Edit_Emitter_SaveDialog( vgui::Panel *pParent, const char *pElementName, CASW_VGUI_Edit_Emitter* pEditFrame ) 
 :	vgui::Frame( pParent, pElementName )
{	
	m_pEditFrame = pEditFrame;
	SetTitle("Save Template", true);
	SetSizeable(false);
	SetMoveable(false);
	SetTall(140);
	SetWide(320);
	SetCloseButtonVisible(false);
	MoveToCenterOfScreen();

	vgui::Label* pPleaseLabel = new vgui::Label(this, "SaveDLabel", "Please enter a name to save this template as:");
	pPleaseLabel->SetPos(20,25);
	pPleaseLabel->SetWide(290);
	pPleaseLabel->SetTall(20);

	//vgui::Label* pLabel = new vgui::Label(this, "SaveDLabel", "Template Name:");
	//pLabel->SetPos(20,45);
	//pLabel->SetWide(220);
	//pLabel->SetTall(20);

	m_pSaveText = new vgui::TextEntry(this, "SaveDText");
	m_pSaveText->SetPos(20,45);
	m_pSaveText->SetWide(220);
	m_pSaveText->SetTall(20);
	char buf[MAX_PATH];
	m_pEditFrame->m_pTemplateCombo->GetText(buf, MAX_PATH);
	m_pSaveText->SetText(buf);

	m_pSaveButton = new vgui::Button(this, "SaveDButton", "Save");
	m_pSaveButton->SetCommand(new KeyValues("SaveDButton"));
	m_pSaveButton->SetWide(60);
	m_pSaveButton->SetTall(20);
	m_pSaveButton->SetPos(190, 115);
	m_pSaveButton->AddActionSignalTarget(this);

	m_pCancelButton = new vgui::Button(this, "CancelDButton", "Cancel");
	m_pCancelButton->SetCommand(new KeyValues("CancelDButton"));
	m_pCancelButton->SetWide(60);
	m_pCancelButton->SetTall(20);
	m_pCancelButton->SetPos(255, 115);
	m_pCancelButton->AddActionSignalTarget(this);

	m_pExistsLabel = new vgui::Label(this, "ExistsLabel", " ");
	m_pExistsLabel->SetPos(20,70);
	m_pExistsLabel->SetWide(300);
	m_pExistsLabel->SetTall(40);

	TextEntryChanged(m_pSaveText);
}
void CASW_VGUI_Computer_Splash::PerformLayout()
{
	m_fScale = ScreenHeight() / 768.0f;

	int w = GetParent()->GetWide();
	int h = GetParent()->GetTall();
	SetWide(w);
	SetTall(h);
	SetPos(ScreenWidth()*0.5f - w*0.5f, ScreenHeight()*0.5f - h*0.5f);

	m_pLogoImage->SetShouldScaleImage(true);
	m_pLogoImage->SetPos(w*0.25f,h*0.15f);
	m_pLogoImage->SetSize(w*0.5f, h*0.5f);
	m_pLogoImage->SetImage("swarm/Computer/SynTekLogo2");
	m_pLogoImage->SetZPos(160);
	
	m_pLogoGlitchImage->SetShouldScaleImage(true);
	m_pLogoGlitchImage->SetPos(w*0.25f,h*0.25f);
	m_pLogoGlitchImage->SetSize(w*0.5f, h*0.5f);
	m_pLogoGlitchImage->SetImage("swarm/Computer/SynTekLogo2");
	m_pLogoGlitchImage->SetZPos(159);

	m_pSloganLabel->SetSize(w, h * 0.2f);
	m_pSloganLabel->SetContentAlignment(vgui::Label::a_center);
	m_pSloganLabel->SetPos(0, h*0.75f);
	m_pSloganLabel->SetZPos(160);
	m_pSynTekLabel->SetSize(w, h * 0.2f);
	m_pSynTekLabel->SetContentAlignment(vgui::Label::a_center);
	m_pSynTekLabel->SetPos(0, h*0.65f);
	m_pSynTekLabel->SetZPos(160);
	
	for (int i=0;i<ASW_SPLASH_SCROLL_LINES;i++)
	{		
		m_pScrollLine[i]->SetSize(w, h * 0.2f);
		m_pScrollLine[i]->SetContentAlignment(vgui::Label::a_northwest);
	}

	if (m_bSlidOut)
	{
		m_pLogoImage->SetBounds( w*0.05f, h*0.05f, w*0.13f, h*0.13f);
		m_pSynTekLabel->SetPos(0, 0);
	}

	SetZPos(161);
}
VideoPanel::VideoPanel( unsigned int nXPos, unsigned int nYPos, unsigned int nHeight, unsigned int nWidth, vgui::VPANEL pParent ) : 
	BaseClass( NULL, "VideoPanel" ),
	m_BIKHandle( BIKHANDLE_INVALID ),
	m_nPlaybackWidth( 0 ),
	m_nPlaybackHeight( 0 )
{
	
	if (pParent == NULL)
	{
		SetParent( enginevgui->GetPanel( PANEL_GAMEUIDLL ) );
	}
	else
	{
		SetParent( pParent );
	}
	
	SetVisible( false );

	m_czLastFile[0] = '\0';
	m_bPlaying = false;
	m_bRepeat = false;

	m_bBlackBackground = true;

	SetKeyBoardInputEnabled( true );
	SetMouseInputEnabled( false );

	SetProportional( false );
	SetVisible( true );
	SetPaintBackgroundEnabled( false );
	SetPaintBorderEnabled( false );
	SetAutoDelete( true );
	
	// Set us up
	SetTall( nHeight );
	SetWide( nWidth );
	SetPos( nXPos, nYPos );

	SetScheme(vgui::scheme()->LoadSchemeFromFile( "resource/VideoPanelScheme.res", "VideoPanelScheme"));
	LoadControlSettings("resource/UI/VideoPanel.res");
}
void CASW_VGUI_Door_Tooltip::Paint()
{	
	BaseClass::Paint();

	if (GetAlpha() > 0)
	{
		int padding = (2.0f / 1024.0f) * ScreenWidth();
		if (padding < 1)
			padding = 1;

		int bar_width = (96.0f / 1024.0f) * ScreenWidth();
		int bar_height = (12.0f / 1024.0f) * ScreenWidth();
		DrawHorizontalBar( padding, padding, bar_width, bar_height, m_fDoorHealthFraction, 255, 255, 255, 255 );

		if (GetWide() < bar_width + padding + padding)
		{
			SetWide(bar_width + padding + padding - 1);
		}
		SetTall( bar_height + padding + padding - 1);
	}
}
VideoPlayerPanel::VideoPlayerPanel( vgui::Panel *parent, const char *panelName, int nXpos, int nYpos, int nWidth, int nHeight, const char *pVideoFile ) : 
	BaseClass( parent, panelName ),
	m_VideoMaterial( NULL ),
	m_VideoFileName( NULL ),
	m_VideoLoaded( false ),
	m_VideoPlaying( false )
{
	Assert( g_pVideo != NULL );

	// init all the video realted member vars
	ClearVideo();

	SetVisible( false );
	
	SetKeyBoardInputEnabled( false );
	SetMouseInputEnabled( false );

	SetProportional( false );
	SetPaintBackgroundEnabled( false );
	SetPaintBorderEnabled( false );
	
	// Set us up
	SetTall( nHeight );
	SetWide( nWidth );
	SetPos( nXpos, nYpos );

	// use defaults for scheme and control settings for now

	// SetScheme( vgui::scheme()->LoadSchemeFromFile( "resource/VideoPlayerPanelScheme.res", "VideoPlayerPanelScheme"));
	//LoadControlSettings("resource/UI/VideoPlayerPanel.res");

	// Assign video file if supplied
	SetVideo( pVideoFile );
	
	SetVisible( true );

}									
void CASW_VGUI_Computer_Frame::PerformLayout()
{
	m_fScale = ScreenHeight() / 768.0f;
	int w = m_fScale * (0.65f * 1024);
	int h = m_fScale * (0.65f * 768);
	SetWide(w);
	SetTall(h);
	int frame_border = 10.0f * m_fScale;
	int frame_title_border = 40.0f * m_fScale;
	SetPos(frame_border,frame_title_border);	// assumes its inside an asw_vgui_frame..

	if (m_pCurrentPanel)
		m_pCurrentPanel->SetPos(0,0);
	if (m_pSplash)
		m_pSplash->SetPos(0,0);

	m_iScanHeight = 0.166667f * 768 * m_fScale;
	for (int i=0;i<3;i++)
	{
		m_pScan[i]->SetSize(w, m_iScanHeight);
		m_pScan[i]->SetPos(0,-m_iScanHeight);
		m_pScan[i]->SetZPos(200);	// make sure scan lines are on top of everything (or should they be under?)
	}

	m_pBackdropImage->SetShouldScaleImage(true);
	m_pBackdropImage->SetPos(0,0);
	m_pBackdropImage->SetSize(w, h);

	if (m_pMenuPanel)
		m_pMenuPanel->InvalidateLayout(true);

	m_pLogoffLabel->SetSize(128 * m_fScale, 28 * m_fScale);
	//m_pLogoffLabel->SetPos(w*0.05, h*0.9);
	m_pLogoffLabel->SetPos( w * 0.75, h*0.9 );
	m_pLogoffLabel->SetZPos(200);
}
void CASW_VGUI_Computer_Weather::PerformLayout()
{
    m_fScale = ScreenHeight() / 768.0f;

    int w = GetParent()->GetWide();
    int h = GetParent()->GetTall();
    SetWide(w);
    SetTall(h);
    SetPos(0, 0);

    m_pBackButton->SetPos(w * 0.75, h*0.9);
    m_pBackButton->SetSize(128 * m_fScale, 28 * m_fScale);

    m_pTitleLabel->SetContentAlignment(vgui::Label::a_center);
    m_pTitleLabel->SetSize(w, h * 0.2f);
    m_pTitleLabel->SetPos(0, 0);//h*0.65f);
    m_pTitleLabel->SetZPos(160);

    m_pTitleIcon->SetShouldScaleImage(true);
    int ix,iy,iw,it;
    ix = w*0.05f;//w*0.25f;
    iy = h*0.05f;//h*0.15f;
    iw = w*0.5f;
    it = h*0.5f;
    m_pTitleIcon->SetPos(ix,iy);
    m_pTitleIcon->SetSize(iw, it);
    m_pTitleIcon->SetZPos(160);

    iw = it = 96 * m_fScale;
    m_pTitleIcon->SetShouldScaleImage(true);
    m_pTitleIcon->SetSize(iw,it);
    m_pTitleIcon->SetZPos(155);
    m_pTitleIconShadow->SetShouldScaleImage(true);
    m_pTitleIconShadow->SetSize(iw * 1.3f, it * 1.3f);
    //m_pTitleIconShadow[i]->SetAlpha(m_pMenuIcon[i]->GetAlpha()*0.5f);
    m_pTitleIconShadow->SetZPos(154);
    m_pTitleIconShadow->SetPos(ix - iw * 0.25f, iy + it * 0.0f);

    //const float row_height = 0.05f * h;

    const int weather_top = h * 0.28f;
    const int label_width = h * 0.4f;
    const int value_width = 0.4f * w;
    const int weather_line_height = 0.05f * h;

    const float left_edge = 0.5 * w - ((label_width + value_width) * 0.5f);

    for (int i=0; i<ASW_WEATHER_ENTRIES; i++)
    {
        int x = left_edge;// + 0.02f * w;
        int ypos = weather_top + weather_line_height * i;
        //if (i > 0)
        //ypos += weather_line_height * 0.5f;
        m_pWeatherLabel[i]->SetBounds(x, ypos, label_width, weather_line_height);
        x+= label_width;
        m_pWeatherValue[i]->SetBounds(x, ypos, value_width, weather_line_height);
        x+= value_width;
    }

    const int warning_width = 0.8f * w;
    const int warning_edge = 0.5f * w - (warning_width * 0.5f);

    m_pWarningLabel->GetTextImage()->SetDrawWidth(warning_width);
    int texwide, texttall;
    m_pWarningLabel->GetTextImage()->GetContentSize(texwide, texttall);
    m_pWarningLabel->SetSize(texwide, texttall);
    m_pWarningLabel->SetPos(warning_edge, weather_top + weather_line_height * (ASW_WEATHER_ENTRIES + 1));

    // make sure all the labels expand to cover the new sizes
    m_pTitleLabel->InvalidateLayout();
}