Clean Up
This commit is contained in:
@@ -98,12 +98,12 @@ void cSound::setLoops( const long int loops /*= -1*/ )
|
||||
}
|
||||
|
||||
///Gets
|
||||
const cString cSound::getDir() const
|
||||
const cString& cSound::getDir() const
|
||||
{
|
||||
return m_dir;
|
||||
}
|
||||
|
||||
const cString cSound::getFileName() const
|
||||
const cString& cSound::getFileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ namespace AudioEngine {
|
||||
|
||||
///Gets
|
||||
/* Gets the directory of the sound */
|
||||
const cString getDir() const;
|
||||
const cString& getDir() const;
|
||||
/* Gets the file name of the sound */
|
||||
const cString getFileName() const;
|
||||
const cString& getFileName() const;
|
||||
/* Gets the Volume of the sound */
|
||||
const unsigned char getVolume() const;
|
||||
/* Gets the Distance of the sound */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace GUIHelpers;
|
||||
|
||||
const RGBA GUIHelpers::StringtoRGBA( const cString& colour )
|
||||
const RGBA& GUIHelpers::StringtoRGBA( const cString& colour )
|
||||
{
|
||||
RGBA rtn = DEFAULT;
|
||||
cString check = colour.upper();
|
||||
|
||||
@@ -39,9 +39,7 @@ namespace GUIHelpers {
|
||||
static const RGBA ROSE = { 255, 0, 128, 255 };
|
||||
|
||||
|
||||
const RGBA StringtoRGBA(const cString& colour);
|
||||
|
||||
|
||||
const RGBA& StringtoRGBA(const cString& colour);
|
||||
}/// END NAMESPACE DEFINITION GUIHelpers
|
||||
#endif/// END IFNDEF _GUIUTILITY_HPP_
|
||||
|
||||
|
||||
@@ -83,9 +83,9 @@ void cXMLoader::GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* p
|
||||
tmp->Resize();
|
||||
}
|
||||
|
||||
const cString cXMLoader::GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const
|
||||
const cString& cXMLoader::GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const
|
||||
{
|
||||
cString rtn = "";
|
||||
cString rtn;
|
||||
const char* str = element.Attribute(attribute.c_str());
|
||||
if ((str == nullptr) && (m_debugXML == true))
|
||||
cUtility::Inst().Message("Error no attribute: " + attribute + " found in tag <" + element.Value() + ">");
|
||||
@@ -211,18 +211,17 @@ GUIEngine::cBoxSizer* cXMLoader::BoxSizerBuild(const tinyxml2::XMLElement& eleme
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const cString cXMLoader::getDir(const tinyxml2::XMLElement& element) const
|
||||
const cString& cXMLoader::getDir(const tinyxml2::XMLElement& element) const
|
||||
{
|
||||
cString rtn = GetAttribute(element, "dir");
|
||||
return rtn;
|
||||
return GetAttribute(element, "dir");
|
||||
}
|
||||
|
||||
const cString cXMLoader::getFileName(const tinyxml2::XMLElement& element) const
|
||||
const cString& cXMLoader::getFileName(const tinyxml2::XMLElement& element) const
|
||||
{
|
||||
cString rtn = GetAttribute(element, "filename");
|
||||
return rtn;
|
||||
return GetAttribute(element, "filename");
|
||||
}
|
||||
|
||||
|
||||
const unsigned long int cXMLoader::getDebug( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
unsigned long int rtn = 99;
|
||||
@@ -316,7 +315,7 @@ const GUIHelpers::eLayout cXMLoader::getLayout( const tinyxml2::XMLElement& elem
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Position cXMLoader::getPosition( const tinyxml2::XMLElement& element ) const
|
||||
const GUIHelpers::Position& cXMLoader::getPosition( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::Position rtn = { -1, -1 };
|
||||
|
||||
@@ -338,7 +337,7 @@ const GUIHelpers::Position cXMLoader::getPosition( const tinyxml2::XMLElement& e
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Size cXMLoader::getSize( const tinyxml2::XMLElement& element ) const
|
||||
const GUIHelpers::Size& cXMLoader::getSize( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::Size rtn = { -1, -1 };
|
||||
|
||||
@@ -360,7 +359,7 @@ const GUIHelpers::Size cXMLoader::getSize( const tinyxml2::XMLElement& element )
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Padding cXMLoader::getPadding( const tinyxml2::XMLElement& element ) const
|
||||
const GUIHelpers::Padding& cXMLoader::getPadding( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::Padding rtn = { -1, -1, -1, -1 };
|
||||
|
||||
@@ -386,12 +385,12 @@ const GUIHelpers::Padding cXMLoader::getPadding( const tinyxml2::XMLElement& ele
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const cString cXMLoader::getText( const tinyxml2::XMLElement& element ) const
|
||||
const cString& cXMLoader::getText( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
return GetAttribute(element, "text");
|
||||
}
|
||||
|
||||
const GUIHelpers::RGBA cXMLoader::getColour( const tinyxml2::XMLElement& element ) const
|
||||
const GUIHelpers::RGBA& cXMLoader::getColour( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::RGBA rtn = GUIHelpers::DEFAULT;
|
||||
cString str = GetAttribute(element, "colour");
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace GUIHelpers {
|
||||
|
||||
private:
|
||||
void GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* parent = nullptr ) const;
|
||||
const cString GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const;
|
||||
const cString& GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const;
|
||||
|
||||
void Include( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
void GUISetup( const tinyxml2::XMLElement& element ) const;
|
||||
@@ -43,20 +43,20 @@ namespace GUIHelpers {
|
||||
GUIEngine::cLabel* LabelBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
GUIEngine::cBoxSizer* BoxSizerBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
|
||||
const cString getDir( const tinyxml2::XMLElement& element ) const;
|
||||
const cString getFileName( const tinyxml2::XMLElement& element ) const;
|
||||
const cString& getDir( const tinyxml2::XMLElement& element ) const;
|
||||
const cString& getFileName( const tinyxml2::XMLElement& element ) const;
|
||||
const unsigned long int getDebug( const tinyxml2::XMLElement& element ) const;
|
||||
const bool cXMLoader::getDebugXML(const tinyxml2::XMLElement& element) const;
|
||||
const signed long int getID( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::eOrientation getOrientation( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::eAlign getAlign( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::eLayout getLayout( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Position getPosition( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Size getSize( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Padding getPadding( const tinyxml2::XMLElement& element ) const;
|
||||
const cString getText( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Position& getPosition( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Size& getSize( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Padding& getPadding( const tinyxml2::XMLElement& element ) const;
|
||||
const cString& getText( const tinyxml2::XMLElement& element ) const;
|
||||
|
||||
const GUIHelpers::RGBA getColour( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::RGBA& getColour( const tinyxml2::XMLElement& element ) const;
|
||||
const signed long int getFontSize( const tinyxml2::XMLElement& element ) const;
|
||||
|
||||
void LoadDefault() const;
|
||||
|
||||
@@ -34,7 +34,7 @@ void cBoxSizer::Create( cWindow* parent, const signed int id, const GUIHelpers::
|
||||
return GUIHelpers::eType::CBOXSIZER;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cBoxSizer::getDebugColour() const
|
||||
/*virtual*/ const GUIHelpers::RGBA& cBoxSizer::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::CYAN;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace GUIEngine {
|
||||
const cString& name = sNAME );
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
virtual const GUIHelpers::RGBA& getDebugColour() const;
|
||||
private:
|
||||
private:
|
||||
};/// END CLASS DEFINITION cBoxSizer
|
||||
|
||||
@@ -102,7 +102,7 @@ const cString& cLabel::getText() const
|
||||
return GUIHelpers::eType::CLABEL;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cLabel::getDebugColour() const
|
||||
/*virtual*/ const GUIHelpers::RGBA& cLabel::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::GREEN;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace GUIEngine {
|
||||
const TextTypeEngine::cFont* getFont() const;
|
||||
const cString& getText() const;
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
virtual const GUIHelpers::RGBA& getDebugColour() const;
|
||||
|
||||
|
||||
//virtual void Resize();
|
||||
|
||||
@@ -43,7 +43,7 @@ cLayout::cLayout(cWindow* parent, const signed int id, const GUIHelpers::eOrient
|
||||
return GUIHelpers::eType::CLAYOUT;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cLayout::getDebugColour() const
|
||||
/*virtual*/ const GUIHelpers::RGBA& cLayout::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::BLUE;
|
||||
}
|
||||
@@ -40,10 +40,9 @@ namespace GUIEngine {
|
||||
///Set
|
||||
|
||||
///Get
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
virtual const GUIHelpers::RGBA& getDebugColour() const;
|
||||
|
||||
private:
|
||||
GUIHelpers::eOrientation m_orientation;
|
||||
|
||||
@@ -34,7 +34,7 @@ cPanel::cPanel( cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, con
|
||||
return GUIHelpers::eType::CPANEL;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cPanel::getDebugColour() const
|
||||
/*virtual*/ const GUIHelpers::RGBA& cPanel::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::RED;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace GUIEngine {
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
virtual const GUIHelpers::RGBA& getDebugColour() const;
|
||||
|
||||
private:
|
||||
};/// END CLASS DEFINITION cPanel
|
||||
|
||||
@@ -41,12 +41,12 @@ void cTextButton::setTextSize(const unsigned long int size)
|
||||
}
|
||||
|
||||
///Gets
|
||||
const cString cTextButton::getText() const
|
||||
const cString& cTextButton::getText() const
|
||||
{
|
||||
return m_label.getText();
|
||||
}
|
||||
|
||||
const GUIHelpers::RGBA cTextButton::getTextColour()
|
||||
const GUIHelpers::RGBA& cTextButton::getTextColour()
|
||||
{
|
||||
return m_label.getFontColour();
|
||||
}
|
||||
@@ -61,6 +61,7 @@ const unsigned long int cTextButton::getTextSize()
|
||||
return GUIHelpers::eType::CTEXTBUTTON;
|
||||
}
|
||||
|
||||
/// Private
|
||||
void CreateLabel()
|
||||
{}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace GUIEngine {
|
||||
void setTextSize( const unsigned long int size );
|
||||
|
||||
///Gets
|
||||
const cString getText() const;
|
||||
const GUIHelpers::RGBA getTextColour();
|
||||
const cString& getText() const;
|
||||
const GUIHelpers::RGBA& getTextColour();
|
||||
const unsigned long int getTextSize();
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
@@ -449,7 +449,7 @@ cWindow* cWindow::getParent()
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cWindow::getDebugColour() const
|
||||
/*virtual*/ const GUIHelpers::RGBA& cWindow::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::WHITE;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace GUIEngine {
|
||||
virtual void RePos();
|
||||
virtual void RebuildPos();
|
||||
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
virtual const GUIHelpers::RGBA& getDebugColour() const;
|
||||
|
||||
/*protected:*/
|
||||
std::vector<cWindow*>& getChildren();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -17,8 +17,7 @@ namespace VideoEngine {
|
||||
class EXPORT_FROM_MYDLL cImage
|
||||
{
|
||||
public:
|
||||
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( 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 );
|
||||
cImage( SDL_Surface* surface );
|
||||
cImage( SDL_Texture* texture );
|
||||
@@ -32,13 +31,6 @@ namespace VideoEngine {
|
||||
const cImage* NewImage( SDL_Rect& area ) const;
|
||||
|
||||
///Sets
|
||||
/* Sets the Directory of the image */
|
||||
void setDir( const cString& dir );
|
||||
/* Sets the File Name of the image */
|
||||
void setFileName( const cString& filename );
|
||||
/* Sets the File Name and the Directory of the image */
|
||||
void setFileNameandDir( const cString& filename, const cString& dir = "" );
|
||||
|
||||
/* Sets Transparent on if set to true */
|
||||
void setTransparent( const bool transparent = true );
|
||||
/* Sets the colour to be made transparent */
|
||||
@@ -50,6 +42,8 @@ namespace VideoEngine {
|
||||
/* Gets a pointer to the SDL_Surface */
|
||||
SDL_Surface* getSurface() const;
|
||||
/* Gets a pointer to the SDL_Texture */
|
||||
SDL_Texture* getTexture() const;
|
||||
/* Gets a pointer to the SDL_Texture */
|
||||
SDL_Texture* getImage() const;
|
||||
/* Gets the width of the image */
|
||||
const unsigned long int getWidth() const;
|
||||
@@ -59,12 +53,7 @@ namespace VideoEngine {
|
||||
const SDL_Rect getWH() const;
|
||||
/* Gets the Width and Height of the image */
|
||||
void getWH( unsigned long int& w, unsigned long int& h ) const;
|
||||
|
||||
/* Gets the Directory of the image */
|
||||
const cString getDir() const;
|
||||
/* Gets the File Name of the image */
|
||||
const cString getFileName() const;
|
||||
|
||||
|
||||
/* Gets return true if transparent on false if off */
|
||||
const bool getTransparent() const;
|
||||
/* Gets return the colour to be made transparent */
|
||||
@@ -89,20 +78,13 @@ namespace VideoEngine {
|
||||
private:
|
||||
///Functions
|
||||
void TransparentSetup();
|
||||
virtual void LoadImage(); //cFont over rides this
|
||||
void UnloadImage();
|
||||
|
||||
private:
|
||||
///Variables
|
||||
SDL_Texture* mp_texture;// = nullptr
|
||||
SDL_Surface* mp_surface;// = nullptr
|
||||
|
||||
cString m_dir;// = ""
|
||||
cString m_fileName;// = ""
|
||||
|
||||
//char m_dir[255];
|
||||
//char m_fileName[255];
|
||||
|
||||
bool m_transparent;// = false
|
||||
|
||||
unsigned char m_transRed;// = 0
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "cImageFile.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cRenderer.hpp"
|
||||
#include "../UtilityEngine/cUtility.hpp"
|
||||
|
||||
using VideoEngine::cImageFile;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
cImageFile::cImageFile(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 bool isSurface /*= false*/)
|
||||
: cImage(transparent, red, blue, green, translevel, isSurface), m_dir(dir), m_fileName(filename)
|
||||
{
|
||||
if (m_fileName != (char*)"")
|
||||
LoadImage();
|
||||
}
|
||||
|
||||
cImageFile::cImageFile(const cImageFile& copy, const bool surfaceCopy /*= true*/)
|
||||
: cImage(copy)
|
||||
{}
|
||||
|
||||
cImageFile::~cImageFile()
|
||||
{}
|
||||
|
||||
///Sets
|
||||
void cImageFile::setDir(const cString& dir)
|
||||
{
|
||||
m_dir = dir;
|
||||
}
|
||||
|
||||
void cImageFile::setFileName(const cString& filename)
|
||||
{
|
||||
m_fileName = filename;
|
||||
LoadImage();
|
||||
}
|
||||
|
||||
void cImageFile::setFileNameandDir(const cString& filename, const cString& dir /*= ""*/)
|
||||
{
|
||||
setDir(dir);
|
||||
setFileName(filename);
|
||||
}
|
||||
|
||||
const cString& cImageFile::getDir() const
|
||||
{
|
||||
return m_dir;
|
||||
}
|
||||
|
||||
const cString& cImageFile::getFileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
///private
|
||||
///Functions
|
||||
void cImageFile::LoadImage()
|
||||
{
|
||||
SDL_Texture* tempText = nullptr;
|
||||
SDL_Surface* tempSurface = nullptr;
|
||||
|
||||
if (m_fileName != "")
|
||||
{
|
||||
cString temp = m_dir + m_fileName;
|
||||
|
||||
if (this->getIsSurface() == 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
|
||||
this->setImage(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
|
||||
this->setImage(tempSurface);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef _CIMAGEFILE_HPP_
|
||||
#define _CIMAGEFILE_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cImage.hpp"
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace VideoEngine {
|
||||
class EXPORT_FROM_MYDLL cImageFile : public cImage
|
||||
{
|
||||
public:
|
||||
cImageFile(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 bool isSurface = false);
|
||||
/* Copy constructor */
|
||||
cImageFile(const cImageFile& copy, const bool surfaceCopy = true);
|
||||
~cImageFile();
|
||||
|
||||
///Sets
|
||||
/* Sets the Directory of the image */
|
||||
void setDir(const cString& dir);
|
||||
/* Sets the File Name of the image */
|
||||
void setFileName(const cString& filename);
|
||||
/* Sets the File Name and the Directory of the image */
|
||||
void setFileNameandDir(const cString& filename, const cString& dir = "");
|
||||
|
||||
///Gets
|
||||
/* Gets the Directory of the image */
|
||||
const cString& getDir() const;
|
||||
/* Gets the File Name of the image */
|
||||
const cString& getFileName() const;
|
||||
|
||||
private:
|
||||
///Functions
|
||||
void LoadImage();
|
||||
|
||||
private:
|
||||
///Variables
|
||||
cString m_dir;// = ""
|
||||
cString m_fileName;// = ""
|
||||
};/// END CLASS DEFINITION cImageFile
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CIMAGEFILE_HPP_
|
||||
@@ -12,6 +12,7 @@ using UtilityEngine::cUtility;
|
||||
|
||||
//private:
|
||||
cRenderer::cRenderer()
|
||||
: mp_renderer(nullptr), mp_rendererSoftware(nullptr)
|
||||
{
|
||||
Setup();
|
||||
}
|
||||
@@ -42,7 +43,11 @@ const bool cRenderer::Setup()
|
||||
if (cVideo::Inst().IsInit() == false)
|
||||
cUtility::Inst().Message("Unable to setup until SDL_Video is initialized.");
|
||||
else {
|
||||
CleanUp();
|
||||
mp_renderer = cVideo::Inst().CreateRender();
|
||||
SDL_Surface* surface = SDL_GetWindowSurface(cVideo::Inst().getWindow());
|
||||
mp_rendererSoftware = SDL_CreateSoftwareRenderer(surface);
|
||||
//mp_rendererCopy = cVideo::Inst().CreateRender();
|
||||
if (mp_renderer != nullptr)
|
||||
rtn = true;
|
||||
}
|
||||
@@ -51,8 +56,13 @@ const bool cRenderer::Setup()
|
||||
|
||||
void cRenderer::CleanUp()
|
||||
{
|
||||
SDL_DestroyRenderer(mp_renderer);
|
||||
if (mp_renderer != nullptr)
|
||||
SDL_DestroyRenderer(mp_renderer);
|
||||
if (mp_rendererSoftware != nullptr)
|
||||
SDL_DestroyRenderer(mp_rendererSoftware);
|
||||
|
||||
mp_renderer = nullptr;
|
||||
mp_rendererSoftware = nullptr;
|
||||
}
|
||||
|
||||
void cRenderer::Render( SDL_Texture* texture, SDL_Rect* srcrect, SDL_Rect* dstrect )
|
||||
@@ -111,24 +121,12 @@ 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());
|
||||
SDL_Surface* saveSurface = NewSurface();
|
||||
|
||||
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)
|
||||
cUtility::Inst().Message("Failed to read pixel data from SDL_Renderer object.\n", __AT__, cUtility::eTypeSDL::SDL);
|
||||
else
|
||||
SaveSurface(saveSurface, filename, dir);
|
||||
SDL_FreeSurface(infoSurface);
|
||||
infoSurface = nullptr;
|
||||
}
|
||||
SDL_FreeSurface(saveSurface);
|
||||
saveSurface = nullptr;
|
||||
SDL_Surface *sshot = NewSurface();
|
||||
SDL_RenderReadPixels(getRenderer(), nullptr, SDL_PIXELFORMAT_RGBA32, sshot->pixels, sshot->pitch);
|
||||
SaveSurface(sshot, filename, dir);
|
||||
SDL_FreeSurface(sshot);
|
||||
}
|
||||
|
||||
|
||||
void cRenderer::SaveSurface( SDL_Surface* surface, const cString& fileName, const cString& dir /*= ""*/ )
|
||||
{
|
||||
cString temp = dir + fileName;
|
||||
@@ -169,57 +167,27 @@ SDL_Surface* cRenderer::TextureToSurface( SDL_Texture* texture )
|
||||
|
||||
rtn = NewSurface(w, h);
|
||||
|
||||
void* srcPixels = nullptr;
|
||||
int srcPitch = 0;
|
||||
SDL_Rect rec = { 0, 0, w, h };
|
||||
|
||||
SDL_Texture* tmp_texture = NewTexture(w, h, true); // Create a new texture with Software Renderer
|
||||
CopyTexture(texture, tmp_texture, true); // Copy old texture to the Software Renderer Texture renderer
|
||||
|
||||
Render(tmp_texture, nullptr, mp_rendererSoftware, &rec); // Render to the mp_rendererSoftware
|
||||
|
||||
//Lock texture for manipulation
|
||||
if (SDL_LockTexture( texture, nullptr, &srcPixels, &srcPitch ) < 0)
|
||||
cUtility::Inst().Message("Unable to lock texture. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
if (SDL_LockSurface(rtn))
|
||||
cUtility::Inst().Message("Unable to lock surface rtn. SDL_LockSurface():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
//Copy loaded/formatted surface pixels
|
||||
memcpy( rtn->pixels, srcPixels, srcPitch * h );
|
||||
|
||||
//Unlock texture to update
|
||||
SDL_UnlockSurface(rtn);
|
||||
SDL_UnlockTexture( texture );
|
||||
|
||||
srcPixels = nullptr;
|
||||
|
||||
SDL_RenderReadPixels(mp_rendererSoftware, nullptr, SDL_PIXELFORMAT_RGBA32, rtn->pixels, rtn->pitch);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cRenderer::CopyTexture( SDL_Texture* src, SDL_Texture* dst )
|
||||
void cRenderer::CopyTexture( SDL_Texture* src, SDL_Texture* dst, bool software /*= false*/ )
|
||||
{
|
||||
void* srcPixels = nullptr;
|
||||
int srcPitch = 0;
|
||||
|
||||
void* dstPixels = nullptr;
|
||||
int dstPitch = 0;
|
||||
|
||||
int height = 0;
|
||||
|
||||
if (SDL_QueryTexture( src, nullptr, nullptr, nullptr, &height ) < 0)
|
||||
cUtility::Inst().Message("Unable to query texture. SDL_QueryTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
//Lock texture for manipulation
|
||||
if (SDL_LockTexture( src, nullptr, &srcPixels, &srcPitch ) < 0)
|
||||
cUtility::Inst().Message("Unable to lock texture src. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
if (SDL_LockTexture( dst, nullptr, &dstPixels, &dstPitch ) < 0)
|
||||
cUtility::Inst().Message("Unable to lock texture dst. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
//Copy loaded/formatted surface pixels
|
||||
memcpy( dstPixels, srcPixels, srcPitch * height );
|
||||
|
||||
//Unlock texture to update
|
||||
SDL_UnlockTexture( dst );
|
||||
SDL_UnlockTexture( src );
|
||||
srcPixels = nullptr;
|
||||
dstPixels = nullptr;
|
||||
|
||||
SDL_Renderer* render = mp_renderer;
|
||||
if (software == true)
|
||||
render = mp_rendererSoftware;
|
||||
if (SDL_SetRenderTarget(render, dst) < 0)
|
||||
cUtility::Inst().Message("Unable to set render target to dst. SDL_SetRenderTarget():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
Render(src, nullptr, render, nullptr);
|
||||
ResetRenderTarget();
|
||||
}
|
||||
|
||||
SDL_Surface* cRenderer::CopySurface( SDL_Surface* src )
|
||||
@@ -242,19 +210,72 @@ SDL_Surface* cRenderer::NewSurface( long int width /*= -1*/, long int height /*=
|
||||
return rtn;
|
||||
}
|
||||
|
||||
SDL_Texture* cRenderer::NewTexture( long int width, long int height, const unsigned long int access /*= SDL_TEXTUREACCESS_TARGET*/ ) const
|
||||
SDL_Texture* cRenderer::NewTexture( long int width, long int height, const bool copyRenderer /*= false*/, const unsigned long int access /*= SDL_TEXTUREACCESS_TARGET*/ ) const
|
||||
{
|
||||
if (width < 0)
|
||||
width = cVideo::Inst().getWidth();
|
||||
if (height < 0)
|
||||
height = cVideo::Inst().getHeight();
|
||||
|
||||
SDL_Texture* rtn = SDL_CreateTexture(mp_renderer, SDL_PIXELFORMAT_ABGR8888, access, width, height);
|
||||
SDL_Renderer* renderer = nullptr;
|
||||
if (copyRenderer == false)
|
||||
renderer = mp_renderer;
|
||||
else
|
||||
renderer = mp_rendererSoftware;
|
||||
|
||||
SDL_Texture* rtn = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, access, width, height);
|
||||
if (rtn == nullptr)
|
||||
cUtility::Inst().Message("Unable to create texture. SDL_CreateTexture:", __AT__, cUtility::eTypeSDL::SDL);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const bool cRenderer::AreEqual(SDL_Surface& one, SDL_Surface& two)
|
||||
{
|
||||
bool rtn = false;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
if (SDL_MUSTLOCK(&one) > 0)
|
||||
SDL_LockSurface(&one);
|
||||
|
||||
if (SDL_MUSTLOCK(&two) > 0)
|
||||
SDL_LockSurface(&two);
|
||||
|
||||
if ((one.pitch == two.pitch) && (one.h == two.h)) {
|
||||
unsigned char *one_pixels = (unsigned char *)one.pixels;
|
||||
unsigned char *two_pixels = (unsigned char *)two.pixels;
|
||||
|
||||
rtn = true; // we are equal so far....
|
||||
|
||||
for (x = 0; x < one.pitch; x++) {
|
||||
for (y = 0; y < one.h; y++) {
|
||||
if (one_pixels[y + x] != two_pixels[y + x]) {
|
||||
rtn = false;
|
||||
x = one.pitch + two.pitch + 1; // break out of the top for loop
|
||||
y = one.h + two.h + 1;
|
||||
break; // we found a pixel that is not equal no need to continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_MUSTLOCK(&one) > 0)
|
||||
SDL_UnlockSurface(&one);
|
||||
|
||||
if (SDL_MUSTLOCK(&two) > 0)
|
||||
SDL_UnlockSurface(&two);
|
||||
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cRenderer::SetRenderTarget(SDL_Renderer* renderer, SDL_Texture* target /*= nullptr*/)
|
||||
{
|
||||
if (SDL_SetRenderTarget(renderer, target) < 0)
|
||||
cUtility::Inst().Message("Unable to set render target to dst. SDL_SetRenderTarget():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
void cRenderer::SetRenderTarget( SDL_Texture* target /*= nullptr*/ )
|
||||
{
|
||||
if (SDL_SetRenderTarget(mp_renderer, target) < 0)
|
||||
@@ -271,3 +292,8 @@ SDL_Renderer* cRenderer::getRenderer()
|
||||
{
|
||||
return mp_renderer;
|
||||
}
|
||||
|
||||
SDL_Renderer* cRenderer::getRendererCopy()
|
||||
{
|
||||
return mp_rendererSoftware;
|
||||
}
|
||||
@@ -47,23 +47,28 @@ namespace VideoEngine {
|
||||
SDL_Texture* SurfaceToTexture( SDL_Surface* surface );
|
||||
SDL_Surface* TextureToSurface( SDL_Texture* texture );
|
||||
|
||||
void CopyTexture( SDL_Texture* src, SDL_Texture* dst );
|
||||
void CopyTexture( SDL_Texture* src, SDL_Texture* dst, bool software = false);
|
||||
|
||||
SDL_Surface* CopySurface( SDL_Surface* src );
|
||||
|
||||
SDL_Surface* NewSurface( long int width = -1, long int height = -1 ) const;
|
||||
SDL_Texture* NewTexture( long int width = -1, long int height = -1, const unsigned long int access = SDL_TEXTUREACCESS_TARGET ) const;
|
||||
SDL_Texture* NewTexture( long int width = -1, long int height = -1, const bool copyRenderer = false, const unsigned long int access = SDL_TEXTUREACCESS_TARGET ) const;
|
||||
|
||||
void SetRenderTarget( SDL_Texture* target = nullptr );
|
||||
const bool AreEqual(SDL_Surface& one, SDL_Surface& two);
|
||||
|
||||
void SetRenderTarget(SDL_Renderer* renderer, SDL_Texture* target = nullptr);
|
||||
void SetRenderTarget(SDL_Texture* target = nullptr);
|
||||
void ResetRenderTarget();
|
||||
|
||||
///Sets
|
||||
|
||||
///Gets
|
||||
SDL_Renderer* getRenderer();
|
||||
SDL_Renderer* getRenderer();
|
||||
SDL_Renderer* getRendererCopy();
|
||||
|
||||
private:
|
||||
SDL_Renderer* mp_renderer;
|
||||
SDL_Renderer* mp_rendererSoftware;
|
||||
|
||||
static cRenderer* sp_inst;// = nullptr
|
||||
};/// END CLASS DEFINITION cRenderer
|
||||
|
||||
@@ -67,7 +67,7 @@ const bool cVideo::Setup()
|
||||
CleanUp();
|
||||
VideoSettings();
|
||||
|
||||
mp_window = SDL_CreateWindow("Hello World!", 100, 100, m_width, m_height, SDL_WINDOW_SHOWN);
|
||||
mp_window = SDL_CreateWindow("Hello World!", m_xPos, m_yPos, m_width, m_height, SDL_WINDOW_SHOWN);
|
||||
if (mp_window == nullptr)
|
||||
cUtility::Inst().Message("Unable to set Window. SDL_CreateWindow():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user