Meter is improved but needs a few more things.
This commit is contained in:
parent
3d44b7ccc5
commit
1950f45f46
5 changed files with 141 additions and 22 deletions
|
|
@ -8,19 +8,18 @@ namespace guecs {
|
|||
using std::make_shared;
|
||||
|
||||
// BUG: this seems to center things wrong in lel layouts
|
||||
template<typename T>
|
||||
void sfml_center_helper(T& obj, lel::Cell& cell, int padding) {
|
||||
sf::Vector2f position{float(cell.x + padding), float(cell.y + padding)};
|
||||
void sfml_center_helper(auto& obj, lel::Cell& cell, int padding) {
|
||||
sf::Vector2f position{float(cell.x + padding), float(cell.y + padding)};
|
||||
|
||||
if(cell.center) {
|
||||
auto bounds = obj->getLocalBounds();
|
||||
position = {float(cell.mid_x), float(cell.mid_y)};
|
||||
obj->setOrigin({bounds.size.x/2, bounds.size.y/2});
|
||||
}
|
||||
|
||||
obj->setPosition(position);
|
||||
if(cell.center) {
|
||||
auto bounds = obj->getLocalBounds();
|
||||
position = {float(cell.mid_x), float(cell.mid_y)};
|
||||
obj->setOrigin({bounds.size.x/2, bounds.size.y/2});
|
||||
}
|
||||
|
||||
obj->setPosition(position);
|
||||
}
|
||||
|
||||
inline SpriteTexture load_texture(const string& name, bool is_icon) {
|
||||
if(is_icon) {
|
||||
return BACKEND->get_icon(name);
|
||||
|
|
@ -109,19 +108,20 @@ namespace guecs {
|
|||
}
|
||||
|
||||
void Meter::init(lel::Cell& cell, Rectangle& bg) {
|
||||
bg.shape->setFillColor(color);
|
||||
backing_rect = bg;
|
||||
init(cell);
|
||||
}
|
||||
|
||||
void Meter::init(lel::Cell& cell) {
|
||||
$cell_w = cell.w;
|
||||
$cell_h = cell.h;
|
||||
bar.init(cell);
|
||||
}
|
||||
|
||||
void Meter::render(lel::Cell& cell, sf::RenderTarget& window, sf::Shader *shader_ptr) {
|
||||
float level = std::clamp(percent, 0.0f, 1.0f) * float(cell.w);
|
||||
// ZED: this 6 is a border width, make it a thing
|
||||
bar.shape->setSize({std::max(level, 0.0f), float(cell.h - 6)});
|
||||
window.draw(*bar.shape, shader_ptr);
|
||||
void Meter::render(sf::RenderTarget& window, sf::Shader *shader_ptr) {
|
||||
float level = std::clamp(percent, 0.0f, 1.0f) * float($cell_w);
|
||||
bar.shape->setSize({std::max(level, 0.0f) - padding * 2, float($cell_h) - padding * 2});
|
||||
bar.render(window, shader_ptr);
|
||||
}
|
||||
|
||||
void Sound::play(bool hover) {
|
||||
|
|
|
|||
|
|
@ -135,9 +135,9 @@ namespace guecs {
|
|||
rect.render(window, shader_ptr);
|
||||
});
|
||||
|
||||
query<lel::Cell, Meter>([&](auto ent, auto& cell, auto &meter) {
|
||||
query<Meter>([&](auto ent, auto &meter) {
|
||||
auto shader_ptr = find_shader(ent, true);
|
||||
meter.render(cell, window, shader_ptr);
|
||||
meter.render(window, shader_ptr);
|
||||
});
|
||||
|
||||
query<Sprite>([&](auto ent, auto& sprite) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue