From 4ba1e814b748d57631f6b7afb7eaa63e8435c24e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 13 Nov 2024 22:18:30 +0100 Subject: Add application audio option --- src/gui/CheckBox.cpp | 12 +-- src/gui/Label.cpp | 4 + src/gui/LineSeparator.cpp | 45 ++++++++++ src/gui/SettingsPage.cpp | 215 +++++++++++++++++++++++++++++++++++++++------- src/gui/Subsection.cpp | 18 +++- 5 files changed, 255 insertions(+), 39 deletions(-) create mode 100644 src/gui/LineSeparator.cpp (limited to 'src/gui') diff --git a/src/gui/CheckBox.cpp b/src/gui/CheckBox.cpp index 9ae3b41..e2f591c 100644 --- a/src/gui/CheckBox.cpp +++ b/src/gui/CheckBox.cpp @@ -10,7 +10,7 @@ namespace gsr { static const float spacing_scale = 0.005f; static const float check_animation_speed = 10.0f; - static mgl::Color color_multiply(mgl::Color color, float multiply) { + static mgl::Color color_multiply_ignore_alpha(mgl::Color color, float multiply) { return mgl::Color(color.r * multiply, color.g * multiply, color.b * multiply, color.a); } @@ -18,12 +18,12 @@ namespace gsr { return source + (destination - source) * interpolation; } - static mgl::Color interpolate_color(mgl::Color source, mgl::Color destination, float interpolation) { + static mgl::Color interpolate_color_ignore_alpha(mgl::Color source, mgl::Color destination, float interpolation) { mgl::Color color; color.r = linear_interpolation(source.r, destination.r, interpolation); color.g = linear_interpolation(source.g, destination.g, interpolation); color.b = linear_interpolation(source.b, destination.b, interpolation); - color.a = linear_interpolation(source.a, destination.a, interpolation); + color.a = source.a; return color; } @@ -61,9 +61,9 @@ namespace gsr { apply_animation(); - const mgl::Color background_color_unchecked(0, 0, 0, 120); - const mgl::Color background_color_checked = color_multiply(get_color_theme().tint_color, 0.6f); - background_sprite.set_color(interpolate_color(background_color_unchecked, background_color_checked, toggle_animation_value)); + const mgl::Color background_color_unchecked = color_multiply_ignore_alpha(mgl::Color(25, 30, 34), 0.6f); + const mgl::Color background_color_checked = color_multiply_ignore_alpha(get_color_theme().tint_color, 0.6f); + background_sprite.set_color(interpolate_color_ignore_alpha(background_color_unchecked, background_color_checked, toggle_animation_value)); background_sprite.set_position(draw_pos.floor()); window.draw(background_sprite); diff --git a/src/gui/Label.cpp b/src/gui/Label.cpp index 22a302f..773c2f9 100644 --- a/src/gui/Label.cpp +++ b/src/gui/Label.cpp @@ -22,6 +22,10 @@ namespace gsr { text.set_string(std::move(str)); } + const std::string& Label::get_text() const { + return text.get_string(); + } + mgl::vec2f Label::get_size() { if(!visible) return {0.0f, 0.0f}; diff --git a/src/gui/LineSeparator.cpp b/src/gui/LineSeparator.cpp new file mode 100644 index 0000000..637c84f --- /dev/null +++ b/src/gui/LineSeparator.cpp @@ -0,0 +1,45 @@ +#include "../../include/gui/LineSeparator.hpp" +#include "../../include/Theme.hpp" + +#include +#include + +namespace gsr { + static const float height_scale = 0.001f; + + static mgl::Color color_add_ignore_alpha(mgl::Color color, mgl::Color add) { + return { + (uint8_t)std::min((int)color.r + (int)add.r, 255), + (uint8_t)std::min((int)color.g + (int)add.g, 255), + (uint8_t)std::min((int)color.b + (int)add.b, 255), + color.a + }; + } + + LineSeparator::LineSeparator(Type type, float width) : type(type), width(width) { + + } + + bool LineSeparator::on_event(mgl::Event&, mgl::Window&, mgl::vec2f) { + return true; + } + + void LineSeparator::draw(mgl::Window &window, mgl::vec2f offset) { + if(!visible) + return; + + const mgl::vec2f draw_pos = (position + offset).floor(); + const mgl::vec2f size = mgl::vec2f(width, std::max(1.0f, height_scale * get_theme().window_height)).floor(); + mgl::Rectangle rectangle(draw_pos, size); + rectangle.set_color(color_add_ignore_alpha(mgl::Color(25, 30, 34), mgl::Color(30, 30, 30))); + window.draw(rectangle); + } + + mgl::vec2f LineSeparator::get_size() { + if(!visible) + return {0.0f, 0.0f}; + + const mgl::vec2f size = mgl::vec2f(width, std::max(1.0f, height_scale * get_theme().window_height)).floor(); + return size; + } +} \ No newline at end of file diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index a08bd52..083fec5 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -1,6 +1,7 @@ #include "../../include/gui/SettingsPage.hpp" #include "../../include/gui/GsrPage.hpp" #include "../../include/gui/Label.hpp" +#include "../../include/gui/LineSeparator.hpp" #include "../../include/gui/PageStack.hpp" #include "../../include/gui/FileChooser.hpp" #include "../../include/gui/Subsection.hpp" @@ -13,15 +14,19 @@ #include #include +#include + namespace gsr { - SettingsPage::SettingsPage(Type type, const GsrInfo &gsr_info, std::vector audio_devices, Config &config, PageStack *page_stack) : + SettingsPage::SettingsPage(Type type, const GsrInfo &gsr_info, Config &config, PageStack *page_stack) : StaticPage(mgl::vec2f(get_theme().window_width, get_theme().window_height).floor()), type(type), config(config), - audio_devices(std::move(audio_devices)), page_stack(page_stack), settings_title_text("Settings", get_theme().title_font) { + audio_devices = get_audio_devices(); + application_audio = get_application_audio(); + auto content_page = std::make_unique(); content_page->add_button("Back", "back", get_color_theme().page_bg_color); content_page->on_click = [page_stack](const std::string &id) { @@ -177,7 +182,7 @@ namespace gsr { return std::make_unique("Record area", std::move(ll), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)); } - std::unique_ptr SettingsPage::create_audio_track_selection_checkbox() { + std::unique_ptr SettingsPage::create_audio_device_selection_combobox() { auto audio_device_box = std::make_unique(&get_theme().body_font); for(const auto &audio_device : audio_devices) { audio_device_box->add_item(audio_device.description, audio_device.name); @@ -185,7 +190,7 @@ namespace gsr { return audio_device_box; } - std::unique_ptr