Basic UI quad, yay
This commit is contained in:
@@ -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/)
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
class Panel : Element
|
||||
{
|
||||
public:
|
||||
Panel();
|
||||
virtual ~Panel();
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "Layout.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Layout::Layout(PElement element)
|
||||
: element(element)
|
||||
{
|
||||
}
|
||||
|
||||
Layout::~Layout()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "RenderHierarchy.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
RenderElement::RenderElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderElement::~RenderElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderHierarchy::RenderHierarchy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderHierarchy::~RenderHierarchy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user