Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "IconPanel.h"
  8. #include "KeyValues.h"
  9. DECLARE_BUILD_FACTORY( CIconPanel );
  10. CIconPanel::CIconPanel( vgui::Panel *parent, const char *name ) : vgui::Panel( parent, name )
  11. {
  12. m_szIcon[0] = '\0';
  13. m_icon = NULL;
  14. m_bScaleImage = false;
  15. }
  16. void CIconPanel::ApplySettings( KeyValues *inResourceData )
  17. {
  18. Q_strncpy( m_szIcon, inResourceData->GetString( "icon", "" ), sizeof( m_szIcon ) );
  19. m_icon = gHUD.GetIcon( m_szIcon );
  20. m_bScaleImage = inResourceData->GetInt("scaleImage", 0);
  21. BaseClass::ApplySettings( inResourceData );
  22. }
  23. void CIconPanel::SetIcon( const char *szIcon )
  24. {
  25. Q_strncpy( m_szIcon, szIcon, sizeof(m_szIcon) );
  26. m_icon = gHUD.GetIcon( m_szIcon );
  27. }
  28. void CIconPanel::Paint()
  29. {
  30. BaseClass::Paint();
  31. if ( m_icon )
  32. {
  33. int x, y, w, h;
  34. GetBounds( x, y, w, h );
  35. if ( m_bScaleImage )
  36. {
  37. m_icon->DrawSelf( 0, 0, w, h, m_IconColor );
  38. }
  39. else
  40. {
  41. m_icon->DrawSelf( 0, 0, m_IconColor );
  42. }
  43. }
  44. }
  45. void CIconPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  46. {
  47. BaseClass::ApplySchemeSettings( pScheme );
  48. if ( m_szIcon[0] != '\0' )
  49. {
  50. m_icon = gHUD.GetIcon( m_szIcon );
  51. }
  52. SetFgColor( pScheme->GetColor( "FgColor", Color( 255, 255, 255, 255 ) ) );
  53. }