Extract app frame and export dialog helpers
This commit is contained in:
@@ -16,13 +16,6 @@
|
||||
#include "node_dialog_browse.h"
|
||||
#include "node_dialog_resize.h"
|
||||
#include "node_dialog_cloud.h"
|
||||
#include "node_dialog_export_ppbr.h"
|
||||
|
||||
#include <codec_api.h>
|
||||
#define MP4V2_NO_STDINT_DEFS
|
||||
#include <mp4v2/mp4v2.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#ifdef __QUEST__
|
||||
#include "oculus_vr.h"
|
||||
@@ -34,95 +27,18 @@ void open_changelog_dialog(App& app);
|
||||
void open_about_dialog(App& app);
|
||||
void open_whatsnew_dialog(App& app, bool force_show);
|
||||
void open_shortcuts_dialog(App& app);
|
||||
void open_document_export_dialog(App& app, std::string ext);
|
||||
void open_document_export_layers_dialog(App& app);
|
||||
void open_document_export_anim_frames_dialog(App& app);
|
||||
void open_document_export_depth_dialog(App& app);
|
||||
void open_document_export_cube_faces_dialog(App& app);
|
||||
void open_document_timelapse_export_dialog(App& app);
|
||||
void open_document_export_mp4_dialog(App& app);
|
||||
void open_ppbr_export_dialog(App& app);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] bool can_start_document_export(App& app, bool requires_license)
|
||||
{
|
||||
const auto decision = pp::app::plan_document_export_start(
|
||||
requires_license,
|
||||
!requires_license || app.check_license(),
|
||||
app.canvas != nullptr);
|
||||
|
||||
switch (decision) {
|
||||
case pp::app::DocumentExportStartDecision::start_now:
|
||||
return true;
|
||||
case pp::app::DocumentExportStartDecision::show_license_disabled:
|
||||
{
|
||||
const auto plan = pp::app::plan_document_export_license_disabled_dialog();
|
||||
app.message_box(plan.title, plan.message, plan.show_cancel);
|
||||
return false;
|
||||
}
|
||||
case pp::app::DocumentExportStartDecision::unavailable_no_canvas:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void start_document_export_collection(
|
||||
App& app,
|
||||
pp::app::DocumentExportCollectionKind kind)
|
||||
{
|
||||
const auto plan = pp::app::plan_document_export_collection_target(
|
||||
kind,
|
||||
app.uses_work_directory_document_export_collections());
|
||||
const auto success_kind = pp::app::document_export_collection_success_kind(kind);
|
||||
|
||||
if (plan.destination == pp::app::DocumentExportCollectionDestination::work_directory_collection) {
|
||||
const auto target = pp::app::make_document_export_collection_target(
|
||||
app.work_path,
|
||||
app.doc_name,
|
||||
plan.suffix);
|
||||
if (!target) {
|
||||
const auto dialog = pp::app::plan_document_export_failure_dialog(success_kind, target.status().message);
|
||||
app.message_box(dialog.title, dialog.message, dialog.show_cancel);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto status = pp::panopainter::execute_legacy_document_export_collection(
|
||||
app,
|
||||
plan.kind,
|
||||
target.value());
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(
|
||||
kind == pp::app::DocumentExportCollectionKind::layers
|
||||
? pp::app::DocumentExportExecutionKind::layers_collection
|
||||
: pp::app::DocumentExportExecutionKind::animation_frames_collection),
|
||||
status.message);
|
||||
return;
|
||||
}
|
||||
|
||||
app.pick_dir([
|
||||
&app,
|
||||
kind = plan.kind,
|
||||
success_kind
|
||||
](std::string path) {
|
||||
const auto target = pp::app::make_document_export_stem_target(path, app.doc_name);
|
||||
if (!target) {
|
||||
const auto dialog = pp::app::plan_document_export_failure_dialog(success_kind, target.status().message);
|
||||
app.message_box(dialog.title, dialog.message, dialog.show_cancel);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto status = pp::panopainter::execute_legacy_document_export_stem(
|
||||
app,
|
||||
kind,
|
||||
target.value());
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(
|
||||
kind == pp::app::DocumentExportCollectionKind::layers
|
||||
? pp::app::DocumentExportExecutionKind::layers_stem
|
||||
: pp::app::DocumentExportExecutionKind::animation_frames_stem),
|
||||
status.message);
|
||||
});
|
||||
}
|
||||
|
||||
void wire_document_browse_dialog_actions(
|
||||
App& app,
|
||||
const std::shared_ptr<NodeDialogBrowse>& dialog,
|
||||
@@ -453,59 +369,22 @@ void App::dialog_save()
|
||||
|
||||
void App::dialog_export(std::string ext)
|
||||
{
|
||||
if (!can_start_document_export(*this, true))
|
||||
return;
|
||||
|
||||
// TODO: use picker
|
||||
const auto target = pp::app::make_document_export_file_target(work_path, doc_name, ext);
|
||||
if (!target) {
|
||||
const auto dialog = pp::app::plan_document_export_failure_dialog(
|
||||
pp::app::DocumentExportSuccessKind::equirectangular,
|
||||
target.status().message);
|
||||
message_box(dialog.title, dialog.message, dialog.show_cancel);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto status = pp::panopainter::execute_legacy_document_export_file(*this, target.value());
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(
|
||||
pp::app::DocumentExportExecutionKind::equirectangular_file),
|
||||
status.message);
|
||||
pp::panopainter::open_document_export_dialog(*this, ext);
|
||||
}
|
||||
|
||||
void App::dialog_export_layers()
|
||||
{
|
||||
if (!can_start_document_export(*this, true))
|
||||
return;
|
||||
|
||||
start_document_export_collection(
|
||||
*this,
|
||||
pp::app::DocumentExportCollectionKind::layers);
|
||||
pp::panopainter::open_document_export_layers_dialog(*this);
|
||||
}
|
||||
|
||||
void App::dialog_export_anim_frames()
|
||||
{
|
||||
if (!can_start_document_export(*this, true))
|
||||
return;
|
||||
|
||||
start_document_export_collection(
|
||||
*this,
|
||||
pp::app::DocumentExportCollectionKind::animation_frames);
|
||||
pp::panopainter::open_document_export_anim_frames_dialog(*this);
|
||||
}
|
||||
|
||||
void App::dialog_export_depth()
|
||||
{
|
||||
if (!can_start_document_export(*this, true))
|
||||
return;
|
||||
|
||||
const auto status = pp::panopainter::execute_legacy_document_export_depth(*this, doc_name);
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(pp::app::DocumentExportExecutionKind::depth),
|
||||
status.message);
|
||||
pp::panopainter::open_document_export_depth_dialog(*this);
|
||||
}
|
||||
|
||||
void App::dialog_resize()
|
||||
@@ -551,15 +430,7 @@ void App::dialog_resize()
|
||||
|
||||
void App::dialog_export_cube_faces()
|
||||
{
|
||||
if (!can_start_document_export(*this, false))
|
||||
return;
|
||||
|
||||
const auto status = pp::panopainter::execute_legacy_document_export_cube_faces(*this, doc_name);
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(pp::app::DocumentExportExecutionKind::cube_faces),
|
||||
status.message);
|
||||
pp::panopainter::open_document_export_cube_faces_dialog(*this);
|
||||
}
|
||||
|
||||
void App::dialog_layer_rename()
|
||||
@@ -613,169 +484,17 @@ void App::dialog_preset_download()
|
||||
|
||||
void App::dialog_ppbr_export()
|
||||
{
|
||||
auto* overlay_anchor = layout[main_id];
|
||||
if (!overlay_anchor) {
|
||||
LOG("PPBR export dialog open failed: main layout anchor is missing");
|
||||
return;
|
||||
}
|
||||
|
||||
auto dialog = pp::panopainter::make_legacy_overlay_node<NodeDialogExportPPBR>(*this);
|
||||
|
||||
const auto overlay = pp::panopainter::open_legacy_overlay_node_with_handle(*overlay_anchor, dialog);
|
||||
if (!overlay) {
|
||||
LOG("PPBR export dialog open failed: %s", overlay.status().message);
|
||||
return;
|
||||
}
|
||||
const auto overlay_handle = overlay.value();
|
||||
|
||||
const auto close_dialog = [overlay_anchor, overlay_handle]() {
|
||||
const auto close_status = pp::panopainter::close_legacy_overlay_node(*overlay_anchor, overlay_handle);
|
||||
(void)close_status;
|
||||
};
|
||||
|
||||
dialog->btn_ok->on_click = [this, dialog] (Node*) {
|
||||
const auto request = pp::panopainter::make_legacy_brush_package_export_request(*dialog);
|
||||
|
||||
if (uses_prepared_file_writes())
|
||||
{
|
||||
pick_file_save("ppbr", "exported-brushes",
|
||||
[this, dialog, request] (std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_export(
|
||||
*this,
|
||||
*dialog,
|
||||
request,
|
||||
path,
|
||||
pp::panopainter::LegacyBrushPackageExportMode::inline_export_only);
|
||||
if (!status.ok())
|
||||
LOG("PPBR export failed: %s", status.message);
|
||||
},
|
||||
[dialog] (const std::string& path, bool saved) {
|
||||
(void)path;
|
||||
pp::panopainter::complete_legacy_brush_package_export(*dialog, saved);
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
pick_file_save({ "ppbr" }, [this, dialog, request] (std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_export(
|
||||
*this,
|
||||
*dialog,
|
||||
request,
|
||||
path,
|
||||
pp::panopainter::LegacyBrushPackageExportMode::desktop_async_close_and_message);
|
||||
if (!status.ok())
|
||||
LOG("PPBR export failed: %s", status.message);
|
||||
});
|
||||
};
|
||||
dialog->btn_cancel->on_click = [close_dialog](Node*)
|
||||
{
|
||||
close_dialog();
|
||||
};
|
||||
pp::panopainter::open_ppbr_export_dialog(*this);
|
||||
}
|
||||
|
||||
void App::dialog_timelapse_export()
|
||||
{
|
||||
if (!can_start_document_export(*this, false))
|
||||
return;
|
||||
|
||||
if (uses_prepared_file_writes())
|
||||
{
|
||||
const auto target = pp::app::make_document_export_suggested_name(doc_name, "-timelapse");
|
||||
if (!target) {
|
||||
const auto dialog = pp::app::plan_document_export_failure_dialog(
|
||||
pp::app::DocumentExportSuccessKind::timelapse,
|
||||
target.status().message);
|
||||
message_box(dialog.title, dialog.message, dialog.show_cancel);
|
||||
return;
|
||||
}
|
||||
|
||||
pick_file_save("mp4", target.value().name,
|
||||
[this](std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_document_video_export(
|
||||
*this,
|
||||
pp::app::DocumentVideoExportKind::timelapse,
|
||||
path,
|
||||
false);
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(
|
||||
pp::app::DocumentExportExecutionKind::timelapse),
|
||||
status.message);
|
||||
},
|
||||
[](const std::string& path, bool saved) {
|
||||
(void)path;
|
||||
(void)saved;
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
pick_file_save({ "mp4" }, [this](std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_document_video_export(
|
||||
*this,
|
||||
pp::app::DocumentVideoExportKind::timelapse,
|
||||
path,
|
||||
true);
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(pp::app::DocumentExportExecutionKind::timelapse),
|
||||
status.message);
|
||||
});
|
||||
pp::panopainter::open_document_timelapse_export_dialog(*this);
|
||||
}
|
||||
|
||||
void App::dialog_export_mp4()
|
||||
{
|
||||
if (!can_start_document_export(*this, false))
|
||||
return;
|
||||
|
||||
if (uses_prepared_file_writes())
|
||||
{
|
||||
const auto target = pp::app::make_document_export_suggested_name(doc_name, "-animation");
|
||||
if (!target) {
|
||||
const auto dialog = pp::app::plan_document_export_failure_dialog(
|
||||
pp::app::DocumentExportSuccessKind::animation_mp4,
|
||||
target.status().message);
|
||||
message_box(dialog.title, dialog.message, dialog.show_cancel);
|
||||
return;
|
||||
}
|
||||
|
||||
pick_file_save("mp4", target.value().name,
|
||||
[this](std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_document_video_export(
|
||||
*this,
|
||||
pp::app::DocumentVideoExportKind::animation_mp4,
|
||||
path,
|
||||
false);
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(
|
||||
pp::app::DocumentExportExecutionKind::animation_mp4),
|
||||
status.message);
|
||||
},
|
||||
[](const std::string& path, bool saved) {
|
||||
(void)path;
|
||||
(void)saved;
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
pick_file_save({ "mp4" }, [this](std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_document_video_export(
|
||||
*this,
|
||||
pp::app::DocumentVideoExportKind::animation_mp4,
|
||||
path,
|
||||
true);
|
||||
if (!status.ok())
|
||||
LOG(
|
||||
"%s: %s",
|
||||
pp::app::document_export_execution_log_message(pp::app::DocumentExportExecutionKind::animation_mp4),
|
||||
status.message);
|
||||
});
|
||||
pp::panopainter::open_document_export_mp4_dialog(*this);
|
||||
}
|
||||
|
||||
void App::dialog_whatsnew(bool force_show)
|
||||
|
||||
Reference in New Issue
Block a user