normalitzat Audio
This commit is contained in:
@@ -106,6 +106,40 @@ class IntOption : public MenuOption {
|
||||
int min_value_, max_value_, step_value_;
|
||||
};
|
||||
|
||||
// VolumeOption: emmagatzema un float 0.0..1.0 però es mostra/edita com a int 0..100.
|
||||
// Pensat per als sliders de volum que l'usuari veu com percentatge però que
|
||||
// internament viuen en float (API unificada del motor d'àudio).
|
||||
class VolumeOption : public MenuOption {
|
||||
public:
|
||||
VolumeOption(const std::string& cap, ServiceMenu::SettingsGroup grp, float* var, int step_percent = 5)
|
||||
: MenuOption(cap, grp),
|
||||
linked_variable_(var),
|
||||
step_value_(step_percent) {}
|
||||
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::ADJUST; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override {
|
||||
int pct = static_cast<int>(*linked_variable_ * 100.0F + 0.5F);
|
||||
return std::to_string(pct);
|
||||
}
|
||||
void adjustValue(bool adjust_up) override {
|
||||
int current = static_cast<int>(*linked_variable_ * 100.0F + 0.5F);
|
||||
int new_value = std::clamp(current + (adjust_up ? step_value_ : -step_value_), 0, 100);
|
||||
*linked_variable_ = static_cast<float>(new_value) / 100.0F;
|
||||
}
|
||||
auto getMaxValueWidth(Text* text_renderer) const -> int override {
|
||||
int max_width = 0;
|
||||
for (int value = 0; value <= 100; value += step_value_) {
|
||||
int width = text_renderer->length(std::to_string(value), -2);
|
||||
max_width = std::max(max_width, width);
|
||||
}
|
||||
return max_width;
|
||||
}
|
||||
|
||||
private:
|
||||
float* linked_variable_;
|
||||
int step_value_;
|
||||
};
|
||||
|
||||
class ListOption : public MenuOption {
|
||||
public:
|
||||
ListOption(const std::string& cap, ServiceMenu::SettingsGroup grp, std::vector<std::string> values, std::function<std::string()> current_value_getter, std::function<void(const std::string&)> new_value_setter)
|
||||
|
||||
Reference in New Issue
Block a user