diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-11-05 00:17:03 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-11-05 00:17:03 +0100 |
commit | 07a64ffd954b4273bd6afc7fa03b284c3dced640 (patch) | |
tree | 5689dc492cec6d009de3b858fd9dfeb326b0c062 | |
parent | 610fca510d4cafd4ed5851109bca6fe17154c578 (diff) |
Add replay ram usage estimation
-rw-r--r-- | include/gui/Entry.hpp | 2 | ||||
-rw-r--r-- | include/gui/Label.hpp | 2 | ||||
-rw-r--r-- | include/gui/SettingsPage.hpp | 4 | ||||
-rw-r--r-- | src/gui/Entry.cpp | 2 | ||||
-rw-r--r-- | src/gui/Label.cpp | 4 | ||||
-rw-r--r-- | src/gui/SettingsPage.cpp | 40 |
6 files changed, 49 insertions, 5 deletions
diff --git a/include/gui/Entry.hpp b/include/gui/Entry.hpp index b8ff37a..449a87c 100644 --- a/include/gui/Entry.hpp +++ b/include/gui/Entry.hpp @@ -26,6 +26,8 @@ namespace gsr { // 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. EntryValidateHandler validate_handler; + + std::function<void(const std::string &text)> on_changed; private: mgl::Text text; float max_width; diff --git a/include/gui/Label.hpp b/include/gui/Label.hpp index 3cb91de..a702497 100644 --- a/include/gui/Label.hpp +++ b/include/gui/Label.hpp @@ -17,6 +17,8 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; mgl::vec2f get_size() override; + + void set_text(std::string str); private: mgl::Text text; }; diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp index a0bc518..467463f 100644 --- a/include/gui/SettingsPage.hpp +++ b/include/gui/SettingsPage.hpp @@ -14,6 +14,7 @@ namespace gsr { class GsrPage; class PageStack; class ScrollablePage; + class Label; class SettingsPage : public StaticPage { public: @@ -83,6 +84,8 @@ namespace gsr { std::unique_ptr<List> create_replay_time(); std::unique_ptr<CheckBox> create_start_replay_on_startup(); std::unique_ptr<CheckBox> create_save_replay_in_game_folder(); + std::unique_ptr<Label> create_estimated_file_size(); + void update_estimated_file_size(); std::unique_ptr<CheckBox> create_save_recording_in_game_folder(); void add_replay_widgets(); void add_record_widgets(); @@ -147,6 +150,7 @@ namespace gsr { List *container_list_ptr = nullptr; CheckBox *start_replay_automatically_ptr = nullptr; CheckBox *save_replay_in_game_folder_ptr = nullptr; + Label *estimated_file_size_ptr = nullptr; CheckBox *show_replay_started_notification_checkbox_ptr = nullptr; CheckBox *show_replay_stopped_notification_checkbox_ptr = nullptr; CheckBox *show_replay_saved_notification_checkbox_ptr = nullptr; diff --git a/src/gui/Entry.cpp b/src/gui/Entry.cpp index 4f318ec..9a3fccf 100644 --- a/src/gui/Entry.cpp +++ b/src/gui/Entry.cpp @@ -89,6 +89,8 @@ namespace gsr { if(!validate_handler || validate_handler(str)) { text.set_string(std::move(str)); caret_offset_x = text.find_character_pos(99999).x - this->text.get_position().x; + if(on_changed) + on_changed(text.get_string()); } } diff --git a/src/gui/Label.cpp b/src/gui/Label.cpp index 09fd1a6..22a302f 100644 --- a/src/gui/Label.cpp +++ b/src/gui/Label.cpp @@ -18,6 +18,10 @@ namespace gsr { window.draw(text); } + void Label::set_text(std::string str) { + text.set_string(std::move(str)); + } + mgl::vec2f Label::get_size() { if(!visible) return {0.0f, 0.0f}; diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index eb9523d..94c33fd 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -449,8 +449,11 @@ namespace gsr { (void)text; const bool custom_selected = id == "custom"; video_bitrate_list_ptr->set_visible(custom_selected); + + if(estimated_file_size_ptr) + estimated_file_size_ptr->set_visible(custom_selected); }; - video_quality_box_ptr->on_selection_changed("Very high", "very_high"); + video_quality_box_ptr->on_selection_changed("", video_quality_box_ptr->get_selected_id()); if(!gsr_info.supported_capture_options.monitors.empty()) record_area_box_ptr->set_selected_item(gsr_info.supported_capture_options.monitors.front().name); @@ -545,11 +548,30 @@ namespace gsr { return checkbox; } + std::unique_ptr<Label> SettingsPage::create_estimated_file_size() { + auto label = std::make_unique<Label>(&get_theme().body_font, "Estimated video max file size in RAM: 5.23MB", get_color_theme().text_color); + estimated_file_size_ptr = label.get(); + return label; + } + + void SettingsPage::update_estimated_file_size() { + const int64_t replay_time_seconds = atoi(replay_time_entry_ptr->get_text().c_str()); + const int64_t video_bitrate_bps = atoi(video_bitrate_entry_ptr->get_text().c_str()) * 1000LL; + const double video_filesize_mb = ((double)replay_time_seconds * (double)video_bitrate_bps) / 1024.0 / 1024.0 / 3.3333; // Why 3.3333? + + char buffer[512]; + snprintf(buffer, sizeof(buffer), "Estimated video max file size in RAM: %.2fMB", video_filesize_mb); + estimated_file_size_ptr->set_text(buffer); + } + void SettingsPage::add_replay_widgets() { - auto file_info_list = std::make_unique<List>(List::Orientation::HORIZONTAL); - file_info_list->add_widget(create_save_directory("Directory to save replays:")); - file_info_list->add_widget(create_container_section()); - file_info_list->add_widget(create_replay_time()); + auto file_info_list = std::make_unique<List>(List::Orientation::VERTICAL); + auto file_info_data_list = std::make_unique<List>(List::Orientation::HORIZONTAL); + file_info_data_list->add_widget(create_save_directory("Directory to save replays:")); + file_info_data_list->add_widget(create_container_section()); + file_info_data_list->add_widget(create_replay_time()); + file_info_list->add_widget(std::move(file_info_data_list)); + file_info_list->add_widget(create_estimated_file_size()); settings_list_ptr->add_widget(std::make_unique<Subsection>("File info", std::move(file_info_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f))); auto general_list = std::make_unique<List>(List::Orientation::VERTICAL); @@ -589,6 +611,14 @@ namespace gsr { settings_scrollable_page_ptr->reset_scroll(); }; view_radio_button_ptr->on_selection_changed("Simple", "simple"); + + replay_time_entry_ptr->on_changed = [this](const std::string&) { + update_estimated_file_size(); + }; + + video_bitrate_entry_ptr->on_changed = [this](const std::string&) { + update_estimated_file_size(); + }; } std::unique_ptr<CheckBox> SettingsPage::create_save_recording_in_game_folder() { |