summaryrefslogtreecommitdiff
path: root/vgui2/matsys_controls/tgapreviewpanel.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /vgui2/matsys_controls/tgapreviewpanel.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'vgui2/matsys_controls/tgapreviewpanel.cpp')
-rw-r--r--vgui2/matsys_controls/tgapreviewpanel.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/vgui2/matsys_controls/tgapreviewpanel.cpp b/vgui2/matsys_controls/tgapreviewpanel.cpp
new file mode 100644
index 0000000..c91b6f3
--- /dev/null
+++ b/vgui2/matsys_controls/tgapreviewpanel.cpp
@@ -0,0 +1,72 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//===========================================================================//
+
+#include "matsys_controls/tgapreviewpanel.h"
+#include "bitmap/tgaloader.h"
+#include "tier1/utlbuffer.h"
+#include "filesystem.h"
+
+using namespace vgui;
+
+
+//-----------------------------------------------------------------------------
+//
+// TGA Preview panel
+//
+//-----------------------------------------------------------------------------
+
+
+//-----------------------------------------------------------------------------
+// constructor
+//-----------------------------------------------------------------------------
+CTGAPreviewPanel::CTGAPreviewPanel( vgui::Panel *pParent, const char *pName ) :
+ BaseClass( pParent, pName )
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Sets the current TGA
+//-----------------------------------------------------------------------------
+void CTGAPreviewPanel::SetTGA( const char *pFullPath )
+{
+ int nWidth, nHeight;
+ ImageFormat format;
+ float flGamma;
+
+ CUtlBuffer buf;
+ if ( !g_pFullFileSystem->ReadFile( pFullPath, NULL, buf ) )
+ {
+ Warning( "Can't open TGA file: %s\n", pFullPath );
+ return;
+ }
+
+ TGALoader::GetInfo( buf, &nWidth, &nHeight, &format, &flGamma );
+
+ Shutdown();
+ Init( nWidth, nHeight, true );
+ m_TGAName = pFullPath;
+
+ buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
+ if ( !TGALoader::Load( (unsigned char*)GetImageBuffer(), buf,
+ nWidth, nHeight, IMAGE_FORMAT_BGRA8888, flGamma, false ) )
+ {
+ Shutdown();
+ }
+ else
+ {
+ DownloadTexture();
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// Gets the current TGA
+//-----------------------------------------------------------------------------
+const char *CTGAPreviewPanel::GetTGA() const
+{
+ return m_TGAName;
+}