73 lines
1.5 KiB
C++
Raw Normal View History

2023-10-03 17:23:56 +03:00
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
2020-04-22 12:56:21 -04:00
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
2023-10-03 17:23:56 +03:00
#include "iconpanel.h"
2020-04-22 12:56:21 -04:00
#include "KeyValues.h"
2023-10-03 17:23:56 +03:00
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
2020-04-22 12:56:21 -04:00
DECLARE_BUILD_FACTORY( CIconPanel );
CIconPanel::CIconPanel( vgui::Panel *parent, const char *name ) : vgui::Panel( parent, name )
{
m_szIcon[0] = '\0';
m_icon = NULL;
m_bScaleImage = false;
}
void CIconPanel::ApplySettings( KeyValues *inResourceData )
{
Q_strncpy( m_szIcon, inResourceData->GetString( "icon", "" ), sizeof( m_szIcon ) );
2023-10-03 17:23:56 +03:00
m_icon = HudIcons().GetIcon( m_szIcon );
2020-04-22 12:56:21 -04:00
2023-10-03 17:23:56 +03:00
m_bScaleImage = inResourceData->GetBool( "scaleImage", false );
2020-04-22 12:56:21 -04:00
BaseClass::ApplySettings( inResourceData );
}
void CIconPanel::SetIcon( const char *szIcon )
{
Q_strncpy( m_szIcon, szIcon, sizeof(m_szIcon) );
2023-10-03 17:23:56 +03:00
m_icon = HudIcons().GetIcon( m_szIcon );
2020-04-22 12:56:21 -04:00
}
void CIconPanel::Paint()
{
BaseClass::Paint();
if ( m_icon )
{
int x, y, w, h;
GetBounds( x, y, w, h );
if ( m_bScaleImage )
{
m_icon->DrawSelf( 0, 0, w, h, m_IconColor );
}
else
{
m_icon->DrawSelf( 0, 0, m_IconColor );
}
}
}
void CIconPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
if ( m_szIcon[0] != '\0' )
{
2023-10-03 17:23:56 +03:00
m_icon = HudIcons().GetIcon( m_szIcon );
2020-04-22 12:56:21 -04:00
}
SetFgColor( pScheme->GetColor( "FgColor", Color( 255, 255, 255, 255 ) ) );
}