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