You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.0 KiB
76 lines
2.0 KiB
3 weeks ago
|
#pragma once
|
||
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||
|
#include <SFML/Graphics/Font.hpp>
|
||
|
#include <SFML/Graphics/Text.hpp>
|
||
|
#include "lel.hpp"
|
||
|
|
||
|
namespace gui {
|
||
|
struct Label {
|
||
|
sf::Font &font;
|
||
|
sf::Text text;
|
||
|
lel::Cell& cell;
|
||
|
|
||
|
Label(lel::Cell& cell, std::string label_text, sf::Font &font) :
|
||
|
font(font),
|
||
|
text(font, label_text),
|
||
|
cell(cell)
|
||
|
{
|
||
|
auto bounds = text.getLocalBounds();
|
||
|
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell);
|
||
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
||
|
text.setPosition({float(text_cell.x), float(text_cell.y) - text_cell.h / 2});
|
||
|
}
|
||
|
|
||
|
void draw(sf::RenderWindow& window) {
|
||
|
window.draw(text);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct Button {
|
||
|
Label label;
|
||
|
lel::Cell& cell;
|
||
|
sf::RectangleShape shape;
|
||
|
|
||
|
Button(lel::Cell& cell, std::string label_text, sf::Font &font) :
|
||
|
label(cell, label_text, font),
|
||
|
cell(cell)
|
||
|
{
|
||
|
shape.setPosition({float(cell.x + 3), float(cell.y + 3)});
|
||
|
shape.setSize({float(cell.w - 6), float(cell.h - 6)});
|
||
|
shape.setFillColor(ColorValue::DARK_MID);
|
||
|
shape.setOutlineColor(ColorValue::MID);
|
||
|
shape.setOutlineThickness(1);
|
||
|
}
|
||
|
|
||
|
void draw(sf::RenderWindow& window) {
|
||
|
window.draw(shape);
|
||
|
label.draw(window);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct Meter {
|
||
|
sf::RectangleShape shape;
|
||
|
lel::Cell& cell;
|
||
|
|
||
|
Meter(lel::Cell& cell) :
|
||
|
cell(cell)
|
||
|
{
|
||
|
shape.setPosition({float(cell.x + 3), float(cell.y + 3)});
|
||
|
shape.setSize({float(cell.w - 6), float(cell.h - 6)});
|
||
|
shape.setFillColor(ColorValue::DARK_MID);
|
||
|
shape.setOutlineColor(ColorValue::MID);
|
||
|
shape.setOutlineThickness(1);
|
||
|
}
|
||
|
|
||
|
void draw(sf::RenderWindow& window) {
|
||
|
window.draw(shape);
|
||
|
}
|
||
|
|
||
|
void set_percent(float percent) {
|
||
|
float level = percent * float(cell.w);
|
||
|
// ZED: this 6 is a border to make it a thing
|
||
|
shape.setSize({std::max(level, 0.0f), float(cell.h - 6)});
|
||
|
}
|
||
|
};
|
||
|
}
|