Add project files.

This commit is contained in:
2018-06-25 21:48:45 -04:00
parent b04a25689b
commit 3c1b7d28e8
425 changed files with 35333 additions and 0 deletions
@@ -0,0 +1,25 @@
#include "cFontHolder.hpp"
using TextTypeHelpers::cFontHolder;
cFontHolder::cFontHolder( TTF_Font* font, const unsigned long int size )
: mp_font(font), m_size(size)
{}
cFontHolder::~cFontHolder()
{
if (mp_font != nullptr) {
TTF_CloseFont(mp_font);
mp_font = nullptr;
}
}
TTF_Font* cFontHolder::getFont() const
{
return mp_font;
}
const unsigned long int cFontHolder::getSize() const
{
return m_size;
}
@@ -0,0 +1,28 @@
#ifndef _CFONTHOLDER_HPP_
#define _CFONTHOLDER_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
#include <SDL_ttf.h>
/*** DLL Header File ***/
#include "dllExport.h"
namespace TextTypeHelpers {
class EXPORT_FROM_MYDLL cFontHolder
{
public:
cFontHolder( TTF_Font* font, const unsigned long int size );
~cFontHolder();
///Sets
///Gets
TTF_Font* getFont() const;
const unsigned long int getSize() const;
private:
TTF_Font* mp_font;// = nullptr
unsigned long int m_size;// = 16
};/// END CLASS DEFINITION cFontHolder
}/// END NAMESPACE DEFINITION TextTypeHelpers
#endif/// END IFNDEF _CFONTHOLDER_HPP_
@@ -0,0 +1,121 @@
#include "cFont.hpp"
/*** Custom Header Files ***/
#include "../UtilityEngine/cUtility.hpp"
using TextTypeEngine::cFont;
using TextTypeHelpers::cFontHolder;
using UtilityEngine::cUtility;
cFont::cFont( const cString& filename /*= ""*/, const cString& dir /*= ""*/, const unsigned long int size /*= 16*/ )
: m_dir(dir), m_fileName(filename), mpp_default(nullptr)
{
setSize(size);
}
cFont::cFont( const cFont& copy )
: m_dir(copy.getDir()), m_fileName(copy.getFileName()), mpp_default(nullptr)
{
setSize(copy.getSize());
}
cFont::~cFont()
{
UnloadFont();
}
///Functions
///Sets
void cFont::setDir( const cString& dir )
{
m_dir = dir;
}
void cFont::setFileName( const cString& filename )
{
m_fileName = filename;
}
void cFont::setFileNameandDir( const cString& filename, const cString& dir /*= ""*/ )
{
setDir(dir);
setFileName(filename);
}
void cFont::setSize( const unsigned long int size /*= 16*/ )
{
while ((mpp_default == nullptr) || ((*mpp_default) == nullptr)) {
getFont(size);
mpp_default = (cFontHolder**)getFontHolder(size);
}
}
///Gets
const cString& cFont::getDir() const
{
return m_dir;
}
const cString& cFont::getFileName() const
{
return m_fileName;
}
const unsigned long int cFont::getSize() const
{
return (*mpp_default)->getSize();
}
TTF_Font* cFont::getFont()
{
return (*mpp_default)->getFont();
}
TTF_Font* cFont::getFont( const unsigned long int size )
{
TTF_Font* rtn = nullptr;
rtn = getFontHolder(size)->getFont();
//We Can't find the Font in that size so we make a new one
if (rtn == nullptr) {
rtn = LoadFont(size);
}
return rtn;
}
//private:
TTF_Font* cFont::LoadFont( const unsigned long int size )
{
TTF_Font* rtn = nullptr;
if (m_fileName != "") {
cString temp = m_dir + m_fileName;
if ((rtn = TTF_OpenFont(temp.c_str(), size)) == nullptr)
cUtility::Inst().Message("Unable to load necessary TTF file. " + temp + " TTF_OpenFont():", "", cUtility::eTypeSDL::TTF);
else {
cFontHolder* holder = new cFontHolder(rtn, size);
m_fonts.push_back(holder);
}
}
return rtn;
}
TextTypeHelpers::cFontHolder* cFont::getFontHolder(const unsigned long int size)
{
cFontHolder* rtn = nullptr;
std::vector<cFontHolder*>::iterator it;
for (it = m_fonts.begin(); it < m_fonts.end(); it++) {
if (size == (*it)->getSize()) {
rtn = (*it);
//break out of the for loop
break;
}
}
return rtn;
}
void cFont::UnloadFont()
{
m_fonts.clear();
}
@@ -0,0 +1,75 @@
#ifndef _CFONT_HPP_
#define _CFONT_HPP_
/*** ANSI C++ Header Files ***/
#include <vector>
/*** SDL Header Files ***/
#include <SDL.h>
#include <SDL_ttf.h>
/*** TextTypeHelpers ***/
#include "TextTypeHelpers/cFontHolder.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "../UtilityEngine/cString.hpp"
using UtilityEngine::cString;
/*#pragma warning (disable : 4231)*/
EXPIMP_TEMPLATE template class EXPORT_FROM_MYDLL std::allocator<TextTypeHelpers::cFontHolder*>;
EXPIMP_TEMPLATE template class EXPORT_FROM_MYDLL std::vector<TextTypeHelpers::cFontHolder*, std::allocator<TextTypeHelpers::cFontHolder*> >;
/*#pragma warning (default : 4231)*/
namespace TextTypeEngine {
class EXPORT_FROM_MYDLL cFont
{
public:
cFont(const cString& filename = "", const cString& dir = "", const unsigned long int size = 16 );
cFont( const cFont& copy );
~cFont();
///Functions
///Sets
/* Sets the Directory of the TTF file */
void setDir( const cString& dir );
/* Sets the Filename of the TTF file */
void setFileName( const cString& filename );
/* Sets the Filename and Directory of the TTF file */
void setFileNameandDir( const cString& filename, const cString& dir = "" );
/* Sets the size of the TTF. Default is 16 */
void setSize( const unsigned long int size = 16 );
///Gets
/* Gets the Directory of the TTF file */
const cString& getDir() const;
/* Gets the Filename of the TTF file */
const cString& getFileName() const;
/* Gets the size of the TTF file. */
const unsigned long int getSize() const;
/* Gets the TTF_Font. */
TTF_Font* getFont();
/* Gets the TTF_Font. */
TTF_Font* getFont( const unsigned long int size );
private:
TTF_Font* LoadFont( const unsigned long int size );
TextTypeHelpers::cFontHolder* getFontHolder( const unsigned long int size );
void UnloadFont();
private:
std::vector<TextTypeHelpers::cFontHolder*> m_fonts;
//cFontHolder m_fonts;
//cFont::cFontHolder m_fonts;
TextTypeHelpers::cFontHolder** mpp_default;
cString m_dir;// = ""
cString m_fileName;// = ""
};/// END CLASS DEFINITION cFont
}/// END NAMESPACE DEFINITION TextTypeEngine
#endif/// END IFNDEF _CFONT_HPP_
@@ -0,0 +1,206 @@
#include "cText.hpp"
/*** SDL Header Files ***/
#include <SDL2_gfxPrimitives.h>
#include <SDL2_gfxPrimitives_font.h>
#include <SDL2_rotozoom.h>
/*** Custom Header Files ***/
#include "../VideoEngine/cRenderer.hpp"
#include "../FXEngine/cGFX.hpp"
#include "../UtilityEngine/cUtility.hpp"
using TextTypeEngine::cText;
using VideoEngine::cRenderer;
using FXEngine::cGFX;
using UtilityEngine::cUtility;
cText::cText( const cString& text, const unsigned long int size /*= 8*/ )
: mpp_font(nullptr), m_text(text), m_size(size), m_render(eRender::Solid)
{
White();
}
cText::cText( SDL_Colour& colour, TextTypeEngine::cFont** font /*= nullptr*/, const cString& text /*= ""*/, const unsigned long int size /*= 8*/, const eRender& render /*= eRender::Solid*/ )
: mpp_font(font), m_text(text), m_size(size), m_render(render)
{
setColour(colour);
}
cText::cText( TextTypeEngine::cFont** font /*= nullptr*/, const cString& text /*= ""*/, const unsigned long int size /*= 8*/,
const unsigned long int red /*= 0*/, const unsigned long int green /*= 0*/, const unsigned long int blue /*= 0*/, const eRender& render /*= eRender::Solid*/ )
: mpp_font(font), m_text(text), m_size(size), m_render(render)
{
setColour(red, green, blue);
}
cText::cText( const cText& copy )
: mpp_font(nullptr), m_text(copy.getText()), m_render(copy.getRender())
{
setColour(copy.getColour());
}
cText::~cText()
{}
///Function
void cText::White()
{
setColour(255, 255, 255);
}
void cText::Black()
{
setColour();
}
void cText::Blue()
{
setColour(0, 0, 255);
}
void cText::Green()
{
setColour(0, 255);
}
void cText::Red()
{
setColour(255);
}
///Sets
void cText::setSize(const unsigned long int size /*= 8*/)
{
m_size = size;
if ((mpp_font != nullptr) && ((*mpp_font) != nullptr))
(*mpp_font)->setSize(size);
}
void cText::setFont( TextTypeEngine::cFont** font )
{
mpp_font = font;
Text();
}
void cText::setText( const cString& text )
{
if (m_text != text) {
m_text = text;
Text();
}
}
void cText::setColour( const SDL_Colour& colour )
{
m_colour = colour;
Text();
}
void cText::setColour( const unsigned long int red /*= 0*/, const unsigned long int green /*= 0*/, const unsigned long int blue /*= 0*/, unsigned long int alpha /*= 255*/ )
{
SDL_Colour colour = {Uint8(red), Uint8(green), Uint8(blue), Uint8(alpha)};
setColour(colour);
}
void cText::setRender( const eRender& render /*= eRender::Solid*/ )
{
m_render = render;
Text();
}
///Gets
const unsigned long int cText::getSize() const
{
unsigned long int rtn = m_size;
if ((mpp_font != nullptr) && ((*mpp_font) != nullptr))
return (*mpp_font)->getSize();
return rtn;
}
TextTypeEngine::cFont* cText::getFont() const
{
return (*mpp_font);
}
const cString& cText::getText() const
{
return m_text;
}
const SDL_Colour& cText::getColour() const
{
return m_colour;
}
void cText::getColour( unsigned long int& red, unsigned long int& green, unsigned long int& blue, unsigned long int& alpha ) const
{
red = m_colour.r;
green = m_colour.g;
blue = m_colour.b;
alpha = m_colour.a;
}
const cText::eRender& cText::getRender() const
{
return m_render;
}
//Private
void cText::Text()
{
if((mpp_font != nullptr) && (*mpp_font != nullptr)) {
SDL_Surface* sur = nullptr;
switch (m_render)
{
case Solid:
if ((sur = TTF_RenderText_Solid((*mpp_font)->getFont(m_size), m_text.c_str(), m_colour) ) == nullptr)
cUtility::Inst().Message("Unable to render text. TTF_RenderText_Solid():", __AT__, cUtility::eTypeSDL::TTF);
break;
case Shaded:
//sur = TTF_RenderText_Shaded(mp_font, text.c_str(), m_colour,
break;
case Blended:
if ((sur = TTF_RenderText_Blended((*mpp_font)->getFont(m_size), m_text.c_str(), m_colour) ) == nullptr)
cUtility::Inst().Message("Unable to render text. TTF_RenderText_Blended():", __AT__, cUtility::eTypeSDL::TTF);
break;
}
setImage(sur);
} else {
SDL_Rect pos = { 0, 0, 0, 0 };
//m_size == 25;
SDL_Texture* texture = cRenderer::Inst().NewTexture(8 * m_text.length(), 8, SDL_TEXTUREACCESS_TARGET);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
//int t = SDL_SetTextureColorMod(texture, 0, 255, 0);
// 376840196
//t = SDL_SetTextureAlphaMod(texture, 0);
//SDL_fill
//cRenderer::Inst().SetRenderTarget(texture);
//SDL_Colour col = { 0, 255, 255, 255};
//SDL_Rect re= { 0, 0, 100, 100};
//cGFX::Inst().RoundedRectangle(pos, 4, col, texture);
//cRenderer::Inst().RenderDrawColor(col);
//cRenderer::Inst().RenderDrawRect(re, texture);
//cGFX::Inst().RoundedRectangle(pos, 4, col, texture);
//cRenderer::Inst().Render( texture, nullptr, nullptr);
//SDL_RenderCopy(cRenderer::Inst().getRenderer(), texture, nullptr, nullptr);
//cRenderer::Inst().Render(texture, nullptr, nullptr);
//cRenderer::Inst().ResetRenderTarget();
if (texture != nullptr) {
//cGFX::Inst().StringDefault(m_text, pos, m_colour);
cGFX::Inst().StringDefault(m_text, pos, m_colour, texture);
//cGFX::Inst().ZoomIn(texture, m_size * m_text.length(), m_size, SMOOTHING_ON);
setImage(texture);
}
}
}
@@ -0,0 +1,92 @@
#ifndef _CTEXT_HPP_
#define _CTEXT_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
#include <SDL_ttf.h>
/*** VideoEngine ***/
#include "../VideoEngine/cImage.hpp"
/*** TextTypeEngine ***/
#include "cFont.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "../UtilityEngine/cString.hpp"
using UtilityEngine::cString;
namespace TextTypeEngine {
class EXPORT_FROM_MYDLL cText : public VideoEngine::cImage
{
public:
enum eRender: unsigned int
{
Solid = 0,
Shaded,
Blended
};
public:
cText( const cString& text, const unsigned long int size = 8 );
cText( SDL_Colour& colour, TextTypeEngine::cFont** font = nullptr, const cString& text = "", const unsigned long int size = 8, const eRender& render = eRender::Solid );
cText( TextTypeEngine::cFont** font = nullptr, const cString& text = "", const unsigned long int size = 8,
const unsigned long int red = 0, const unsigned long int green = 0, const unsigned long int blue = 0, const eRender& render = eRender::Solid );
cText( const cText& copy );
~cText();
///Function
/* Change the colour of the text to White */
void White();
/* Change the colour of the text to Black */
void Black();
/* Change the colour of the text to Blue */
void Blue();
/* Change the colour of the text to Green */
void Green();
/* Change the colour of the text to Red */
void Red();
///Sets
/* Sets the Size */
void setSize( const unsigned long int size = 8 );
void setFont( cFont** font );
/* Sets the text to be printed */
void setText( const cString& text );
/* Sets the colour of the text via SDL_Colour. */
void setColour( const SDL_Colour& colour );
/* Sets the colour of the text via RGB. Default is Black */
void setColour( const unsigned long int red = 0, const unsigned long int green = 0, const unsigned long int blue = 0, unsigned long int alpha = 255 );
/* Sets the render of the text. Default is Solid */
void setRender( const eRender& render = eRender::Solid );
///Gets
/* Gets the Size */
const unsigned long int getSize() const;
cFont* getFont() const;
/* Gets the text to be printed. */
const cString& getText() const;
/* Gets the SDL_Colour of the text */
const SDL_Colour& getColour() const;
/* Gets the RGB of the text. */
void getColour( unsigned long int& red, unsigned long int& green, unsigned long int& blue, unsigned long int& alpha ) const;
/* Gets the render of the text. */
const eRender& getRender() const;
private:
void Text();
private:
TextTypeEngine::cFont** mpp_font;
cString m_text;// = ""
unsigned long int m_size;// = 16
SDL_Colour m_colour;// = nullptr
eRender m_render;// = Solid
};/// END CLASS DEFINITION cText
}/// END NAMESPACE DEFINITION TextTypeEngine
#endif/// END IFNDEF _CTEXT_HPP_
@@ -0,0 +1,86 @@
#include "cTextType.hpp"
/*** Custom Header Files ***/
#include "../UtilityEngine/cUtility.hpp"
using TextTypeEngine::cTextType;
using UtilityEngine::cUtility;
/*static*/ cTextType* cTextType::sp_inst = nullptr;
//private
cTextType::cTextType()
{
}
cTextType::~cTextType()
{
CleanUp();
TTF_Quit();
}
//public:
///Functions
/*static*/ cTextType& cTextType::Inst()
{
if (sp_inst == nullptr)
sp_inst = new cTextType();
return *sp_inst;
}
/*static*/ void cTextType::Delete()
{
delete sp_inst;
sp_inst = nullptr;
}
const bool cTextType::Initialize() const
{
bool rtn = IsInit();
if (rtn == false) {
if (TTF_Init() == 0) {
cUtility::Inst().Message("True Type Font Initialized.");
rtn = true;
} else
cUtility::Inst().Message("Could not initialize True Type Font. TTF_Init():", __AT__, cUtility::eTypeSDL::TTF);
}
return rtn;
}
/* Creates the cTextType's*/
const bool cTextType::Setup()
{
/*bool rtn = false;
CleanUp();
rtn = Init();
return rtn;*/
return true;
}
void cTextType::CleanUp()
{
}
void cTextType::PrintVersion() const
{
cUtility::Inst().PrintVersion(cUtility::eTypeSDL::TTF);
}
///Sets
///Gets
const bool cTextType::IsInit() const
{
bool rtn = false;
if (TTF_WasInit() != 0) {
cUtility::Inst().Message("True Type Font is initialized.");
rtn = true;
} else
cUtility::Inst().Message("True Type Font is not initialized.");
return rtn;
}
@@ -0,0 +1,40 @@
#ifndef _CTEXTTYPE_HPP_
#define _CTEXTTYPE_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
#include <SDL_ttf.h>
/*** DLL Header File ***/
#include "dllExport.h"
namespace TextTypeEngine {
/* Singleton */
class EXPORT_FROM_MYDLL cTextType
{
private:
cTextType();
~cTextType();
public:
///Functions
static cTextType& Inst();
static void Delete();
const bool Initialize() const;
const bool Setup();
void CleanUp();
void PrintVersion() const;
///Sets
///Gets
/* Gets return true if Text was initialized */
const bool IsInit() const;
private:
static cTextType* sp_inst;// = nullptr
};/// END CLASS DEFINITION cTextType
}/// END NAMESPACE DEFINITION TextTypeEngine
#endif/// END IFNDEF _CTEXTTYPE_HPP_