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,101 @@
#include "cGFX.hpp"
/*** SDL Header Files ***/
#include <SDL2_gfxPrimitives.h>
/*** 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_Texture* texture ) const
{
cRenderer::Inst().SetRenderTarget(texture);
StringDefault(text, pos, colour);
cRenderer::Inst().ResetRenderTarget();
}
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();
}
@@ -0,0 +1,275 @@
#include "cWindow.hpp"
#include "../UtilityEngine/cUtility.hpp"
#include "cGUI.hpp"
#include "cLabel.hpp"
#include "cLayout.hpp"
using GUIEngine::cWindow;
/*static*/ const UtilityEngine::cString cWindow::sNAME = "windows";
/*static*/ GUIHelpers::Position cWindow::sPOSITION = { 0, 0 };
/*static*/ GUIHelpers::Size cWindow::sSIZE = { 0, 0 };
/*static*/ GUIHelpers::Padding cWindow::sPADDING = { 5, 5, 5, 5 };
/*static*/ GUIHelpers::RBGA cWindow::sCOLOUR = { 100, 100, 100, 255 };
/*static*/ GUIHelpers::eAlign cWindow::sALIGN = GUIHelpers::eAlign::CENTER;
/*static*/ GUIHelpers::eLayout cWindow::sLAYOUT = GUIHelpers::eLayout::FILL_PARENT;
cWindow::cWindow(cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, const GUIHelpers::eAlign& align /*= sALIGN*/, const GUIHelpers::eLayout& layout /*= sLAYOUT*/,
const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/, const GUIHelpers::Padding& padding /*= sPADDING*/, const cString& name /*= sNAME*/ )
: mp_parent(parent), GUIHelpers::cObject(id), m_align(align), m_layout(layout), m_pos(pos), m_size(size), m_content(size), m_padding(padding), m_name(name)
{
// if (mp_parent != nullptr) {
// switch (this->getType()) {
// case GUIHelpers::eType::CLABEL:
// mp_parent->AddChild((cLabel*)this);
// break;
// case GUIHelpers::eType::CLAYOUT:
// mp_parent->AddChild((cLayout*)this);
// break;
// }
// }
}
/*virtual*/ cWindow::~cWindow()
{
m_children.clear();
}
/*virtual*/ void cWindow::Display() {
std::vector<cWindow*>::iterator it;
for (it = m_children.begin(); it < m_children.end(); it++) {
(*it)->Display();
}
}
///Functions
const bool cWindow::Inside(const MathEngine::iVector2& location) const
{
bool rtn = false;
if ((location.x >= m_pos.x) && (location.y >= m_pos.y)) {
if ((location.x <= (m_pos.x + m_size.x)) && (location.y <= (m_pos.y + m_size.y)))
rtn = true;
}
return rtn;
}
void cWindow::AddChild(cWindow* obj)
{
//m_obj = obj;
m_children.push_back(obj);
}
void cWindow::RemoveChild(cWindow* obj)
{
std::vector<cWindow*>::iterator it;
for (it = m_children.begin(); it < m_children.end(); it++) {
if (obj == (*it)) {
m_children.erase(it);
//break out of the for loop
break;
}
}
}
void cWindow::AddSizeX(const unsigned long int x)
{
m_size.x += x;
}
void cWindow::AddSizeY(const unsigned long int y)
{
m_size.y += y;
}
///Sets
void cWindow::setAlign( const GUIHelpers::eAlign& align /*= GUIHelpers::eAlign::CENTER*/)
{
m_align = align;
}
void cWindow::setLayout(const GUIHelpers::eLayout& layout /*= GUIHelpers::eLayout::FILL_PARENT*/)
{
m_layout = layout;
}
void cWindow::setPosition(const GUIHelpers::Position& pos /*= POSITION*/)
{
m_pos = pos;
}
void cWindow::setSize(const GUIHelpers::Size& size /*= SIZE*/)
{
m_size = size;
this->Resize();
}
void cWindow::setPadding(const GUIHelpers::Padding& padding/* = PADDING*/)
{
m_padding = padding;
}
void cWindow::setContentSize(const GUIHelpers::Size& content)
{
m_content = content;
}
void cWindow::setName(const cString& name /*= NAME*/)
{
m_name = name;
}
void cWindow::setParent(cWindow* parent)
{
mp_parent = parent;
}
///Gets
const GUIHelpers::eAlign& cWindow::getAlign() const
{
return m_align;
}
const GUIHelpers::eLayout& cWindow::getLayout() const
{
if (m_layout == GUIHelpers::eLayout::MATCH_PARENT) {
if (mp_parent != nullptr)
return mp_parent->getLayout();
}
return m_layout;
}
const GUIHelpers::Position& cWindow::getPosition() const
{
return m_pos;
}
const GUIHelpers::Size& cWindow::getSize() const
{
return m_size;
}
const GUIHelpers::Padding& cWindow::getPadding() const
{
return m_padding;
}
const GUIHelpers::Size& cWindow::getContentSize() const
{
return m_content;
}
const cString& cWindow::getName() const
{
return m_name;
}
cWindow* cWindow::getParent()
{
return mp_parent;
}
/*virtual*/ const GUIHelpers::eType cWindow::getType() const
{
return GUIHelpers::eType::CWINDOW;
}
///Protected
/*virtual*/ void cWindow::Resize()
{
RebuildLayout(this->getLayout());
RePos();
}
/*virtual*/ void cWindow::RebuildLayout(const GUIHelpers::eLayout& layout)
{
GUIHelpers::Size mySize = (0, 0);
std::vector<cWindow*>::iterator it;
switch (layout)
{
case GUIHelpers::eLayout::MATCH_PARENT:
case GUIHelpers::eLayout::FILL_PARENT:
if (mp_parent != nullptr) {
mySize = mp_parent->getSize();
mySize.x -= m_padding.x + m_padding.w;
mySize.y -= m_padding.y + m_padding.z;
} else {
mySize = GUIEngine::cGUI::Inst().DisplayArea();
}
m_size = mySize;
for (it = m_children.begin(); it < m_children.end(); it++) {
//if ((*it)->getLayout() != GUIHelpers::eLayout::WRAP_CONTENT)
(*it)->Resize();
}
break;
case GUIHelpers::eLayout::WRAP_CONTENT:
GUIHelpers::Size size = { 0, 0 };
GUIHelpers::Padding pad = { 0, 0, 0, 0 };
for (it = m_children.begin(); it < m_children.end(); it++) {
(*it)->Resize();
size = (*it)->getSize();
pad = (*it)->getPadding();
size.x += pad.x + pad.w;
size.y += pad.y + pad.z;
mySize += size;
//AddSize(size.x, size.y, mySize);
}
m_size = mySize;
break;
}
}
/*virtual*/ void cWindow::RePos()
{
if (mp_parent != nullptr)
RebuildPos();
std::vector<cWindow*>::iterator it;
for (it = m_children.begin(); it < m_children.end(); it++) {
(*it)->RePos();
}
}
/*virtual*/ void cWindow::RebuildPos()
{
GUIHelpers::Size prtSize = mp_parent->getSize();
GUIHelpers::Position prtCenter = { (prtSize.x / 2), (prtSize.y / 2) };
GUIHelpers::Size ourSize = this->getSize();
GUIHelpers::Position ourCenter = { (ourSize.x / 2), (ourSize.y / 2) };
GUIHelpers::Position ourSet = { 0, 0 };
switch (this->getAlign()) {
case GUIHelpers::eAlign::CENTER:
ourSet.x = prtCenter.x - ourCenter.x;
ourSet.y = prtCenter.y - ourCenter.y;
this->setPosition(ourSet);
break;
case GUIHelpers::eAlign::TOP:
break;
case GUIHelpers::eAlign::RIGHT:
break;
case GUIHelpers::eAlign::BOTTOM:
break;
case GUIHelpers::eAlign::LEFT:
break;
}
}
std::vector<cWindow*>& cWindow::getChildren()
{
return m_children;
}