Error message when trying to save a screenshot in an unsupported format
(cherry-picked from commit 93f956ed4c
)
This commit is contained in:
parent
066894c188
commit
e20e840700
5 changed files with 27 additions and 14 deletions
|
@ -190,7 +190,7 @@ void editor_controller::do_screenshot(const std::string& screenshot_filename /*
|
|||
{
|
||||
try {
|
||||
surface screenshot = gui().screenshot(true);
|
||||
if(screenshot.null() || !image::save_image(screenshot, screenshot_filename)) {
|
||||
if(screenshot.null() || image::save_image(screenshot, screenshot_filename) != image::save_result::success) {
|
||||
ERR_ED << "Screenshot creation failed!\n";
|
||||
}
|
||||
} catch (wml_exception& e) {
|
||||
|
|
|
@ -601,7 +601,7 @@ bool game_launcher::play_render_image_mode()
|
|||
outfile = *cmdline_opts_.render_image_dst;
|
||||
}
|
||||
|
||||
if (!image::save_image(*cmdline_opts_.render_image, outfile)) {
|
||||
if (image::save_image(*cmdline_opts_.render_image, outfile) != image::save_result::success) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "gettext.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -124,11 +125,16 @@ void screenshot_notification::save_screenshot()
|
|||
boost::filesystem::path path(screenshots_dir_path_);
|
||||
path /= filename;
|
||||
|
||||
const bool res = image::save_image(screenshot_, path.string());
|
||||
if(!res) {
|
||||
image::save_result res = image::save_image(screenshot_, path.string());
|
||||
if(res == image::save_result::unsupported_format) {
|
||||
gui2::show_error_message(_("Unsupported image format.\n\n"
|
||||
"Try to save the screenshot as PNG instead."));
|
||||
} else if(res == image::save_result::save_failed) {
|
||||
gui2::show_error_message(
|
||||
translation::dsgettext("wesnoth", "Screenshot creation failed.\n\n"
|
||||
"Make sure there is enough space on the drive holding Wesnoth’s player resource files and that file permissions are set up correctly."));
|
||||
"Make sure there is enough space on the drive holding Wesnoth’s player resource files and that file permissions are set up correctly."));
|
||||
} else if(res != image::save_result::success) {
|
||||
throw std::logic_error("Unexpected error while trying to save a screenshot");
|
||||
} else {
|
||||
path_box.set_active(false);
|
||||
find_widget<button>(&window, "open", false).set_active(true);
|
||||
|
|
|
@ -1285,15 +1285,15 @@ bool precached_file_exists(const std::string& file)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool save_image(const locator& i_locator, const std::string& filename)
|
||||
save_result save_image(const locator& i_locator, const std::string& filename)
|
||||
{
|
||||
return save_image(get_image(i_locator), filename);
|
||||
}
|
||||
|
||||
bool save_image(const surface& surf, const std::string& filename)
|
||||
save_result save_image(const surface& surf, const std::string& filename)
|
||||
{
|
||||
if(surf.null()) {
|
||||
return false;
|
||||
return save_result::no_image;
|
||||
}
|
||||
|
||||
#ifdef SDL_IMAGE_VERSION_ATLEAST
|
||||
|
@ -1302,7 +1302,7 @@ bool save_image(const surface& surf, const std::string& filename)
|
|||
LOG_DP << "Writing a JPG image to " << filename << std::endl;
|
||||
|
||||
const int err = IMG_SaveJPG_RW(surf, filesystem::make_write_RWops(filename).release(), true, 75); // SDL takes ownership of the RWops
|
||||
return err == 0;
|
||||
return err == 0 ? save_result::success : save_result::save_failed;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1311,11 +1311,16 @@ bool save_image(const surface& surf, const std::string& filename)
|
|||
LOG_DP << "Writing a PNG image to " << filename << std::endl;
|
||||
|
||||
const int err = IMG_SavePNG_RW(surf, filesystem::make_write_RWops(filename).release(), true); // SDL takes ownership of the RWops
|
||||
return err == 0;
|
||||
return err == 0 ? save_result::success : save_result::save_failed;
|
||||
}
|
||||
|
||||
LOG_DP << "Writing a BMP image to " << filename << std::endl;
|
||||
return SDL_SaveBMP(surf, filename.c_str()) == 0;
|
||||
if(filesystem::ends_with(filename, ".bmp")) {
|
||||
LOG_DP << "Writing a BMP image to " << filename << std::endl;
|
||||
const int err = SDL_SaveBMP(surf, filename.c_str()) == 0;
|
||||
return err == 0 ? save_result::success : save_result::save_failed;
|
||||
}
|
||||
|
||||
return save_result::unsupported_format;
|
||||
}
|
||||
|
||||
bool update_from_preferences()
|
||||
|
|
|
@ -222,6 +222,8 @@ namespace image {
|
|||
/// initialize any private data, e.g. algorithm choices from preferences
|
||||
bool update_from_preferences();
|
||||
|
||||
bool save_image(const locator& i_locator, const std::string& outfile);
|
||||
bool save_image(const surface& surf, const std::string& outfile);
|
||||
enum class save_result {success, unsupported_format, save_failed, no_image};
|
||||
|
||||
save_result save_image(const locator& i_locator, const std::string& outfile);
|
||||
save_result save_image(const surface& surf, const std::string& outfile);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue