ns/main/source/ui/MemoryInputStream.cpp
tankefugl 577727d9a5 Mantis 994:
o Fixed bug where the voice comm icon would not be displayed while using a mic

The new MemoryInputStream class either contains a bug or doesn't match what the vgui::BitmapTGA class expects. I've inserted the old code to get this working till Karl can take a look at it, as it's a bit painstaking to sort it out when I don't even know what method(s) it fails in.

I also fixed a bug in the constructor for the new MemoryInputStream where the length parameter would not be applied to the length member.

git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@232 67975925-1194-0748-b3d5-c16f83f1a3a1
2005-07-04 21:22:39 +00:00

106 lines
No EOL
2.3 KiB
C++

#include "MemoryInputStream.h"
#include <memory.h>
#include <stdlib.h>
MemoryInputStream::MemoryInputStream(void) : m_pData(NULL), m_DataLen(0), m_ReadPos(0) {}
MemoryInputStream::MemoryInputStream(uchar* pData, int nLength) : m_pData(pData), m_DataLen(nLength), m_ReadPos(0) {}
MemoryInputStream::~MemoryInputStream(void) {}
void MemoryInputStream::setSource(uchar* pData, int nLength)
{
m_pData = pData;
m_DataLen = nLength;
m_ReadPos = 0;
}
void MemoryInputStream::seekStart(bool& success)
{
m_ReadPos = 0;
success = (m_pData != NULL);
}
void MemoryInputStream::seekRelative(int count, bool& success)
{
int newPos = m_ReadPos + count;
if( m_pData != NULL && newPos >= 0 && newPos <= m_DataLen )
{
m_ReadPos = newPos;
success = true;
}
else
{
success = false;
}
}
void MemoryInputStream::seekEnd(bool& success)
{
m_ReadPos = m_DataLen;
success = (m_pData != NULL);
}
int MemoryInputStream::getAvailable(bool& success)
{
success = (m_pData != NULL && m_ReadPos != m_DataLen);
return m_DataLen - m_ReadPos;
}
uchar MemoryInputStream::readUChar(bool& success)
{
if( m_pData != NULL && m_ReadPos != m_DataLen )
{
success = true;
uchar val = m_pData[m_ReadPos];
++m_ReadPos;
return val;
}
success = false;
return 0;
}
void MemoryInputStream::readUChar(uchar* buf, int count, bool& success)
{
if( m_pData != NULL )
{
int diff = m_DataLen - m_ReadPos;
int numToRead = count < diff ? count : diff;
memcpy(buf,m_pData,numToRead);
success = (numToRead == count);
return;
}
success = false;
}
void MemoryInputStream::close(bool& success)
{
m_pData = NULL;
m_DataLen = 0;
m_ReadPos = 0;
success = true;
}
/*
#include "vgui_inputstream.h"
class MemoryInputStream : public vgui::InputStream
{
public:
MemoryInputStream();
MemoryInputStream(uchar* pData, int nLength);
virtual MemoryInputStream(void);
virtual void setSource(uchar* pData, int nLength);
virtual void seekStart(bool& success);
virtual void seekRelative(int count, bool& success);
virtual void seekEnd(bool& success);
virtual int getAvailable(bool& success);
virtual uchar readUChar(bool& success);
virtual void readUChar(uchar* buf, int count, bool& success);
virtual void close(bool& success);
private:
uchar* m_pData;
int m_DataLen;
int m_ReadPos;
};
*/