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.

94 lines
2.3 KiB

  1. //===== Copyright � 1996-2005, 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. // NOTE: This has to be the last file included!
  11. #include "tier0/memdbgon.h"
  12. using namespace vgui;
  13. //-----------------------------------------------------------------------------
  14. //
  15. // TGA Preview panel
  16. //
  17. //-----------------------------------------------------------------------------
  18. //-----------------------------------------------------------------------------
  19. // constructor
  20. //-----------------------------------------------------------------------------
  21. CTGAPreviewPanel::CTGAPreviewPanel( vgui::Panel *pParent, const char *pName ) :
  22. BaseClass( pParent, pName )
  23. {
  24. }
  25. //-----------------------------------------------------------------------------
  26. // Sets the current TGA
  27. //-----------------------------------------------------------------------------
  28. void CTGAPreviewPanel::SetTGA( const char *pFullPath )
  29. {
  30. int nWidth, nHeight;
  31. ImageFormat format;
  32. float flGamma;
  33. CUtlBuffer buf;
  34. if ( !g_pFullFileSystem->ReadFile( pFullPath, NULL, buf ) )
  35. {
  36. Warning( "Can't open TGA file: %s\n", pFullPath );
  37. return;
  38. }
  39. TGALoader::GetInfo( buf, &nWidth, &nHeight, &format, &flGamma );
  40. Shutdown();
  41. Init( nWidth, nHeight, true );
  42. m_TGAName = pFullPath;
  43. buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
  44. if ( !TGALoader::Load( (unsigned char*)GetImageBuffer(), buf,
  45. nWidth, nHeight, IMAGE_FORMAT_BGRA8888, flGamma, false ) )
  46. {
  47. Shutdown();
  48. }
  49. else
  50. {
  51. DownloadTexture();
  52. }
  53. InvalidateLayout();
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Gets the current TGA
  57. //-----------------------------------------------------------------------------
  58. const char *CTGAPreviewPanel::GetTGA() const
  59. {
  60. return m_TGAName;
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Lays out the panel
  64. //-----------------------------------------------------------------------------
  65. void CTGAPreviewPanel::PerformLayout()
  66. {
  67. BaseClass::PerformLayout();
  68. Rect_t paintRect;
  69. paintRect.x = 0;
  70. paintRect.y = 0;
  71. paintRect.width = GetImageWidth();
  72. paintRect.height = GetImageHeight();
  73. SetPaintRect( &paintRect );
  74. }