Plotter element

This commit is contained in:
MihailRis
2024-04-20 21:23:00 +03:00
parent c92cb52e2a
commit c82d95b97d
11 changed files with 176 additions and 71 deletions
+4 -40
View File
@@ -18,6 +18,7 @@
#include "../graphics/ui/elements/containers.h"
#include "../graphics/ui/elements/controls.h"
#include "../graphics/ui/elements/UINode.h"
#include "../graphics/ui/elements/Plotter.hpp"
#include "../graphics/ui/GUI.h"
#include "../items/Inventories.h"
#include "../items/Inventory.h"
@@ -60,43 +61,6 @@ extern std::shared_ptr<gui::UINode> create_debug_panel(
Player* player
);
class DeltaGrapher : public gui::UINode {
std::unique_ptr<int[]> points;
float multiplier;
int index = 0;
int dmwidth;
int dmheight;
public:
DeltaGrapher(uint width, uint height, float multiplier)
: gui::UINode(glm::vec2(width, height)),
multiplier(multiplier),
dmwidth(width),
dmheight(height)
{
points = std::make_unique<int[]>(width);
}
void act(float delta) override {
index = index + 1 % dmwidth;
int value = static_cast<int>(delta * multiplier);
points[index % dmwidth] = std::min(value, dmheight);
}
void draw(const GfxContext* pctx, Assets* assets) override {
glm::vec2 pos = calcPos();
auto batch = pctx->getBatch2D();
batch->texture(nullptr);
batch->lineWidth(1);
for (int i = index+1; i < index+dmwidth; i++) {
int j = i % dmwidth;
batch->line(
pos.x + i - index, pos.y + size.y - points[j],
pos.x + i - index, pos.y + size.y, 1.0f, 1.0f, 1.0f, 0.2f
);
}
}
};
HudElement::HudElement(
hud_element_mode mode,
UiDocument* document,
@@ -224,9 +188,9 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
gui->add(contentAccessPanel);
gui->add(grabbedItemView);
auto dgrapher = std::make_shared<DeltaGrapher>(350, 250, 2000);
dgrapher->setGravity(gui::Gravity::bottom_right);
add(HudElement(hud_element_mode::permanent, nullptr, dgrapher, true));
auto dplotter = std::make_shared<gui::Plotter>(350, 250, 2000, 16);
dplotter->setGravity(gui::Gravity::bottom_right);
add(HudElement(hud_element_mode::permanent, nullptr, dplotter, true));
}
Hud::~Hud() {