From f38661593795e51e45e2dc2ead8a7bf897d226f6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 9 Dec 2024 16:29:36 +0100 Subject: Start on global settings, add tint color setting --- images/settings_small.png | Bin 0 -> 1903 bytes include/Config.hpp | 1 + include/Theme.hpp | 4 +- include/gui/Button.hpp | 7 ++++ include/gui/GlobalSettingsPage.hpp | 34 +++++++++++++++ include/gui/SettingsPage.hpp | 2 - include/gui/Utils.hpp | 1 + meson.build | 1 + src/Config.cpp | 1 + src/Overlay.cpp | 19 ++++++++- src/Theme.cpp | 48 +++++++++++++-------- src/gui/Button.cpp | 44 ++++++++++++++++++-- src/gui/GlobalSettingsPage.cpp | 83 +++++++++++++++++++++++++++++++++++++ src/gui/SettingsPage.cpp | 3 +- src/gui/Utils.cpp | 17 ++++++++ 15 files changed, 237 insertions(+), 28 deletions(-) create mode 100644 images/settings_small.png create mode 100644 include/gui/GlobalSettingsPage.hpp create mode 100644 src/gui/GlobalSettingsPage.cpp diff --git a/images/settings_small.png b/images/settings_small.png new file mode 100644 index 0000000..30534e6 Binary files /dev/null and b/images/settings_small.png differ diff --git a/include/Config.hpp b/include/Config.hpp index 02f1634..c61ca10 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -40,6 +40,7 @@ namespace gsr { struct MainConfig { int32_t config_file_version = 0; bool software_encoding_warning_shown = false; + std::string tint_color; }; struct YoutubeStreamConfig { diff --git a/include/Theme.hpp b/include/Theme.hpp index 23bcbb7..185bcdc 100644 --- a/include/Theme.hpp +++ b/include/Theme.hpp @@ -8,6 +8,7 @@ #include namespace gsr { + struct Config; struct GsrInfo; struct Theme { @@ -26,6 +27,7 @@ namespace gsr { mgl::Texture combobox_arrow_texture; mgl::Texture settings_texture; + mgl::Texture settings_small_texture; mgl::Texture folder_texture; mgl::Texture up_arrow_texture; mgl::Texture replay_button_texture; @@ -56,7 +58,7 @@ namespace gsr { mgl::Color text_color = mgl::Color(255, 255, 255); }; - bool init_color_theme(const GsrInfo &gsr_info); + bool init_color_theme(const Config &config, const GsrInfo &gsr_info); void deinit_color_theme(); ColorTheme& get_color_theme(); } \ No newline at end of file diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp index bc1dd94..eb68e99 100644 --- a/include/gui/Button.hpp +++ b/include/gui/Button.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace gsr { class Button : public Widget { @@ -20,15 +21,21 @@ namespace gsr { mgl::vec2f get_size() override; void set_border_scale(float scale); + void set_bg_hover_color(mgl::Color color); + void set_icon(mgl::Texture *texture); const std::string& get_text() const; void set_text(std::string str); std::function on_click; + private: + void scale_sprite_to_button_size(); private: mgl::vec2f size; mgl::Color bg_color; + mgl::Color bg_hover_color; mgl::Text text; + mgl::Sprite sprite; float border_scale = 0.0015f; }; } \ No newline at end of file diff --git a/include/gui/GlobalSettingsPage.hpp b/include/gui/GlobalSettingsPage.hpp new file mode 100644 index 0000000..cd4a50c --- /dev/null +++ b/include/gui/GlobalSettingsPage.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "StaticPage.hpp" +#include "../GsrInfo.hpp" +#include "../Config.hpp" + +namespace gsr { + class GsrPage; + class PageStack; + class ScrollablePage; + class Subsection; + class RadioButton; + + class GlobalSettingsPage : public StaticPage { + public: + GlobalSettingsPage(const GsrInfo *gsr_info, Config &config, PageStack *page_stack); + GlobalSettingsPage(const GlobalSettingsPage&) = delete; + GlobalSettingsPage& operator=(const GlobalSettingsPage&) = delete; + + void load(); + void save(); + void on_navigate_away_from_page() override; + private: + std::unique_ptr create_appearance_subsection(ScrollablePage *parent_page); + void add_widgets(); + private: + Config &config; + const GsrInfo *gsr_info = nullptr; + + GsrPage *content_page_ptr = nullptr; + PageStack *page_stack = nullptr; + RadioButton *tint_color_radio_button_ptr = nullptr; + }; +} \ No newline at end of file diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp index b115d78..981c99a 100644 --- a/include/gui/SettingsPage.hpp +++ b/include/gui/SettingsPage.hpp @@ -181,7 +181,5 @@ namespace gsr { RadioButton *turn_on_replay_automatically_mode_ptr = nullptr; PageStack *page_stack = nullptr; - - mgl::Text settings_title_text; }; } \ No newline at end of file diff --git a/include/gui/Utils.hpp b/include/gui/Utils.hpp index 6963bc5..35b2bb7 100644 --- a/include/gui/Utils.hpp +++ b/include/gui/Utils.hpp @@ -15,4 +15,5 @@ namespace gsr { void draw_rectangle_outline(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, mgl::Color color, float border_size); double get_frame_delta_seconds(); void set_frame_delta_seconds(double frame_delta); + mgl::vec2f scale_keep_aspect_ratio(mgl::vec2f from, mgl::vec2f to); } \ No newline at end of file diff --git a/meson.build b/meson.build index 324295a..3b21a93 100644 --- a/meson.build +++ b/meson.build @@ -27,6 +27,7 @@ src = [ 'src/gui/CustomRendererWidget.cpp', 'src/gui/FileChooser.cpp', 'src/gui/SettingsPage.cpp', + 'src/gui/GlobalSettingsPage.cpp', 'src/gui/GsrPage.cpp', 'src/gui/Subsection.cpp', 'src/Utils.cpp', diff --git a/src/Config.cpp b/src/Config.cpp index 2263df7..4deaaf4 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -49,6 +49,7 @@ namespace gsr { return { {"main.config_file_version", &config.main_config.config_file_version}, {"main.software_encoding_warning_shown", &config.main_config.software_encoding_warning_shown}, + {"main.tint_color", &config.main_config.tint_color}, {"streaming.record_options.record_area_option", &config.streaming_config.record_options.record_area_option}, {"streaming.record_options.record_area_width", &config.streaming_config.record_options.record_area_width}, diff --git a/src/Overlay.cpp b/src/Overlay.cpp index 555c1d4..e10b1e4 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -7,8 +7,10 @@ #include "../include/gui/DropdownButton.hpp" #include "../include/gui/CustomRendererWidget.hpp" #include "../include/gui/SettingsPage.hpp" +#include "../include/gui/GlobalSettingsPage.hpp" #include "../include/gui/Utils.hpp" #include "../include/gui/PageStack.hpp" +#include "../include/gui/GsrPage.hpp" #include "../include/WindowUtils.hpp" #include "../include/GlobalHotkeys.hpp" @@ -420,7 +422,7 @@ namespace gsr { if(new_config) config = std::move(new_config.value()); - init_color_theme(this->gsr_info); + init_color_theme(config, this->gsr_info); power_supply_online_filepath = get_power_supply_online_filepath(); @@ -863,6 +865,7 @@ namespace gsr { const int button_width = button_height; auto main_buttons_list = std::make_unique(List::Orientation::HORIZONTAL); + List * main_buttons_list_ptr = main_buttons_list.get(); main_buttons_list->set_spacing(0.0f); { auto button = std::make_unique(&get_theme().title_font, &get_theme().body_font, "Instant Replay", "Off", &get_theme().replay_button_texture, @@ -928,6 +931,20 @@ namespace gsr { main_buttons_list->set_position((mgl::vec2f(window_size.x * 0.5f, window_size.y * 0.25f) - main_buttons_list_size * 0.5f).floor()); front_page_ptr->add_widget(std::move(main_buttons_list)); + { + const mgl::vec2f main_buttons_size = main_buttons_list_ptr->get_size(); + const int settings_button_size = main_buttons_size.y * 0.2f; + auto button = std::make_unique