Uniform arrays working.
This commit is contained in:
10
src/dawn/ui/CMakeLists.txt
Normal file
10
src/dawn/ui/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UIComponent.cpp
|
||||
UIRectangle.cpp
|
||||
)
|
13
src/dawn/ui/UIAlign.hpp
Normal file
13
src/dawn/ui/UIAlign.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct UIAlign {
|
||||
glm::vec2 position;
|
||||
};
|
||||
}
|
37
src/dawn/ui/UIComponent.cpp
Normal file
37
src/dawn/ui/UIComponent.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIComponent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::shared_ptr<UIComponent>> UIComponent::getChildren() {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<struct UIQuad> UIComponent::getQuads(
|
||||
const glm::mat4 parent
|
||||
) {
|
||||
// Get self transform
|
||||
glm::mat4 transform = glm::translate(
|
||||
glm::mat4(1.0f), glm::vec3(position, 0.0f)
|
||||
);
|
||||
|
||||
// Add parent transform
|
||||
transform = parent * transform;
|
||||
|
||||
// Get self quads and insert new transform.
|
||||
std::vector<struct UIQuad> quads;
|
||||
auto selfQuads = this->getSelfQuads(transform);
|
||||
|
||||
// Get children
|
||||
auto children = getChildren();
|
||||
for(auto &c : children) {
|
||||
auto childQuads = c->getQuads(transform);
|
||||
quads.insert(quads.end(), childQuads.begin(), childQuads.end());
|
||||
}
|
||||
|
||||
return quads;
|
||||
}
|
30
src/dawn/ui/UIComponent.hpp
Normal file
30
src/dawn/ui/UIComponent.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "ui/UIAlign.hpp"
|
||||
#include "ui/UIQuad.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UICanvas;
|
||||
|
||||
class UIComponent {
|
||||
protected:
|
||||
virtual std::vector<struct UIQuad> getSelfQuads(
|
||||
const glm::mat4 transform
|
||||
) = 0;
|
||||
|
||||
virtual std::vector<std::shared_ptr<UIComponent>> getChildren();
|
||||
|
||||
std::vector<struct UIQuad> getQuads(
|
||||
const glm::mat4 parent
|
||||
);
|
||||
|
||||
public:
|
||||
glm::vec2 position;
|
||||
|
||||
friend class UICanvas;
|
||||
};
|
||||
}
|
34
src/dawn/ui/UIQuad.hpp
Normal file
34
src/dawn/ui/UIQuad.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct UIQuad {
|
||||
glm::mat4 transform;
|
||||
glm::vec4 quad;
|
||||
glm::vec4 uv;
|
||||
struct Color color;
|
||||
std::shared_ptr<Texture> texture;
|
||||
|
||||
UIQuad(
|
||||
const glm::mat4 transform,
|
||||
const glm::vec4 quad,
|
||||
const glm::vec4 uv,
|
||||
const struct Color color,
|
||||
const std::shared_ptr<Texture> texture
|
||||
) :
|
||||
transform(transform),
|
||||
quad(quad),
|
||||
uv(uv),
|
||||
color(color),
|
||||
texture(texture)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
24
src/dawn/ui/UIRectangle.cpp
Normal file
24
src/dawn/ui/UIRectangle.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIRectangle.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<struct UIQuad> UIRectangle::getSelfQuads(
|
||||
const glm::mat4 transform
|
||||
) {
|
||||
std::vector<struct UIQuad> quads;
|
||||
|
||||
quads.push_back(UIQuad(
|
||||
transform,
|
||||
glm::vec4(0,0,size.x,size.y),
|
||||
uv,
|
||||
color,
|
||||
texture
|
||||
));
|
||||
|
||||
return quads;
|
||||
}
|
22
src/dawn/ui/UIRectangle.hpp
Normal file
22
src/dawn/ui/UIRectangle.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "ui/UIComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIRectangle final : public UIComponent {
|
||||
protected:
|
||||
std::vector<struct UIQuad> getSelfQuads(
|
||||
const glm::mat4 transform
|
||||
) override;
|
||||
|
||||
public:
|
||||
struct Color color = COLOR_WHITE;
|
||||
std::shared_ptr<Texture> texture = nullptr;
|
||||
glm::vec2 size = glm::vec2(32, 32);
|
||||
glm::vec4 uv = glm::vec4(0,0,1,1);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user