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.

78 lines
1.6 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. void CBitmapImagePanel::PaintBackground()
  25. {
  26. if (!m_szTexture[0])
  27. return;
  28. if ( !m_bUploaded )
  29. forceUpload();
  30. int w, h;
  31. GetSize( w, h );
  32. surface()->DrawSetColor( Color( 255, 255, 255, 255 ) );
  33. surface()->DrawSetTexture( m_nTextureId );
  34. surface()->DrawTexturedRect( 0, 0, w, h );
  35. }
  36. void CBitmapImagePanel::setTexture( char const *filename )
  37. {
  38. Q_strncpy( m_szTexture, filename, sizeof( m_szTexture ) );
  39. if ( m_bUploaded )
  40. {
  41. forceReload();
  42. }
  43. else
  44. {
  45. forceUpload();
  46. }
  47. }
  48. void CBitmapImagePanel::forceUpload()
  49. {
  50. if ( !m_szTexture[ 0 ] )
  51. return;
  52. m_bUploaded = true;
  53. m_nTextureId = surface()->CreateNewTextureID();
  54. surface()->DrawSetTextureFile( m_nTextureId, m_szTexture, false, true);
  55. }
  56. void CBitmapImagePanel::forceReload( void )
  57. {
  58. if ( !m_bUploaded )
  59. return;
  60. // Force texture to re-upload to video card
  61. surface()->DrawSetTextureFile( m_nTextureId, m_szTexture, false, true);
  62. }