Add project files.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#ifndef _CTROOPERENGINECORE_HPP_
|
||||
#define _CTROOPERENGINECORE_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
#define __TROOPERENGINE__VERSION "1.0.0"
|
||||
|
||||
namespace TrooperEngineCore {
|
||||
/* Singleton */
|
||||
class EXPORT_FROM_MYDLL cTrooperEngineCore
|
||||
{
|
||||
private:
|
||||
cTrooperEngineCore();
|
||||
~cTrooperEngineCore();
|
||||
|
||||
public:
|
||||
///Functions
|
||||
static const char* Version();
|
||||
static cTrooperEngineCore& Inst();
|
||||
static void Delete();
|
||||
|
||||
/* Initiates the video */
|
||||
const bool VideoInit();
|
||||
/* Initiates the audio */
|
||||
const bool AudioInit();
|
||||
/* Initiates the input (Keyboard Mouse Joystick)*/
|
||||
const bool InputInit();
|
||||
/* Initiates the joystick */
|
||||
const bool JoystickInit();
|
||||
/* Initiates the timer */
|
||||
const bool TimerInit();
|
||||
/* Initiates the text */
|
||||
const bool TextTypeInit();
|
||||
/* Initiates the event */
|
||||
const bool EventInit();
|
||||
|
||||
/* Print lib versions */
|
||||
void PrintSDLVersion() const;
|
||||
|
||||
/* Cleans up */
|
||||
void CleanUp();
|
||||
|
||||
///Gets
|
||||
/* Gets returns true if Video was initiated other wise it returns false */
|
||||
const bool getVideo() const;
|
||||
/* Gets returns true if Audio was initiated other wise it returns false */
|
||||
const bool getAudio() const;
|
||||
/* Gets returns true if Input was initiated other wise it returns false */
|
||||
const bool getInput() const;
|
||||
/* Gets returns true if Joystick was initiated other wise it returns false */
|
||||
const bool getJoystick() const;
|
||||
/* Gets returns true if Timer was initiated other wise it returns false */
|
||||
const bool getTimer() const;
|
||||
/* Gets returns true if Text was initiated other wise it returns false */
|
||||
const bool getText() const;
|
||||
/* Gets returns true if Event was initiated other wise it returns false */
|
||||
const bool getEvent() const;
|
||||
|
||||
private:
|
||||
///Variables
|
||||
static cTrooperEngineCore* sp_inst;// = nullptr
|
||||
};/// END CLASS DEFINITION cTrooperEngineCore
|
||||
}/// END NAMESPACE DEFINITION TroopperENgineCore
|
||||
#endif/// END IFNDEF _CTROOPERENGINECORE_HPP_
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef _CLABEL_HPP_
|
||||
#define _CLABEL_HPP_
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cWindow.hpp"
|
||||
|
||||
#include "../TextTypeEngine/cText.hpp"
|
||||
#include "../VideoEngine/cSprite.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
namespace GUIEngine {
|
||||
class EXPORT_FROM_MYDLL cLabel : public cWindow, public VideoEngine::cSprite
|
||||
{
|
||||
public:
|
||||
static const cString sNAME; /*= "label";*/
|
||||
static const GUIHelpers::eLayout sLAYOUT;/* = GUIHelpers::eLayout::WRAP_CONTENT;*/
|
||||
|
||||
cLabel(cWindow* parent, const signed int id, const cString& label = "", 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 ~cLabel();
|
||||
|
||||
///Functions
|
||||
void Create(cWindow* parent, const signed int id, const cString& label = "", 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 void Display();
|
||||
|
||||
void GenerateTexture();
|
||||
|
||||
//Sets
|
||||
void setFontColour( const GUIHelpers::RBGA& colour );
|
||||
void setFontSize( const unsigned long int size );
|
||||
void setText( const cString& text );
|
||||
void setFont( const TextTypeEngine::cFont* font );
|
||||
|
||||
///Gets
|
||||
const GUIHelpers::RBGA& getFontColour() const;
|
||||
const unsigned long int getFontSize() const;
|
||||
const TextTypeEngine::cFont* getFont() const;
|
||||
const cString& getText() const;
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
|
||||
virtual void Resize();
|
||||
virtual void RebuildLayout(const GUIHelpers::eLayout& layout);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
private:
|
||||
TextTypeEngine::cText* mp_text;// = nullptr
|
||||
};/// END CLASS DEFINITION cLabel
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CLABEL_HPP_
|
||||
@@ -0,0 +1,251 @@
|
||||
#include "cXMLoader.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../../UtilityEngine/cUtility.hpp"
|
||||
|
||||
#include "../cGUI.hpp"
|
||||
#include "../cLayout.hpp"
|
||||
|
||||
using GUIHelpers::cXMLoader;
|
||||
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
/*static*/ cXMLoader* cXMLoader::sp_inst = nullptr;
|
||||
|
||||
cXMLoader::cXMLoader()
|
||||
{}
|
||||
|
||||
cXMLoader::~cXMLoader()
|
||||
{}
|
||||
|
||||
//PUBLIC
|
||||
///Functions
|
||||
/*static*/ cXMLoader& cXMLoader::Inst()
|
||||
{
|
||||
if (sp_inst == nullptr)
|
||||
sp_inst = new cXMLoader();
|
||||
return *sp_inst;
|
||||
}
|
||||
|
||||
/*static*/ void cXMLoader::Delete()
|
||||
{
|
||||
delete sp_inst;
|
||||
sp_inst = nullptr;
|
||||
}
|
||||
|
||||
void cXMLoader::Load( const cString& filename, const cString& dir /*= ""*/ ) const
|
||||
{
|
||||
cString file = dir + filename;
|
||||
tinyxml2::XMLDocument doc;
|
||||
|
||||
if (doc.LoadFile(file.c_str()) != tinyxml2::XMLError::XML_NO_ERROR)
|
||||
cUtility::Inst().Message("Could not load file. " + file + " Error='" + doc.ErrorName() + "'.");
|
||||
else {
|
||||
tinyxml2::XMLNode* node = doc.FirstChildElement("GUI");
|
||||
|
||||
if (node == nullptr)
|
||||
cUtility::Inst().Message("No GUI tag found.");
|
||||
else
|
||||
GetElement(*node->ToElement());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void cXMLoader::GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* parent /*= nullptr*/ ) const
|
||||
{
|
||||
cString name = element.Name();
|
||||
GUIEngine::cWindow* tmp = nullptr;
|
||||
if (name == "GUI")
|
||||
GUISetup(element);
|
||||
if (name == "Layout")
|
||||
tmp = LayoutBuild(element, parent);
|
||||
if (name == "Label")
|
||||
tmp = LabelBuild(element, parent);
|
||||
tinyxml2::XMLElement* child = element.FirstChildElement();
|
||||
if (child != nullptr)
|
||||
GetElement(*child, tmp);
|
||||
|
||||
tinyxml2::XMLElement* sibling = element.NextSiblingElement();
|
||||
if (sibling != nullptr)
|
||||
GetElement(*sibling, parent);
|
||||
|
||||
if ((parent == nullptr) && (tmp != nullptr))
|
||||
tmp->Resize();
|
||||
}
|
||||
|
||||
const cString cXMLoader::GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const
|
||||
{
|
||||
cString rtn = "";
|
||||
const char* str = element.Attribute(attribute.c_str());
|
||||
if (str == nullptr)
|
||||
cUtility::Inst().Message("Error no attribute: " + attribute + " found in tag <" + element.Value() + ">");
|
||||
else
|
||||
rtn = str;
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cXMLoader::GUISetup( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
unsigned long int debug = getDebug(element);
|
||||
|
||||
GUIEngine::cWindow::sDebug = debug;
|
||||
}
|
||||
|
||||
GUIEngine::cLayout* cXMLoader::LayoutBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const
|
||||
{
|
||||
signed long int id = getID(element);
|
||||
GUIHelpers::eOrientation orientation = getOrientation(element);
|
||||
GUIHelpers::eAlign align = getAlign(element);
|
||||
GUIHelpers::eLayout layout = getLayout(element);
|
||||
GUIHelpers::Position pos = getPosition(element);
|
||||
GUIHelpers::Size size = getSize(element);
|
||||
GUIHelpers::Padding pad = getPadding(element);
|
||||
|
||||
|
||||
GUIEngine::cLayout* rtn = new GUIEngine::cLayout(parent, id, orientation, align, layout, pos, size, pad);
|
||||
|
||||
|
||||
if (parent == nullptr)
|
||||
GUIEngine::cGUI::Inst().AddObject(rtn);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
GUIEngine::cLabel* cXMLoader::LabelBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const
|
||||
{
|
||||
signed long int id = getID(element);
|
||||
//GUIHelpers::eOrientation orientation = getOrientation(element);
|
||||
GUIHelpers::eAlign align = getAlign(element);
|
||||
GUIHelpers::eLayout layout = getLayout(element);
|
||||
GUIHelpers::Position pos = getPosition(element);
|
||||
GUIHelpers::Size size = getSize(element);
|
||||
GUIHelpers::Padding pad = getPadding(element);
|
||||
|
||||
cString txt = getText(element);
|
||||
|
||||
GUIEngine::cLabel* rtn = new GUIEngine::cLabel(parent, id, txt, align, layout, pos, size, pad);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const unsigned long int cXMLoader::getDebug( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
unsigned long int rtn = 0;
|
||||
cString str = GetAttribute(element, "debug").lower();
|
||||
|
||||
if ((str != "") && (str != "false")) {
|
||||
if (str == "true")
|
||||
rtn = 1;
|
||||
else
|
||||
rtn = str.ToInt();
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const signed long int cXMLoader::getID( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
cString rtn = GetAttribute(element, "id");
|
||||
return rtn.ToInt();
|
||||
}
|
||||
|
||||
const GUIHelpers::eOrientation cXMLoader::getOrientation( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::eOrientation rtn = GUIHelpers::eOrientation::DEFAULT_ORIENTATION;
|
||||
|
||||
cString str = GetAttribute(element, "orientation").lower();
|
||||
|
||||
if (str == "none")
|
||||
rtn = GUIHelpers::eOrientation::NONE;
|
||||
if (str == "horizontal")
|
||||
rtn = GUIHelpers::eOrientation::HORIZONTAL;
|
||||
if (str == "vertical")
|
||||
rtn = GUIHelpers::eOrientation::VERTICAL;
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::eAlign cXMLoader::getAlign( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::eAlign rtn = GUIHelpers::eAlign::DEFAULT_ALIGN;
|
||||
|
||||
cString str = GetAttribute(element, "align").lower();
|
||||
|
||||
if (str == "center")
|
||||
rtn = GUIHelpers::eAlign::CENTER;
|
||||
if (str == "top")
|
||||
rtn = GUIHelpers::eAlign::TOP;
|
||||
if (str == "right")
|
||||
rtn = GUIHelpers::eAlign::RIGHT;
|
||||
if (str == "bottom")
|
||||
rtn = GUIHelpers::eAlign::BOTTOM;
|
||||
if (str == "left")
|
||||
rtn = GUIHelpers::eAlign::LEFT;
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::eLayout cXMLoader::getLayout( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::eLayout rtn = GUIHelpers::eLayout::DEFAULT_LAYOUT;
|
||||
|
||||
cString str = GetAttribute(element, "layout").lower();
|
||||
|
||||
if (str == "fill_parent")
|
||||
rtn = GUIHelpers::eLayout::FILL_PARENT;
|
||||
if (str == "match_parent")
|
||||
rtn = GUIHelpers::eLayout::MATCH_PARENT;
|
||||
if (str == "wrap_content")
|
||||
rtn = GUIHelpers::eLayout::WRAP_CONTENT;
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Position cXMLoader::getPosition( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::Position rtn = { 0, 0 };
|
||||
|
||||
/*cString str = GetAttribute(element, "position");*/
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Size cXMLoader::getSize( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::Size rtn = { 0, 0 };
|
||||
|
||||
/*cString str = GetAttribute(element, "position");*/
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Padding cXMLoader::getPadding( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::Padding rtn = { -1, -1, -1, -1 };
|
||||
|
||||
cString str = GetAttribute(element, "padding");
|
||||
|
||||
if (str != "") {
|
||||
rtn = { 0, 0, 0, 0 };
|
||||
std::vector<cString> strV = str.split(",");
|
||||
|
||||
switch (strV.size())
|
||||
{
|
||||
case 4:
|
||||
rtn.z = strV[3].ToInt();
|
||||
case 3:
|
||||
rtn.w = strV[2].ToInt();
|
||||
case 2:
|
||||
rtn.y = strV[1].ToInt();
|
||||
case 1:
|
||||
rtn.x = strV[0].ToInt();
|
||||
}
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const cString cXMLoader::getText( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
return GetAttribute(element, "text");
|
||||
}
|
||||
Reference in New Issue
Block a user