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.

72 lines
1.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "matsys_controls/tgapreviewpanel.h"
  7. #include "bitmap/tgaloader.h"
  8. #include "tier1/utlbuffer.h"
  9. #include "filesystem.h"
  10. using namespace vgui;
  11. //-----------------------------------------------------------------------------
  12. //
  13. // TGA Preview panel
  14. //
  15. //-----------------------------------------------------------------------------
  16. //-----------------------------------------------------------------------------
  17. // constructor
  18. //-----------------------------------------------------------------------------
  19. CTGAPreviewPanel::CTGAPreviewPanel( vgui::Panel *pParent, const char *pName ) :
  20. BaseClass( pParent, pName )
  21. {
  22. }
  23. //-----------------------------------------------------------------------------
  24. // Sets the current TGA
  25. //-----------------------------------------------------------------------------
  26. void CTGAPreviewPanel::SetTGA( const char *pFullPath )
  27. {
  28. int nWidth, nHeight;
  29. ImageFormat format;
  30. float flGamma;
  31. CUtlBuffer buf;
  32. if ( !g_pFullFileSystem->ReadFile( pFullPath, NULL, buf ) )
  33. {
  34. Warning( "Can't open TGA file: %s\n", pFullPath );
  35. return;
  36. }
  37. TGALoader::GetInfo( buf, &nWidth, &nHeight, &format, &flGamma );
  38. Shutdown();
  39. Init( nWidth, nHeight, true );
  40. m_TGAName = pFullPath;
  41. buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
  42. if ( !TGALoader::Load( (unsigned char*)GetImageBuffer(), buf,
  43. nWidth, nHeight, IMAGE_FORMAT_BGRA8888, flGamma, false ) )
  44. {
  45. Shutdown();
  46. }
  47. else
  48. {
  49. DownloadTexture();
  50. }
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Gets the current TGA
  54. //-----------------------------------------------------------------------------
  55. const char *CTGAPreviewPanel::GetTGA() const
  56. {
  57. return m_TGAName;
  58. }