Basic UI quad, yay

This commit is contained in:
Dynamitos
2021-09-23 10:10:39 +02:00
parent df977110d3
commit 632d120f6d
51 changed files with 579 additions and 187 deletions
+8 -4
View File
@@ -1,8 +1,12 @@
target_sources(SeeleEngine
PRIVATE
Element.h
Element.cpp
HorizontalLayout.h
HorizontalLayout.cpp
Layout.h
Layout.cpp
RenderHierarchy.h
RenderHierarchy.cpp
UIRenderPath.h
UIRenderPath.cpp)
VerticalLayout.h
VerticalLayout.cpp)
add_subdirectory(Elements/)
-27
View File
@@ -1,27 +0,0 @@
#pragma once
#include "MinimalEngine.h"
namespace Seele
{
namespace UI
{
//Element defines any part of the UI
DECLARE_REF(Element)
class Element
{
public:
Element();
virtual ~Element();
void addElement(PElement element);
const Array<PElement> getChildren() const;
void clear();
void remove(PElement element);
void setEnabled(bool newEnabled);
bool isEnabled() const;
protected:
bool enabled;
Array<PElement> children;
};
DEFINE_REF(Element)
} // namespace UI
} // namespace Seele
+4
View File
@@ -0,0 +1,4 @@
target_sources(SeeleEngine
PRIVATE
Element.h
Element.cpp)
@@ -11,12 +11,12 @@ Element::~Element()
{
}
void Element::addElement(PElement element)
void Element::addChild(PElement element)
{
children.add(element);
children.add(element);
}
const Array<PElement> Element::getChildren() const
const Array<PElement> Element::getChildren()
{
return children;
}
@@ -39,4 +39,14 @@ void Element::setEnabled(bool newEnabled)
bool Element::isEnabled() const
{
return enabled;
}
Rect& Element::getBoundingBox()
{
return boundingBox;
}
const Rect Element::getBoundingBox() const
{
return boundingBox;
}
+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include "MinimalEngine.h"
namespace Seele
{
namespace UI
{
//Element defines any part of the UI
DECLARE_REF(Element)
class Element
{
public:
Element();
virtual ~Element();
void setParent(PElement element);
PElement getParent() const;
void addChild(PElement element);
const Array<PElement> getChildren();
void clear();
void remove(PElement element);
void setEnabled(bool newEnabled);
bool isEnabled() const;
// maybe not the healthiest inteface
// non-const version
Rect& getBoundingBox();
// The bounding box describes the relative size of any Element
// relative to the total view, meaning a bounding box of (0,0), (1,1)
// would take up the entire view
const Rect getBoundingBox() const;
protected:
Rect boundingBox;
bool enabled;
PElement parent;
Array<PElement> children;
friend class Layout;
friend class RenderElement;
};
DEFINE_REF(Element)
} // namespace UI
} // namespace Seele
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include "Element.h"
namespace Seele
{
namespace UI
{
class Panel : Element
{
public:
Panel();
virtual ~Panel();
};
} // namespace UI
} // namespace Seele
+33
View File
@@ -0,0 +1,33 @@
#include "HorizontalLayout.h"
using namespace Seele;
using namespace Seele::UI;
HorizontalLayout::HorizontalLayout(PElement element)
: Layout(element)
{
}
HorizontalLayout::~HorizontalLayout()
{
}
void HorizontalLayout::apply()
{
Array<PElement> children = element->getChildren();
const Rect parent = element->getBoundingBox();
float xOffset = parent.offset.x;
float yOffset = parent.offset.y;
float xSize = parent.size.x / children.size();
float ySize = parent.size.y;
for(uint32 index = 0; index < children.size(); ++index)
{
Rect& child = children[index]->getBoundingBox();
child.offset.x = xOffset + (index * xSize);
child.offset.y = yOffset;
child.size.x = xSize;
child.size.y = ySize;
}
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "Layout.h"
namespace Seele
{
namespace UI
{
class HorizontalLayout : Layout
{
public:
HorizontalLayout(PElement element);
~HorizontalLayout();
virtual void apply() override;
private:
};
} // namespace UI
} // namespace Seele
+14
View File
@@ -0,0 +1,14 @@
#include "Layout.h"
using namespace Seele;
using namespace Seele::UI;
Layout::Layout(PElement element)
: element(element)
{
}
Layout::~Layout()
{
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "Elements/Element.h"
namespace Seele
{
namespace UI
{
class Layout
{
public:
Layout(PElement element);
virtual ~Layout();
virtual void apply() = 0;
protected:
PElement element;
};
} // namespace UI
} // namespace Seele
+24
View File
@@ -0,0 +1,24 @@
#include "RenderHierarchy.h"
using namespace Seele;
using namespace Seele::UI;
RenderElement::RenderElement()
{
}
RenderElement::~RenderElement()
{
}
RenderHierarchy::RenderHierarchy()
{
}
RenderHierarchy::~RenderHierarchy()
{
}
+16 -2
View File
@@ -1,15 +1,29 @@
#pragma once
#include "Elements/Element.h"
namespace Seele
{
namespace UI
{
DECLARE_NAME_REF(Gfx, RenderCommand);
class RenderElement
{
public:
RenderElement();
virtual ~RenderElement();
private:
PElement referencedElement;
Gfx::PRenderCommand renderCommand;
friend class RenderHierarchy;
};
class RenderHierarchy
{
public:
RenderHierarchy();
~RenderHierarchy();
private:
// List of all drawable elements in draw order
Array<RenderElement> drawElements;
};
} // namespace UI
} // namespace Seele
View File
-20
View File
@@ -1,20 +0,0 @@
#pragma once
#include "Window/RenderPath.h"
#include "Element.h"
namespace Seele
{
class UIRenderPath : public RenderPath
{
public:
UIRenderPath();
virtual ~UIRenderPath();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
private:
Array<UI::PElement> rootElements;
};
DEFINE_REF(UIRenderPath);
} // namespace Seele
+33
View File
@@ -0,0 +1,33 @@
#include "VerticalLayout.h"
using namespace Seele;
using namespace Seele::UI;
VerticalLayout::VerticalLayout(PElement element)
: Layout(element)
{
}
VerticalLayout::~VerticalLayout()
{
}
void VerticalLayout::apply()
{
Array<PElement> children = element->getChildren();
const Rect parent = element->getBoundingBox();
float xOffset = parent.offset.x;
float yOffset = parent.offset.y;
float xSize = parent.size.x;
float ySize = parent.size.y / children.size();
for(uint32 index = 0; index < children.size(); ++index)
{
Rect& child = children[index]->getBoundingBox();
child.offset.x = xOffset;
child.offset.y = yOffset + (index * ySize);
child.size.x = xSize;
child.size.y = ySize;
}
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "Layout.h"
namespace Seele
{
namespace UI
{
class VerticalLayout : Layout
{
public:
VerticalLayout(PElement element);
~VerticalLayout();
virtual void apply() override;
private:
};
} // namespace UI
} // namespace Seele