Add project files.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#ifndef _ENUMS_HPP_
|
||||
#define _ENUMS_HPP_
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
namespace GUIHelpers {
|
||||
enum EXPORT_FROM_MYDLL eLayout: unsigned int
|
||||
{
|
||||
DEFAULT_LAYOUT = 0,
|
||||
FILL_PARENT,
|
||||
MATCH_PARENT,
|
||||
WRAP_CONTENT
|
||||
};/// END enum DEFINITION eLayout
|
||||
|
||||
enum EXPORT_FROM_MYDLL eType: unsigned int
|
||||
{
|
||||
COBJECT,
|
||||
CWINDOW,
|
||||
CPANEL,
|
||||
CLAYOUT,
|
||||
CBOXSIZER,
|
||||
CBUTTON,
|
||||
CTEXTBUTTON,
|
||||
CLABEL,
|
||||
};/// END enum DEFINITION eType
|
||||
|
||||
enum EXPORT_FROM_MYDLL eOrientation: unsigned int
|
||||
{
|
||||
DEFAULT_ORIENTATION = 0,
|
||||
NONE,
|
||||
VERTICAL,
|
||||
HORIZONTAL
|
||||
};/// END enum DEFINITION eOrientation
|
||||
|
||||
enum EXPORT_FROM_MYDLL eAlign: unsigned int
|
||||
{
|
||||
DEFAULT_ALIGN = 0,
|
||||
CENTER,
|
||||
TOP,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
LEFT
|
||||
};/// END enum DEFINITION eAlign
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _ENUMS_HPP_
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "GUIUtility.hpp"
|
||||
|
||||
using namespace GUIHelpers;
|
||||
|
||||
const RGBA GUIHelpers::StringtoRGBA( const cString& colour )
|
||||
{
|
||||
RGBA rtn = DEFAULT;
|
||||
cString check = colour.upper();
|
||||
if (check == "WHITE")
|
||||
rtn = WHITE;
|
||||
if (check == "BLACK")
|
||||
rtn = BLACK;
|
||||
if (check == "RED")
|
||||
rtn = RED;
|
||||
if (check == "ORANGE")
|
||||
rtn = ORANGE;
|
||||
if (check == "YELLOW")
|
||||
rtn = YELLOW;
|
||||
if (check == "GREEN")
|
||||
rtn = GREEN;
|
||||
if (check == "CYAN")
|
||||
rtn = CYAN;
|
||||
if (check == "BLUE")
|
||||
rtn = BLUE;
|
||||
if (check == "VIOLET")
|
||||
rtn = VIOLET;
|
||||
if (check == "MAGENTA")
|
||||
rtn = MAGENTA;
|
||||
if (check == "ROSE")
|
||||
rtn = ROSE;
|
||||
|
||||
return rtn;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef _GUIUTILITY_HPP_
|
||||
#define _GUIUTILITY_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../../MathEngine/iVector/iVector2.hpp"
|
||||
#include "../../MathEngine/iVector/iVector4.hpp"
|
||||
|
||||
#include "../../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace GUIHelpers {
|
||||
typedef struct MathEngine::iVector2 Size, Position;
|
||||
typedef struct MathEngine::iVector4 Padding;
|
||||
typedef struct SDL_Colour RGBA;
|
||||
typedef struct SDL_Rect Area;
|
||||
|
||||
static const RGBA DEFAULT = { 0, 0, 0, 0 };
|
||||
|
||||
static const RGBA WHITE = { 255, 255, 255, 255 };
|
||||
static const RGBA BLACK = { 0, 0, 0, 255 };
|
||||
|
||||
static const RGBA RED = { 255, 0, 0, 255 };
|
||||
|
||||
static const RGBA ORANGE = { 255, 128, 0, 255 };
|
||||
static const RGBA YELLOW = { 255, 255, 0, 255 };
|
||||
|
||||
static const RGBA GREEN = { 0, 255, 0, 255 };
|
||||
|
||||
static const RGBA CYAN = { 0, 255, 255, 255 };
|
||||
|
||||
static const RGBA BLUE = { 0, 0, 255, 255 };
|
||||
|
||||
static const RGBA VIOLET = { 128, 0, 255, 255 };
|
||||
static const RGBA MAGENTA = { 255, 0, 255, 255 };
|
||||
static const RGBA ROSE = { 255, 0, 128, 255 };
|
||||
|
||||
|
||||
const RGBA StringtoRGBA(const cString& colour);
|
||||
|
||||
|
||||
}/// END NAMESPACE DEFINITION GUIHelpers
|
||||
#endif/// END IFNDEF _GUIUTILITY_HPP_
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "cObject.hpp"
|
||||
|
||||
#include "../cGUI.hpp"
|
||||
|
||||
using GUIHelpers::cObject;
|
||||
|
||||
cObject::cObject( const signed int id )
|
||||
: m_id(id)
|
||||
{
|
||||
//GUIEngine::cGUI::Inst().AddObject(this);
|
||||
}
|
||||
|
||||
/*virtual*/ cObject::~cObject()
|
||||
{}
|
||||
|
||||
bool cObject::operator == (const cObject& other)
|
||||
{
|
||||
if (m_id == other.getID())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
///Functions
|
||||
|
||||
///Sets
|
||||
const void cObject::setID( const signed int id )
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
///Gets
|
||||
const signed int cObject::getID() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cObject::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::COBJECT;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef _COBJECT_HPP_
|
||||
#define _COBJECT_HPP_
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "Enums.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
namespace GUIHelpers {
|
||||
class EXPORT_FROM_MYDLL cObject
|
||||
{
|
||||
public:
|
||||
cObject( const signed int id );
|
||||
virtual ~cObject();
|
||||
|
||||
bool operator == (const cObject& other);
|
||||
|
||||
///Functions
|
||||
|
||||
///Sets
|
||||
const void setID( const signed int id );
|
||||
|
||||
///Gets
|
||||
const signed int getID() const;
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
private:
|
||||
signed int m_id;// = 0
|
||||
};/// END CLASS DEFINITION cObject
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _COBJECT_HPP_
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "cTexture.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../../VideoEngine/cRenderer.hpp"
|
||||
#include "../../FXEngine/cGFX.hpp"
|
||||
#include "GUIUtility.hpp"
|
||||
|
||||
using GUIHelpers::cTexture;
|
||||
|
||||
cTexture::cTexture()
|
||||
{}
|
||||
|
||||
cTexture::~cTexture()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
|
||||
//private
|
||||
SDL_Texture* cTexture::GenerateTexture( const SDL_Rect& dimensions, TextTypeEngine::cText* text /*= nullptr*/ )
|
||||
{
|
||||
SDL_Rect t = text->getWH();
|
||||
SDL_Rect centerText = { 0, 0, 0, 0 };
|
||||
SDL_Rect centerButton = { 0, 0, 0, 0 };
|
||||
SDL_Rect dim = dimensions;
|
||||
|
||||
///Find the min padding around the text.
|
||||
// if (dim.w < (t.w + GUIHelpers::default::text::PADDING.x + GUIHelpers::default::text::PADDING.w) )
|
||||
// dim.w += (t.w + GUIHelpers::default::text::PADDING.x + GUIHelpers::default::text::PADDING.w);
|
||||
//
|
||||
// if (dim.h < (t.h + GUIHelpers::default::text::PADDING.y + GUIHelpers::default::text::PADDING.z) )
|
||||
// dim.h += (t.h + GUIHelpers::default::text::PADDING.y + GUIHelpers::default::text::PADDING.z);
|
||||
|
||||
///Find the center of the button
|
||||
centerButton.x = dim.w / 2;
|
||||
centerButton.y = dim.h / 2;
|
||||
|
||||
///Find the center of the text
|
||||
centerText.x = t.w / 2;
|
||||
centerText.y = t.h / 2;
|
||||
|
||||
if (centerText.x < centerButton.x)
|
||||
t.x = centerButton.x - centerText.x;
|
||||
|
||||
if (centerText.y < centerButton.y)
|
||||
t.y = centerButton.y - centerText.y;
|
||||
|
||||
SDL_Texture* temptext = VideoEngine::cRenderer::Inst().NewTexture(dim.w, dim.h, SDL_TEXTUREACCESS_TARGET );
|
||||
|
||||
GUIHelpers::RGBA colour = { 100, 100, 100, 255 };
|
||||
|
||||
FXEngine::cGFX::Inst().RoundedBox(dim, 0, colour, temptext);
|
||||
|
||||
|
||||
VideoEngine::cRenderer::Inst().RenderToTexture(text->getImage(), nullptr, temptext, &t);
|
||||
|
||||
|
||||
//cRenderer::Inst().Render(temptext, nullptr, nullptr);
|
||||
|
||||
//cRenderer::Inst().RenderToTexture(temptext, nullptr, text->getImage(), nullptr);
|
||||
|
||||
/*SDL_Surface* tempsurface = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), dimensions.w, dimensions.h, cVideo::Inst().getColour(),
|
||||
0, 0, 0, 0);
|
||||
|
||||
SDL_FillRect(tempsurface, nullptr, SDL_MapRGB(tempsurface->format, 0, 255, 0));
|
||||
|
||||
/*if (roundedBoxRGBA(tempsurface, dimensions.x, dimensions.y, dimensions.w, dimensions.h, 10, 255, 255, 0, 255) != 0)
|
||||
cerr << "Unable to generate GUI Texture." << endl << SDL_GetError() << endl;*/
|
||||
|
||||
|
||||
/*if (text != nullptr) {
|
||||
SDL_Rect srcrect, dstrect = dimensions;
|
||||
cVideo::Inst().Render(text->getImage(), &srcrect, temptext, &dstrect);
|
||||
}
|
||||
|
||||
this->setImage(temptext);
|
||||
this->setTransparent();*/
|
||||
|
||||
setImage(temptext);
|
||||
|
||||
return temptext;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _CTEXTURE_HPP_
|
||||
#define _CTEXTURE_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../../VideoEngine/cImage.hpp"
|
||||
#include "../../TextTypeEngine/cText.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
namespace GUIHelpers {
|
||||
class EXPORT_FROM_MYDLL cTexture : public VideoEngine::cImage
|
||||
{
|
||||
public:
|
||||
cTexture();
|
||||
~cTexture();
|
||||
|
||||
///Functions
|
||||
SDL_Texture* GenerateTexture( const SDL_Rect& dimensions, TextTypeEngine::cText* text = nullptr );
|
||||
|
||||
private:
|
||||
|
||||
};/// END CLASS DEFINITION cTexture
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CTEXTURE_HPP_
|
||||
@@ -0,0 +1,451 @@
|
||||
#include "cXMLoader.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../../UtilityEngine/cUtility.hpp"
|
||||
|
||||
#include "../cGUI.hpp"
|
||||
#include "../cLayout.hpp"
|
||||
|
||||
using GUIHelpers::cXMLoader;
|
||||
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
|
||||
cXMLoader::cXMLoader()
|
||||
{
|
||||
m_loadDef = false;
|
||||
m_orientation = GUIHelpers::eOrientation::DEFAULT_ORIENTATION;
|
||||
m_align = GUIHelpers::eAlign::DEFAULT_ALIGN;
|
||||
m_layout = GUIHelpers::eLayout::DEFAULT_LAYOUT;
|
||||
m_pos = { -1, -1 };
|
||||
m_size = { -1, -1 };
|
||||
m_pad = { -1, -1, -1, -1 };
|
||||
}
|
||||
|
||||
cXMLoader::~cXMLoader()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
|
||||
void cXMLoader::Load( const cString& filename, const cString& dir /*= ""*/, GUIEngine::cWindow* parent /*= nullptr*/ )
|
||||
{
|
||||
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::XMLElement* element = doc.FirstChildElement();
|
||||
|
||||
if (element == nullptr)
|
||||
cUtility::Inst().Message("No tag found.");
|
||||
else {
|
||||
//OK check for defaults
|
||||
tinyxml2::XMLElement* defaultEl = element->FirstChildElement("default");
|
||||
if (defaultEl != nullptr)
|
||||
Default(*defaultEl);
|
||||
tinyxml2::XMLElement* debugEl = element->FirstChildElement("debug");
|
||||
if (debugEl != nullptr)
|
||||
Debug(*debugEl);
|
||||
GetElement(*element, parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void cXMLoader::GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* parent /*= nullptr*/ ) const
|
||||
{
|
||||
cString name = element.Name();
|
||||
name = name.lower();
|
||||
GUIEngine::cWindow* tmp = nullptr;
|
||||
if (name == "include")
|
||||
Include(element, parent);
|
||||
if (name == "gui")
|
||||
GUISetup(element);
|
||||
if (name == "panel")
|
||||
tmp = PanelBuild(element, parent);
|
||||
if (name == "layout")
|
||||
tmp = LayoutBuild(element, parent);
|
||||
if (name == "label")
|
||||
tmp = LabelBuild(element, parent);
|
||||
if (name == "boxsizer")
|
||||
tmp = BoxSizerBuild(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) && (m_debugXML == true))
|
||||
cUtility::Inst().Message("Error no attribute: " + attribute + " found in tag <" + element.Value() + ">");
|
||||
else
|
||||
rtn = str;
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cXMLoader::Include(const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent) const
|
||||
{
|
||||
cString dir = getDir(element);
|
||||
cString filename = getFileName(element);
|
||||
|
||||
cXMLoader include;
|
||||
include.Load(filename, dir, parent);
|
||||
|
||||
LoadDefault();
|
||||
}
|
||||
|
||||
void cXMLoader::GUISetup( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
unsigned long int debug = getDebug(element);
|
||||
|
||||
GUIEngine::cGUI::Inst().setDebugLevel(debug);
|
||||
}
|
||||
|
||||
void cXMLoader::Default( const tinyxml2::XMLElement& element )
|
||||
{
|
||||
m_orientation = getOrientation(element);
|
||||
m_align = getAlign(element);
|
||||
m_layout = getLayout(element);
|
||||
m_pos = getPosition(element);
|
||||
m_size = getSize(element);
|
||||
m_pos = getPadding(element);
|
||||
|
||||
m_loadDef = true;
|
||||
|
||||
LoadDefault();
|
||||
}
|
||||
|
||||
void cXMLoader::Debug(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
unsigned long int debug = getDebug(element);
|
||||
m_debugXML = getDebugXML(element);
|
||||
|
||||
GUIEngine::cGUI::Inst().setDebugLevel(debug);
|
||||
}
|
||||
|
||||
GUIEngine::cPanel* cXMLoader::PanelBuild(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::cPanel* rtn = new GUIEngine::cPanel(parent, id, orientation, align, layout, pos, size, pad);
|
||||
|
||||
if (parent == nullptr)
|
||||
GUIEngine::cGUI::Inst().AddObject(rtn);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
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 = { -1, -1 };// 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 = { -1, -1 };//getSize(element);
|
||||
GUIHelpers::Padding pad = getPadding(element);
|
||||
GUIHelpers::RGBA colour = getColour(element);
|
||||
signed long int fontSize = getFontSize(element);
|
||||
|
||||
cString txt = getText(element);
|
||||
|
||||
GUIEngine::cLabel* rtn = new GUIEngine::cLabel(parent, id, txt, align, layout, pos, size, pad);
|
||||
rtn->setFontColour(colour);
|
||||
if (fontSize > 0)
|
||||
rtn->setFontSize((unsigned long int)fontSize);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
GUIEngine::cBoxSizer* cXMLoader::BoxSizerBuild(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::cBoxSizer* rtn = new GUIEngine::cBoxSizer(parent, id, align, layout, pos, size, pad);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const cString cXMLoader::getDir(const tinyxml2::XMLElement& element) const
|
||||
{
|
||||
cString rtn = GetAttribute(element, "dir");
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const cString cXMLoader::getFileName(const tinyxml2::XMLElement& element) const
|
||||
{
|
||||
cString rtn = GetAttribute(element, "filename");
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const unsigned long int cXMLoader::getDebug( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
unsigned long int rtn = 99;
|
||||
cString str = GetAttribute(element, "level").lower();
|
||||
|
||||
if (str != "") {
|
||||
if (str == "true")
|
||||
rtn = 1;
|
||||
else {
|
||||
if (str != "false")
|
||||
rtn = 0;
|
||||
else
|
||||
rtn = str.ToInt();
|
||||
}
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const bool cXMLoader::getDebugXML(const tinyxml2::XMLElement& element) const
|
||||
{
|
||||
bool rtn = false;
|
||||
cString str = GetAttribute(element, "xml").lower();
|
||||
|
||||
if ((str != "") && (str != "false")) {
|
||||
if (str == "true")
|
||||
rtn = true;
|
||||
else {
|
||||
if (str.ToInt() > 0)
|
||||
rtn = true;
|
||||
}
|
||||
}
|
||||
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 = { -1, -1 };
|
||||
|
||||
cString str = GetAttribute(element, "position");
|
||||
|
||||
if (str != "") {
|
||||
rtn = { 0, 0 };
|
||||
std::vector<cString> strV = str.split(",");
|
||||
|
||||
switch (strV.size())
|
||||
{
|
||||
case 2:
|
||||
rtn.y = strV[1].ToInt();
|
||||
case 1:
|
||||
rtn.x = strV[0].ToInt();
|
||||
}
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Size cXMLoader::getSize( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::Size rtn = { -1, -1 };
|
||||
|
||||
cString str = GetAttribute(element, "size");
|
||||
|
||||
if (str != "") {
|
||||
rtn = { 0, 0 };
|
||||
std::vector<cString> strV = str.split(",");
|
||||
|
||||
switch (strV.size())
|
||||
{
|
||||
case 2:
|
||||
rtn.y = strV[1].ToInt();
|
||||
case 1:
|
||||
rtn.x = strV[0].ToInt();
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
const GUIHelpers::RGBA cXMLoader::getColour( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
GUIHelpers::RGBA rtn = GUIHelpers::DEFAULT;
|
||||
cString str = GetAttribute(element, "colour");
|
||||
|
||||
if (str == "")
|
||||
str = GetAttribute(element, "color");
|
||||
|
||||
if (str != "") {
|
||||
std::vector<cString> strV = str.split(",");
|
||||
|
||||
switch (strV.size())
|
||||
{
|
||||
case 4:
|
||||
rtn.a = strV[3].ToInt();
|
||||
case 3:
|
||||
rtn.b = strV[2].ToInt();
|
||||
case 2:
|
||||
rtn.g = strV[1].ToInt();
|
||||
case 1:
|
||||
if (strV[0].IsInt() == true) {
|
||||
rtn.r = strV[0].ToInt();
|
||||
if (strV.size() < 4)
|
||||
rtn.a = 255;
|
||||
}
|
||||
else
|
||||
rtn = GUIHelpers::StringtoRGBA(str);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const signed long int cXMLoader::getFontSize( const tinyxml2::XMLElement& element ) const
|
||||
{
|
||||
signed long int rtn = -1;
|
||||
cString str = GetAttribute(element, "fontsize");
|
||||
|
||||
if (str != "")
|
||||
rtn = str.ToInt();
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cXMLoader::LoadDefault() const
|
||||
{
|
||||
if (m_loadDef == false)
|
||||
return;
|
||||
GUIEngine::cWindow::OrientationDefault(m_orientation);
|
||||
GUIEngine::cWindow::AlignDefault(m_align);
|
||||
GUIEngine::cWindow::LayoutDefault(m_layout);
|
||||
GUIEngine::cWindow::PositionDefault(m_pos);
|
||||
GUIEngine::cWindow::SizeDefault(m_size);
|
||||
GUIEngine::cWindow::PaddingDefault(m_pad);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef _CXMLOADER_HPP_
|
||||
#define _CXMLOADER_HPP_
|
||||
|
||||
/*** TinyXML Header File ***/
|
||||
#include "tinyxml2.h"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "GUIUtility.hpp"
|
||||
|
||||
#include "../cWindow.hpp"
|
||||
#include "../cPanel.hpp"
|
||||
#include "../cLayout.hpp"
|
||||
#include "../cLabel.hpp"
|
||||
#include "../cBoxSizer.hpp"
|
||||
|
||||
#include "../../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace GUIHelpers {
|
||||
class EXPORT_FROM_MYDLL cXMLoader
|
||||
{
|
||||
public:
|
||||
cXMLoader();
|
||||
~cXMLoader();
|
||||
|
||||
void Load( const cString& filename, const cString& dir = "", GUIEngine::cWindow* parent = nullptr );
|
||||
|
||||
private:
|
||||
void GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* parent = nullptr ) const;
|
||||
const cString GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const;
|
||||
|
||||
void Include( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
void GUISetup( const tinyxml2::XMLElement& element ) const;
|
||||
void Default( const tinyxml2::XMLElement& element );
|
||||
void Debug( const tinyxml2::XMLElement& element );
|
||||
|
||||
GUIEngine::cPanel* PanelBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
GUIEngine::cLayout* LayoutBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
GUIEngine::cLabel* LabelBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
GUIEngine::cBoxSizer* BoxSizerBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
|
||||
|
||||
const cString getDir( const tinyxml2::XMLElement& element ) const;
|
||||
const cString getFileName( const tinyxml2::XMLElement& element ) const;
|
||||
const unsigned long int getDebug( const tinyxml2::XMLElement& element ) const;
|
||||
const bool cXMLoader::getDebugXML(const tinyxml2::XMLElement& element) const;
|
||||
const signed long int getID( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::eOrientation getOrientation( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::eAlign getAlign( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::eLayout getLayout( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Position getPosition( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Size getSize( const tinyxml2::XMLElement& element ) const;
|
||||
const GUIHelpers::Padding getPadding( const tinyxml2::XMLElement& element ) const;
|
||||
const cString getText( const tinyxml2::XMLElement& element ) const;
|
||||
|
||||
const GUIHelpers::RGBA getColour( const tinyxml2::XMLElement& element ) const;
|
||||
const signed long int getFontSize( const tinyxml2::XMLElement& element ) const;
|
||||
|
||||
void LoadDefault() const;
|
||||
|
||||
private:
|
||||
bool m_loadDef;// = false;
|
||||
bool m_debugXML;
|
||||
|
||||
GUIHelpers::eOrientation m_orientation;// = GUIHelpers::eOrientation::DEFAULT_ORIENTATION;
|
||||
GUIHelpers::eAlign m_align;// = GUIHelpers::eAlign::DEFAULT_ALIGN;
|
||||
GUIHelpers::eLayout m_layout;// = GUIHelpers::eLayout::DEFAULT_LAYOUT;
|
||||
GUIHelpers::Position m_pos;// = { -1, -1 };
|
||||
GUIHelpers::Size m_size;// = { -1, -1 };
|
||||
GUIHelpers::Padding m_pad;// = { -1, -1, -1, -1 };
|
||||
};/// END CLASS DEFINITION cXMLoader
|
||||
}/// END NAMESPACE DEFINITION GUIHelpers
|
||||
#endif/// END IFNDEF _CXMLOADER_HPP_
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "cBoxSizer.hpp"
|
||||
|
||||
using GUIEngine::cBoxSizer;
|
||||
|
||||
/*static*/ const cString cBoxSizer::sNAME = "boxsizer";
|
||||
/*static*/ GUIHelpers::Size cBoxSizer::sSIZE = { 5, 5 };
|
||||
|
||||
cBoxSizer::cBoxSizer( cWindow* parent, const signed int id, 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*/ )
|
||||
{
|
||||
Create(parent, id, align, layout, pos, size, padding, name);
|
||||
}
|
||||
|
||||
/*virtual*/ cBoxSizer::~cBoxSizer()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
void cBoxSizer::Create( cWindow* parent, const signed int id, 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*/ )
|
||||
{
|
||||
GUIHelpers::Size sz = size;
|
||||
if (size.x < 0)
|
||||
sz = sSIZE;
|
||||
cWindow::Create(parent, id, sORIENTATION, align, layout, pos, sz, padding, name);
|
||||
if (this->getParent() != nullptr) {
|
||||
this->getParent()->AddChild(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cBoxSizer::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::CBOXSIZER;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cBoxSizer::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::CYAN;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef _CBOXSIZER_HPP_
|
||||
#define _CBOXSIZER_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cPanel.hpp"
|
||||
#include "GUIHelpers/cObject.hpp"
|
||||
#include "GUIHelpers/Enums.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cWindow.hpp"
|
||||
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace GUIEngine {
|
||||
class EXPORT_FROM_MYDLL cBoxSizer : public cWindow
|
||||
{
|
||||
public:
|
||||
static const cString sNAME; /*= "boxsizer";*/
|
||||
static GUIHelpers::Size sSIZE; /*= { 5, 5 }*/
|
||||
|
||||
cBoxSizer( cWindow* parent, const signed int id, 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 ~cBoxSizer();
|
||||
|
||||
///Functions
|
||||
void Create( cWindow* parent, const signed int id, 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 const GUIHelpers::eType getType() const;
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
private:
|
||||
private:
|
||||
};/// END CLASS DEFINITION cBoxSizer
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CBOXSIZER_HPP_
|
||||
@@ -0,0 +1,170 @@
|
||||
#include "cButton.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "GUIHelpers/Enums.hpp"
|
||||
#include "../VideoEngine/cRenderer.hpp"
|
||||
#include "../FXEngine/cGFX.hpp"
|
||||
|
||||
using GUIEngine::cButton;
|
||||
|
||||
using MathEngine::iVector2;
|
||||
using MathEngine::iVector4;
|
||||
|
||||
/*static*/ const cString cButton::sNAME = "button";
|
||||
|
||||
cButton::cButton()
|
||||
{}
|
||||
|
||||
cButton::cButton( cWindow* parent, const signed int id, 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*/, VideoEngine::cImage** image /*= nullptr*/ )
|
||||
: cWindow(parent, id, sORIENTATION, align, layout, pos, size, padding, name)
|
||||
{
|
||||
//Create(parent, id, align, layout, pos, size, padding, name, image);
|
||||
mp_texture = nullptr;
|
||||
mp_texturePress = nullptr;
|
||||
|
||||
mpp_image = image;
|
||||
|
||||
GenerateImage();
|
||||
}
|
||||
|
||||
/*virtual*/ cButton::~cButton()
|
||||
{
|
||||
delete mp_texture;
|
||||
mp_texture = nullptr;
|
||||
|
||||
delete mp_texturePress;
|
||||
mp_texturePress = nullptr;
|
||||
|
||||
}
|
||||
|
||||
///Functions
|
||||
void cButton::Create( cWindow* parent, const signed int id, 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*/, VideoEngine::cImage** image /*= nullptr*/ )
|
||||
{
|
||||
cWindow::Create(parent, id, sORIENTATION, align, layout, pos, size, padding, name);
|
||||
mp_texture = nullptr;
|
||||
mp_texturePress = nullptr;
|
||||
|
||||
mpp_image = image;
|
||||
|
||||
GenerateImage();
|
||||
}
|
||||
|
||||
/*virtual*/ void cButton::Press()
|
||||
{
|
||||
mp_texture->SaveImage("hello.bmp");
|
||||
}
|
||||
|
||||
// void cButton::setLabel( const cString& label )
|
||||
// {
|
||||
// if (label.size() > 0) {
|
||||
// if (mp_label == nullptr)
|
||||
// mp_label = new TextTypeEngine::cText(label);
|
||||
// else
|
||||
// mp_label->setText(label);
|
||||
// }
|
||||
// }
|
||||
|
||||
///Gets
|
||||
// const cString cButton::getLabel() const
|
||||
// {
|
||||
// cString rtn = "";
|
||||
// if (mp_label != nullptr)
|
||||
// rtn = mp_label->getText();
|
||||
// return rtn;
|
||||
// }
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cButton::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::CBUTTON;
|
||||
}
|
||||
|
||||
|
||||
//private
|
||||
void cButton::GenerateImage()
|
||||
{
|
||||
GenerateTexture();
|
||||
//GenerateTexture( mp_texturePress );
|
||||
|
||||
this->setImage((VideoEngine::cImage**)(&mp_texture));
|
||||
|
||||
this->setImageArea(mp_texture->getWH());
|
||||
}
|
||||
|
||||
void cButton::GenerateTexture()
|
||||
{
|
||||
// SDL_Rect t = { 0, 0, 0, 0 };
|
||||
// if (mp_label != nullptr)
|
||||
// t = mp_label->getWH();
|
||||
// SDL_Rect centerText = { 0, 0, 0, 0 };
|
||||
// SDL_Rect centerButton = { 0, 0, 0, 0 };
|
||||
// SDL_Rect dim = this->getImageArea();
|
||||
//
|
||||
// GUIHelpers::Padding TXTPADDING = PADDING;
|
||||
// ///Find the min padding around the text.
|
||||
// if (dim.w < (t.w + TXTPADDING.x + TXTPADDING.w) )
|
||||
// dim.w += (t.w + TXTPADDING.x + TXTPADDING.w);
|
||||
//
|
||||
// if (dim.h < (t.h + TXTPADDING.y + TXTPADDING.z) )
|
||||
// dim.h += (t.h + TXTPADDING.y + TXTPADDING.z);
|
||||
//
|
||||
// ///Find the center of the button
|
||||
// centerButton.x = dim.w / 2;
|
||||
// centerButton.y = dim.h / 2;
|
||||
//
|
||||
// ///Find the center of the text
|
||||
// centerText.x = t.w / 2;
|
||||
// centerText.y = t.h / 2;
|
||||
//
|
||||
// if (centerText.x < centerButton.x)
|
||||
// t.x = centerButton.x - centerText.x;
|
||||
//
|
||||
// if (centerText.y < centerButton.y)
|
||||
// t.y = centerButton.y - centerText.y;
|
||||
//
|
||||
// SDL_Texture* temptext = VideoEngine::cRenderer::Inst().NewTexture(dim.w, dim.h, SDL_TEXTUREACCESS_TARGET );
|
||||
//
|
||||
// GUIHelpers::RBGA colour = { 100, 100, 100, 255 };
|
||||
//
|
||||
// FXEngine::cGFX::Inst().RoundedRectangle(dim, 4, colour, temptext);
|
||||
//
|
||||
//
|
||||
// if (mp_label != nullptr)
|
||||
// VideoEngine::cRenderer::Inst().RenderToTexture(mp_label->getImage(), nullptr, temptext, &t);
|
||||
|
||||
|
||||
//cRenderer::Inst().Render(temptext, nullptr, nullptr);
|
||||
|
||||
//cRenderer::Inst().RenderToTexture(temptext, nullptr, text->getImage(), nullptr);
|
||||
|
||||
/*SDL_Surface* tempsurface = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), dimensions.w, dimensions.h, cVideo::Inst().getColour(),
|
||||
0, 0, 0, 0);
|
||||
|
||||
SDL_FillRect(tempsurface, nullptr, SDL_MapRGB(tempsurface->format, 0, 255, 0));
|
||||
|
||||
/*if (roundedBoxRGBA(tempsurface, dimensions.x, dimensions.y, dimensions.w, dimensions.h, 10, 255, 255, 0, 255) != 0)
|
||||
cerr << "Unable to generate GUI Texture." << endl << SDL_GetError() << endl;*/
|
||||
|
||||
|
||||
/*if (text != nullptr) {
|
||||
SDL_Rect srcrect, dstrect = dimensions;
|
||||
cVideo::Inst().Render(text->getImage(), &srcrect, temptext, &dstrect);
|
||||
}
|
||||
|
||||
this->setImage(temptext);
|
||||
this->setTransparent();*/
|
||||
|
||||
// delete mp_texture;
|
||||
// mp_texture = nullptr;
|
||||
//
|
||||
// mp_texture = new VideoEngine::cImage(temptext);
|
||||
//
|
||||
// GUIHelpers::Size size = { 0, 0 };
|
||||
// mp_texture->getWH((unsigned long&)size.x, (unsigned long&)size.y);
|
||||
// cWindow::setSize(size);
|
||||
// image->setImage(temptext);
|
||||
//image->setImage(temptext);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef _CBUTTON_HPP_
|
||||
#define _CBUTTON_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cWindow.hpp"
|
||||
|
||||
#include "GUIHelpers/Enums.hpp"
|
||||
#include "GUIHelpers/GUIUtility.hpp"
|
||||
#include "../VideoEngine/cSprite.hpp"
|
||||
#include "../VideoEngine/cImage.hpp"
|
||||
#include "../MathEngine/iVector/iVector2.hpp"
|
||||
|
||||
#include "cPanel.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace GUIEngine {
|
||||
class EXPORT_FROM_MYDLL cButton : public cWindow, public VideoEngine::cSprite
|
||||
{
|
||||
public:
|
||||
static const cString sNAME; /*= "button";*/
|
||||
|
||||
cButton();
|
||||
cButton( cWindow* parent, const signed int id, 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, VideoEngine::cImage** image = nullptr );
|
||||
virtual ~cButton();
|
||||
|
||||
///Functions
|
||||
void Create( cWindow* parent, const signed int id, 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, VideoEngine::cImage** image = nullptr );
|
||||
|
||||
virtual void Press();
|
||||
|
||||
//Sets
|
||||
|
||||
///Gets
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
private:
|
||||
void CreateLabel();
|
||||
void GenerateImage();
|
||||
void GenerateTexture();
|
||||
|
||||
private:
|
||||
VideoEngine::cImage* mp_texture;// = nullptr
|
||||
VideoEngine::cImage* mp_texturePress;// = nullptr
|
||||
|
||||
//Pointer to the image that will be displayed on the button.
|
||||
VideoEngine::cImage** mpp_image;// = nullptr
|
||||
};/// END CLASS DEFINITION cButton
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CBUTTON_HPP_
|
||||
@@ -0,0 +1,215 @@
|
||||
#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 UtilityEngine::cUtility;
|
||||
|
||||
/*static*/ cGUI* cGUI::sp_inst = nullptr;
|
||||
|
||||
//private
|
||||
cGUI::cGUI()
|
||||
: m_debugLevel(0), mp_font(nullptr), m_inited(false)
|
||||
{
|
||||
setTextColour();
|
||||
setPadding();
|
||||
}
|
||||
|
||||
cGUI::~cGUI()
|
||||
{
|
||||
delete mp_font;
|
||||
mp_font = nullptr;
|
||||
|
||||
for (int i = 0; i < m_children.size(); ++i) {
|
||||
delete m_children[i];
|
||||
m_children[i] = nullptr;
|
||||
}
|
||||
m_children.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 xml;
|
||||
xml.Load(filename, dir);
|
||||
//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( GUIEngine::cWindow* obj )
|
||||
{
|
||||
m_children.push_back(obj);
|
||||
}
|
||||
|
||||
std::vector<GUIEngine::cWindow*>& cGUI::GetObjects()
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
|
||||
void cGUI::Display()
|
||||
{
|
||||
//m_obj->Display();
|
||||
std::vector<GUIEngine::cWindow*>::iterator it;
|
||||
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
(*it)->Display();
|
||||
}
|
||||
}
|
||||
|
||||
///Sets
|
||||
void cGUI::setDebugLevel(const unsigned long int debugLevel)
|
||||
{
|
||||
m_debugLevel = debugLevel;
|
||||
}
|
||||
|
||||
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::RGBA& 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::RGBA 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
|
||||
const unsigned long int cGUI::getDebugLevel() const
|
||||
{
|
||||
return m_debugLevel;
|
||||
}
|
||||
|
||||
TextTypeEngine::cFont* cGUI::getFont()
|
||||
{
|
||||
return mp_font;
|
||||
}
|
||||
|
||||
const GUIHelpers::RGBA& 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;*/
|
||||
return{};
|
||||
}
|
||||
|
||||
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;*/
|
||||
return GUIHelpers::eAlign::CENTER;
|
||||
}
|
||||
|
||||
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,105 @@
|
||||
#ifndef _CGUI_HPP_
|
||||
#define _CGUI_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../TextTypeEngine/cFont.hpp"
|
||||
#include "../MathEngine/iVector/iVector4.hpp"
|
||||
|
||||
#include "cWindow.hpp"
|
||||
//#include "cPanel.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
#include "../MathEngine/iVector/iVector2.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace GUIEngine {
|
||||
/* Singleton */
|
||||
class EXPORT_FROM_MYDLL cGUI
|
||||
{
|
||||
private:
|
||||
cGUI();
|
||||
~cGUI();
|
||||
|
||||
public:
|
||||
enum EXPORT_FROM_MYDLL eGUIEventType: unsigned int
|
||||
{
|
||||
MouseButton1 = 0,
|
||||
MouseButton2,
|
||||
MouseButton3,
|
||||
Keyboard
|
||||
};
|
||||
///Functions
|
||||
static cGUI& Inst();
|
||||
static void Delete();
|
||||
|
||||
const bool Initialize( const cString& filename, const cString& dir = "", const unsigned long int size = 16 );
|
||||
|
||||
void Event( const MathEngine::iVector2& location, const eGUIEventType& type );
|
||||
const MathEngine::iVector2 DisplayArea() const;
|
||||
|
||||
void AddObject( GUIEngine::cWindow* obj );
|
||||
|
||||
std::vector<GUIEngine::cWindow*>& GetObjects();
|
||||
|
||||
void Display();
|
||||
|
||||
///Sets
|
||||
void setDebugLevel( const unsigned long int debugLevel );
|
||||
|
||||
void setFont( TextTypeEngine::cFont* font );
|
||||
void setFont( const cString& filename, const cString& dir = "", const unsigned long int size = 16 );
|
||||
|
||||
void setTextColour( const GUIHelpers::RGBA& colour );
|
||||
void setTextColour( const unsigned long int red = 0, const unsigned long int green = 0, const unsigned long int blue = 0 );
|
||||
|
||||
void setPadding( const GUIHelpers::Padding& padding );
|
||||
void setPadding( const unsigned int top = 5, const unsigned int right = 5, const unsigned int bottom = 5, const unsigned int left = 5 );
|
||||
|
||||
void setAlign( const GUIHelpers::eAlign& align = GUIHelpers::eAlign::CENTER );
|
||||
|
||||
///Gets
|
||||
const unsigned long int getDebugLevel() const;
|
||||
|
||||
TextTypeEngine::cFont* getFont();
|
||||
|
||||
const GUIHelpers::RGBA& getTextColour() const;
|
||||
void getTextColour( unsigned long int& red, unsigned long int& green, unsigned long int& blue ) const;
|
||||
|
||||
const GUIHelpers::Padding& getPadding() const;
|
||||
void getPadding( unsigned int& top, unsigned int& right, unsigned int& bottom, unsigned int& left ) const;
|
||||
|
||||
const GUIHelpers::eAlign& getAlign() const;
|
||||
|
||||
const bool IsInit() const;
|
||||
|
||||
private:
|
||||
static cGUI* sp_inst;// = nullptr
|
||||
|
||||
unsigned long int m_debugLevel;// = 0
|
||||
|
||||
bool m_inited;// = false
|
||||
|
||||
/* default GUI font */
|
||||
TextTypeEngine::cFont* mp_font;// = nullptr
|
||||
|
||||
/* default GUI text colour black*/
|
||||
//GUIHelpers::RBGA m_textColour;// = { 0, 0, 0 }
|
||||
|
||||
/* default GUI padding */
|
||||
//GUIHelpers::Padding m_padding;// = { 5, 5, 5, 5 }
|
||||
|
||||
/* default GUI align */
|
||||
//GUIHelpers::eAlign m_align;// = GUIHelpers::eAlign::CENTER
|
||||
|
||||
std::vector<GUIEngine::cWindow*> m_children;
|
||||
};/// END CLASS DEFINITION cGUI
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CGUI_HPP_
|
||||
@@ -0,0 +1,132 @@
|
||||
#include "cLabel.hpp"
|
||||
|
||||
using GUIEngine::cLabel;
|
||||
|
||||
/*static*/ const cString cLabel::sNAME = "label";
|
||||
/*static*/ const GUIHelpers::eLayout cLabel::sLAYOUT = GUIHelpers::eLayout::WRAP_CONTENT;
|
||||
|
||||
cLabel::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*/)
|
||||
{
|
||||
mp_text = new TextTypeEngine::cText(label);
|
||||
Create(parent, id, label, align, layout, pos, size, padding, name);
|
||||
}
|
||||
|
||||
/*virtual*/ cLabel::~cLabel()
|
||||
{
|
||||
delete mp_text;
|
||||
mp_text = nullptr;
|
||||
}
|
||||
|
||||
///Functions
|
||||
void cLabel::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*/)
|
||||
{
|
||||
cWindow::Create(parent, id, sORIENTATION, align, layout, pos, size, padding, name);
|
||||
if (this->getParent() != nullptr) {
|
||||
this->getParent()->AddChild(this);
|
||||
}
|
||||
setText(label);
|
||||
}
|
||||
|
||||
/*virtual*/ void cLabel::Display()
|
||||
{
|
||||
GenerateTexture();
|
||||
|
||||
m_sprite.setPosition(cWindow::getPosition());
|
||||
m_sprite.Draw();
|
||||
//cSprite::SaveImage("test.bmp", "xml/");
|
||||
cWindow::Display();
|
||||
}
|
||||
|
||||
void cLabel::GenerateTexture()
|
||||
{
|
||||
m_sprite.setImage((VideoEngine::cImage**)(&mp_text));
|
||||
|
||||
m_sprite.setImageArea(mp_text->getWH());
|
||||
|
||||
|
||||
|
||||
//this->setTransparent();
|
||||
//this->setPosition()
|
||||
}
|
||||
|
||||
//Sets
|
||||
void cLabel::setFontColour(const GUIHelpers::RGBA& colour)
|
||||
{
|
||||
mp_text->setColour(colour);
|
||||
}
|
||||
|
||||
void cLabel::setFontSize(const unsigned long int size)
|
||||
{
|
||||
mp_text->setSize(size);
|
||||
SetSize();
|
||||
}
|
||||
|
||||
void cLabel::setText(const cString& text)
|
||||
{
|
||||
mp_text->setText(text);
|
||||
SetSize();
|
||||
}
|
||||
|
||||
void cLabel::setFont(const TextTypeEngine::cFont* font)
|
||||
{
|
||||
mp_text->setFont((TextTypeEngine::cFont**)(&font));
|
||||
}
|
||||
|
||||
///Gets
|
||||
const GUIHelpers::RGBA& cLabel::getFontColour() const
|
||||
{
|
||||
return mp_text->getColour();
|
||||
}
|
||||
|
||||
const unsigned long int cLabel::getFontSize() const
|
||||
{
|
||||
return mp_text->getSize();
|
||||
}
|
||||
|
||||
const TextTypeEngine::cFont* cLabel::getFont() const
|
||||
{
|
||||
return mp_text->getFont();
|
||||
}
|
||||
|
||||
const cString& cLabel::getText() const
|
||||
{
|
||||
return mp_text->getText();
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cLabel::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::CLABEL;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cLabel::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::GREEN;
|
||||
}
|
||||
|
||||
// /*virtual*/ void cLabel::Resize()
|
||||
// {
|
||||
// RebuildLayout(this->getLayout());
|
||||
// cWindow::RePos();
|
||||
// }
|
||||
|
||||
/*virtual*/ void cLabel::RebuildLayout(const GUIHelpers::eLayout& layout)
|
||||
{
|
||||
SetSize();
|
||||
}
|
||||
|
||||
void cLabel::SetSize()
|
||||
{
|
||||
if (mp_text != nullptr) {
|
||||
long int y = mp_text->getSize();
|
||||
long int x = (mp_text->getText().length() * y);
|
||||
|
||||
GUIHelpers::Size size = { x, y };
|
||||
// size.x += this->getPadding().x + this->getPadding().w;
|
||||
// size.y += this->getPadding().y + this->getPadding().z;
|
||||
this->setSize(size);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#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:
|
||||
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::RGBA& colour );
|
||||
void setFontSize( const unsigned long int size );
|
||||
void setText( const cString& text );
|
||||
void setFont( const TextTypeEngine::cFont* font );
|
||||
|
||||
///Gets
|
||||
const GUIHelpers::RGBA& getFontColour() const;
|
||||
const unsigned long int getFontSize() const;
|
||||
const TextTypeEngine::cFont* getFont() const;
|
||||
const cString& getText() const;
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
|
||||
|
||||
//virtual void Resize();
|
||||
virtual void RebuildLayout(const GUIHelpers::eLayout& layout);
|
||||
|
||||
private:
|
||||
void SetSize();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
VideoEngine::cSprite m_sprite;
|
||||
TextTypeEngine::cText* mp_text;// = nullptr
|
||||
};/// END CLASS DEFINITION cLabel
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CLABEL_HPP_
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "cLayout.hpp"
|
||||
|
||||
using GUIEngine::cLayout;
|
||||
|
||||
/*static*/ const cString cLayout::sNAME = "layout";
|
||||
/*static*/ const GUIHelpers::eOrientation cLayout::sORIENTATION = GUIHelpers::eOrientation::VERTICAL;
|
||||
|
||||
cLayout::cLayout(cWindow* parent, const signed int id, 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*/)
|
||||
{
|
||||
Create(parent, id, orientation, align, layout, pos, size, padding, name);
|
||||
}
|
||||
|
||||
/*virtual*/ cLayout::~cLayout()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
/*virtual*/ void cLayout::Create(cWindow* parent, const signed int id, 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*/)
|
||||
{
|
||||
GUIHelpers::eOrientation ori = orientation;
|
||||
if (ori == GUIHelpers::eOrientation::DEFAULT_ORIENTATION)
|
||||
ori = sORIENTATION;
|
||||
cWindow::Create(parent, id, ori, align, layout, pos, size, padding, name);
|
||||
if (this->getParent() != nullptr) {
|
||||
this->getParent()->AddChild(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ void cLayout::Display()
|
||||
{
|
||||
cWindow::Display();
|
||||
}
|
||||
|
||||
///Set
|
||||
|
||||
///Get
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cLayout::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::CLAYOUT;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cLayout::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::BLUE;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef _CLAYOUT_HPP_
|
||||
#define _CLAYOUT_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cWindow.hpp"
|
||||
|
||||
#include "GUIHelpers/GUIUtility.hpp"
|
||||
#include "GUIHelpers/Enums.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace GUIEngine {
|
||||
class EXPORT_FROM_MYDLL cLayout : public cWindow
|
||||
{
|
||||
public:
|
||||
static const cString sNAME; /*= "layout";*/
|
||||
static const GUIHelpers::eOrientation sORIENTATION; /*= GUIHelpers::eOrientation::VERTICAL;*/
|
||||
|
||||
cLayout( 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 ~cLayout();
|
||||
|
||||
///Functions
|
||||
virtual void Create( cWindow* parent, const signed int id, 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 void Display();
|
||||
|
||||
///Set
|
||||
|
||||
///Get
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
|
||||
private:
|
||||
GUIHelpers::eOrientation m_orientation;
|
||||
};/// END CLASS DEFINITION cLayout
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CLAYOUT_HPP_
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "cPanel.hpp"
|
||||
|
||||
|
||||
using GUIEngine::cPanel;
|
||||
|
||||
/*static*/ const UtilityEngine::cString cPanel::sNAME = "panel";
|
||||
|
||||
cPanel::cPanel( 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*/ )
|
||||
{
|
||||
Create( parent, id, orientation, align, layout, pos, size, padding, name );
|
||||
}
|
||||
|
||||
/*virtual*/ cPanel::~cPanel()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
/*virtual*/ void cPanel::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*/)
|
||||
{
|
||||
padding;
|
||||
cLayout::Create( parent, id, orientation, align, layout, pos, size, { 0,0,0,0 }, name );
|
||||
}
|
||||
|
||||
/*virtual*/ void cPanel::Display()
|
||||
{
|
||||
cLayout::Display();
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cPanel::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::CPANEL;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cPanel::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::RED;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef _CPANEL_HPP_
|
||||
#define _CPANEL_HPP_
|
||||
|
||||
/** C++ Header Files **/
|
||||
#include <vector>
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cLayout.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
namespace GUIEngine {
|
||||
class EXPORT_FROM_MYDLL cPanel : public GUIEngine::cLayout
|
||||
{
|
||||
public:
|
||||
static const UtilityEngine::cString sNAME; /*= "panel";*/
|
||||
|
||||
public:
|
||||
cPanel( 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 ~cPanel();
|
||||
|
||||
///Functions
|
||||
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 );
|
||||
|
||||
virtual void Display();
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
|
||||
private:
|
||||
};/// END CLASS DEFINITION cPanel
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CPANEL_HPP_
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "cTextButton.hpp"
|
||||
|
||||
using GUIEngine::cTextButton;
|
||||
|
||||
/*static*/ const cString cTextButton::sNAME = "textButton";
|
||||
|
||||
cTextButton::cTextButton(cWindow* parent, const signed int id, const cString& text, const GUIHelpers::eAlign& align /*= GUIHelpers::eAlign::CENTER*/,
|
||||
const GUIHelpers::eLayout& layout /*= GUIHelpers::eLayout::FILL_PARENT*/, const GUIHelpers::Position& pos /*= POSITION*/,
|
||||
const GUIHelpers::Size& size /*= SIZE*/, const GUIHelpers::Padding& padding /*= PADDING*/, const cString& name /*= NAME*/)
|
||||
: m_label(this, -1, text)
|
||||
{
|
||||
Create(parent, id, text, align, layout, pos, size, padding, name);
|
||||
}
|
||||
|
||||
/*virtual*/ cTextButton::~cTextButton()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
void cTextButton::Create(cWindow* parent, const signed int id, const cString& text, const GUIHelpers::eAlign& align /*= GUIHelpers::eAlign::CENTER*/,
|
||||
const GUIHelpers::eLayout& layout /*= GUIHelpers::eLayout::FILL_PARENT*/, const GUIHelpers::Position& pos /*= POSITION*/,
|
||||
const GUIHelpers::Size& size /*= SIZE*/, const GUIHelpers::Padding& padding /*= PADDING*/, const cString& name /*= NAME*/)
|
||||
{
|
||||
cButton::Create(parent, id, align, layout, pos, size, padding, name);
|
||||
setText(text);
|
||||
}
|
||||
|
||||
//Sets
|
||||
void cTextButton::setText(const cString& text)
|
||||
{
|
||||
m_label.setText(text);
|
||||
}
|
||||
|
||||
void cTextButton::setTextColour(const GUIHelpers::RGBA& colour)
|
||||
{
|
||||
m_label.setFontColour(colour);
|
||||
}
|
||||
|
||||
void cTextButton::setTextSize(const unsigned long int size)
|
||||
{
|
||||
m_label.setSize(size);
|
||||
}
|
||||
|
||||
///Gets
|
||||
const cString cTextButton::getText() const
|
||||
{
|
||||
return m_label.getText();
|
||||
}
|
||||
|
||||
const GUIHelpers::RGBA cTextButton::getTextColour()
|
||||
{
|
||||
return m_label.getFontColour();
|
||||
}
|
||||
|
||||
const unsigned long int cTextButton::getTextSize()
|
||||
{
|
||||
return m_label.getFontSize();
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cTextButton::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::CTEXTBUTTON;
|
||||
}
|
||||
|
||||
void CreateLabel()
|
||||
{}
|
||||
|
||||
void GenerateImage()
|
||||
{}
|
||||
|
||||
void GenerateTexture()
|
||||
{}
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef _CTEXTBUTTON_HPP_
|
||||
#define _CTEXTBUTTON_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cButton.hpp"
|
||||
#include "cLabel.hpp"
|
||||
|
||||
#include "GUIHelpers/Enums.hpp"
|
||||
#include "GUIHelpers/GUIUtility.hpp"
|
||||
#include "../VideoEngine/cSprite.hpp"
|
||||
#include "../VideoEngine/cImage.hpp"
|
||||
#include "../MathEngine/iVector/iVector2.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace GUIEngine {
|
||||
class EXPORT_FROM_MYDLL cTextButton : public cButton
|
||||
{
|
||||
public:
|
||||
static const cString sNAME; /*= "button";*/
|
||||
|
||||
cTextButton(cWindow* parent, const signed int id, const cString& text, const GUIHelpers::eAlign& align = GUIHelpers::eAlign::CENTER,
|
||||
const GUIHelpers::eLayout& layout = GUIHelpers::eLayout::FILL_PARENT, const GUIHelpers::Position& pos = sPOSITION,
|
||||
const GUIHelpers::Size& size = sSIZE, const GUIHelpers::Padding& padding = sPADDING, const cString& name = sNAME);
|
||||
virtual ~cTextButton();
|
||||
|
||||
///Functions
|
||||
void Create(cWindow* parent, const signed int id, const cString& text, const GUIHelpers::eAlign& align = GUIHelpers::eAlign::CENTER,
|
||||
const GUIHelpers::eLayout& layout = GUIHelpers::eLayout::FILL_PARENT, const GUIHelpers::Position& pos = sPOSITION,
|
||||
const GUIHelpers::Size& size = sSIZE, const GUIHelpers::Padding& padding = sPADDING, const cString& name = sNAME);
|
||||
|
||||
//Sets
|
||||
void setText( const cString& text );
|
||||
void setTextColour( const GUIHelpers::RGBA& colour );
|
||||
void setTextSize( const unsigned long int size );
|
||||
|
||||
///Gets
|
||||
const cString getText() const;
|
||||
const GUIHelpers::RGBA getTextColour();
|
||||
const unsigned long int getTextSize();
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
private:
|
||||
void CreateLabel();
|
||||
void GenerateImage();
|
||||
void GenerateTexture();
|
||||
|
||||
private:
|
||||
cLabel m_label;// = nullptr
|
||||
};/// END CLASS DEFINITION cButton
|
||||
}/// END NAMESPACE DEFINITION GUIEngine
|
||||
#endif/// END IFNDEF _CBUTTON_HPP_
|
||||
@@ -0,0 +1,546 @@
|
||||
#include "cWindow.hpp"
|
||||
|
||||
|
||||
#include "../FXEngine/cGFX.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::RGBA 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()
|
||||
{
|
||||
for (unsigned int i = 0; i < m_children.size(); ++i) {
|
||||
delete m_children[i];
|
||||
m_children[i] = nullptr;
|
||||
}
|
||||
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);
|
||||
setPosition(pos);
|
||||
setSize(size);
|
||||
setPadding(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();
|
||||
}
|
||||
|
||||
DebugDisplay();
|
||||
}
|
||||
|
||||
///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);
|
||||
}
|
||||
|
||||
const bool cWindow::RemoveChild( cWindow* obj )
|
||||
{
|
||||
bool rtn = false;
|
||||
std::vector<cWindow*>::iterator it;
|
||||
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
if (obj == (*it)) {
|
||||
m_children.erase(it);
|
||||
rtn = true;
|
||||
//break out of the for loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
///Sets
|
||||
/*static*/ void cWindow::PositionDefault( const GUIHelpers::Position& pos )
|
||||
{
|
||||
if (pos.x >= 0)
|
||||
sPOSITION = pos;
|
||||
}
|
||||
|
||||
/*static*/ void cWindow::SizeDefault( const GUIHelpers::Size& size )
|
||||
{
|
||||
if (size.x >= 0)
|
||||
sSIZE = size;
|
||||
}
|
||||
|
||||
/*static*/ void cWindow::PaddingDefault( const GUIHelpers::Padding& pad )
|
||||
{
|
||||
if (pad.x >= 0)
|
||||
sPADDING = pad;
|
||||
}
|
||||
|
||||
/*static*/ void cWindow::AlignDefault( const GUIHelpers::eAlign& align )
|
||||
{
|
||||
if (align != GUIHelpers::eAlign::DEFAULT_ALIGN)
|
||||
sALIGN = align;
|
||||
}
|
||||
|
||||
/*static*/ void cWindow::LayoutDefault( const GUIHelpers::eLayout& layout )
|
||||
{
|
||||
if (layout != GUIHelpers::eLayout::DEFAULT_LAYOUT)
|
||||
sLAYOUT = layout;
|
||||
}
|
||||
|
||||
/*static*/ void cWindow::OrientationDefault( const GUIHelpers::eOrientation& orientation )
|
||||
{
|
||||
if (orientation != GUIHelpers::eOrientation::DEFAULT_ORIENTATION)
|
||||
sORIENTATION = orientation;
|
||||
}
|
||||
|
||||
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;
|
||||
RebuildPos();
|
||||
}
|
||||
|
||||
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*/ )
|
||||
{
|
||||
if (pos.x < 0)
|
||||
m_pos = cWindow::sPOSITION;
|
||||
else
|
||||
m_pos = pos;
|
||||
}
|
||||
|
||||
void cWindow::setSize( const GUIHelpers::Size& size /*= sSIZE*/ )
|
||||
{
|
||||
if (size.x < 0)
|
||||
m_size = cWindow::sSIZE;
|
||||
else
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
void cWindow::setPadding( const GUIHelpers::Padding& padding /*= PADDING*/ )
|
||||
{
|
||||
if (padding.x < 0)
|
||||
m_padding = cWindow::sPADDING;
|
||||
else
|
||||
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::Position cWindow::getCenter( const bool pad /*= true*/ ) const
|
||||
{
|
||||
GUIHelpers::Position rtn = { 0, 0 };
|
||||
rtn.x = (m_size.x / 2) + m_pos.x;
|
||||
rtn.y = (m_size.y / 2) + m_pos.y;
|
||||
if (pad == true) {
|
||||
rtn.x += (m_padding.x - m_padding.w);
|
||||
rtn.y += (m_padding.y - m_padding.z);
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
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 bool pad /*= true*/ ) const
|
||||
{
|
||||
GUIHelpers::Position rtn = m_pos;
|
||||
|
||||
if (pad == false) {
|
||||
rtn.x -= m_padding.x;
|
||||
rtn.y -= m_padding.y;
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const GUIHelpers::Size cWindow::getSize( const bool pad /*= true*/ ) const
|
||||
{
|
||||
GUIHelpers::Size rtn = m_size;
|
||||
|
||||
if (pad == true) {
|
||||
rtn.x += m_padding.x + m_padding.w;
|
||||
rtn.y += m_padding.y + m_padding.z;
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const GUIHelpers::Size cWindow::getChildrenSize( const cWindow* ignore /*= nullptr*/ )
|
||||
{
|
||||
GUIHelpers::Size rtn = { 0, 0 };
|
||||
|
||||
std::vector<cWindow*>::iterator it;
|
||||
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
if ((ignore == nullptr) || ((*it) != ignore))
|
||||
rtn += (*it)->getSize();
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
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) {
|
||||
GUIHelpers::Position myPos = mp_parent->getPosition(false);
|
||||
myPos.x += m_padding.x;
|
||||
myPos.y += m_padding.y;
|
||||
mySize = mp_parent->getSize(false);
|
||||
|
||||
if (mp_parent->getType() == GUIHelpers::eType::CLAYOUT) {
|
||||
if (mp_parent->getChildren().size() > 1)
|
||||
mySize -= mp_parent->getChildrenSize(this);
|
||||
if (mp_parent->getOrientation() == GUIHelpers::eOrientation::VERTICAL)
|
||||
mySize.x = m_size.x;
|
||||
if (mp_parent->getOrientation() == GUIHelpers::eOrientation::HORIZONTAL)
|
||||
mySize.y = m_size.y;
|
||||
}
|
||||
|
||||
mySize.x -= m_padding.x + m_padding.w;
|
||||
mySize.y -= m_padding.y + m_padding.z;
|
||||
m_pos = myPos;
|
||||
m_size = mySize;
|
||||
}
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
(*it)->Resize();
|
||||
}
|
||||
break;
|
||||
case GUIHelpers::eLayout::WRAP_CONTENT:
|
||||
GUIHelpers::Size size = { 0, 0 };
|
||||
if (m_children.size() > 0) {
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
(*it)->Resize();
|
||||
size = (*it)->getSize();
|
||||
AddSize(size.x, size.y, mySize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (mp_parent != nullptr)
|
||||
m_pos = mp_parent->getCenter();
|
||||
}
|
||||
m_size = mySize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ void cWindow::RePos()
|
||||
{
|
||||
std::vector<cWindow*>::iterator it;
|
||||
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
(*it)->RePos();
|
||||
}
|
||||
|
||||
if (this->getType() == GUIHelpers::eType::CLAYOUT) {
|
||||
GUIHelpers::Position prtCenter = getCenter();
|
||||
GUIHelpers::Position ourSet = prtCenter;
|
||||
GUIHelpers::Size totalSize = { 0, 0 };
|
||||
GUIHelpers::Position totalCenter = { 0, 0 };
|
||||
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
totalSize += (*it)->getSize();
|
||||
}
|
||||
|
||||
totalCenter.x = totalSize.x / 2;
|
||||
totalCenter.y = totalSize.y / 2;
|
||||
|
||||
ourSet.x -= totalCenter.x;
|
||||
ourSet.y -= totalCenter.y;
|
||||
|
||||
GUIHelpers::Position posSet = ourSet;
|
||||
GUIHelpers::Position posNext = posSet;
|
||||
for (it = m_children.begin(); it < m_children.end(); it++) {
|
||||
posSet = posNext;
|
||||
GUIHelpers::Padding pad = (*it)->getPadding();
|
||||
GUIHelpers::Size size = (*it)->getSize(false);
|
||||
if (m_orientation == GUIHelpers::eOrientation::HORIZONTAL) {
|
||||
posSet.x += pad.x;
|
||||
posSet.y = (pad.y - pad.z - (size.y / 2)) + prtCenter.y;
|
||||
|
||||
posNext = posSet;
|
||||
|
||||
posNext.x += size.x + pad.w;
|
||||
//posNext.y = ourSet.y;
|
||||
}
|
||||
else {
|
||||
posSet.x = (pad.x - pad.w - (size.x / 2)) + prtCenter.x;
|
||||
posSet.y += pad.y;
|
||||
|
||||
posNext = posSet;
|
||||
|
||||
//posNext.x = ourSet.x;
|
||||
posNext.y += size.y + pad.z;
|
||||
}
|
||||
|
||||
(*it)->setPosition(posSet);
|
||||
(*it)->RebuildPos();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ void cWindow::RebuildPos()
|
||||
{
|
||||
if ((mp_parent != nullptr) && (mp_parent->getOrientation() != GUIHelpers::eOrientation::NONE)) {
|
||||
GUIHelpers::Position prtPos = mp_parent->getPosition();
|
||||
GUIHelpers::Size prtSize = mp_parent->getSize();
|
||||
|
||||
GUIHelpers::Position pos = this->getPosition();
|
||||
GUIHelpers::Size size = this->getSize();
|
||||
|
||||
GUIHelpers::Padding pad = this->getPadding();
|
||||
|
||||
if (mp_parent->getOrientation() == GUIHelpers::eOrientation::HORIZONTAL) {
|
||||
switch (this->getAlign()) {
|
||||
default:
|
||||
case GUIHelpers::eAlign::CENTER:
|
||||
pos.y = mp_parent->getCenter().y - (this->getSize(false).y / 2);
|
||||
break;
|
||||
case GUIHelpers::eAlign::BOTTOM:
|
||||
pos.y = prtSize.y - size.y;
|
||||
break;
|
||||
case GUIHelpers::eAlign::TOP:
|
||||
pos.y = prtPos.y + pad.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mp_parent->getOrientation() == GUIHelpers::eOrientation::VERTICAL) {
|
||||
switch (this->getAlign()) {
|
||||
default:
|
||||
case GUIHelpers::eAlign::CENTER:
|
||||
pos.x = mp_parent->getCenter().x - (this->getSize(false).x / 2);
|
||||
break;
|
||||
case GUIHelpers::eAlign::RIGHT:
|
||||
pos.x = prtSize.x - size.x;
|
||||
break;
|
||||
case GUIHelpers::eAlign::LEFT:
|
||||
pos.x = prtPos.x + pad.x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->setPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cWindow::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::WHITE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void cWindow::DebugDisplay() const
|
||||
{
|
||||
// Debug Level 0 display nothing
|
||||
// Debug Level 1 display a coloured rectangle and center pixel for each GUI element.
|
||||
// Debug Level 2 display the type of GUI element
|
||||
unsigned long int debugLvl = GUIEngine::cGUI::Inst().getDebugLevel();
|
||||
if (debugLvl >= 1) {
|
||||
SDL_Rect rect;
|
||||
rect.x = m_pos.x;
|
||||
rect.y = m_pos.y;
|
||||
rect.w = m_pos.x + m_size.x;
|
||||
rect.h = m_pos.y + m_size.y;
|
||||
|
||||
GUIHelpers::Position strPos = getCenter();
|
||||
|
||||
GUIHelpers::RGBA colour = getDebugColour();
|
||||
FXEngine::cGFX::Inst().Pixel(strPos.x, strPos.y, colour);
|
||||
|
||||
cString str = "";
|
||||
str.format("X: %d Y: %d", strPos.x, strPos.y);
|
||||
FXEngine::cGFX::Inst().StringDefault(str, { strPos.x + 2, strPos.y + 2, 0, 0 }, colour);
|
||||
|
||||
if (debugLvl >= 2) {
|
||||
SDL_Rect typePos = { 2, 2, 0, 0 };
|
||||
cString type = "";
|
||||
switch (getType()) {
|
||||
case GUIHelpers::eType::CPANEL:
|
||||
type = "Panel";
|
||||
break;
|
||||
case GUIHelpers::eType::CLAYOUT:
|
||||
type = "Layout";
|
||||
break;
|
||||
case GUIHelpers::eType::CLABEL:
|
||||
typePos = { -10, -10, 0, 0 };
|
||||
type = "Label";
|
||||
break;
|
||||
default:
|
||||
type = "";
|
||||
}
|
||||
|
||||
typePos.x += m_pos.x;
|
||||
typePos.y += m_pos.y;
|
||||
|
||||
FXEngine::cGFX::Inst().StringDefault(type, typePos, colour);
|
||||
|
||||
// if (debugLvl >= 3) {
|
||||
// GUIHelpers::Position pos = getPosPPad();
|
||||
// //GUIHelpers::Size size = getSizePPad();
|
||||
// SDL_Rect box{ 0, 0, 0, 0 };
|
||||
// box.x += pos.x;
|
||||
// box.y += pos.y;
|
||||
// box.h += pos.y + m_size.y + m_padding.y + m_padding.z;
|
||||
// box.w += pos.x + m_padding.x;
|
||||
//
|
||||
// FXEngine::cGFX::Inst().Box(box, colour);
|
||||
// }
|
||||
}
|
||||
|
||||
FXEngine::cGFX::Inst().Rectangle(rect, colour);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
#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
|
||||
{
|
||||
protected:
|
||||
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::RGBA 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 );
|
||||
|
||||
public:
|
||||
virtual ~cWindow();
|
||||
|
||||
protected:
|
||||
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 );
|
||||
|
||||
const bool RemoveChild( cWindow* obj );
|
||||
|
||||
///Sets
|
||||
static void PositionDefault( const GUIHelpers::Position& pos );
|
||||
static void SizeDefault( const GUIHelpers::Size& size );
|
||||
static void PaddingDefault( const GUIHelpers::Padding& pad );
|
||||
static void AlignDefault( const GUIHelpers::eAlign& align );
|
||||
static void LayoutDefault( const GUIHelpers::eLayout& layout );
|
||||
static void OrientationDefault( const GUIHelpers::eOrientation& orientation );
|
||||
|
||||
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::Position getCenter( const bool pad = true ) const;
|
||||
|
||||
const GUIHelpers::eOrientation& getOrientation() const;
|
||||
const GUIHelpers::eAlign& getAlign() const;
|
||||
const GUIHelpers::eLayout& getLayout() const;
|
||||
const GUIHelpers::Position getPosition( const bool pad = true ) const;
|
||||
const GUIHelpers::Size getSize( const bool pad = true ) const;
|
||||
const GUIHelpers::Padding& getPadding() const;
|
||||
const GUIHelpers::Size& getContentSize() const;
|
||||
const cString& getName() const;
|
||||
|
||||
const GUIHelpers::Size getChildrenSize( const cWindow* ignore = nullptr );
|
||||
|
||||
cWindow* getParent();
|
||||
|
||||
virtual const GUIHelpers::eType getType() const;
|
||||
|
||||
virtual void Resize();
|
||||
virtual void RebuildLayout( const GUIHelpers::eLayout& layout );
|
||||
|
||||
virtual void RePos();
|
||||
virtual void RebuildPos();
|
||||
|
||||
virtual const GUIHelpers::RGBA getDebugColour() const;
|
||||
|
||||
/*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;
|
||||
|
||||
void DebugDisplay() 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_
|
||||
Reference in New Issue
Block a user