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,193 @@
#include "cGUI.hpp"
/*** Custom Header Files ***/
#include "../VideoEngine/cVideo.hpp"
#include "../UtilityEngine/cUtility.hpp"
#include "GUIHelpers/Enums.hpp"
#include "cButton.hpp"
#include "GUIHelpers/cXMLoader.hpp"
using GUIEngine::cGUI;
using GUIEngine::cWindow;
using UtilityEngine::cUtility;
/*static*/ cGUI* cGUI::sp_inst = nullptr;
//private
cGUI::cGUI()
: mp_font(nullptr), m_inited(false)
{
setTextColour();
setPadding();
}
cGUI::~cGUI()
{
delete mp_font;
mp_font = nullptr;
m_guiObjects.clear();
}
//public:
///Functions
/*static*/ cGUI& cGUI::Inst()
{
if (sp_inst == nullptr)
sp_inst = new cGUI();
return *sp_inst;
}
/*static*/ void cGUI::Delete()
{
delete sp_inst;
sp_inst = nullptr;
}
const bool cGUI::Initialize( const cString& filename, const cString& dir /*= ""*/, const unsigned long int size /*= 16*/ )
{
bool rtn = IsInit();
GUIHelpers::cXMLoader::Inst().Load(filename, dir);
// if (rtn == false) {
// setFont( filename, dir, size );
// cUtility::Inst().Message("GUI initialized.");
// }
return rtn;
}
void cGUI::Event(const MathEngine::iVector2& location, const eGUIEventType& type)
{
location;
type;
// std::vector<GUIHelpers::cObject*>::iterator it;
//
// for (it = m_objects.begin(); it < m_objects.end(); it++) {
// switch ((*it)->getType()) {
// case GUIHelpers::eType::CBUTTON:
// cButton* tmp = (cButton*)(*it);
// if (tmp->InSide(location) == true)
// cUtility::Inst().Message("Button Inside!");
// break;
// }
// }
}
const MathEngine::iVector2 cGUI::DisplayArea() const
{
MathEngine::iVector2 rtn = { 0, 0 };
rtn.x = VideoEngine::cVideo::Inst().getWidth();
rtn.y = VideoEngine::cVideo::Inst().getHeight();
return rtn;
}
void cGUI::AddObject(cWindow* obj)
{
//this->m_obj = obj;
m_guiObjects.push_back(obj);
}
void cGUI::Display()
{
//m_obj->Display();
std::vector<cWindow*>::iterator it;
for (it = m_guiObjects.begin(); it < m_guiObjects.end(); it++) {
(*it)->Display();
}
}
///Sets
void cGUI::setFont( TextTypeEngine::cFont* font )
{
delete mp_font;
mp_font = nullptr;
mp_font = font;
}
void cGUI::setFont( const cString& filename, const cString& dir /*= ""*/, const unsigned long int size /*= 16*/)
{
delete mp_font;
mp_font = nullptr;
mp_font = new TextTypeEngine::cFont( dir, filename, size );
}
void cGUI::setTextColour( const GUIHelpers::RBGA& colour )
{
cWindow::sCOLOUR = colour;
}
void cGUI::setTextColour( const unsigned long int red /*= 0*/, const unsigned long int green /*= 0*/, const unsigned long int blue /*= 0*/ )
{
GUIHelpers::RBGA colour = {Uint8(red), Uint8(green), Uint8(blue)};
setTextColour(colour);
}
void cGUI::setPadding( const GUIHelpers::Padding& padding )
{
cWindow::sPADDING = padding;
}
void cGUI::setPadding( const unsigned int top /*= 5*/, const unsigned int right /*= 5*/, const unsigned int bottom /*= 5*/, const unsigned int left /*= 5*/ )
{
setPadding(GUIHelpers::Padding(top, right, bottom, left));
}
void cGUI::setAlign( const GUIHelpers::eAlign& align /*= GUIHelpers::eAlign::CENTER*/ )
{
cWindow::sALIGN = align;
}
///Gets
TextTypeEngine::cFont* cGUI::getFont()
{
return mp_font;
}
const GUIHelpers::RBGA& cGUI::getTextColour() const
{
return cWindow::sCOLOUR;
}
void cGUI::getTextColour( unsigned long int& red, unsigned long int& green, unsigned long int& blue ) const
{
red = cWindow::sCOLOUR.r;
green = cWindow::sCOLOUR.g;
blue = cWindow::sCOLOUR.b;
}
const GUIHelpers::Padding& cGUI::getPadding() const
{
return cWindow::sPADDING;
}
void cGUI::getPadding( unsigned int& top, unsigned int& right, unsigned int& bottom, unsigned int& left ) const
{
top = cWindow::sPADDING.x;
right = cWindow::sPADDING.y;
bottom = cWindow::sPADDING.z;
left = cWindow::sPADDING.w;
}
const GUIHelpers::eAlign& cGUI::getAlign() const
{
return cWindow::sALIGN;
}
const bool cGUI::IsInit() const
{
bool rtn = m_inited;
if (rtn == true)
cUtility::Inst().Message("GUI is initialized.");
else
cUtility::Inst().Message("GUI is not initialized.");
return rtn;
}
@@ -0,0 +1,19 @@
#ifndef _CNETWORK_HPP_
#define _CNETWORK_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
///#include <SDL/SDL_net.h> ///For networking
/*** DLL Header File ***/
#include "dllExport.h"
namespace NetworkEngine {
class EXPORT_FROM_MYDLL cNetwork
{
public:
cNetwork();
~cNetwork();
};/// END CLASS DEFINITION cNetwork
}/// END NAMESPACE NetworkEngine
#endif /// END IFNDEF _CNETWORK_HPP_
@@ -0,0 +1,322 @@
#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;
/*static*/ GUIHelpers::eOrientation cWindow::sORIENTATION = GUIHelpers::eOrientation::NONE;
cWindow::cWindow(cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, const GUIHelpers::eOrientation& orientation /*= sORIENTATION*/, 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*/)
: cObject(id)
{
Create(parent, id, orientation, align, layout, pos, size, padding, name);
}
/*virtual*/ cWindow::~cWindow()
{
m_children.clear();
}
/*virtual*/ void cWindow::Create(cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, const GUIHelpers::eOrientation& orientation /*= sORIENTATION*/, 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;
cObject::setID(id);
setOrientation(orientation);
setAlign(align);
setLayout(layout);
m_pos = pos;
m_size = size;
m_padding = padding;
m_name = name;
}
/*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_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;
}
}
}
///Sets
void cWindow::setOrientation( const GUIHelpers::eOrientation& orientation /*= sORIENTATION*/ )
{
if (orientation == GUIHelpers::eOrientation::DEFAULT_ORIENTATION)
m_orientation = cWindow::sORIENTATION;
else
m_orientation = orientation;
}
void cWindow::setAlign( const GUIHelpers::eAlign& align /*= sALIGN*/ )
{
if (align == GUIHelpers::eAlign::DEFAULT_ALIGN)
m_align = cWindow::sALIGN;
else
m_align = align;
}
void cWindow::setLayout( const GUIHelpers::eLayout& layout /*= sLAYOUT*/ )
{
if (layout == GUIHelpers::eLayout::DEFAULT_LAYOUT)
m_layout = cWindow::sLAYOUT;
else
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;
}
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::eOrientation& cWindow::getOrientation() const
{
return m_orientation;
}
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::Position prtPos = mp_parent->getPosition();
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;
break;
case GUIHelpers::eAlign::TOP:
ourSet.x = prtCenter.x - ourCenter.x;
ourSet.y = prtPos.y + m_padding.y;
break;
case GUIHelpers::eAlign::RIGHT:
ourSet.x = prtSize.x - ourSize.x - m_padding.w;
ourSet.y = prtCenter.y - ourCenter.y;
break;
case GUIHelpers::eAlign::BOTTOM:
ourSet.x = prtCenter.x - ourCenter.x;
ourSet.y = prtSize.y - ourSize.y - m_padding.z;
break;
case GUIHelpers::eAlign::LEFT:
ourSet.x = prtPos.x + m_padding.x;
ourSet.y = prtCenter.y - ourCenter.y;
break;
}
this->setPosition(ourSet);
}
std::vector<cWindow*>& cWindow::getChildren()
{
return m_children;
}
//private
void cWindow::AddSize(int x, int y, GUIHelpers::Size& mySize) const
{
int& addFrom = x;
int& largestFrom = y;
int& addTo = mySize.x;
int& largestTo = mySize.y;
if (m_orientation == GUIHelpers::eOrientation::HORIZONTAL) {
addFrom = y;
largestFrom = x;
addTo = mySize.y;
largestTo = mySize.x;
}
/*We do the real work here.*/
if (largestTo > largestFrom)
largestTo = largestFrom;
addTo += addFrom;
}