Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
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.

113 lines
2.3 KiB

9 years ago
//========= Copyright <EFBFBD> 1996-2002, Valve LLC, All rights reserved. ============
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "../cl_dll/wrect.h"
#include "../cl_dll/cl_dll.h"
#include "VGUI.h"
9 years ago
#include "vgui_loadtga.h"
#include "VGUI_InputStream.h"
9 years ago
// ---------------------------------------------------------------------- //
// Helper class for loading tga files.
// ---------------------------------------------------------------------- //
class MemoryInputStream : public vgui::InputStream
{
public:
MemoryInputStream()
{
m_pData = NULL;
m_DataLen = m_ReadPos = 0;
}
9 years ago
virtual void seekStart( bool &success )
{
m_ReadPos = 0;
success = true;
}
virtual void seekRelative( int count, bool &success )
{
m_ReadPos += count;
success = true;
}
virtual void seekEnd( bool &success )
9 years ago
{
m_ReadPos = m_DataLen;
success = true;
}
virtual int getAvailable( bool &success )
{
// This is what vgui does for files...
success = false;
return 0;
}
virtual uchar readUChar( bool & success )
{
if( m_ReadPos >= 0 && m_ReadPos < m_DataLen )
9 years ago
{
success = true;
9 years ago
uchar ret = m_pData[m_ReadPos];
++m_ReadPos;
return ret;
}
else
{
success = false;
9 years ago
return 0;
}
}
virtual void readUChar( uchar *buf, int count, bool &success )
9 years ago
{
for( int i = 0; i < count; i++)
buf[i] = readUChar( success );
9 years ago
}
virtual void close( bool &success)
9 years ago
{
m_pData = NULL;
m_DataLen = m_ReadPos = 0;
}
uchar *m_pData;
int m_DataLen;
int m_ReadPos;
9 years ago
};
vgui::BitmapTGA *vgui_LoadTGA( char const *pFilename )
9 years ago
{
MemoryInputStream stream;
stream.m_pData = gEngfuncs.COM_LoadFile( (char*)pFilename, 5, &stream.m_DataLen );
if( !stream.m_pData )
9 years ago
return NULL;
stream.m_ReadPos = 0;
vgui::BitmapTGA *pRet = new vgui::BitmapTGA( &stream, true );
gEngfuncs.COM_FreeFile( stream.m_pData );
9 years ago
return pRet;
}
vgui::BitmapTGA *vgui_LoadTGANoInvertAlpha( char const *pFilename )
9 years ago
{
MemoryInputStream stream;
stream.m_pData = gEngfuncs.COM_LoadFile( (char*)pFilename, 5, &stream.m_DataLen );
if( !stream.m_pData )
9 years ago
return NULL;
9 years ago
stream.m_ReadPos = 0;
vgui::BitmapTGA *pRet = new vgui::BitmapTGA( &stream, false );
gEngfuncs.COM_FreeFile( stream.m_pData );
9 years ago
return pRet;
}