diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 302 |
1 files changed, 158 insertions, 144 deletions
diff --git a/src/main.cpp b/src/main.cpp index 79132ed..9b9d41c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "../include/gui/Button.hpp" #include "../include/gui/ComboBox.hpp" #include "../include/gui/Label.hpp" +#include "../include/gui/List.hpp" #include "../include/Process.hpp" #include "../include/Theme.hpp" #include "../include/GsrInfo.hpp" @@ -181,6 +182,162 @@ static std::string color_to_hex_str(mgl::Color color) { return result; } +static void add_widgets_to_settings_page(mgl::Font &title_font, mgl::vec2i window_size, mgl::vec2f settings_page_position, mgl::vec2f settings_page_size, gsr::Page *settings_page, gsr::Page *settings_content_page, const gsr::GsrInfo &gsr_info, const std::vector<gsr::AudioDevice> &audio_devices, std::function<void()> settings_back_button_callback) { +auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f(window_size.x / 10, window_size.y / 15), gsr::get_theme().scrollable_page_bg_color); + back_button->set_position(settings_page_position + mgl::vec2f(settings_page_size.x + window_size.x / 50, 0.0f).floor()); + back_button->on_click = settings_back_button_callback; + settings_page->add_widget(std::move(back_button)); + + auto settings_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + settings_list->set_position(mgl::vec2f(50.0f, 50.0f)); + { + auto record_area_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + record_area_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Record area:", gsr::get_theme().text_color)); + auto record_area_box = std::make_unique<gsr::ComboBox>(&title_font); + // TODO: Show options not supported but disable them + if(gsr_info.supported_capture_options.window) + record_area_box->add_item("Window", "window"); + if(gsr_info.supported_capture_options.focused) + record_area_box->add_item("Focused window", "focused"); + if(gsr_info.supported_capture_options.screen) + record_area_box->add_item("All monitors", "screen"); + for(const auto &monitor : gsr_info.supported_capture_options.monitors) { + char name[256]; + snprintf(name, sizeof(name), "%s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y); + record_area_box->add_item(name, monitor.name); + } + if(gsr_info.supported_capture_options.portal) + record_area_box->add_item("Desktop portal", "portal"); + record_area_list->add_widget(std::move(record_area_box)); + } + settings_list->add_widget(std::move(record_area_list)); + + auto audio_devices_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + audio_devices_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Audio:", gsr::get_theme().text_color)); + auto audio_device_box = std::make_unique<gsr::ComboBox>(&title_font); + for(const auto &audio_device : audio_devices) { + audio_device_box->add_item(audio_device.description, audio_device.name); + } + audio_devices_list->add_widget(std::move(audio_device_box)); + } + settings_list->add_widget(std::move(audio_devices_list)); + + auto quality_list = std::make_unique<gsr::List>(gsr::List::Orientation::HORIZONTAL); + { + auto video_quality_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + video_quality_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Video quality:", gsr::get_theme().text_color)); + auto video_quality_box = std::make_unique<gsr::ComboBox>(&title_font); + video_quality_box->add_item("Medium", "medium"); + video_quality_box->add_item("High (Recommended for live streaming)", "high"); + video_quality_box->add_item("Very High (Recommended)", "very_high"); + video_quality_box->add_item("Ultra", "ultra"); + video_quality_list->add_widget(std::move(video_quality_box)); + } + quality_list->add_widget(std::move(video_quality_list)); + + auto color_range_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + color_range_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Color range:", gsr::get_theme().text_color)); + auto color_range_box = std::make_unique<gsr::ComboBox>(&title_font); + color_range_box->add_item("Limited", "limited"); + color_range_box->add_item("Full", "full"); + color_range_list->add_widget(std::move(color_range_box)); + } + quality_list->add_widget(std::move(color_range_list)); + + auto framerate_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + framerate_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Frame rate:", gsr::get_theme().text_color)); + auto framerate_box = std::make_unique<gsr::ComboBox>(&title_font); + framerate_box->add_item("60", "60"); + framerate_box->add_item("30", "30"); + framerate_list->add_widget(std::move(framerate_box)); + } + quality_list->add_widget(std::move(framerate_list)); + } + settings_list->add_widget(std::move(quality_list)); + + auto codec_list = std::make_unique<gsr::List>(gsr::List::Orientation::HORIZONTAL); + { + auto video_codec_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + video_codec_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Video codec:", gsr::get_theme().text_color)); + auto video_codec_box = std::make_unique<gsr::ComboBox>(&title_font); + // TODO: Show options not supported but disable them + video_codec_box->add_item("Auto (Recommended)", "auto"); + if(gsr_info.supported_video_codecs.h264) + video_codec_box->add_item("H264", "h264"); + if(gsr_info.supported_video_codecs.hevc) + video_codec_box->add_item("HEVC", "hevc"); + if(gsr_info.supported_video_codecs.av1) + video_codec_box->add_item("AV1", "av1"); + if(gsr_info.supported_video_codecs.vp8) + video_codec_box->add_item("VP8", "vp8"); + if(gsr_info.supported_video_codecs.vp9) + video_codec_box->add_item("VP9", "vp9"); + // TODO: Add hdr options + video_codec_box->add_item("H264 Software Encoder (Slow, not recommended)", "h264_software"); + video_codec_list->add_widget(std::move(video_codec_box)); + } + codec_list->add_widget(std::move(video_codec_list)); + + auto audio_codec_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + audio_codec_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Audio codec:", gsr::get_theme().text_color)); + auto audio_codec_box = std::make_unique<gsr::ComboBox>(&title_font); + audio_codec_box->add_item("Opus (Recommended)", "opus"); + audio_codec_box->add_item("AAC", "aac"); + audio_codec_list->add_widget(std::move(audio_codec_box)); + } + codec_list->add_widget(std::move(audio_codec_list)); + } + settings_list->add_widget(std::move(codec_list)); + + auto framerate_mode_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + framerate_mode_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Frame rate mode:", gsr::get_theme().text_color)); + auto framerate_mode_box = std::make_unique<gsr::ComboBox>(&title_font); + framerate_mode_box->add_item("Auto (Recommended)", "auto"); + framerate_mode_box->add_item("Constant", "cfr"); + framerate_mode_box->add_item("Variable", "vfr"); + framerate_mode_list->add_widget(std::move(framerate_mode_box)); + } + settings_list->add_widget(std::move(framerate_mode_list)); + + auto file_list = std::make_unique<gsr::List>(gsr::List::Orientation::HORIZONTAL); + { + auto save_directory_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + save_directory_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Directory to save the video:", gsr::get_theme().text_color)); + auto directory_selection_box = std::make_unique<gsr::ComboBox>(&title_font); + // TODO: + directory_selection_box->add_item("/home/dec05eba/Videos", "mp4"); + save_directory_list->add_widget(std::move(directory_selection_box)); + } + file_list->add_widget(std::move(save_directory_list)); + + auto container_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL); + { + container_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Container:", gsr::get_theme().text_color)); + auto container_box = std::make_unique<gsr::ComboBox>(&title_font); + container_box->add_item("mp4", "mp4"); + container_box->add_item("mkv", "matroska"); + container_box->add_item("flv", "flv"); + container_box->add_item("mov", "mov"); + container_box->add_item("ts", "mpegts"); + container_box->add_item("m3u8", "hls"); + container_list->add_widget(std::move(container_box)); + } + file_list->add_widget(std::move(container_list)); + } + settings_list->add_widget(std::move(file_list)); + } + settings_content_page->add_widget(std::move(settings_list)); +} + int main(int argc, char **argv) { if(argc != 1) usage(); @@ -566,153 +723,10 @@ int main(int argc, char **argv) { current_page = &front_page; }; - const mgl::vec2f page_widget_spacing{window_size.x / 100.0f, window_size.y / 40.0f}; for(int i = 0; i < num_settings_pages; ++i) { - mgl::vec2f settings_page_widget_pos{50.0f, 50.0f}; gsr::Page *settings_page = settings_pages[i]; gsr::Page *settings_content_page = settings_content_pages[i]; - - auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f(window_size.x / 10, window_size.y / 15), gsr::get_theme().scrollable_page_bg_color); - back_button->set_position(settings_page_position + mgl::vec2f(settings_page_size.x + window_size.x / 50, 0.0f).floor()); - back_button->on_click = settings_back_button_callback; - settings_page->add_widget(std::move(back_button)); - - auto record_area_label = std::make_unique<gsr::Label>(&title_font, "Record area:", gsr::get_theme().text_color); - record_area_label->set_position(settings_page_widget_pos); - settings_page_widget_pos.y += record_area_label->get_size().y + page_widget_spacing.y / 3; - - auto record_area_box = std::make_unique<gsr::ComboBox>(&title_font); - record_area_box->set_position(settings_page_widget_pos); - // TODO: Show options not supported but disable them - if(gsr_info.supported_capture_options.window) - record_area_box->add_item("Window", "window"); - if(gsr_info.supported_capture_options.focused) - record_area_box->add_item("Focused window", "focused"); - if(gsr_info.supported_capture_options.screen) - record_area_box->add_item("All monitors", "screen"); - for(const auto &monitor : gsr_info.supported_capture_options.monitors) { - char name[256]; - snprintf(name, sizeof(name), "%s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y); - record_area_box->add_item(name, monitor.name); - } - if(gsr_info.supported_capture_options.portal) - record_area_box->add_item("Desktop portal", "portal"); - settings_page_widget_pos.y += record_area_box->get_size().y + page_widget_spacing.y; - - auto audio_device_box = std::make_unique<gsr::ComboBox>(&title_font); - audio_device_box->set_position(settings_page_widget_pos); - for(const auto &audio_device : audio_devices) { - audio_device_box->add_item(audio_device.description, audio_device.name); - } - settings_page_widget_pos.y += audio_device_box->get_size().y + page_widget_spacing.y; - - auto framerate_label = std::make_unique<gsr::Label>(&title_font, "Frame rate:", gsr::get_theme().text_color); - framerate_label->set_position(settings_page_widget_pos); - settings_page_widget_pos.y += framerate_label->get_size().y + page_widget_spacing.y / 3; - - auto framerate_box = std::make_unique<gsr::ComboBox>(&title_font); - framerate_box->set_position(settings_page_widget_pos); - framerate_box->add_item("60", "60"); - framerate_box->add_item("30", "30"); - settings_page_widget_pos.y += framerate_box->get_size().y + page_widget_spacing.y; - - auto video_quality_label = std::make_unique<gsr::Label>(&title_font, "Video quality:", gsr::get_theme().text_color); - video_quality_label->set_position(settings_page_widget_pos); - const auto video_quality_label_pos = video_quality_label->get_position(); - settings_page_widget_pos.y += video_quality_label->get_size().y + page_widget_spacing.y / 3; - - auto video_quality_box = std::make_unique<gsr::ComboBox>(&title_font); - video_quality_box->set_position(settings_page_widget_pos); - video_quality_box->add_item("Medium", "medium"); - video_quality_box->add_item("High (Recommended for live streaming)", "high"); - video_quality_box->add_item("Very High (Recommended)", "very_high"); - video_quality_box->add_item("Ultra", "ultra"); - const auto video_quality_box_pos = video_quality_box->get_position(); - const mgl::vec2f video_quality_box_size = video_quality_box->get_size(); - settings_page_widget_pos.y += video_quality_box_size.y + page_widget_spacing.y; - - auto color_range_label = std::make_unique<gsr::Label>(&title_font, "Color range:", gsr::get_theme().text_color); - color_range_label->set_position(video_quality_label_pos + mgl::vec2f(video_quality_box_size.x + page_widget_spacing.x, 0.0f).floor()); - - auto color_range_box = std::make_unique<gsr::ComboBox>(&title_font); - color_range_box->set_position(video_quality_box_pos + mgl::vec2f(video_quality_box_size.x + page_widget_spacing.x, 0.0f).floor()); - color_range_box->add_item("Limited", "limited"); - color_range_box->add_item("Full", "full"); - - auto video_codec_label = std::make_unique<gsr::Label>(&title_font, "Video codec:", gsr::get_theme().text_color); - video_codec_label->set_position(settings_page_widget_pos); - settings_page_widget_pos.y += video_codec_label->get_size().y + page_widget_spacing.y / 3; - - auto video_codec_box = std::make_unique<gsr::ComboBox>(&title_font); - video_codec_box->set_position(settings_page_widget_pos); - // TODO: Show options not supported but disable them - video_codec_box->add_item("Auto (Recommended)", "auto"); - if(gsr_info.supported_video_codecs.h264) - video_codec_box->add_item("H264", "h264"); - if(gsr_info.supported_video_codecs.hevc) - video_codec_box->add_item("HEVC", "hevc"); - if(gsr_info.supported_video_codecs.av1) - video_codec_box->add_item("AV1", "av1"); - if(gsr_info.supported_video_codecs.vp8) - video_codec_box->add_item("VP8", "vp8"); - if(gsr_info.supported_video_codecs.vp9) - video_codec_box->add_item("VP9", "vp9"); - // TODO: Add hdr options - video_codec_box->add_item("H264 Software Encoder (Slow, not recommended)", "h264_software"); - settings_page_widget_pos.y += video_codec_box->get_size().y + page_widget_spacing.y; - - auto audio_codec_label = std::make_unique<gsr::Label>(&title_font, "Audio codec:", gsr::get_theme().text_color); - audio_codec_label->set_position(settings_page_widget_pos); - settings_page_widget_pos.y += audio_codec_label->get_size().y + page_widget_spacing.y / 3; - - auto audio_codec_box = std::make_unique<gsr::ComboBox>(&title_font); - audio_codec_box->set_position(settings_page_widget_pos); - audio_codec_box->add_item("Opus (Recommended)", "opus"); - audio_codec_box->add_item("AAC", "aac"); - settings_page_widget_pos.y += audio_codec_box->get_size().y + page_widget_spacing.y; - - auto framerate_mode_label = std::make_unique<gsr::Label>(&title_font, "Frame rate mode:", gsr::get_theme().text_color); - framerate_mode_label->set_position(settings_page_widget_pos); - settings_page_widget_pos.y += framerate_mode_label->get_size().y + page_widget_spacing.y / 3; - - auto framerate_mode_box = std::make_unique<gsr::ComboBox>(&title_font); - framerate_mode_box->set_position(settings_page_widget_pos); - framerate_mode_box->add_item("Auto (Recommended)", "auto"); - framerate_mode_box->add_item("Constant", "cfr"); - framerate_mode_box->add_item("Variable", "vfr"); - settings_page_widget_pos.y += framerate_mode_box->get_size().y + page_widget_spacing.y; - - auto container_label = std::make_unique<gsr::Label>(&title_font, "Container:", gsr::get_theme().text_color); - container_label->set_position(settings_page_widget_pos); - settings_page_widget_pos.y += container_label->get_size().y + page_widget_spacing.y / 3; - - auto container_box = std::make_unique<gsr::ComboBox>(&title_font); - container_box->set_position(settings_page_widget_pos); - container_box->add_item("mp4", "mp4"); - container_box->add_item("mkv", "matroska"); - container_box->add_item("flv", "flv"); - container_box->add_item("mov", "mov"); - container_box->add_item("ts", "mpegts"); - container_box->add_item("m3u8", "hls"); - settings_page_widget_pos.y += container_box->get_size().y + page_widget_spacing.y; - - settings_content_page->add_widget(std::move(record_area_label)); - settings_content_page->add_widget(std::move(record_area_box)); - settings_content_page->add_widget(std::move(audio_device_box)); - settings_content_page->add_widget(std::move(framerate_label)); - settings_content_page->add_widget(std::move(framerate_box)); - settings_content_page->add_widget(std::move(video_quality_label)); - settings_content_page->add_widget(std::move(video_quality_box)); - settings_content_page->add_widget(std::move(color_range_label)); - settings_content_page->add_widget(std::move(color_range_box)); - settings_content_page->add_widget(std::move(video_codec_label)); - settings_content_page->add_widget(std::move(video_codec_box)); - settings_content_page->add_widget(std::move(audio_codec_label)); - settings_content_page->add_widget(std::move(audio_codec_box)); - settings_content_page->add_widget(std::move(framerate_mode_label)); - settings_content_page->add_widget(std::move(framerate_mode_box)); - settings_content_page->add_widget(std::move(container_label)); - settings_content_page->add_widget(std::move(container_box)); + add_widgets_to_settings_page(title_font, window_size, settings_page_position, settings_page_size, settings_page, settings_content_page, gsr_info, audio_devices, settings_back_button_callback); } mgl::Texture close_texture; |