mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Add menu to select language
This commit is contained in:
@@ -178,6 +178,7 @@ namespace gsr {
|
||||
{"main.joystick_hotkeys_enable_option", &config.main_config.joystick_hotkeys_enable_option},
|
||||
{"main.tint_color", &config.main_config.tint_color},
|
||||
{"main.notification_speed", &config.main_config.notification_speed},
|
||||
{"main.language", &config.main_config.language},
|
||||
{"main.show_hide_hotkey", &config.main_config.show_hide_hotkey},
|
||||
|
||||
{"streaming.record_options.record_area_option", &config.streaming_config.record_options.record_area_option},
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "../include/CursorTracker/CursorTrackerWayland.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -853,6 +852,12 @@ namespace gsr {
|
||||
bool Overlay::draw() {
|
||||
remove_widgets_to_be_removed();
|
||||
|
||||
if(reload_ui) {
|
||||
reload_ui = false;
|
||||
if(visible)
|
||||
recreate_frontpage_ui_components();
|
||||
}
|
||||
|
||||
update_notification_process_status();
|
||||
process_gsr_output();
|
||||
update_gsr_process_status();
|
||||
@@ -1142,7 +1147,7 @@ namespace gsr {
|
||||
update_compositor_texture(*focused_monitor);
|
||||
|
||||
visible = true;
|
||||
create_frontpage_ui_components();
|
||||
recreate_frontpage_ui_components();
|
||||
|
||||
// The focused application can be an xwayland application but the cursor can hover over a wayland application.
|
||||
// This is even the case when hovering over the titlebar of the xwayland application.
|
||||
@@ -1211,7 +1216,7 @@ namespace gsr {
|
||||
}
|
||||
}
|
||||
|
||||
void Overlay::create_frontpage_ui_components() {
|
||||
void Overlay::recreate_frontpage_ui_components() {
|
||||
bg_screenshot_overlay = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height));
|
||||
top_bar_background = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height*0.06f).floor());
|
||||
top_bar_text = mgl::Text("GPU Screen Recorder", get_theme().top_bar_font);
|
||||
@@ -1351,6 +1356,7 @@ namespace gsr {
|
||||
button->set_bg_hover_color(mgl::Color(0, 0, 0, 255));
|
||||
button->set_icon(&get_theme().settings_small_texture);
|
||||
button->on_click = [&]() {
|
||||
std::string language_before = config.main_config.language;
|
||||
auto settings_page = std::make_unique<GlobalSettingsPage>(this, &gsr_info, config, &page_stack);
|
||||
|
||||
settings_page->on_startup_changed = [&](bool enable, int exit_status) {
|
||||
@@ -1385,7 +1391,7 @@ namespace gsr {
|
||||
global_hotkeys_js.reset();
|
||||
};
|
||||
|
||||
settings_page->on_page_closed = [this]() {
|
||||
settings_page->on_page_closed = [this, language_before]() {
|
||||
replay_dropdown_button_ptr->set_item_description("start", config.replay_config.start_stop_hotkey.to_string(false, false));
|
||||
replay_dropdown_button_ptr->set_item_description("save", config.replay_config.save_hotkey.to_string(false, false));
|
||||
replay_dropdown_button_ptr->set_item_description("save_1_min", config.replay_config.save_1_min_hotkey.to_string(false, false));
|
||||
@@ -1395,6 +1401,9 @@ namespace gsr {
|
||||
record_dropdown_button_ptr->set_item_description("pause", config.record_config.pause_unpause_hotkey.to_string(false, false));
|
||||
|
||||
stream_dropdown_button_ptr->set_item_description("start", config.streaming_config.start_stop_hotkey.to_string(false, false));
|
||||
|
||||
if(config.main_config.language != language_before)
|
||||
reload_ui = true;
|
||||
};
|
||||
|
||||
page_stack.push(std::move(settings_page));
|
||||
|
||||
@@ -68,6 +68,9 @@ namespace gsr {
|
||||
bool Translation::load_language(const char* lang) {
|
||||
translations.clear();
|
||||
|
||||
if(lang[0] == '\0')
|
||||
lang = "en";
|
||||
|
||||
if (!is_language_supported(lang)) {
|
||||
fprintf(stderr, "Warning: language '%s' is not supported\n", lang);
|
||||
return false;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "../../include/gui/Label.hpp"
|
||||
#include "../../include/gui/Image.hpp"
|
||||
#include "../../include/gui/RadioButton.hpp"
|
||||
#include "../../include/gui/ComboBox.hpp"
|
||||
#include "../../include/gui/LineSeparator.hpp"
|
||||
#include "../../include/gui/CustomRendererWidget.hpp"
|
||||
|
||||
@@ -519,12 +520,37 @@ namespace gsr {
|
||||
return list;
|
||||
}
|
||||
|
||||
std::unique_ptr<List> GlobalSettingsPage::create_language() {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
list->add_widget(std::make_unique<Label>(&get_theme().body_font, TR("Language"), get_color_theme().text_color));
|
||||
|
||||
auto combo_box = std::make_unique<ComboBox>(&get_theme().body_font);
|
||||
language_combo_box_ptr = combo_box.get();
|
||||
combo_box->add_item(TR("System language"), "");
|
||||
combo_box->add_item("English", "en");
|
||||
combo_box->add_item("Русский", "ru");
|
||||
combo_box->add_item("українська", "uk");
|
||||
combo_box->on_selection_changed = [](const std::string&, const std::string &id) {
|
||||
Translation::instance().load_language(id.c_str());
|
||||
return true;
|
||||
};
|
||||
list->add_widget(std::move(combo_box));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
std::unique_ptr<Subsection> GlobalSettingsPage::create_application_options_subsection(ScrollablePage *parent_page) {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
List *list_ptr = list.get();
|
||||
auto subsection = std::make_unique<Subsection>(TR("Application options"), std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||
|
||||
list_ptr->add_widget(create_notification_speed());
|
||||
{
|
||||
auto horizontal_list = std::make_unique<List>(List::Orientation::HORIZONTAL);
|
||||
horizontal_list->set_spacing(0.02f);
|
||||
horizontal_list->add_widget(create_notification_speed());
|
||||
horizontal_list->add_widget(create_language());
|
||||
list_ptr->add_widget(std::move(horizontal_list));
|
||||
}
|
||||
list_ptr->add_widget(std::make_unique<LineSeparator>(LineSeparator::Orientation::HORIZONTAL, subsection->get_inner_size().x));
|
||||
|
||||
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
|
||||
@@ -614,6 +640,7 @@ namespace gsr {
|
||||
enable_joystick_hotkeys_radio_button_ptr->set_selected_item(config.main_config.joystick_hotkeys_enable_option, false, false);
|
||||
|
||||
notification_speed_button_ptr->set_selected_item(config.main_config.notification_speed);
|
||||
language_combo_box_ptr->set_selected_item(config.main_config.language);
|
||||
|
||||
load_hotkeys();
|
||||
}
|
||||
@@ -644,6 +671,7 @@ namespace gsr {
|
||||
config.main_config.hotkeys_enable_option = enable_keyboard_hotkeys_radio_button_ptr->get_selected_id();
|
||||
config.main_config.joystick_hotkeys_enable_option = enable_joystick_hotkeys_radio_button_ptr->get_selected_id();
|
||||
config.main_config.notification_speed = notification_speed_button_ptr->get_selected_id();
|
||||
config.main_config.language = language_combo_box_ptr->get_selected_id();
|
||||
save_config(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,8 @@ int main(int argc, char **argv) {
|
||||
#endif
|
||||
}
|
||||
|
||||
gsr::Translation::instance().init((resources_path + "translations/").c_str(), nullptr);
|
||||
std::optional<gsr::Config> config = read_config(gsr::SupportedCaptureOptions{});
|
||||
gsr::Translation::instance().init((resources_path + "translations/").c_str(), config.has_value() ? config.value().main_config.language.c_str() : nullptr);
|
||||
|
||||
if(geteuid() == 0) {
|
||||
fprintf(stderr, "Error: don't run gsr-ui as the root user\n");
|
||||
|
||||
Reference in New Issue
Block a user