parent
7c1f05c801
commit
8d9c2d8c05
@ -0,0 +1,75 @@ |
||||
#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)}); |
||||
} |
||||
}; |
||||
} |
Loading…
Reference in new issue