]> git.localhorst.tv Git - blobs.git/blob - src/ui/ui.cpp
cleaned up ui a little
[blobs.git] / src / ui / ui.cpp
1 #include "CreaturePanel.hpp"
2
3 #include "../app/Assets.hpp"
4 #include "../creature/Creature.hpp"
5 #include "../graphics/Viewport.hpp"
6
7 #include <glm/gtx/transform.hpp>
8
9
10 namespace blobs {
11 namespace ui {
12
13 CreaturePanel::CreaturePanel(const app::Assets &assets)
14 : c(nullptr)
15 , name(new Label(assets.fonts.large))
16 , panel() {
17         panel
18                 .Add(name)
19                 .Padding(glm::vec2(10.0f))
20                 .Spacing(10.0f)
21                 .Direction(Panel::VERTICAL)
22                 .Background(glm::vec4(0.7f, 0.7f, 0.7f, 1.0f))
23                 .Origin(Gravity::NORTH_EAST);
24 }
25
26 CreaturePanel::~CreaturePanel() {
27 }
28
29
30 void CreaturePanel::Show(creature::Creature &cr) {
31         c = &cr;
32         name->Text(c->Name());
33         panel.Relayout();
34 }
35
36 void CreaturePanel::Hide() noexcept {
37         c = nullptr;
38 }
39
40 void CreaturePanel::Draw(app::Assets &assets, graphics::Viewport &viewport) noexcept {
41         if (!c) return;
42
43         const glm::vec2 margin(20.0f);
44
45         panel.Position(glm::vec3(viewport.Width() - margin.x, margin.y, 0.0f));
46         panel.Draw(assets, viewport);
47 }
48
49 }
50 }