Clean Up
This commit is contained in:
@@ -7,35 +7,28 @@
|
||||
using VideoEngine::cImage;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
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*/,
|
||||
cImage::cImage( const bool transparent /*= false*/, const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/,
|
||||
const unsigned char translevel /*= 255*/, const bool isSurface /*= false*/ )
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_dir(dir), m_fileName(filename), m_transparent(transparent),
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_transparent(transparent),
|
||||
m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel), m_isSurface(isSurface)
|
||||
{
|
||||
if (m_fileName != (char*)"")
|
||||
LoadImage();
|
||||
if (mp_texture != nullptr)
|
||||
TransparentSetup();
|
||||
}
|
||||
{}
|
||||
|
||||
cImage::cImage( SDL_Surface* surface )
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
: mp_texture(nullptr), mp_surface(nullptr), 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), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
: mp_texture(nullptr), mp_surface(nullptr), 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), mp_surface(nullptr), m_dir(copy.getDir()),
|
||||
m_fileName(copy.getFileName()), m_transparent(copy.getTransparent()), m_transRed(copy.getRedTrans()),
|
||||
: mp_texture(nullptr), mp_surface(nullptr), m_transparent(copy.getTransparent()), m_transRed(copy.getRedTrans()),
|
||||
m_transBlue(copy.getBlueTrans()), m_transGreen(copy.getGreenTrans()), m_transLevel(copy.getLevelTrans())
|
||||
{
|
||||
if (surfaceCopy == true)
|
||||
@@ -78,23 +71,6 @@ const cImage* cImage::NewImage( SDL_Rect& area ) const
|
||||
}
|
||||
|
||||
///Sets
|
||||
void cImage::setDir( const cString& dir )
|
||||
{
|
||||
m_dir = dir;
|
||||
}
|
||||
|
||||
void cImage::setFileName( const cString& filename )
|
||||
{
|
||||
m_fileName = filename;
|
||||
LoadImage();
|
||||
}
|
||||
|
||||
void cImage::setFileNameandDir( const cString& filename, const cString& dir /*= ""*/ )
|
||||
{
|
||||
setDir(dir);
|
||||
setFileName(filename);
|
||||
}
|
||||
|
||||
void cImage::setTransparent( const bool transparent /*= true*/ )
|
||||
{
|
||||
m_transparent = transparent;
|
||||
@@ -117,8 +93,17 @@ void cImage::setLevelTrans( const unsigned char translevel /*= 255*/ )
|
||||
///Gets
|
||||
SDL_Surface* cImage::getSurface() const
|
||||
{
|
||||
return mp_surface;
|
||||
//return cRenderer::Inst().TextureToSurface(mp_texture);
|
||||
SDL_Surface* rtn = nullptr;
|
||||
if (m_isSurface == false)
|
||||
rtn = cRenderer::Inst().TextureToSurface(mp_texture);
|
||||
else
|
||||
rtn = mp_surface;
|
||||
return rtn;
|
||||
}
|
||||
|
||||
SDL_Texture* cImage::getTexture() const
|
||||
{
|
||||
return mp_texture;
|
||||
}
|
||||
|
||||
SDL_Texture* cImage::getImage() const
|
||||
@@ -165,16 +150,6 @@ void cImage::getWH( unsigned long int& w, unsigned long int& h ) const
|
||||
h = height;
|
||||
}
|
||||
|
||||
const cString cImage::getDir() const
|
||||
{
|
||||
return m_dir;
|
||||
}
|
||||
|
||||
const cString cImage::getFileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
const bool cImage::getTransparent() const
|
||||
{
|
||||
return m_transparent;
|
||||
@@ -217,9 +192,12 @@ void cImage::setImage( SDL_Surface* surface )
|
||||
{
|
||||
UnloadImage();
|
||||
|
||||
mp_texture = cRenderer::Inst().SurfaceToTexture(surface);
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
if (m_isSurface == false) {
|
||||
mp_texture = cRenderer::Inst().SurfaceToTexture(surface);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
else
|
||||
mp_surface = surface;
|
||||
}
|
||||
|
||||
void cImage::setImage( SDL_Texture* texture )
|
||||
@@ -232,46 +210,26 @@ void cImage::setImage( SDL_Texture* texture )
|
||||
///Functions
|
||||
void cImage::TransparentSetup()
|
||||
{
|
||||
if( (m_transparent == true) && (mp_texture != nullptr) ) {
|
||||
if (m_transparent == false)
|
||||
return;
|
||||
|
||||
if( mp_texture != nullptr ) {
|
||||
if ((SDL_SetTextureColorMod(mp_texture, m_transRed, m_transGreen, m_transBlue) | SDL_SetTextureAlphaMod(mp_texture, m_transLevel)) < 0)
|
||||
cUtility::Inst().Message("Unable to set Transparent. SDL_SetTextureColorMod:", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
//LoadImage();
|
||||
}
|
||||
|
||||
void cImage::LoadImage()
|
||||
{
|
||||
UnloadImage();
|
||||
|
||||
SDL_Texture* tempText = nullptr;
|
||||
SDL_Surface* tempSurface = nullptr;
|
||||
|
||||
if (m_fileName != "")
|
||||
{
|
||||
cString temp = m_dir + m_fileName;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
if ((m_isSurface == true) && (mp_surface != nullptr)) {
|
||||
if ((SDL_SetSurfaceColorMod(mp_surface, m_transRed, m_transGreen, m_transBlue) | SDL_SetSurfaceAlphaMod(mp_surface, m_transLevel)) < 0)
|
||||
cUtility::Inst().Message("Unable to set Transparent. SDL_SetSurfaceColorMod:", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
}
|
||||
|
||||
void cImage::UnloadImage()
|
||||
{
|
||||
if (mp_texture != nullptr)
|
||||
{
|
||||
SDL_DestroyTexture(mp_texture);
|
||||
mp_texture = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (mp_surface != nullptr)
|
||||
SDL_FreeSurface(mp_surface);
|
||||
|
||||
mp_texture = nullptr;
|
||||
mp_surface = nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user