cImage Surface
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
using VideoEngine::cImage;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
cImage::cImage( const cString& dir /*= ""*/, const cString& filename /*= ""*/, const bool transparent /*= false*/,
|
||||
cImage::cImage( const cString& filename, const cString& dir /*= ""*/, const bool transparent /*= false*/,
|
||||
const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/,
|
||||
const unsigned char translevel /*= 255*/)
|
||||
: mp_texture(nullptr), m_dir(dir), m_fileName(filename), m_transparent(transparent),
|
||||
m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel)
|
||||
const unsigned char translevel /*= 255*/, const bool isSurface /*= false*/ )
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_dir(dir), m_fileName(filename), m_transparent(transparent),
|
||||
m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel), m_isSurface(isSurface)
|
||||
{
|
||||
if (m_fileName != (char*)"")
|
||||
LoadImage();
|
||||
@@ -20,21 +20,21 @@ m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel
|
||||
}
|
||||
|
||||
cImage::cImage( SDL_Surface* surface )
|
||||
: mp_texture(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255)
|
||||
{
|
||||
setImage(surface);
|
||||
}
|
||||
|
||||
cImage::cImage( SDL_Texture* texture )
|
||||
: mp_texture(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255)
|
||||
{
|
||||
setImage(texture);
|
||||
}
|
||||
|
||||
cImage::cImage( const cImage& copy, const bool surfaceCopy /*= true*/)
|
||||
: mp_texture(nullptr), m_dir(copy.getDir()),
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_dir(copy.getDir()),
|
||||
m_fileName(copy.getFileName()), m_transparent(copy.getTransparent()), m_transRed(copy.getRedTrans()),
|
||||
m_transBlue(copy.getBlueTrans()), m_transGreen(copy.getGreenTrans()), m_transLevel(copy.getLevelTrans())
|
||||
{
|
||||
@@ -50,7 +50,10 @@ cImage::~cImage()
|
||||
///Functions
|
||||
void cImage::SaveImage( const cString& fileName, const cString& dir /*= ""*/ )
|
||||
{
|
||||
cRenderer::Inst().SaveTexture( mp_texture, fileName, dir );
|
||||
if (m_isSurface == false)
|
||||
cRenderer::Inst().SaveTexture(mp_texture, fileName, dir);
|
||||
else
|
||||
cRenderer::Inst().SaveSurface(mp_surface, fileName, dir);
|
||||
}
|
||||
|
||||
const cImage* cImage::NewImage( SDL_Rect& area ) const
|
||||
@@ -114,7 +117,8 @@ void cImage::setLevelTrans( const unsigned char translevel /*= 255*/ )
|
||||
///Gets
|
||||
SDL_Surface* cImage::getSurface() const
|
||||
{
|
||||
return cRenderer::Inst().TextureToSurface(mp_texture);
|
||||
return mp_surface;
|
||||
//return cRenderer::Inst().TextureToSurface(mp_texture);
|
||||
}
|
||||
|
||||
SDL_Texture* cImage::getImage() const
|
||||
@@ -203,6 +207,11 @@ const unsigned char cImage::getLevelTrans() const
|
||||
return m_transLevel;
|
||||
}
|
||||
|
||||
const bool cImage::getIsSurface() const
|
||||
{
|
||||
return m_isSurface;
|
||||
}
|
||||
|
||||
//protected:
|
||||
void cImage::setImage( SDL_Surface* surface )
|
||||
{
|
||||
@@ -235,13 +244,24 @@ void cImage::LoadImage()
|
||||
UnloadImage();
|
||||
|
||||
SDL_Texture* tempText = nullptr;
|
||||
SDL_Surface* tempSurface = nullptr;
|
||||
|
||||
if (m_fileName != "")
|
||||
{
|
||||
cString temp = m_dir + m_fileName;
|
||||
|
||||
if ((tempText = IMG_LoadTexture( cRenderer::Inst().getRenderer(), temp.c_str() )) == nullptr)
|
||||
cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_LoadTexture():", __AT__, cUtility::eTypeSDL::IMAGE);
|
||||
if (m_isSurface == false) {
|
||||
if ((tempText = IMG_LoadTexture(cRenderer::Inst().getRenderer(), temp.c_str())) == nullptr)
|
||||
cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_LoadTexture():", __AT__, cUtility::eTypeSDL::IMAGE);
|
||||
else
|
||||
mp_texture = tempText;
|
||||
}
|
||||
else {
|
||||
if ((tempSurface = IMG_Load(temp.c_str())) == nullptr)
|
||||
cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_Load():", __AT__, cUtility::eTypeSDL::IMAGE);
|
||||
else
|
||||
mp_surface = tempSurface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user