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,108 @@
#ifndef _CWINDOW_HPP_
#define _CWINDOW_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** Custom Header Files ***/
#include "GUIHelpers/cObject.hpp"
#include "GUIHelpers/Enums.hpp"
#include "GUIHelpers/GUIUtility.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "../UtilityEngine/cString.hpp"
using UtilityEngine::cString;
namespace GUIEngine {
class EXPORT_FROM_MYDLL cWindow : public GUIHelpers::cObject
{
public:
static const UtilityEngine::cString sNAME; /*= "windows";*/
static GUIHelpers::Position sPOSITION; /*= Position(0, 0);*/
static GUIHelpers::Size sSIZE; /*= Size(0, 0);*/
static GUIHelpers::Padding sPADDING; /*= Padding(5, 5, 5, 5);*/
static GUIHelpers::RBGA sCOLOUR; /*= { 100, 100, 100, 255 };*/
static GUIHelpers::eAlign sALIGN; /*= GUIHelpers::eAlign::CENTER;*/
static GUIHelpers::eLayout sLAYOUT; /*= FILL_PARENT*/
static GUIHelpers::eOrientation sORIENTATION; /*= GUIHelpers::eOrientation::NONE;*/
protected:
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 );
virtual ~cWindow();
virtual void 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);
public:
///Functions
virtual void Display();
const bool Inside( const MathEngine::iVector2& location ) const;
void AddChild( cWindow* obj );
void RemoveChild( cWindow* obj );
///Sets
void setOrientation( const GUIHelpers::eOrientation& orientation = sORIENTATION );
void setAlign( const GUIHelpers::eAlign& align = sALIGN );
void setLayout( const GUIHelpers::eLayout& layout = sLAYOUT );
void setPosition( const GUIHelpers::Position& pos = sPOSITION );
void setSize( const GUIHelpers::Size& size = sSIZE );
void setPadding(const GUIHelpers::Padding& padding = sPADDING);
void setContentSize( const GUIHelpers::Size& content );
void setName( const cString& name = sNAME );
void setParent( cWindow* parent );
///Gets
const GUIHelpers::eOrientation& getOrientation() const;
const GUIHelpers::eAlign& getAlign() const;
const GUIHelpers::eLayout& getLayout() const;
const GUIHelpers::Position& getPosition() const;
const GUIHelpers::Size& getSize() const;
const GUIHelpers::Padding& getPadding() const;
const GUIHelpers::Size& getContentSize() const;
const cString& getName() const;
cWindow* getParent();
virtual const GUIHelpers::eType getType() const;
virtual void Resize();
virtual void RebuildLayout(const GUIHelpers::eLayout& layout);
virtual void RePos();
virtual void RebuildPos();
protected:
std::vector<cWindow*>& getChildren();
private:
void Rebuild( cWindow* const parent, const GUIHelpers::eLayout& layout );
void AddSize(int x, int y, GUIHelpers::Size& mySize) const;
private:
GUIHelpers::eOrientation m_orientation;// = GUIHelper::eOrientation::NONE;
GUIHelpers::eAlign m_align;// = GUIHelper::eAlign::CENTER;
GUIHelpers::eLayout m_layout;// = GUIHelper::eLayout::FILL_PARENT;
GUIHelpers::Position m_pos;// = POSITION;
GUIHelpers::Size m_size;// = SIZE;
GUIHelpers::Padding m_padding;// = PADDING;
GUIHelpers::Size m_content;// = m_size;
cString m_name;// = NAME;
std::vector<cWindow*> m_children;
cWindow* mp_parent;// = nullptr;
};/// END CLASS DEFINITION cBoxSizer
}/// END NAMESPACE DEFINITION GUIEngine
#endif/// END IFNDEF _CBOXSIZER_HPP_
@@ -0,0 +1,39 @@
#ifndef _IVECTOR4_HPP_
#define _IVECTOR4_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header File ***/
#include "iVector3.hpp"
namespace MathEngine {
struct Vector4;
struct EXPORT_FROM_MYDLL iVector4 : public iVector3
{
iVector4( const int X = 0, const int Y = 0, const int Z = 0, const int W = 0 );
iVector4( const iVector2& copy );
iVector4( const iVector3& copy );
iVector4( const SDL_Rect& copy );
iVector4& operator=( const SDL_Rect& copy );
bool operator==( const SDL_Rect& other ) const;
iVector4( const Vector4& copy );
iVector4& operator=( const Vector4& copy );
bool operator==( const iVector4& other ) const;
int w;
};/// END STRUCT DEFINITION iVector4
}/// END NAMESPACE DEFINITION MathEngine
#endif/// END IFNDEF _IVECTOR4_HPP_
@@ -0,0 +1,393 @@
#include "cString.hpp"
/*** ANSI C Header Files ***/
#include <stdlib.h> /* strtol */
#ifdef _MSC_VER
// disable _s warnings
# define _CRT_SECURE_NO_WARNINGS
// disable pragma warnings
# pragma warning( disable : 4068 )
# pragma warning( disable : 4996 )
# include "MSUNIX/msunix.hpp"
#endif
using UtilityEngine::cString;
cString::cString()
{
clear();
}
cString::cString(const char* s)
{
copy_str(s);
}
cString::cString(const cString& copy)
{
copy_str(copy);
}
cString::~cString()
{
clear();
}
const char* cString::alloc_str(size_t sz)
{
if (mp_str)
clear();
m_len = (sz > __cString__MAX_LEN) ? __cString__MAX_LEN : sz;
mp_str = (char *)calloc(1, m_len + 1);
return mp_str;
}
void cString::clear()
{
if (mp_str)
free((void *)mp_str);
mp_str = nullptr;
m_len = 0;
}
const char* cString::c_str() const
{
return mp_str;
}
const char* cString::copy_str(const char* copy)
{
if (copy) {
size_t len = strnlen(copy, __cString__MAX_LEN);
alloc_str(len);
strncpy((char *)mp_str, copy, len);
m_len = len;
}
return mp_str;
}
bool cString::have_value() const
{
if (mp_str)
return true;
else
return false;
}
size_t cString::length() const
{
return m_len;
}
size_t cString::size() const
{
return m_len;
}
// string format
cString& cString::format(const char* format, ...)
{
char * buffer;
va_list args;
va_start(args, format);
vasprintf(&buffer, format, args);
copy_str(buffer);
free(buffer);
return *this;
}
// trim leading and trailing spaces
cString& cString::trim()
{
const static char * whitespace = "\x20\x1b\t\r\n\v\b\f\a";
if (!have_value())
return *this; // make sure we have a string
size_t begin = 0;
size_t end = length() - 1;
for (begin = 0; begin <= end; ++begin) {
if (strchr(whitespace, mp_str[begin]) == nullptr) {
break;
}
}
for (; end > begin; --end) {
if (strchr(whitespace, mp_str[end]) == nullptr) {
break;
}
else {
mp_str[end] = '\0';
}
}
if (begin) {
for (size_t i = 0; mp_str[i]; ++i) {
mp_str[i] = mp_str[begin++];
}
}
m_len = strlen(mp_str);
return *this;
}
cString cString::lower() const
{
cString rs = *this;
for (size_t i = 0; rs.mp_str[i]; ++i) {
rs.mp_str[i] = (char)tolower(rs.mp_str[i]);
}
return rs;
}
cString cString::upper() const
{
cString rs = *this;
for (size_t i = 0; rs.mp_str[i]; ++i) {
rs.mp_str[i] = (char)toupper(rs.mp_str[i]);
}
return rs;
}
const char & cString::last_char() const
{
return mp_str[length() - 1];
}
// non-destructive split
const std::vector<cString> cString::split(const char match) const
{
const char match_s[2] = { match, 0 };
return split(match_s, -1);
}
const std::vector<cString> cString::split(const char* match) const
{
return split(match, -1);
}
const std::vector<cString> cString::split(const char* match, int max_split) const
{
std::vector<cString> rv;
if (length() < 1)
return rv;
size_t match_len = strnlen(match, __cString__MAX_LEN);
if (match_len >= __cString__MAX_LEN)
return rv;
char * mi; // match index
char * pstr = mp_str; // string pointer
mi = strstr(pstr, match);
while ((mi) && (max_split < 0 || --max_split)) {
if (mi != pstr) {
size_t lhsz = mi - pstr;
char * cslhs = (char *)malloc(lhsz + 1);
cslhs[lhsz] = '\0'; // strncpy doesn't terminate it
rv.emplace_back(strncpy(cslhs, pstr, lhsz)); // calls BWString copy ctor
pstr += lhsz;
free(cslhs);
}
pstr += match_len;
}
if (*pstr != '\0') {
rv.emplace_back(pstr);
}
return rv;
}
const cString& cString::char_repl(const char& match, const char& repl)
{
for (size_t i = 0; mp_str[i]; ++i) {
if (mp_str[i] == match) mp_str[i] = repl;
}
return *this;
}
long int cString::char_find(const char& match) const
{
for (size_t i = 0; mp_str[i]; ++i) {
if (mp_str[i] == match)
return i;
}
return -1;
}
cString cString::substr(size_t start, size_t length) const
{
cString rs;
char * buf;
if ((length + 1) > __cString__MAX_LEN)
return rs;
if ((start + length) > __cString__MAX_LEN)
return rs;
if (length > m_len - start)
return rs;
if (!mp_str)
return rs;
buf = (char *)calloc(sizeof(char), length + 1);
memcpy(buf, mp_str + start, length);
rs = buf;
return rs;
}
long int cString::find(const cString& match)
{
char * pos = strstr(mp_str, match.c_str());
if (pos)
return (long)(pos - mp_str);
else
return -1;
}
const cString cString::replace(const cString& match, const cString& repl)
{
cString rs;
long f1 = find(match);
if (f1 >= 0) {
size_t pos1 = (size_t)f1;
size_t pos2 = pos1 + match.length();
cString s1 = pos1 > 0 ? substr(0, pos1) : "";
cString s2 = substr(pos2, length() - pos2);
rs = s1 + repl + s2;
}
return rs;
}
const long int cString::ToInt() const
{
return strtol(mp_str, NULL, 10);
}
cString& cString::operator = (const char* rhs)
{
copy_str(rhs);
return *this;
}
cString& cString::operator = (const cString& rhs)
{
copy_str(rhs.c_str());
return *this;
}
cString& cString::operator += (const char rhs)
{
operator+=(&rhs);
return *this;
}
cString& cString::operator += (const char* rhs)
{
if (rhs) {
size_t newlen = m_len + strnlen(rhs, __cString__MAX_LEN);
if (newlen > __cString__MAX_LEN)
newlen = __cString__MAX_LEN;
char * buf = (char *)calloc(1, newlen + 1);
if (!buf)
return *this;
if (mp_str && m_len)
strncpy(buf, mp_str, m_len);
strncpy(buf + m_len, rhs, newlen - m_len);
buf[newlen] = '\0';
copy_str(buf);
free(buf);
}
return *this;
}
cString& cString::operator += (const cString& rhs)
{
operator+=(rhs.c_str());
return *this;
}
bool cString::operator == (const char* rhs) const
{
if (std::strncmp(this->c_str(), rhs, __cString__MAX_LEN) == 0)
return true;
else
return false;
}
bool cString::operator == (const cString & rhs) const
{
if (std::strncmp(this->c_str(), rhs.c_str(), __cString__MAX_LEN) == 0)
return true;
else
return false;
}
bool cString::operator != (const char* rhs) const
{
if (std::strncmp(this->c_str(), rhs, __cString__MAX_LEN) != 0)
return true;
else
return false;
}
bool cString::operator != (const cString & rhs) const
{
if (std::strncmp(this->c_str(), rhs.c_str(), __cString__MAX_LEN) != 0)
return true;
else
return false;
}
bool cString::operator > (const cString & rhs) const
{
if (std::strncmp(this->c_str(), rhs.c_str(), __cString__MAX_LEN) > 0)
return true;
else
return false;
}
bool cString::operator < (const cString & rhs) const
{
if (std::strncmp(this->c_str(), rhs.c_str(), __cString__MAX_LEN) < 0)
return true;
else
return false;
}
bool cString::operator >= (const cString & rhs) const
{
if (std::strncmp(this->c_str(), rhs.c_str(), __cString__MAX_LEN) >= 0)
return true;
else
return false;
}
bool cString::operator <= (const cString & rhs) const
{
if (std::strncmp(this->c_str(), rhs.c_str(), __cString__MAX_LEN) <= 0)
return true;
else return false;
}
cString::operator const char* () const
{
return c_str();
}
cString::operator std::string () const
{
return std::string(c_str());
}
cString operator + (const cString& lhs, const cString& rhs)
{
cString rs = lhs;
rs += rhs;
return rs;
}