Extract canvas clear command planning
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "app_core/canvas_tool_ui.h"
|
||||
#include "app_core/document_animation.h"
|
||||
#include "app_core/document_canvas.h"
|
||||
#include "app_core/document_export.h"
|
||||
#include "app_core/document_cloud.h"
|
||||
#include "app_core/document_layer.h"
|
||||
@@ -226,6 +227,14 @@ struct PlanDocumentResizeArgs {
|
||||
int selected_resolution_index = 0;
|
||||
};
|
||||
|
||||
struct PlanCanvasClearArgs {
|
||||
bool has_canvas = true;
|
||||
float r = 0.0F;
|
||||
float g = 0.0F;
|
||||
float b = 0.0F;
|
||||
float a = 0.0F;
|
||||
};
|
||||
|
||||
struct PlanLayerRenameArgs {
|
||||
std::string old_name = "Layer 1";
|
||||
std::string new_name;
|
||||
@@ -1005,6 +1014,7 @@ void print_help()
|
||||
<< " plan-recording-session [--running] [--frame-count N] [--platform-deletes-recorded-files]\n"
|
||||
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
||||
<< " plan-app-status [--doc-name NAME] [--unsaved] [--resolution N] [--resolution-index N] [--zoom N] [--history-bytes N] [--recording-running] [--encoder-available] [--encoded-frames N]\n"
|
||||
<< " plan-canvas-clear [--no-canvas] [--r N] [--g N] [--b N] [--a N]\n"
|
||||
<< " plan-document-resize [--current-resolution N] [--selected-resolution-index N]\n"
|
||||
<< " plan-layer-rename --old-name NAME --new-name NAME\n"
|
||||
<< " plan-layer-operation --kind add|duplicate|select|reorder|remove|opacity|visibility|alpha-lock|blend-mode|highlight [--layer-count N] [--index N] [--from-index N] [--to-index N] [--source-index N] [--name NAME] [--opacity N] [--blend-mode N] [--enabled]\n"
|
||||
@@ -2609,6 +2619,79 @@ int plan_document_resize(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_canvas_clear_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanCanvasClearArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--r" || key == "--g" || key == "--b" || key == "--a") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = parse_float_arg(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
if (key == "--r") {
|
||||
args.r = value.value();
|
||||
} else if (key == "--g") {
|
||||
args.g = value.value();
|
||||
} else if (key == "--b") {
|
||||
args.b = value.value();
|
||||
} else {
|
||||
args.a = value.value();
|
||||
}
|
||||
} else if (key == "--no-canvas") {
|
||||
args.has_canvas = false;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_canvas_clear(int argc, char** argv)
|
||||
{
|
||||
PlanCanvasClearArgs args;
|
||||
const auto status = parse_plan_canvas_clear_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-canvas-clear", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto plan = pp::app::plan_document_canvas_clear(
|
||||
args.has_canvas,
|
||||
args.r,
|
||||
args.g,
|
||||
args.b,
|
||||
args.a);
|
||||
if (!plan) {
|
||||
print_error("plan-canvas-clear", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = plan.value();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-canvas-clear\""
|
||||
<< ",\"state\":{\"hasCanvas\":" << json_bool(args.has_canvas)
|
||||
<< ",\"r\":" << args.r
|
||||
<< ",\"g\":" << args.g
|
||||
<< ",\"b\":" << args.b
|
||||
<< ",\"a\":" << args.a
|
||||
<< "},\"plan\":{\"r\":" << value.r
|
||||
<< ",\"g\":" << value.g
|
||||
<< ",\"b\":" << value.b
|
||||
<< ",\"a\":" << value.a
|
||||
<< ",\"clearsCanvas\":" << json_bool(value.clears_canvas)
|
||||
<< ",\"recordsUndo\":" << json_bool(value.records_undo)
|
||||
<< ",\"marksUnsaved\":" << json_bool(value.marks_unsaved)
|
||||
<< ",\"noOp\":" << json_bool(value.no_op)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_layer_rename_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -5999,6 +6082,10 @@ int main(int argc, char** argv)
|
||||
return plan_document_resize(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-canvas-clear") {
|
||||
return plan_canvas_clear(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-layer-rename") {
|
||||
return plan_layer_rename(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user