Implement vertical meters.

This commit is contained in:
Zed A. Shaw 2026-04-19 23:47:14 -04:00
parent ad116b5515
commit 48b672eec4
3 changed files with 26 additions and 4 deletions

View file

@ -113,6 +113,8 @@ namespace guecs {
}
void Meter::init(lel::Cell& cell) {
$cell_x = cell.x;
$cell_y = cell.y;
$cell_w = cell.w;
$cell_h = cell.h;
bar.init(cell);
@ -125,8 +127,15 @@ namespace guecs {
void Meter::update_percent(float pct) {
percent = pct;
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});
if(vertical) {
float level = std::clamp(percent, 0.0f, 1.0f) * float($cell_h);
sf::Vector2f size{float($cell_w) - padding * 2, std::max(level, 0.0f) - padding};
bar.shape->setSize(size);
bar.shape->setPosition({float($cell_x + padding), float($cell_y) + (float($cell_h) - size.y)});
} else {
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});
}
}
void Sound::play(bool hover) {