Menu screen prototype, refactor

This commit is contained in:
MihailRis
2023-11-16 03:00:05 +03:00
parent 5af04e20d1
commit b03bcb5191
14 changed files with 267 additions and 52 deletions
+19 -11
View File
@@ -3,33 +3,35 @@
#include "panels.h"
#include <iostream>
#include <algorithm>
#include "../../assets/Assets.h"
#include "../../graphics/Batch2D.h"
#include "../../graphics/Shader.h"
#include "../../window/Events.h"
#include "../../window/input.h"
#include "../../window/Camera.h"
using std::shared_ptr;
using namespace gui;
GUI::GUI() {
container = new Container(vec2(0, 0), vec2(Window::width, Window::height));
uicamera = new Camera(vec3(), Window::height);
uicamera->perspective = false;
uicamera->flipped = true;
}
GUI::~GUI() {
delete uicamera;
delete container;
}
void GUI::act(float delta) {
for (IntervalEvent& event : intervalEvents) {
event.timer += delta;
if (event.timer > event.interval) {
event.callback();
event.timer = fmod(event.timer, event.interval);
}
}
container->size(vec2(Window::width, Window::height));
container->act(delta);
int mx = Events::x;
int my = Events::y;
@@ -77,6 +79,12 @@ void GUI::act(float delta) {
}
void GUI::draw(Batch2D* batch, Assets* assets) {
uicamera->fov = Window::height;
Shader* uishader = assets->getShader("ui");
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjection()*uicamera->getView());
batch->begin();
container->draw(batch, assets);
}
@@ -93,6 +101,6 @@ void GUI::add(shared_ptr<UINode> panel) {
container->add(panel);
}
void GUI::interval(float interval, ontimeout callback) {
intervalEvents.push_back({callback, interval, 0.0f});
}
void GUI::remove(std::shared_ptr<UINode> panel) {
container->remove(panel);
}