frontend/gui refactor

This commit is contained in:
MihailRis
2024-01-31 04:26:35 +03:00
parent 49fdcdfb27
commit 8c722b146e
17 changed files with 331 additions and 332 deletions
+14 -10
View File
@@ -8,6 +8,7 @@
#include "../../assets/Assets.h"
#include "../../graphics/Batch2D.h"
#include "../../graphics/Shader.h"
#include "../../graphics/GfxContext.h"
#include "../../window/Events.h"
#include "../../window/input.h"
#include "../../window/Camera.h"
@@ -42,10 +43,10 @@ PagesControl* GUI::getMenu() {
void GUI::actMouse(float delta) {
auto hover = container->getAt(Events::cursor, nullptr);
if (this->hover && this->hover != hover) {
this->hover->hover(false);
this->hover->setHover(false);
}
if (hover) {
hover->hover(true);
hover->setHover(true);
if (Events::scroll) {
hover->scrolled(Events::scroll);
}
@@ -84,7 +85,7 @@ void GUI::actMouse(float delta) {
}
void GUI::act(float delta) {
container->size(vec2(Window::width, Window::height));
container->setSize(vec2(Window::width, Window::height));
container->act(delta);
auto prevfocus = focus;
@@ -111,21 +112,24 @@ void GUI::act(float delta) {
}
}
}
if (focus && !focus->isfocused()) {
if (focus && !focus->isFocused()) {
focus = nullptr;
}
}
void GUI::draw(Batch2D* batch, Assets* assets) {
menu->setCoord((Window::size() - menu->size()) / 2.0f);
uicamera->setFov(Window::height);
void GUI::draw(const GfxContext* pctx, Assets* assets) {
auto& viewport = pctx->getViewport();
glm::vec2 wsize = viewport.size();
menu->setCoord((wsize - menu->getSize()) / 2.0f);
uicamera->setFov(wsize.y);
Shader* uishader = assets->getShader("ui");
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjection()*uicamera->getView());
batch->begin();
container->draw(batch, assets);
pctx->getBatch2D()->begin();
container->draw(pctx, assets);
}
shared_ptr<UINode> GUI::getFocused() const {
@@ -133,7 +137,7 @@ shared_ptr<UINode> GUI::getFocused() const {
}
bool GUI::isFocusCaught() const {
return focus && focus->isfocuskeeper();
return focus && focus->isFocuskeeper();
}
void GUI::addBack(std::shared_ptr<UINode> panel) {