Skip to content

Commit

Permalink
🤏 [Exporter] Add callback for image export success
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Nov 22, 2024
1 parent 5ce5478 commit 61f30cf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Cool/Exporter/Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ auto Exporter::clock() const -> Clock const&
return _video_export_process->clock(); // NOLINT(bugprone-unchecked-optional-access)
}

auto Exporter::export_image_immediately(Time time, Time delta_time, Polaroid const& polaroid) -> bool
auto Exporter::export_image_immediately(Time time, Time delta_time, Polaroid const& polaroid, std::function<void(std::filesystem::path const& exported_image_path)> const& on_image_exported) -> bool
{
return ExporterU::export_image(_gui.export_size(), time, delta_time, polaroid, _gui.image_export_path());
return ExporterU::export_image(_gui.export_size(), time, delta_time, polaroid, _gui.image_export_path(), on_image_exported);
}

} // namespace Cool
2 changes: 1 addition & 1 deletion src/Cool/Exporter/Exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Exporter {

void set_shared_aspect_ratio(SharedAspectRatio& shared_aspect_ratio) { _gui.set_shared_aspect_ratio(shared_aspect_ratio); }

[[nodiscard]] auto export_image_immediately(Time time, Time delta_time, Polaroid const& polaroid) -> bool;
[[nodiscard]] auto export_image_immediately(Time time, Time delta_time, Polaroid const& polaroid, std::function<void(std::filesystem::path const& exported_image_path)> const& on_image_exported) -> bool;

private:
ExporterGui _gui{};
Expand Down
6 changes: 4 additions & 2 deletions src/Cool/Exporter/ExporterGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ void ExporterGui::imgui_window_export_image(Polaroid polaroid, Time time, Time d
if (ImGui::Button(icon_fmt("Export", ICOMOON_UPLOAD2).c_str()))
{
_image_export_window.close();
if (ExporterU::export_image(_export_size, time, delta_time, polaroid, _image_file))
on_image_exported(_image_file);
ExporterU::export_image(_export_size, time, delta_time, polaroid, _image_file, on_image_exported);
}
});
}
Expand Down Expand Up @@ -124,7 +123,10 @@ void ExporterGui::begin_video_export(std::optional<VideoExportProcess>& video_ex
on_video_export_start();
}
else
{
Log::ToUser::warning("ExporterGui::begin_video_export", "Couldn't start exporting because folder creation failed!");
ExporterU::notification_after_export_failure();
}
}

void ExporterGui::update(Polaroid const& polaroid, std::optional<VideoExportProcess>& video_export_process)
Expand Down
7 changes: 6 additions & 1 deletion src/Cool/Exporter/ExporterU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@

namespace Cool::ExporterU {

auto export_image(img::Size size, Time time, Time delta_time, Polaroid const& polaroid, std::filesystem::path const& file_path) -> bool
auto export_image(img::Size size, Time time, Time delta_time, Polaroid const& polaroid, std::filesystem::path const& file_path, std::function<void(std::filesystem::path const& exported_image_path)> const& on_image_exported) -> bool
{
no_sleep::Scoped disable_sleep{COOL_APP_NAME, COOL_APP_NAME " is exporting an image", no_sleep::Mode::ScreenCanTurnOffButKeepComputing};
polaroid.render(size, time, delta_time);
bool const success = ImageU::save_png(file_path, polaroid.texture().download_pixels());
if (success)
{
on_image_exported(file_path);
notification_after_export_success(file_path, false);
}
else
{
notification_after_export_failure();
}
return success;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cool/Exporter/ExporterU.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Cool::ExporterU {

/// Exports an image as PNG
[[nodiscard]] auto export_image(img::Size size, Time time, Time delta_time, Polaroid const& polaroid, std::filesystem::path const& file_path) -> bool;
auto export_image(img::Size size, Time time, Time delta_time, Polaroid const& polaroid, std::filesystem::path const& file_path, std::function<void(std::filesystem::path const& exported_image_path)> const& on_image_exported) -> bool;

void notification_after_export_success(std::filesystem::path const& path, bool is_video);
void notification_after_export_failure();
Expand Down

0 comments on commit 61f30cf

Please sign in to comment.