Centralize legacy video export bridge

This commit is contained in:
2026-06-04 14:11:24 +02:00
parent 78003923ca
commit ca5b94b044
8 changed files with 259 additions and 16 deletions

View File

@@ -61,6 +61,11 @@ enum class DocumentExportCollectionKind {
animation_frames,
};
enum class DocumentVideoExportKind {
animation_mp4,
timelapse,
};
struct DocumentExportMenuPlan {
DocumentExportMenuKind kind = DocumentExportMenuKind::jpeg;
DocumentExportMenuAction action = DocumentExportMenuAction::show_jpeg_dialog;
@@ -96,6 +101,16 @@ public:
virtual void export_cube_faces(std::string_view document_name) = 0;
};
class DocumentVideoExportServices {
public:
virtual ~DocumentVideoExportServices() = default;
virtual void export_animation_mp4(std::string_view path) = 0;
virtual void export_timelapse_mp4(std::string_view path) = 0;
virtual void show_animation_export_success(std::string_view path) = 0;
virtual void show_timelapse_export_success(std::string_view path) = 0;
};
[[nodiscard]] constexpr DocumentExportStartDecision plan_document_export_start(
bool requires_license,
bool license_valid,
@@ -342,6 +357,29 @@ public:
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_document_video_export(
DocumentVideoExportKind kind,
std::string_view path,
DocumentVideoExportServices& services)
{
if (path.empty()) {
return pp::foundation::Status::invalid_argument("video export path must not be empty");
}
switch (kind) {
case DocumentVideoExportKind::animation_mp4:
services.export_animation_mp4(path);
services.show_animation_export_success(path);
return pp::foundation::Status::success();
case DocumentVideoExportKind::timelapse:
services.export_timelapse_mp4(path);
services.show_timelapse_export_success(path);
return pp::foundation::Status::success();
}
return pp::foundation::Status::invalid_argument("unknown document video export kind");
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_menu_plan(
const DocumentExportMenuPlan& plan,
DocumentExportMenuServices& services)

View File

@@ -566,19 +566,28 @@ void App::dialog_timelapse_export()
pick_file_save("mp4", target.value().name,
[this](std::string path) {
rec_export(path);
const auto status = pp::panopainter::execute_legacy_document_video_export(
*this,
pp::app::DocumentVideoExportKind::timelapse,
path,
false);
if (!status.ok())
LOG("Document timelapse export failed: %s", status.message);
},
[this](const std::string& path, bool saved) {
message_box("Export Timelapse", "Timelapse exported successfully.");
[](const std::string& path, bool saved) {
(void)path;
(void)saved;
}
);
#else
pick_file_save({ "mp4" }, [this](std::string path) {
std::thread([this, path] {
BT_SetTerminate();
rec_export(path);
message_box("Export Timelapse", "Timelapse exported to: " + path);
}).detach();
const auto status = pp::panopainter::execute_legacy_document_video_export(
*this,
pp::app::DocumentVideoExportKind::timelapse,
path,
true);
if (!status.ok())
LOG("Document timelapse export failed: %s", status.message);
});
#endif
}
@@ -597,17 +606,28 @@ void App::dialog_export_mp4()
pick_file_save("mp4", target.value().name,
[this](std::string path) {
export_anim_mp4(path);
const auto status = pp::panopainter::execute_legacy_document_video_export(
*this,
pp::app::DocumentVideoExportKind::animation_mp4,
path,
false);
if (!status.ok())
LOG("Document animation export failed: %s", status.message);
},
[this](const std::string& path, bool saved) {
message_box("Export Animation", "Animation exported successfully.");
[](const std::string& path, bool saved) {
(void)path;
(void)saved;
}
);
#else
pick_file_save({ "mp4" }, [this](std::string path) {
Canvas::I->export_anim_mp4(path, [this, path] {
message_box("Export Animation", "Animation exported to: " + path);
});
const auto status = pp::panopainter::execute_legacy_document_video_export(
*this,
pp::app::DocumentVideoExportKind::animation_mp4,
path,
true);
if (!status.ok())
LOG("Document animation export failed: %s", status.message);
});
#endif
}

View File

@@ -4,6 +4,9 @@
#include "app.h"
#include <string>
#include <thread>
namespace pp::panopainter {
namespace {
@@ -105,6 +108,65 @@ private:
App& app_;
};
class LegacyDocumentVideoExportServices final : public pp::app::DocumentVideoExportServices {
public:
LegacyDocumentVideoExportServices(App& app, bool asynchronous) noexcept
: app_(app)
, asynchronous_(asynchronous)
{
}
void export_animation_mp4(std::string_view path) override
{
auto* app = &app_;
auto path_string = std::string(path);
if (asynchronous_) {
Canvas::I->export_anim_mp4(path_string, [app, path_string] {
app->message_box("Export Animation", "Animation exported to: " + path_string);
});
return;
}
Canvas::I->export_anim_mp4(path_string, [app] {
app->message_box("Export Animation", "Animation exported successfully.");
});
}
void export_timelapse_mp4(std::string_view path) override
{
auto* app = &app_;
auto path_string = std::string(path);
if (asynchronous_) {
std::thread([app, path_string] {
BT_SetTerminate();
app->rec_export(path_string);
app->message_box("Export Timelapse", "Timelapse exported to: " + path_string);
}).detach();
return;
}
app->rec_export(path_string);
}
void show_animation_export_success(std::string_view path) override
{
(void)path;
}
void show_timelapse_export_success(std::string_view path) override
{
if (asynchronous_) {
(void)path;
} else {
app_.message_box("Export Timelapse", "Timelapse exported successfully.");
}
}
private:
App& app_;
bool asynchronous_ = false;
};
} // namespace
pp::foundation::Status execute_legacy_document_export_file(
@@ -149,4 +211,14 @@ pp::foundation::Status execute_legacy_document_export_cube_faces(
return pp::app::execute_document_export_cube_faces(document_name, services);
}
pp::foundation::Status execute_legacy_document_video_export(
App& app,
pp::app::DocumentVideoExportKind kind,
std::string_view path,
bool asynchronous)
{
LegacyDocumentVideoExportServices services(app, asynchronous);
return pp::app::execute_document_video_export(kind, path, services);
}
} // namespace pp::panopainter

View File

@@ -29,4 +29,10 @@ namespace pp::panopainter {
App& app,
std::string_view document_name);
[[nodiscard]] pp::foundation::Status execute_legacy_document_video_export(
App& app,
pp::app::DocumentVideoExportKind kind,
std::string_view path,
bool asynchronous);
} // namespace pp::panopainter