From 4ea5ada9050d22fcb7eed67a72358bce11c9b3df Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 10 Aug 2024 00:45:36 +0200 Subject: Settings page save settings, refactor --- depends/mglpp | 2 +- include/Config.hpp | 21 +- include/SettingsPage.hpp | 37 --- include/gui/ComboBox.hpp | 1 + include/gui/Entry.hpp | 3 +- include/gui/List.hpp | 7 + include/gui/Page.hpp | 3 + include/gui/RadioButton.hpp | 1 + include/gui/SettingsPage.hpp | 128 +++++++++ meson.build | 2 +- src/Config.cpp | 55 ++-- src/SettingsPage.cpp | 464 -------------------------------- src/gui/ComboBox.cpp | 9 + src/gui/Entry.cpp | 12 +- src/gui/List.cpp | 57 ++-- src/gui/RadioButton.cpp | 9 + src/gui/SettingsPage.cpp | 628 +++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 35 ++- 18 files changed, 905 insertions(+), 569 deletions(-) delete mode 100644 include/SettingsPage.hpp create mode 100644 include/gui/SettingsPage.hpp delete mode 100644 src/SettingsPage.cpp create mode 100644 src/gui/SettingsPage.cpp diff --git a/depends/mglpp b/depends/mglpp index 6af6e26..9ea0fb2 160000 --- a/depends/mglpp +++ b/depends/mglpp @@ -1 +1 @@ -Subproject commit 6af6e269ec19626ab3b9ca2f36c87d439002ee66 +Subproject commit 9ea0fb27952bb529e86e3838a2abe356e4292998 diff --git a/include/Config.hpp b/include/Config.hpp index 154bdb0..63e7984 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -1,8 +1,10 @@ #pragma once -#include "Utils.hpp" #include +#include +#include +#include namespace gsr { struct ConfigHotkey { @@ -16,19 +18,15 @@ namespace gsr { int32_t record_area_height = 0; int32_t fps = 60; bool merge_audio_tracks = true; - std::vector audio_input; + std::vector audio_tracks; std::string color_range; - std::string quality; + std::string video_quality; std::string video_codec; std::string audio_codec; std::string framerate_mode; bool advanced_view = false; bool overclock = false; - bool show_recording_started_notifications = false; - bool show_recording_stopped_notifications = false; - bool show_recording_saved_notifications = true; bool record_cursor = true; - bool hide_window_when_recording = false; bool restore_portal_session = true; }; @@ -52,6 +50,8 @@ namespace gsr { struct StreamingConfig { RecordOptions record_options; + bool show_streaming_started_notifications = true; + bool show_streaming_stopped_notifications = true; std::string streaming_service; YoutubeStreamConfig youtube; TwitchStreamConfig twitch; @@ -61,6 +61,8 @@ namespace gsr { struct RecordConfig { RecordOptions record_options; + bool show_recording_started_notifications = true; + bool show_video_saved_notifications = true; std::string save_directory; std::string container; ConfigHotkey start_stop_recording_hotkey; @@ -69,6 +71,9 @@ namespace gsr { struct ReplayConfig { RecordOptions record_options; + bool show_replay_started_notifications = true; + bool show_replay_stopped_notifications = true; + bool show_replay_saved_notifications = true; std::string save_directory; std::string container; int32_t replay_time = 60; @@ -83,6 +88,6 @@ namespace gsr { ReplayConfig replay_config; }; - Config read_config(bool &config_empty); + std::optional read_config(); void save_config(Config &config); } \ No newline at end of file diff --git a/include/SettingsPage.hpp b/include/SettingsPage.hpp deleted file mode 100644 index aec7bed..0000000 --- a/include/SettingsPage.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#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/gui/ComboBox.hpp b/include/gui/ComboBox.hpp index ac9d02b..e501132 100644 --- a/include/gui/ComboBox.hpp +++ b/include/gui/ComboBox.hpp @@ -20,6 +20,7 @@ namespace gsr { void add_item(const std::string &text, const std::string &id); void set_selected_item(const std::string &id, bool trigger_event = true); + const std::string& get_selected_id() const; mgl::vec2f get_size() override; diff --git a/include/gui/Entry.hpp b/include/gui/Entry.hpp index c2d59ac..b8ff37a 100644 --- a/include/gui/Entry.hpp +++ b/include/gui/Entry.hpp @@ -20,7 +20,8 @@ namespace gsr { mgl::vec2f get_size() override; - void set_string(std::string str); + void set_text(std::string str); + const std::string& get_text() const; // Return false to specify that the string should not be accepted. This reverts the string back to its previous value. // The input can be changed by changing the input parameter and returning true. diff --git a/include/gui/List.hpp b/include/gui/List.hpp index 0b1350c..426a66e 100644 --- a/include/gui/List.hpp +++ b/include/gui/List.hpp @@ -27,8 +27,14 @@ namespace gsr { //void remove_child_widget(Widget *widget) override; + // Might not take effect immediately but at the next draw iteration if inside an event loop void add_widget(std::unique_ptr widget); + // Might not take effect immediately but at the next draw iteration if inside an event loop void remove_widget(Widget *widget); + // Excludes widgets from queue + const std::vector>& get_child_widgets() const; + // Returns nullptr if index is invalid + Widget* get_child_widget_by_index(size_t index) const; mgl::vec2f get_size() override; private: @@ -40,5 +46,6 @@ namespace gsr { std::vector remove_queue; Orientation orientation; Alignment content_alignment; + bool inside_event_handler = false; }; } \ No newline at end of file diff --git a/include/gui/Page.hpp b/include/gui/Page.hpp index 47aa02b..4c63702 100644 --- a/include/gui/Page.hpp +++ b/include/gui/Page.hpp @@ -12,6 +12,9 @@ namespace gsr { Page& operator=(const Page&) = delete; virtual ~Page() = default; + virtual void on_navigate_to_page() {} + virtual void on_navigate_away_from_page() {} + //void remove_child_widget(Widget *widget) override; void add_widget(std::unique_ptr widget); diff --git a/include/gui/RadioButton.hpp b/include/gui/RadioButton.hpp index 60f3e82..7839c68 100644 --- a/include/gui/RadioButton.hpp +++ b/include/gui/RadioButton.hpp @@ -18,6 +18,7 @@ namespace gsr { void add_item(const std::string &text, const std::string &id); void set_selected_item(const std::string &id, bool trigger_event = true); + const std::string get_selected_id() const; mgl::vec2f get_size() override; diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp new file mode 100644 index 0000000..28689a1 --- /dev/null +++ b/include/gui/SettingsPage.hpp @@ -0,0 +1,128 @@ +#pragma once + +#include "StaticPage.hpp" +#include "List.hpp" +#include "ComboBox.hpp" +#include "Entry.hpp" +#include "RadioButton.hpp" +#include "CheckBox.hpp" +#include "Button.hpp" +#include "CustomRendererWidget.hpp" +#include "../GsrInfo.hpp" +#include "../Config.hpp" + +#include + +namespace gsr { + class ScrollablePage; + + class SettingsPage : public StaticPage { + public: + enum class Type { + REPLAY, + RECORD, + STREAM + }; + + SettingsPage(Type type, const GsrInfo &gsr_info, const std::vector &audio_devices, std::optional &config); + SettingsPage(const SettingsPage&) = delete; + SettingsPage& operator=(const SettingsPage&) = delete; + + void save(); + void on_navigate_away_from_page() override; + + std::function on_back_button_handler; + private: + std::unique_ptr