#include "cGFX.hpp" /*** SDL Header Files ***/ #include /*** Custom Header Files ***/ #include "../VideoEngine/cRenderer.hpp" #include "../UtilityEngine/cUtility.hpp" using FXEngine::cGFX; using VideoEngine::cRenderer; using UtilityEngine::cUtility; /*static*/ cGFX* cGFX::sp_inst = nullptr; /// private: cGFX::cGFX() {} cGFX::~cGFX() {} /// public: /// Functions /*static*/ cGFX& cGFX::Inst() { if (sp_inst == nullptr) sp_inst = new cGFX(); return *sp_inst; } /*static*/ void cGFX::Delete() { delete sp_inst; sp_inst = nullptr; } void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour ) const { if (stringRGBA(cRenderer::Inst().getRenderer(), (Sint16)pos.x, (Sint16)pos.y, text.c_str(), colour.r, colour.g, colour.b, colour.a) < 0) cUtility::Inst().Message("Unable to render text. stringRGBA():", __AT__, cUtility::eTypeSDL::GFX); } void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Surface* surface ) const { //cRenderer::Inst().SetRenderTarget(texture); //StringDefault(text, pos, colour); //cRenderer::Inst().ResetRenderTarget(); } void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Texture* texture ) const { cRenderer::Inst().SetRenderTarget(texture); StringDefault(text, pos, colour); cRenderer::Inst().ResetRenderTarget(); } SDL_Texture* cGFX::StringTexture( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour ) const { SDL_Texture* rtn = cRenderer::Inst().NewTexture(8 * text.length(), 8, false, SDL_TEXTUREACCESS_TARGET); if (rtn != nullptr) cGFX::Inst().StringDefault(text, pos, colour, rtn); else cUtility::Inst().Message("Unable to create NewTexture in StringTexture. cRenderer::NewTexture():", __AT__); return rtn; } void cGFX::Box( const SDL_Rect& rect, const SDL_Colour& colour ) const { if (boxRGBA(cRenderer::Inst().getRenderer(), (Sint16)rect.x, (Sint16)rect.y, (Sint16)rect.w, (Sint16)rect.h, colour.r, colour.g, colour.b, colour.a) < 0) cUtility::Inst().Message("Unable to make Rounded Rectangle. boxRGBA():", __AT__, cUtility::eTypeSDL::GFX); } void cGFX::Box( const SDL_Rect& rect, const SDL_Colour& colour, SDL_Texture* texture ) const { cRenderer::Inst().SetRenderTarget(texture); Box(rect, colour); cRenderer::Inst().ResetRenderTarget(); } void cGFX::RoundedBox( const SDL_Rect& rect, const unsigned long int rad, const SDL_Colour& colour ) const { if (roundedBoxRGBA(cRenderer::Inst().getRenderer(), (Sint16)rect.x, (Sint16)rect.y, (Sint16)rect.w, (Sint16)rect.h, (Sint16)rad, colour.r, colour.g, colour.b, colour.a) < 0) cUtility::Inst().Message("Unable to make Rounded Rectangle. roundedBoxRGBA():", __AT__, cUtility::eTypeSDL::GFX); } void cGFX::RoundedBox( const SDL_Rect& rect, const unsigned long int rad, const SDL_Colour& colour, SDL_Texture* texture ) const { cRenderer::Inst().SetRenderTarget(texture); RoundedBox(rect, rad, colour); cRenderer::Inst().ResetRenderTarget(); } void cGFX::Pixel( const unsigned long int x, const unsigned long int y, const SDL_Colour& colour ) const { if (pixelRGBA(cRenderer::Inst().getRenderer(), (Sint16)x, (Sint16)y, colour.r, colour.g, colour.b, colour.a) < 0) cUtility::Inst().Message("Unable to make pixel. pixelRGBA():", __AT__, cUtility::eTypeSDL::GFX); } void cGFX::Pixel( const unsigned long int x, const unsigned long int y, const SDL_Colour& colour, SDL_Texture* texture ) const { cRenderer::Inst().SetRenderTarget(texture); Pixel(x, y, colour); cRenderer::Inst().ResetRenderTarget(); } void cGFX::Rectangle( const SDL_Rect& rect, const SDL_Colour& colour ) const { if (rectangleRGBA(cRenderer::Inst().getRenderer(), (Sint16)rect.x, (Sint16)rect.y, (Sint16)rect.w, (Sint16)rect.h, colour.r, colour.g, colour.b, colour.a) < 0) cUtility::Inst().Message("Unable to make pixel. rectangleRGBA():", __AT__, cUtility::eTypeSDL::GFX); } void cGFX::Rectangle( const SDL_Rect& rect, const SDL_Colour& colour, SDL_Texture* texture ) const { cRenderer::Inst().SetRenderTarget(texture); Rectangle(rect, colour); cRenderer::Inst().ResetRenderTarget(); } SDL_Surface* cGFX::ZoomIn( SDL_Surface* surface, const double zoomx, const double zoomy, const unsigned long int smooth /*= SMOOTHING_ON*/ ) const { SDL_Surface* rtn = nullptr; rtn = zoomSurface(surface, zoomx, zoomy, smooth); return rtn; } SDL_Texture* cGFX::ZoomIn( SDL_Texture* texture, const double zoomx, const double zoomy, const unsigned long int smooth /*= SMOOTHING_ON*/ ) const { SDL_Surface* surface = cRenderer::Inst().TextureToSurface(texture); SDL_Surface* zoom_sur = zoomSurface(surface, zoomx, zoomy, smooth); SDL_FreeSurface(surface); surface = nullptr; SDL_Texture* rtn = cRenderer::Inst().SurfaceToTexture(zoom_sur); SDL_FreeSurface(zoom_sur); zoom_sur = nullptr; return rtn; }