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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ namespace VideoEngine {
|
||||
class EXPORT_FROM_MYDLL cImage
|
||||
{
|
||||
public:
|
||||
cImage( const cString& dir = "", const cString& filename = "", const bool transparent = false,
|
||||
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);
|
||||
const unsigned char translevel = 255, const bool isSurface = false );
|
||||
cImage( SDL_Surface* surface );
|
||||
cImage( SDL_Texture* texture );
|
||||
/* Copy constructor */
|
||||
@@ -78,6 +78,8 @@ namespace VideoEngine {
|
||||
/* Gets the transparent level 255 = clear, 0 = solid */
|
||||
const unsigned char getLevelTrans() const;
|
||||
|
||||
const bool getIsSurface() const;
|
||||
|
||||
protected:
|
||||
/* Protected so only derived class can access. *.
|
||||
/* Sets the image to surface */
|
||||
@@ -93,6 +95,7 @@ namespace VideoEngine {
|
||||
private:
|
||||
///Variables
|
||||
SDL_Texture* mp_texture;// = nullptr
|
||||
SDL_Surface* mp_surface;// = nullptr
|
||||
|
||||
cString m_dir;// = ""
|
||||
cString m_fileName;// = ""
|
||||
@@ -106,7 +109,9 @@ namespace VideoEngine {
|
||||
unsigned char m_transBlue;// = 0
|
||||
unsigned char m_transGreen;// = 255
|
||||
|
||||
unsigned char m_transLevel;// = 255
|
||||
unsigned char m_transLevel;// = 255
|
||||
|
||||
bool m_isSurface;
|
||||
};/// END CLASS DEFINITION cImage
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CIMAGE_HPP_
|
||||
|
||||
@@ -112,16 +112,9 @@ void cRenderer::RenderDrawRect( const SDL_Rect& rect, SDL_Texture* dst /*= nullp
|
||||
void cRenderer::ScreenShot( const cString& filename, const cString& dir /*= ""*/ )
|
||||
{
|
||||
SDL_Surface* infoSurface = SDL_GetWindowSurface(VideoEngine::cVideo::Inst().getWindow());
|
||||
if (infoSurface == nullptr)
|
||||
cUtility::Inst().Message("Failed to create info surface from window.\n", __AT__, cUtility::eTypeSDL::SDL);
|
||||
else {
|
||||
SaveSurface(infoSurface, filename, dir);
|
||||
SDL_FreeSurface(infoSurface);
|
||||
infoSurface = NULL;
|
||||
}
|
||||
/*SDL_Surface* saveSurface = NewSurface();
|
||||
SDL_Surface* saveSurface = NewSurface();
|
||||
|
||||
if (infoSurface == NULL) {
|
||||
if (infoSurface == nullptr) {
|
||||
cUtility::Inst().Message("Failed to create info surface from window.\n", __AT__, cUtility::eTypeSDL::SDL);
|
||||
} else {
|
||||
if (SDL_RenderReadPixels(mp_renderer, &infoSurface->clip_rect, infoSurface->format->format, saveSurface->pixels, infoSurface->w * infoSurface->format->BytesPerPixel) != 0)
|
||||
@@ -129,10 +122,10 @@ void cRenderer::ScreenShot( const cString& filename, const cString& dir /*= ""*/
|
||||
else
|
||||
SaveSurface(saveSurface, filename, dir);
|
||||
SDL_FreeSurface(infoSurface);
|
||||
infoSurface = NULL;
|
||||
infoSurface = nullptr;
|
||||
}
|
||||
SDL_FreeSurface(saveSurface);
|
||||
saveSurface = NULL;*/
|
||||
saveSurface = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -157,8 +150,7 @@ void cRenderer::SaveTexture( SDL_Texture* texture, const cString& fileName, cons
|
||||
|
||||
SDL_Texture* cRenderer::SurfaceToTexture( SDL_Surface* surface )
|
||||
{
|
||||
SDL_Texture* rtn = nullptr;
|
||||
rtn = SDL_CreateTextureFromSurface( mp_renderer, surface );
|
||||
SDL_Texture* rtn = SDL_CreateTextureFromSurface( mp_renderer, surface );
|
||||
if ( rtn == nullptr)
|
||||
cUtility::Inst().Message("Unable to create Texture. SDL_CreateTextureFromSurface():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
@@ -242,7 +234,7 @@ SDL_Surface* cRenderer::NewSurface( long int width /*= -1*/, long int height /*=
|
||||
if (height < 0)
|
||||
height = cVideo::Inst().getHeight();
|
||||
|
||||
SDL_Surface* rtn = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), width, height, cVideo::Inst().getColour(), cVideo::Inst().getRmask(), cVideo::Inst().getGmask(), cVideo::Inst().getBmask(), cVideo::Inst().getAmask());
|
||||
SDL_Surface* rtn = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), width, height, cVideo::Inst().getColourDepth(), cVideo::Inst().getRmask(), cVideo::Inst().getGmask(), cVideo::Inst().getBmask(), cVideo::Inst().getAmask());
|
||||
|
||||
if (rtn == nullptr)
|
||||
cUtility::Inst().Message("Unable to create surface. SDL_CreateRGBSurface():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
@@ -76,15 +76,20 @@ cSprite::~cSprite()
|
||||
///Functions
|
||||
void cSprite::Draw()
|
||||
{
|
||||
SDL_Texture* texture = (*mpp_image)->getImage();
|
||||
//SDL_Texture* texture = (*mpp_image)->getImage();
|
||||
|
||||
if (mpp_camera != nullptr && *mpp_camera != nullptr) {
|
||||
CameraDraw();
|
||||
//surface = (*mpp_camera)->getCameraView();
|
||||
}
|
||||
|
||||
if (mpp_image != nullptr && *mpp_image != nullptr)
|
||||
cRenderer::Inst().Render( texture, &m_imageArea, &m_position);
|
||||
if (mpp_image != nullptr && *mpp_image != nullptr) {
|
||||
if ((*mpp_image)->getIsSurface() == false)
|
||||
cRenderer::Inst().Render((*mpp_image)->getImage(), &m_imageArea, &m_position);
|
||||
else
|
||||
cRenderer::Inst().Render((*mpp_image)->getSurface(), &m_imageArea, &m_position);
|
||||
}
|
||||
// cRenderer::Inst().Render((*mpp_image)->getImage(), &m_imageArea, &m_position);
|
||||
}
|
||||
|
||||
void cSprite::CameraDraw()
|
||||
@@ -103,8 +108,12 @@ void cSprite::CameraDraw()
|
||||
|
||||
void cSprite::DefaltDraw()
|
||||
{
|
||||
if (mpp_image != nullptr && *mpp_image != nullptr)
|
||||
cRenderer::Inst().Render( (*mpp_image)->getImage(), nullptr, nullptr);
|
||||
if (mpp_image != nullptr && *mpp_image != nullptr) {
|
||||
if ((*mpp_image)->getIsSurface() == false)
|
||||
cRenderer::Inst().Render((*mpp_image)->getImage(), nullptr, nullptr);
|
||||
else
|
||||
cRenderer::Inst().Render((*mpp_image)->getSurface(), nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void cSprite::AddPosX( const signed long int x )
|
||||
|
||||
@@ -197,11 +197,21 @@ const unsigned long int cVideo::getHeight() const
|
||||
return m_height;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getColour() const
|
||||
const unsigned long int cVideo::getColourDepth() const
|
||||
{
|
||||
return m_colour;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getPitch() const
|
||||
{
|
||||
unsigned long int rtn = 0;
|
||||
if (cVideo::getColourDepth() == 32)
|
||||
rtn = 4; // 4 bytes per pixel
|
||||
else
|
||||
rtn = 3;
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const cString cVideo::getCaption() const
|
||||
{
|
||||
cString rtn = "";
|
||||
|
||||
@@ -68,7 +68,9 @@ namespace VideoEngine {
|
||||
/* Gets the videos height resolution */
|
||||
const unsigned long int getHeight() const;
|
||||
/* Gets the videos colour depth in bits */
|
||||
const unsigned long int getColour() const;
|
||||
const unsigned long int getColourDepth() const;
|
||||
/* Gets the videos pitch */
|
||||
const unsigned long int getPitch() const;
|
||||
/* Gets the caption displayed on the window */
|
||||
const cString getCaption() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user