From ce78dd5b363ec1feb2e937601daf09977bf44648 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 12 Sep 2024 00:51:20 +0200 Subject: Add dropdown icons and description text --- images/play.png | Bin 0 -> 872 bytes images/stop.png | Bin 0 -> 333 bytes include/Theme.hpp | 2 ++ include/gui/DropdownButton.hpp | 5 ++++- src/Overlay.cpp | 14 ++++++++---- src/Theme.cpp | 6 ++++++ src/gui/DropdownButton.cpp | 48 +++++++++++++++++++++++++++++++++-------- 7 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 images/play.png create mode 100644 images/stop.png diff --git a/images/play.png b/images/play.png new file mode 100644 index 0000000..9ea65b0 Binary files /dev/null and b/images/play.png differ diff --git a/images/stop.png b/images/stop.png new file mode 100644 index 0000000..45a1844 Binary files /dev/null and b/images/stop.png differ diff --git a/include/Theme.hpp b/include/Theme.hpp index 1db389a..79ad358 100644 --- a/include/Theme.hpp +++ b/include/Theme.hpp @@ -39,6 +39,8 @@ namespace gsr { mgl::Texture logo_texture; mgl::Texture checkbox_circle_texture; mgl::Texture checkbox_background_texture; + mgl::Texture play_texture; + mgl::Texture stop_texture; double double_click_timeout_seconds = 0.4; diff --git a/include/gui/DropdownButton.hpp b/include/gui/DropdownButton.hpp index 306a327..40d2810 100644 --- a/include/gui/DropdownButton.hpp +++ b/include/gui/DropdownButton.hpp @@ -17,8 +17,9 @@ namespace gsr { bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; - void add_item(const std::string &text, const std::string &id); + void add_item(const std::string &text, const std::string &id, const std::string &description = ""); void set_item_label(const std::string &id, const std::string &new_label); + void set_item_icon(const std::string &id, mgl::Texture *texture); void set_activated(bool activated); @@ -30,6 +31,8 @@ namespace gsr { private: struct Item { mgl::Text text; + mgl::Text description_text; + mgl::Texture *icon_texture = nullptr; std::string id; }; diff --git a/src/Overlay.cpp b/src/Overlay.cpp index 5bc534f..58c7552 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -304,8 +304,9 @@ namespace gsr { auto button = std::make_unique(&get_theme().title_font, &get_theme().body_font, "Instant Replay", "On", "Off", &get_theme().replay_button_texture, mgl::vec2f(button_width, button_height)); replay_dropdown_button_ptr = button.get(); - button->add_item("Start", "start"); + button->add_item("Turn on", "start", "Alt+Shift+F10"); button->add_item("Settings", "settings"); + button->set_item_icon("start", &get_theme().play_texture); button->on_click = std::bind(&Overlay::on_press_start_replay, this, std::placeholders::_1); main_buttons_list->add_widget(std::move(button)); } @@ -313,8 +314,10 @@ namespace gsr { auto button = std::make_unique(&get_theme().title_font, &get_theme().body_font, "Record", "Recording", "Not recording", &get_theme().record_button_texture, mgl::vec2f(button_width, button_height)); record_dropdown_button_ptr = button.get(); - button->add_item("Start", "start"); + button->add_item("Start", "start", "Alt+F9"); + button->add_item("Pause", "pause", "Alt+F7"); button->add_item("Settings", "settings"); + button->set_item_icon("start", &get_theme().play_texture); button->on_click = std::bind(&Overlay::on_press_start_record, this, std::placeholders::_1); main_buttons_list->add_widget(std::move(button)); } @@ -322,8 +325,9 @@ namespace gsr { auto button = std::make_unique(&get_theme().title_font, &get_theme().body_font, "Livestream", "Streaming", "Not streaming", &get_theme().stream_button_texture, mgl::vec2f(button_width, button_height)); stream_dropdown_button_ptr = button.get(); - button->add_item("Start", "start"); + button->add_item("Start", "start", "Alt+F8"); button->add_item("Settings", "settings"); + button->set_item_icon("start", &get_theme().play_texture); button->on_click = std::bind(&Overlay::on_press_start_replay, this, std::placeholders::_1); main_buttons_list->add_widget(std::move(button)); } @@ -509,6 +513,7 @@ namespace gsr { gpu_screen_recorder_process = -1; record_dropdown_button_ptr->set_item_label(id, "Start"); record_dropdown_button_ptr->set_activated(false); + record_dropdown_button_ptr->set_item_icon("start", &get_theme().play_texture); // TODO: Show this with a slight delay to make sure it doesn't show up in the video if(config->record_config.show_video_saved_notifications) { @@ -565,8 +570,9 @@ namespace gsr { if(gpu_screen_recorder_process == -1) { // TODO: Show notification failed to start } else { - record_dropdown_button_ptr->set_item_label(id, "Stop"); + record_dropdown_button_ptr->set_item_label(id, "Stop and save"); record_dropdown_button_ptr->set_activated(true); + record_dropdown_button_ptr->set_item_icon("start", &get_theme().stop_texture); } // TODO: Start recording after this notification has disappeared to make sure it doesn't show up in the video. diff --git a/src/Theme.cpp b/src/Theme.cpp index e08cfb8..037f159 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -88,6 +88,12 @@ namespace gsr { if(!theme->checkbox_background_texture.load_from_file((resources_path + "images/checkbox_background.png").c_str())) goto error; + if(!theme->play_texture.load_from_file((resources_path + "images/play.png").c_str())) + goto error; + + if(!theme->stop_texture.load_from_file((resources_path + "images/stop.png").c_str())) + goto error; + return true; error: diff --git a/src/gui/DropdownButton.cpp b/src/gui/DropdownButton.cpp index 50a3105..b9b962f 100644 --- a/src/gui/DropdownButton.cpp +++ b/src/gui/DropdownButton.cpp @@ -12,6 +12,7 @@ namespace gsr { static const float padding_bottom_scale = 0.00694f; static const float padding_left_scale = 0.009259f; static const float padding_right_scale = 0.009259f; + static const float icon_spacing_scale = 0.008f; static const float border_scale = 0.003f; DropdownButton::DropdownButton(mgl::Font *title_font, mgl::Font *description_font, const char *title, const char *description_activated, const char *description_deactivated, mgl::Texture *icon_texture, mgl::vec2f size) : @@ -69,6 +70,8 @@ namespace gsr { const int padding_top = padding_top_scale * get_theme().window_height; const int padding_bottom = padding_bottom_scale * get_theme().window_height; const int padding_left = padding_left_scale * get_theme().window_height; + const int padding_right = padding_right_scale * get_theme().window_height; + const int icon_spacing = icon_spacing_scale * get_theme().window_height; const int border_size = border_scale * get_theme().window_height; if(show_dropdown) { @@ -137,9 +140,16 @@ namespace gsr { auto &item = items[i]; const auto text_bounds = item.text.get_bounds(); const float item_height = padding_top + text_bounds.size.y + padding_bottom; + const mgl::vec2f item_size(max_size.x, item_height); + + if(i > 0) { + const float separator_height = std::max(1.0f, item_size.y * 0.05f); + mgl::Rectangle separator((item_position - mgl::vec2f(0.0f, separator_height * 0.5f)).floor(), mgl::vec2f(item_size.x, separator_height).floor()); + separator.set_color(get_theme().page_bg_color); + window.draw(separator); + } if(mouse_inside_item == -1) { - const mgl::vec2f item_size(max_size.x, item_height); const bool inside = mgl::FloatRect(item_position, item_size).contains({ (float)mouse_pos.x, (float)mouse_pos.y }); if(inside) { draw_rectangle_outline(window, item_position, item_size, get_theme().tint_color, border_size); @@ -147,15 +157,30 @@ namespace gsr { } } - item.text.set_position((item_position + mgl::vec2f(padding_left, item_height * 0.5f - text_bounds.size.y * 0.5f)).floor()); + float icon_offset = 0.0f; + if(item.icon_texture) { + mgl::Sprite icon(item.icon_texture); + icon.set_height((int)(item_size.y * 0.4f)); + icon.set_position((item_position + mgl::vec2f(padding_left, item_size.y * 0.5f - icon.get_size().y * 0.5f)).floor()); + window.draw(icon); + icon_offset = icon.get_size().x + icon_spacing; + } + + item.text.set_position((item_position + mgl::vec2f(padding_left + icon_offset, item_size.y * 0.5f - text_bounds.size.y * 0.5f)).floor()); window.draw(item.text); - item_position.y += item_height; + + const auto description_bounds = item.description_text.get_bounds(); + item.description_text.set_position((item_position + mgl::vec2f(item_size.x - description_bounds.size.x - padding_right, item_size.y * 0.5f - description_bounds.size.y * 0.5f)).floor()); + item.description_text.set_color(mgl::Color(255, 255, 255, 120)); + window.draw(item.description_text); + + item_position.y += item_size.y; } } } - void DropdownButton::add_item(const std::string &text, const std::string &id) { - items.push_back({mgl::Text(text, *title_font), id}); + void DropdownButton::add_item(const std::string &text, const std::string &id, const std::string &description) { + items.push_back({mgl::Text(text, *title_font), mgl::Text(description, *description_font), nullptr, id}); dirty = true; } @@ -163,7 +188,15 @@ namespace gsr { for(auto &item : items) { if(item.id == id) { item.text.set_string(new_label); - dirty = true; + return; + } + } + } + + void DropdownButton::set_item_icon(const std::string &id, mgl::Texture *texture) { + for(auto &item : items) { + if(item.id == id) { + item.icon_texture = texture; return; } } @@ -192,13 +225,10 @@ namespace gsr { const int padding_top = padding_top_scale * get_theme().window_height; const int padding_bottom = padding_bottom_scale * get_theme().window_height; - const int padding_left = padding_left_scale * get_theme().window_height; - const int padding_right = padding_right_scale * get_theme().window_height; max_size = { size.x, 0.0f }; for(Item &item : items) { const mgl::vec2f bounds = item.text.get_bounds().size; - max_size.x = std::max(max_size.x, bounds.x + padding_left + padding_right); max_size.y += bounds.y + padding_top + padding_bottom; } dirty = false; -- cgit v1.2.3