From b709805cfac4d1fe1bfe28e497a3e48e224372a8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 7 Aug 2024 20:32:59 +0200 Subject: Move settings ui to SettingsPage class, show different widgets for different settings page, show different widgets depending on combobox selections --- include/SettingsPage.hpp | 37 ++++ include/Theme.hpp | 1 + include/gui/ComboBox.hpp | 6 +- include/gui/RadioButton.hpp | 2 +- include/gui/ScrollablePage.hpp | 1 + include/gui/Widget.hpp | 2 + meson.build | 1 + src/SettingsPage.cpp | 411 +++++++++++++++++++++++++++++++++++++++++ src/Theme.cpp | 1 + src/gui/ComboBox.cpp | 15 +- src/gui/List.cpp | 6 +- src/gui/RadioButton.cpp | 10 +- src/gui/ScrollablePage.cpp | 9 +- src/main.cpp | 315 ++----------------------------- 14 files changed, 504 insertions(+), 313 deletions(-) create mode 100644 include/SettingsPage.hpp create mode 100644 src/SettingsPage.cpp diff --git a/include/SettingsPage.hpp b/include/SettingsPage.hpp new file mode 100644 index 0000000..aec7bed --- /dev/null +++ b/include/SettingsPage.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include "gui/StaticPage.hpp" +#include "GsrInfo.hpp" + +#include + +namespace gsr { + class ScrollablePage; + class List; + + class SettingsPage { + public: + enum class Type { + REPLAY, + RECORD, + STREAM + }; + + SettingsPage(Type type, const GsrInfo &gsr_info, const std::vector &audio_devices, std::function back_button_callback); + SettingsPage(const SettingsPage&) = delete; + SettingsPage& operator=(const SettingsPage&) = delete; + + Page& get_page(); + private: + void add_widgets(const gsr::GsrInfo &gsr_info, const std::vector &audio_devices, std::function back_button_callback); + void add_page_specific_widgets(); + void add_replay_widgets(); + void add_record_widgets(); + void add_stream_widgets(); + private: + StaticPage page; + ScrollablePage *content_page_ptr = nullptr; + List *settings_list_ptr = nullptr; + Type type; + }; +} \ No newline at end of file diff --git a/include/Theme.hpp b/include/Theme.hpp index a28c249..ced85bd 100644 --- a/include/Theme.hpp +++ b/include/Theme.hpp @@ -15,6 +15,7 @@ namespace gsr { Theme(const Theme&) = delete; Theme& operator=(const Theme&) = delete; + float window_width = 0.0f; float window_height = 0.0f; mgl::Color tint_color = mgl::Color(118, 185, 0); diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp index b4e7b78..ac9d02b 100644 --- a/include/gui/ComboBox.hpp +++ b/include/gui/ComboBox.hpp @@ -3,6 +3,8 @@ #include "Widget.hpp" #include #include + +#include #include #include @@ -17,9 +19,11 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; void add_item(const std::string &text, const std::string &id); - void set_selected_item(const std::string &id); + void set_selected_item(const std::string &id, bool trigger_event = true); mgl::vec2f get_size() override; + + std::function on_selection_changed; private: void update_if_dirty(); float get_dropdown_arrow_height() const; diff --git a/include/gui/RadioButton.hpp b/include/gui/RadioButton.hpp index d4b1103..60f3e82 100644 --- a/include/gui/RadioButton.hpp +++ b/include/gui/RadioButton.hpp @@ -17,7 +17,7 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; void add_item(const std::string &text, const std::string &id); - void set_selected_item(const std::string &id); + void set_selected_item(const std::string &id, bool trigger_event = true); mgl::vec2f get_size() override; diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp index 9d4623b..60d719f 100644 --- a/include/gui/ScrollablePage.hpp +++ b/include/gui/ScrollablePage.hpp @@ -13,6 +13,7 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; mgl::vec2f get_size() override; + mgl::vec2f get_inner_size() override; void set_margins(float top, float bottom, float left, float right); private: diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp index 5b582da..498ca05 100644 --- a/include/gui/Widget.hpp +++ b/include/gui/Widget.hpp @@ -34,6 +34,8 @@ namespace gsr { virtual mgl::vec2f get_position() const; virtual mgl::vec2f get_size() = 0; + // This can be different from get_size, for example with ScrollablePage this excludes the margins + virtual mgl::vec2f get_inner_size() { return get_size(); } void set_horizontal_alignment(Alignment alignment); void set_vertical_alignment(Alignment alignment); diff --git a/meson.build b/meson.build index 8a35e5a..f04ec23 100644 --- a/meson.build +++ b/meson.build @@ -21,6 +21,7 @@ src = [ 'src/gui/Utils.cpp', 'src/gui/DropdownButton.cpp', 'src/gui/Label.cpp', + 'src/SettingsPage.cpp', 'src/Utils.cpp', 'src/Config.cpp', 'src/GsrInfo.cpp', diff --git a/src/SettingsPage.cpp b/src/SettingsPage.cpp new file mode 100644 index 0000000..187d414 --- /dev/null +++ b/src/SettingsPage.cpp @@ -0,0 +1,411 @@ +#include "../include/SettingsPage.hpp" +#include "../include/Theme.hpp" +#include "../include/gui/Button.hpp" +#include "../include/gui/RadioButton.hpp" +#include "../include/gui/List.hpp" +#include "../include/gui/ComboBox.hpp" +#include "../include/gui/Label.hpp" +#include "../include/gui/Entry.hpp" +#include "../include/gui/CheckBox.hpp" +#include "../include/gui/ScrollablePage.hpp" +#include "../include/GsrInfo.hpp" + +namespace gsr { + SettingsPage::SettingsPage(Type type, const GsrInfo &gsr_info, const std::vector &audio_devices, std::function back_button_callback) : + page(mgl::vec2f(get_theme().window_width, get_theme().window_height).floor()), + type(type) + { + const mgl::vec2f window_size = mgl::vec2f(get_theme().window_width, get_theme().window_height).floor(); + const mgl::vec2f content_page_size = (window_size * mgl::vec2f(0.3333f, 0.7f)).floor(); + const mgl::vec2f content_page_position = mgl::vec2f(window_size * 0.5f - content_page_size * 0.5f).floor(); + const float settings_body_margin = 0.02f; + + auto content_page = std::make_unique(content_page_size); + content_page->set_position(content_page_position); + content_page->set_margins(settings_body_margin, settings_body_margin, settings_body_margin, settings_body_margin); + content_page_ptr = content_page.get(); + page.add_widget(std::move(content_page)); + + add_widgets(gsr_info, audio_devices, back_button_callback); + add_page_specific_widgets(); + } + + Page& SettingsPage::get_page() { + return page; + } + + void SettingsPage::add_widgets(const GsrInfo &gsr_info, const std::vector &audio_devices, std::function back_button_callback) { + RadioButton *view_radio_button_ptr = nullptr; + ComboBox *record_area_box_ptr = nullptr; + List *select_window_list_ptr = nullptr; + List *area_size_list_ptr = nullptr; + Widget *color_range_list_ptr = nullptr; + Widget *codec_list_ptr = nullptr; + Widget *framerate_mode_list_ptr = nullptr; + + const mgl::vec2i window_size(get_theme().window_width, get_theme().window_height); + + auto back_button = std::make_unique