This commit is contained in:
MihailRis
2024-12-09 01:12:41 +03:00
parent 5fe5c6b27a
commit 5ffc054d75
16 changed files with 212 additions and 126 deletions
+3
View File
@@ -92,6 +92,9 @@ DrawContext DrawContext::sub(Flushable* flushable) const {
ctx.parent = this;
ctx.flushable = flushable;
ctx.scissorsCount = 0;
if (auto batch2D = dynamic_cast<Batch2D*>(flushable)) {
ctx.g2d = batch2D;
}
return ctx;
}
+1 -1
View File
@@ -10,7 +10,7 @@ class Framebuffer;
class DrawContext {
const DrawContext* parent;
Viewport viewport;
Batch2D* const g2d;
Batch2D* g2d;
Flushable* flushable = nullptr;
Framebuffer* fbo = nullptr;
bool depthMask = true;
+6 -4
View File
@@ -23,7 +23,7 @@
using namespace gui;
GUI::GUI() {
GUI::GUI() : batch2D(std::make_unique<Batch2D>(1024)) {
container = std::make_shared<Container>(glm::vec2(1000));
uicamera = std::make_unique<Camera>(glm::vec3(), Window::height);
uicamera->perspective = false;
@@ -198,7 +198,9 @@ void GUI::act(float delta, const Viewport& vp) {
}
void GUI::draw(const DrawContext& pctx, const Assets& assets) {
auto& viewport = pctx.getViewport();
auto ctx = pctx.sub(batch2D.get());
auto& viewport = ctx.getViewport();
glm::vec2 wsize = viewport.size();
menu->setPos((wsize - menu->getSize()) / 2.0f);
@@ -208,8 +210,8 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) {
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjView());
pctx.getBatch2D()->begin();
container->draw(pctx, assets);
batch2D->begin();
container->draw(ctx, assets);
}
std::shared_ptr<UINode> GUI::getFocused() const {
+2
View File
@@ -13,6 +13,7 @@ class Viewport;
class DrawContext;
class Assets;
class Camera;
class Batch2D;
/*
Some info about padding and margin.
@@ -52,6 +53,7 @@ namespace gui {
/// @brief The main UI controller
class GUI {
std::unique_ptr<Batch2D> batch2D;
std::shared_ptr<Container> container;
std::shared_ptr<UINode> hover;
std::shared_ptr<UINode> pressed;