Expose document edits through pano cli
This commit is contained in:
@@ -53,6 +53,11 @@ struct SimulateStrokeScriptArgs {
|
||||
std::string path;
|
||||
};
|
||||
|
||||
struct SimulateDocumentEditsArgs {
|
||||
std::uint32_t width = 128;
|
||||
std::uint32_t height = 64;
|
||||
};
|
||||
|
||||
struct SimulateDocumentHistoryArgs {
|
||||
std::uint32_t width = 64;
|
||||
std::uint32_t height = 32;
|
||||
@@ -122,6 +127,7 @@ void print_help()
|
||||
<< " load-project --path FILE\n"
|
||||
<< " parse-layout --path FILE\n"
|
||||
<< " record-render [--width N] [--height N]\n"
|
||||
<< " simulate-document-edits [--width N] [--height N]\n"
|
||||
<< " simulate-document-history [--width N] [--height N] [--history N]\n"
|
||||
<< " simulate-stroke --x1 N --y1 N --x2 N --y2 N [--spacing N]\n"
|
||||
<< " simulate-stroke-script --path FILE\n"
|
||||
@@ -638,6 +644,182 @@ int simulate_stroke_script(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_simulate_document_edits_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
SimulateDocumentEditsArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--width" || key == "--height") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
|
||||
const auto value = pp::foundation::parse_u32(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
|
||||
if (key == "--width") {
|
||||
args.width = value.value();
|
||||
} else {
|
||||
args.height = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
if (args.width == 0 || args.height == 0) {
|
||||
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int simulate_document_edits(int argc, char** argv)
|
||||
{
|
||||
SimulateDocumentEditsArgs args;
|
||||
const auto status = parse_simulate_document_edits_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("simulate-document-edits", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto document_result = pp::document::CanvasDocument::create(
|
||||
pp::document::DocumentConfig {
|
||||
.width = args.width,
|
||||
.height = args.height,
|
||||
.layer_count = 1,
|
||||
});
|
||||
if (!document_result) {
|
||||
print_error("simulate-document-edits", document_result.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
auto document = document_result.value();
|
||||
auto edit_status = document.set_frame_duration(0, 100);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto layer_result = document.add_layer("Paint");
|
||||
if (!layer_result) {
|
||||
print_error("simulate-document-edits", layer_result.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const std::size_t paint_layer = layer_result.value();
|
||||
edit_status = document.rename_layer(paint_layer, "Ink");
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.set_layer_visible(paint_layer, false);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.set_layer_alpha_locked(paint_layer, true);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.set_layer_opacity(paint_layer, 0.625F);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.set_layer_blend_mode(paint_layer, pp::paint::BlendMode::overlay);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.set_active_layer(paint_layer);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto duplicated_frame = document.duplicate_frame(0);
|
||||
if (!duplicated_frame) {
|
||||
print_error("simulate-document-edits", duplicated_frame.status().message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.set_frame_duration(duplicated_frame.value(), 333);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto added_frame = document.add_frame(250);
|
||||
if (!added_frame) {
|
||||
print_error("simulate-document-edits", added_frame.status().message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.move_frame(added_frame.value(), 0);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
edit_status = document.move_layer(paint_layer, 0);
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
edit_status = document.set_layer_frame_face_pixels(
|
||||
0,
|
||||
0,
|
||||
pp::document::LayerFacePixels {
|
||||
.face_index = 2,
|
||||
.x = 1,
|
||||
.y = 2,
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.rgba8 = { 255, 0, 0, 255 },
|
||||
});
|
||||
if (!edit_status.ok()) {
|
||||
print_error("simulate-document-edits", edit_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& active_layer = document.layers()[document.active_layer_index()];
|
||||
std::cout << "{\"ok\":true,\"command\":\"simulate-document-edits\""
|
||||
<< ",\"document\":{\"width\":" << document.width()
|
||||
<< ",\"height\":" << document.height()
|
||||
<< ",\"layers\":" << document.layers().size()
|
||||
<< ",\"frames\":" << document.frames().size()
|
||||
<< ",\"activeLayer\":" << document.active_layer_index()
|
||||
<< ",\"activeFrame\":" << document.active_frame_index()
|
||||
<< ",\"animationDurationMs\":" << document.animation_duration_ms()
|
||||
<< ",\"facePayloads\":" << document.face_pixel_payload_count()
|
||||
<< "},\"activeLayer\":{\"name\":\"" << json_escape(active_layer.name)
|
||||
<< "\",\"visible\":" << (active_layer.visible ? "true" : "false")
|
||||
<< ",\"alphaLocked\":" << (active_layer.alpha_locked ? "true" : "false")
|
||||
<< ",\"opacity\":" << active_layer.opacity
|
||||
<< ",\"blendMode\":\"" << pp::paint::blend_mode_name(active_layer.blend_mode)
|
||||
<< "\",\"frames\":" << active_layer.frames.size()
|
||||
<< "},\"frames\":[";
|
||||
for (std::size_t frame_index = 0; frame_index < document.frames().size(); ++frame_index) {
|
||||
if (frame_index != 0U) {
|
||||
std::cout << ",";
|
||||
}
|
||||
std::cout << document.frames()[frame_index].duration_ms;
|
||||
}
|
||||
std::cout << "],\"activeLayerFrameDurations\":[";
|
||||
for (std::size_t frame_index = 0; frame_index < active_layer.frames.size(); ++frame_index) {
|
||||
if (frame_index != 0U) {
|
||||
std::cout << ",";
|
||||
}
|
||||
std::cout << active_layer.frames[frame_index].duration_ms;
|
||||
}
|
||||
std::cout << "]}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_simulate_document_history_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -975,6 +1157,10 @@ int main(int argc, char** argv)
|
||||
return simulate_stroke_script(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "simulate-document-edits") {
|
||||
return simulate_document_edits(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "simulate-document-history") {
|
||||
return simulate_document_history(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user