Counter Strike : Global Offensive Source Code
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.

87 lines
1.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BitmapImagePanel.h"
  8. #include <vgui/ISurface.h>
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. using namespace vgui;
  12. CBitmapImagePanel::CBitmapImagePanel( Panel *parent, char const *panelName,
  13. char const *filename /*= NULL*/ ) : Panel( parent, panelName )
  14. {
  15. m_szTexture[ 0 ] = 0;
  16. m_bUploaded = false;
  17. m_nTextureId = -1;
  18. SetBounds( 0, 0, 100, 100 );
  19. if ( filename && filename[ 0 ] )
  20. {
  21. Q_strncpy( m_szTexture, filename, sizeof( m_szTexture ) );
  22. }
  23. }
  24. CBitmapImagePanel::~CBitmapImagePanel()
  25. {
  26. if ( vgui::surface() && m_nTextureId != -1 )
  27. {
  28. vgui::surface()->DestroyTextureID( m_nTextureId );
  29. m_nTextureId = -1;
  30. }
  31. }
  32. void CBitmapImagePanel::PaintBackground()
  33. {
  34. if (!m_szTexture[0])
  35. return;
  36. if ( !m_bUploaded )
  37. forceUpload();
  38. int w, h;
  39. GetSize( w, h );
  40. surface()->DrawSetColor( Color( 255, 255, 255, 255 ) );
  41. surface()->DrawSetTexture( m_nTextureId );
  42. surface()->DrawTexturedRect( 0, 0, w, h );
  43. }
  44. void CBitmapImagePanel::setTexture( char const *filename )
  45. {
  46. Q_strncpy( m_szTexture, filename, sizeof( m_szTexture ) );
  47. if ( m_bUploaded )
  48. {
  49. forceReload();
  50. }
  51. else
  52. {
  53. forceUpload();
  54. }
  55. }
  56. void CBitmapImagePanel::forceUpload()
  57. {
  58. if ( !m_szTexture[ 0 ] )
  59. return;
  60. m_bUploaded = true;
  61. m_nTextureId = surface()->CreateNewTextureID();
  62. surface()->DrawSetTextureFile( m_nTextureId, m_szTexture, false, true);
  63. }
  64. void CBitmapImagePanel::forceReload( void )
  65. {
  66. if ( !m_bUploaded )
  67. return;
  68. // Force texture to re-upload to video card
  69. surface()->DrawSetTextureFile( m_nTextureId, m_szTexture, false, true);
  70. }