Finished UI Render Context

This commit is contained in:
2023-12-13 22:55:13 -06:00
parent 952db756a0
commit d2c057cd53
12 changed files with 163 additions and 68 deletions

View File

@ -11,15 +11,12 @@ std::vector<std::shared_ptr<UIComponent>> UIComponent::getChildren() {
return {};
}
std::vector<struct UIShaderQuad> UIComponent::getQuads(const glm::vec2 parent) {
void UIComponent::getQuads(const glm::vec2 parent, UICanvas &ctx) {
glm::vec2 transform = parent + position;
std::vector<struct UIShaderQuad> quads = this->getSelfQuads(transform);
this->getSelfQuads(transform, ctx);
auto children = getChildren();
for(auto &c : children) {
auto childQuads = c->getQuads(transform);
quads.insert(quads.end(), childQuads.begin(), childQuads.end());
c->getQuads(transform, ctx);
}
return quads;
}

View File

@ -6,19 +6,14 @@
#pragma once
#include "ui/UIAlign.hpp"
#include "display/shader/UIShader.hpp"
#include "component/ui/UICanvas.hpp"
namespace Dawn {
class UICanvas;
class UIComponent {
protected:
virtual std::vector<struct UIShaderQuad> getSelfQuads(
const glm::vec2 t
) = 0;
virtual void getSelfQuads(const glm::vec2 t, UICanvas &ctx) = 0;
virtual std::vector<std::shared_ptr<UIComponent>> getChildren();
std::vector<struct UIShaderQuad> getQuads(const glm::vec2 parent);
void getQuads(const glm::vec2 parent, UICanvas &ctx);
public:
glm::vec2 position;

View File

@ -7,30 +7,29 @@
using namespace Dawn;
std::vector<struct UIShaderQuad> UILabel::getSelfQuads(const glm::vec2 t) {
void UILabel::getSelfQuads(const glm::vec2 t, UICanvas &ctx) {
std::vector<struct UIShaderQuad> quads;
if(this->texture == nullptr) return quads;
if(this->texture == nullptr) return;
const std::wstring text = L"Hello World!";
const std::wstring text = L"He";
glm::vec2 position = t;
glm::vec4 quad;
for(wchar_t c : text) {
auto info = texture->getCharacterData(c);
quads.push_back({
.quad = {
ctx.addQuad(
{
position.x,
position.y,
position.x + info.size.x,
position.y + info.size.y
},
.uv = info.quad,
.color = COLOR_WHITE
});
info.quad,
COLOR_WHITE,
texture->texture
);
position += info.advance;
}
return quads;
}
void UILabel::setFont(std::shared_ptr<TrueTypeTexture> texture) {

View File

@ -13,7 +13,7 @@ namespace Dawn {
std::shared_ptr<TrueTypeTexture> texture = nullptr;
protected:
std::vector<struct UIShaderQuad> getSelfQuads(const glm::vec2 t) override;
void getSelfQuads(const glm::vec2 t, UICanvas &ctx) override;
public:
void setFont(std::shared_ptr<TrueTypeTexture> texture);

View File

@ -7,12 +7,12 @@
using namespace Dawn;
std::vector<struct UIShaderQuad> UIRectangle::getSelfQuads(const glm::vec2 t) {
void UIRectangle::getSelfQuads(const glm::vec2 t, UICanvas &ctx) {
std::vector<struct UIShaderQuad> quads;
quads.push_back({
ctx.addQuad(
glm::vec4(t, t + size),
uv,
color
});
return quads;
color,
nullptr
);
}

View File

@ -9,7 +9,7 @@
namespace Dawn {
class UIRectangle final : public UIComponent {
protected:
std::vector<struct UIShaderQuad> getSelfQuads(const glm::vec2 t) override;
void getSelfQuads(const glm::vec2 t, UICanvas &ctx) override;
public:
struct Color color = COLOR_WHITE;