Formatted EVERYTHING
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
#pragma once
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
class Button : public Element
|
||||
{
|
||||
|
||||
};
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class Button : public Element {};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
|
||||
@@ -1,70 +1,35 @@
|
||||
#include "Element.h"
|
||||
#include "UI/System.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "UI/System.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Element::Element()
|
||||
: dirty(false)
|
||||
, enabled(false)
|
||||
{
|
||||
}
|
||||
Element::Element() : dirty(false), enabled(false) {}
|
||||
|
||||
Element::~Element()
|
||||
{
|
||||
}
|
||||
Element::~Element() {}
|
||||
|
||||
void Element::setParent(PElement element)
|
||||
{
|
||||
if(parent != nullptr)
|
||||
{
|
||||
void Element::setParent(PElement element) {
|
||||
if (parent != nullptr) {
|
||||
parent->removeChild(this);
|
||||
}
|
||||
parent = element;
|
||||
}
|
||||
|
||||
PElement Element::getParent() const
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
PElement Element::getParent() const { return parent; }
|
||||
|
||||
void Element::addChild(PElement element)
|
||||
{
|
||||
children.add(element);
|
||||
}
|
||||
void Element::addChild(PElement element) { children.add(element); }
|
||||
|
||||
void Element::removeChild(PElement element)
|
||||
{
|
||||
children.remove(element, false);
|
||||
}
|
||||
void Element::removeChild(PElement element) { children.remove(element, false); }
|
||||
|
||||
const Array<PElement> Element::getChildren()
|
||||
{
|
||||
return children;
|
||||
}
|
||||
const Array<PElement> Element::getChildren() { return children; }
|
||||
|
||||
void Element::clear()
|
||||
{
|
||||
children.clear();
|
||||
}
|
||||
void Element::clear() { children.clear(); }
|
||||
|
||||
void Element::setEnabled(bool newEnabled)
|
||||
{
|
||||
enabled = newEnabled;
|
||||
}
|
||||
void Element::setEnabled(bool newEnabled) { enabled = newEnabled; }
|
||||
|
||||
bool Element::isEnabled() const
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
bool Element::isEnabled() const { return enabled; }
|
||||
|
||||
Rect& Element::getBoundingBox()
|
||||
{
|
||||
return boundingBox;
|
||||
}
|
||||
Rect& Element::getBoundingBox() { return boundingBox; }
|
||||
|
||||
const Rect Element::getBoundingBox() const
|
||||
{
|
||||
return boundingBox;
|
||||
}
|
||||
const Rect Element::getBoundingBox() const { return boundingBox; }
|
||||
@@ -1,18 +1,15 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "Math/Math.h"
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
//Element defines any part of the UI
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
// Element defines any part of the UI
|
||||
DECLARE_REF(Element)
|
||||
DECLARE_REF(System)
|
||||
class Element
|
||||
{
|
||||
public:
|
||||
class Element {
|
||||
public:
|
||||
Element();
|
||||
virtual ~Element();
|
||||
void setParent(PElement element);
|
||||
@@ -30,10 +27,11 @@ public:
|
||||
// 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:
|
||||
|
||||
protected:
|
||||
Rect boundingBox;
|
||||
bool dirty;
|
||||
|
||||
|
||||
bool enabled;
|
||||
PSystem system;
|
||||
PElement parent;
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
class Label : public Element
|
||||
{
|
||||
public:
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class Label : public Element {
|
||||
public:
|
||||
Label();
|
||||
~Label();
|
||||
private:
|
||||
|
||||
private:
|
||||
std::string text;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
|
||||
@@ -4,12 +4,6 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Panel::Panel()
|
||||
{
|
||||
|
||||
}
|
||||
Panel::Panel() {}
|
||||
|
||||
Panel::~Panel()
|
||||
{
|
||||
|
||||
}
|
||||
Panel::~Panel() {}
|
||||
@@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
DECLARE_REF(Layout)
|
||||
class Panel : Element
|
||||
{
|
||||
public:
|
||||
class Panel : Element {
|
||||
public:
|
||||
Panel();
|
||||
virtual ~Panel();
|
||||
private:
|
||||
|
||||
private:
|
||||
PLayout activeLayout;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,27 +4,18 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
HorizontalLayout::HorizontalLayout(PElement element)
|
||||
: Layout(element)
|
||||
{
|
||||
|
||||
}
|
||||
HorizontalLayout::HorizontalLayout(PElement element) : Layout(element) {}
|
||||
|
||||
HorizontalLayout::~HorizontalLayout()
|
||||
{
|
||||
|
||||
}
|
||||
HorizontalLayout::~HorizontalLayout() {}
|
||||
|
||||
void HorizontalLayout::apply()
|
||||
{
|
||||
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)
|
||||
{
|
||||
for (uint32 index = 0; index < children.size(); ++index) {
|
||||
Rect& child = children[index]->getBoundingBox();
|
||||
child.offset.x = xOffset + (index * xSize);
|
||||
child.offset.y = yOffset;
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
#include "Layout.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
class HorizontalLayout : Layout
|
||||
{
|
||||
public:
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class HorizontalLayout : Layout {
|
||||
public:
|
||||
HorizontalLayout(PElement element);
|
||||
~HorizontalLayout();
|
||||
virtual void apply() override;
|
||||
private:
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -4,12 +4,6 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Layout::Layout(PElement element)
|
||||
: element(element)
|
||||
{
|
||||
}
|
||||
Layout::Layout(PElement element) : element(element) {}
|
||||
|
||||
Layout::~Layout()
|
||||
{
|
||||
|
||||
}
|
||||
Layout::~Layout() {}
|
||||
@@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
DECLARE_REF(Element);
|
||||
class Layout
|
||||
{
|
||||
public:
|
||||
class Layout {
|
||||
public:
|
||||
Layout(PElement element);
|
||||
virtual ~Layout();
|
||||
virtual void apply() = 0;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
PElement element;
|
||||
};
|
||||
} // namespace UI
|
||||
|
||||
@@ -3,22 +3,18 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
void AddElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements)
|
||||
{
|
||||
auto parentIt = elements.find([this](RenderElement e){return e.parent == parent;});
|
||||
void AddElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements) {
|
||||
auto parentIt = elements.find([this](RenderElement e) { return e.parent == parent; });
|
||||
parentIt->referencedElement->addChild(addedElement);
|
||||
addedElement->setParent(parentIt->referencedElement);
|
||||
|
||||
elements.emplace(parentIt->referencedElement, addedElement);
|
||||
}
|
||||
|
||||
void RemoveElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements)
|
||||
{
|
||||
auto elementIt = elements.find([this](RenderElement e){return e.referencedElement == element;});
|
||||
if(!removeChildren)
|
||||
{
|
||||
for(auto child : elementIt->referencedElement->getChildren())
|
||||
{
|
||||
void RemoveElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements) {
|
||||
auto elementIt = elements.find([this](RenderElement e) { return e.referencedElement == element; });
|
||||
if (!removeChildren) {
|
||||
for (auto child : elementIt->referencedElement->getChildren()) {
|
||||
child->setParent(elementIt->referencedElement->getParent());
|
||||
}
|
||||
}
|
||||
@@ -27,55 +23,36 @@ void RemoveElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements)
|
||||
elements.remove(elementIt);
|
||||
}
|
||||
|
||||
RenderHierarchy::RenderHierarchy()
|
||||
{
|
||||
|
||||
}
|
||||
RenderHierarchy::RenderHierarchy() {}
|
||||
|
||||
RenderHierarchy::~RenderHierarchy()
|
||||
{
|
||||
|
||||
}
|
||||
RenderHierarchy::~RenderHierarchy() {}
|
||||
|
||||
void RenderHierarchy::addElement(PElement addedElement)
|
||||
{
|
||||
void RenderHierarchy::addElement(PElement addedElement) {
|
||||
std::scoped_lock lock(updateLock);
|
||||
updates.add(new AddElementRenderHierarchyUpdate{
|
||||
addedElement.getHandle(),
|
||||
addedElement->getParent().getHandle()
|
||||
});
|
||||
updates.add(new AddElementRenderHierarchyUpdate{addedElement.getHandle(), addedElement->getParent().getHandle()});
|
||||
}
|
||||
|
||||
void RenderHierarchy::removeElement(PElement elementToRemove)
|
||||
{
|
||||
void RenderHierarchy::removeElement(PElement elementToRemove) {
|
||||
std::scoped_lock lock(updateLock);
|
||||
updates.add(new RemoveElementRenderHierarchyUpdate{
|
||||
elementToRemove.getHandle(),
|
||||
});
|
||||
}
|
||||
|
||||
void RenderHierarchy::moveElement(PElement elementToMove, PElement newParent)
|
||||
{
|
||||
void RenderHierarchy::moveElement(PElement elementToMove, PElement newParent) {
|
||||
std::scoped_lock lock(updateLock);
|
||||
updates.add(new AddElementRenderHierarchyUpdate{
|
||||
elementToMove.getHandle(),
|
||||
newParent.getHandle()
|
||||
});
|
||||
updates.add(new RemoveElementRenderHierarchyUpdate{
|
||||
elementToMove.getHandle()
|
||||
});
|
||||
updates.add(new AddElementRenderHierarchyUpdate{elementToMove.getHandle(), newParent.getHandle()});
|
||||
updates.add(new RemoveElementRenderHierarchyUpdate{elementToMove.getHandle()});
|
||||
}
|
||||
|
||||
void RenderHierarchy::updateHierarchy()
|
||||
{
|
||||
void RenderHierarchy::updateHierarchy() {
|
||||
List<RenderHierarchyUpdate*> localUpdates;
|
||||
{ // make a local copy of the updates so we dont hold the lock for too long
|
||||
std::scoped_lock lock(updateLock);
|
||||
localUpdates = updates;
|
||||
updates.clear();
|
||||
}
|
||||
for(auto update : localUpdates)
|
||||
{
|
||||
for (auto update : localUpdates) {
|
||||
update->apply(drawElements);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +1,56 @@
|
||||
#pragma once
|
||||
#include "Elements/Element.h"
|
||||
#include "Containers/List.h"
|
||||
#include "Elements/Element.h"
|
||||
#include "Graphics/Resources.h"
|
||||
#include "Graphics/Texture.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
struct RenderElementStyle
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
struct RenderElementStyle {
|
||||
Vector position = Vector(0, 0, 0);
|
||||
uint32 backgroundImageIndex = UINT32_MAX;
|
||||
Vector backgroundColor = Vector(1, 1, 1);
|
||||
float opacity = 1.0f;
|
||||
//Vector4 borderBottomColor = Vector4(1, 1, 1, 1);
|
||||
//Vector4 borderLeftColor = Vector4(1, 1, 1, 1);
|
||||
//Vector4 borderRightColor = Vector4(1, 1, 1, 1);
|
||||
//Vector4 borderTopColor = Vector4(1, 1, 1, 1);
|
||||
//float borderBottomLeftRadius = 0;
|
||||
//float borderBottomRightRadius = 0;
|
||||
//float borderTopLeftRadius = 0;
|
||||
//float borderTopRightRadius = 0;
|
||||
// Vector4 borderBottomColor = Vector4(1, 1, 1, 1);
|
||||
// Vector4 borderLeftColor = Vector4(1, 1, 1, 1);
|
||||
// Vector4 borderRightColor = Vector4(1, 1, 1, 1);
|
||||
// Vector4 borderTopColor = Vector4(1, 1, 1, 1);
|
||||
// float borderBottomLeftRadius = 0;
|
||||
// float borderBottomRightRadius = 0;
|
||||
// float borderTopLeftRadius = 0;
|
||||
// float borderTopRightRadius = 0;
|
||||
Vector2 dimensions = Vector2(1, 1);
|
||||
};
|
||||
class RenderElement
|
||||
{
|
||||
public:
|
||||
class RenderElement {
|
||||
public:
|
||||
RenderElement() = default;
|
||||
RenderElement(Element* parent, Element* referencedElement)
|
||||
: parent(parent)
|
||||
, referencedElement(referencedElement)
|
||||
{}
|
||||
RenderElement(Element* parent, Element* referencedElement) : parent(parent), referencedElement(referencedElement) {}
|
||||
~RenderElement() = default;
|
||||
Element* parent;
|
||||
Element* referencedElement;
|
||||
};
|
||||
|
||||
struct RenderHierarchyUpdate
|
||||
{
|
||||
struct RenderHierarchyUpdate {
|
||||
virtual void apply(Array<RenderElement>& elements) = 0;
|
||||
};
|
||||
|
||||
struct AddElementRenderHierarchyUpdate : public RenderHierarchyUpdate
|
||||
{
|
||||
struct AddElementRenderHierarchyUpdate : public RenderHierarchyUpdate {
|
||||
Element* addedElement;
|
||||
Element* parent;
|
||||
AddElementRenderHierarchyUpdate(Element* addedElement, Element* parent)
|
||||
: addedElement(addedElement)
|
||||
, parent(parent)
|
||||
{}
|
||||
AddElementRenderHierarchyUpdate(Element* addedElement, Element* parent) : addedElement(addedElement), parent(parent) {}
|
||||
virtual void apply(Array<RenderElement>& elements) override;
|
||||
};
|
||||
|
||||
struct RemoveElementRenderHierarchyUpdate : public RenderHierarchyUpdate
|
||||
{
|
||||
struct RemoveElementRenderHierarchyUpdate : public RenderHierarchyUpdate {
|
||||
Element* element;
|
||||
bool removeChildren;
|
||||
RemoveElementRenderHierarchyUpdate(Element* elementToRemove, bool removeChildren = false)
|
||||
: element(elementToRemove)
|
||||
, removeChildren(removeChildren)
|
||||
{}
|
||||
: element(elementToRemove), removeChildren(removeChildren) {}
|
||||
virtual void apply(Array<RenderElement>& elements) override;
|
||||
};
|
||||
class RenderHierarchy
|
||||
{
|
||||
public:
|
||||
class RenderHierarchy {
|
||||
public:
|
||||
RenderHierarchy();
|
||||
~RenderHierarchy();
|
||||
// logic thread interface, queue hierarchy changes
|
||||
@@ -75,7 +60,8 @@ public:
|
||||
|
||||
// render thread interface, apply changes
|
||||
void updateHierarchy();
|
||||
private:
|
||||
|
||||
private:
|
||||
static_assert(std::is_trivially_copyable_v<RenderElement>);
|
||||
// List of all drawable elements in draw order
|
||||
Array<RenderElement> drawElements;
|
||||
|
||||
+12
-24
@@ -1,33 +1,21 @@
|
||||
#include "System.h"
|
||||
#include "Elements/Panel.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "Elements/Panel.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
System::System()
|
||||
{
|
||||
|
||||
System::System() {}
|
||||
|
||||
System::~System() {}
|
||||
|
||||
void System::update() {}
|
||||
|
||||
void System::updateViewport(Gfx::PViewport) {
|
||||
// TODO set viewport FoV to 0
|
||||
}
|
||||
|
||||
System::~System()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void System::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void System::updateViewport(Gfx::PViewport)
|
||||
{
|
||||
//TODO set viewport FoV to 0
|
||||
}
|
||||
|
||||
Component::Camera System::getVirtualCamera() const
|
||||
{
|
||||
return virtualCamera;
|
||||
}
|
||||
Component::Camera System::getVirtualCamera() const { return virtualCamera; }
|
||||
|
||||
+9
-10
@@ -1,23 +1,22 @@
|
||||
#pragma once
|
||||
#include "Graphics/RenderPass/TextPass.h"
|
||||
#include "Graphics/RenderPass/UIPass.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include "RenderHierarchy.h"
|
||||
#include "Graphics/RenderPass/UIPass.h"
|
||||
#include "Graphics/RenderPass/TextPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
DECLARE_REF(Panel)
|
||||
class System
|
||||
{
|
||||
public:
|
||||
class System {
|
||||
public:
|
||||
System();
|
||||
virtual ~System();
|
||||
void update();
|
||||
void updateViewport(Gfx::PViewport viewport);
|
||||
Component::Camera getVirtualCamera() const;
|
||||
private:
|
||||
|
||||
private:
|
||||
Component::Camera virtualCamera;
|
||||
PPanel rootPanel;
|
||||
RenderHierarchy hierarchy;
|
||||
|
||||
@@ -4,27 +4,18 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
VerticalLayout::VerticalLayout(PElement element)
|
||||
: Layout(element)
|
||||
{
|
||||
|
||||
}
|
||||
VerticalLayout::VerticalLayout(PElement element) : Layout(element) {}
|
||||
|
||||
VerticalLayout::~VerticalLayout()
|
||||
{
|
||||
|
||||
}
|
||||
VerticalLayout::~VerticalLayout() {}
|
||||
|
||||
void VerticalLayout::apply()
|
||||
{
|
||||
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)
|
||||
{
|
||||
for (uint32 index = 0; index < children.size(); ++index) {
|
||||
Rect& child = children[index]->getBoundingBox();
|
||||
child.offset.x = xOffset;
|
||||
child.offset.y = yOffset + (index * ySize);
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
#include "Layout.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
class VerticalLayout : Layout
|
||||
{
|
||||
public:
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class VerticalLayout : Layout {
|
||||
public:
|
||||
VerticalLayout(PElement element);
|
||||
~VerticalLayout();
|
||||
virtual void apply() override;
|
||||
private:
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user