diff --git a/resources/splashscreen/cars.jpg b/resources/splashscreen/cars.jpg new file mode 100644 index 000000000..c75912a2b Binary files /dev/null and b/resources/splashscreen/cars.jpg differ diff --git a/resources/ui_layout/colors.ini b/resources/ui_layout/colors.ini index ab889d5a3..e9d04d11e 100644 --- a/resources/ui_layout/colors.ini +++ b/resources/ui_layout/colors.ini @@ -21,4 +21,6 @@ Gui_color_very_dark = ada230 Gui_color_dark = cabe39 Gui_color = eddc21 Gui_color_light = ffee38 -Gui_color_very_light = fef48b \ No newline at end of file +Gui_color_very_light = fef48b +splash_screen_editor = cars.jpg +splash_screen_gcodeviewer = prusa-gcodepreview.jpg diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index 34cc0fd71..a0bd7f24a 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -58,6 +58,9 @@ int CLI::run(int argc, char **argv) // Mark the main thread for the debugger and for runtime checks. set_current_thread_name("slic3r_main"); + //init random generator + std::srand(std::time(nullptr)); + #ifdef __WXGTK__ // On Linux, wxGTK has no support for Wayland, and the app crashes on // startup if gtk3 is used. This env var has to be set explicitly to diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 28bf8bf27..8172f02e9 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -214,11 +214,38 @@ void AppConfig::set_defaults() if (get("show_splash_screen").empty()) set("show_splash_screen", "1"); - if (get("splash_screen_editor").empty()) - set("splash_screen_editor", "benchy-splashscreen.jpg"); + if (get("show_splash_screen_random").empty()) + set("show_splash_screen_random", "0"); - if (get("splash_screen_gcodeviewer").empty()) - set("splash_screen_gcodeviewer", "prusa-gcodepreview.jpg"); + { + + //try to load splashscreen from ui file + std::map key2splashscreen = {{"splash_screen_editor", "benchy-splashscreen.jpg"}, {"splash_screen_gcodeviewer", "prusa-gcodepreview.jpg"} }; + boost::property_tree::ptree tree_splashscreen; + boost::filesystem::path path_colors = boost::filesystem::path(resources_dir()) / "ui_layout" / "colors.ini"; + try { + boost::nowide::ifstream ifs; + ifs.imbue(boost::locale::generator()("en_US.UTF-8")); + ifs.open(path_colors.string()); + boost::property_tree::read_ini(ifs, tree_splashscreen); + + for (std::map::iterator it = key2splashscreen.begin(); it != key2splashscreen.end(); ++it) { + std::string splashscreen_filename = tree_splashscreen.get(it->first); + it->second = splashscreen_filename; + } + } + catch (const std::ifstream::failure& err) { + trace(1, (std::string("The splashscreen file cannot be loaded. Reason: ") + err.what(), path_colors.string()).c_str()); + } + catch (const std::runtime_error& err) { + trace(1, (std::string("Failed loading the splashscreen file. Reason: ") + err.what(), path_colors.string()).c_str()); + } + if (get("splash_screen_editor").empty()) + set("splash_screen_editor", key2splashscreen["splash_screen_editor"]); + + if (get("splash_screen_gcodeviewer").empty()) + set("splash_screen_gcodeviewer", key2splashscreen["splash_screen_gcodeviewer"]); + } #if ENABLE_CTRL_M_ON_WINDOWS #ifdef _WIN32 diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index cfb8b7d8e..4b11c2c1a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -827,9 +827,17 @@ bool GUI_App::on_init_inner() std::string file_name = is_editor() ? app_config->get("splash_screen_editor") : app_config->get("splash_screen_gcodeviewer"); + if (app_config->get("show_splash_screen_random") == "1") { + std::vector names; + //get all images in the spashscreen dir + for (const boost::filesystem::directory_entry& dir_entry : boost::filesystem::directory_iterator(boost::filesystem::path(Slic3r::resources_dir()) / "splashscreen")) + if (dir_entry.path().has_extension() && std::set{ ".jpg", ".JPG", ".jpeg" }.count(dir_entry.path().extension().string()) > 0) + names.push_back(dir_entry.path().filename().string()); + file_name = names[rand() % names.size()]; + } wxString artist; if (!file_name.empty() && file_name != (std::string(SLIC3R_APP_NAME) + L(" icon"))) { - wxString splash_screen_path = (boost::filesystem::path(Slic3r::resources_dir()) / "splashscreen" / file_name).string(); + wxString splash_screen_path = wxString::FromUTF8((boost::filesystem::path(Slic3r::resources_dir()) / "splashscreen" / file_name).string()); // make a bitmap with dark grey banner on the left side bmp = SplashScreen::MakeBitmap(wxBitmap(splash_screen_path, wxBITMAP_TYPE_JPEG)); @@ -842,7 +850,7 @@ bool GUI_App::on_init_inner() tag = exif_getTagInfo(ifdArray, IFD_0TH, TAG_Artist); if (tag) { if (!tag->error) { - artist = (_L("Artwork model by") + " " + ((char*)tag->byteData)); + artist = (_L("Artwork model by") + " " + wxString::FromUTF8((char*)tag->byteData)); } } } diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 93ae26001..1461a1bf8 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -238,6 +238,13 @@ void PreferencesDialog::build() def.set_default_value(new ConfigOptionBool{ app_config->get("show_splash_screen") == "1" }); option = Option(def, "show_splash_screen"); m_optgroup_general->append_single_option_line(option); + + def.label = L("Random splash screen"); + def.type = coBool; + def.tooltip = L("Show a random splash screen image from the list at each startup"); + def.set_default_value(new ConfigOptionBool{ app_config->get("show_splash_screen_random") == "1" }); + option = Option(def, "show_splash_screen_random"); + m_optgroup_general->append_single_option_line(option); // splashscreen image {